From c2bdcf4334a3150adb5e11ee7e0331e00c31ae89 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 9 Jan 2026 20:11:28 +0000 Subject: [PATCH 1/5] Initial plan From ccd6b48cb6bca2b87055d533fd285bd2c70b7e3c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 9 Jan 2026 20:15:25 +0000 Subject: [PATCH 2/5] Apply code quality improvements to transaction-explorer.tsx - Add memoization for wallet address Set to improve performance - Rename userWallet parameter to currentWallet for consistency - Simplify fee handling logic - Fix vin.value condition to properly handle zero values - Remove unnecessary blank lines Co-authored-by: jamespepper81 <84083764+jamespepper81@users.noreply.github.com> --- app/transaction-explorer.tsx | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/app/transaction-explorer.tsx b/app/transaction-explorer.tsx index b59f888..5d38cd4 100644 --- a/app/transaction-explorer.tsx +++ b/app/transaction-explorer.tsx @@ -50,6 +50,20 @@ interface TransactionExplorerData { }[]; } +// Memoize the Set of wallet addresses to avoid recreating it on every function call. +let lastAddressesRef: readonly string[] | undefined; +let lastAddressSet: Set | undefined; + +function getAddressSet(addresses: readonly string[] | undefined | null): Set { + const normalized = addresses ?? []; + if (normalized === lastAddressesRef && lastAddressSet) { + return lastAddressSet; + } + lastAddressesRef = normalized; + lastAddressSet = new Set(normalized); + return lastAddressSet; +} + const SATOSHIS_PER_BTC = 1e8; interface NormalizedVoutSource { @@ -184,8 +198,6 @@ export default function TransactionExplorerScreen() { } }; - - if (loading) { return ( @@ -678,7 +690,7 @@ const styles = StyleSheet.create({ const buildExplorerData = ( txDetails: Transaction, bitcoinPrice: { usd?: number } | null, - userWallet: Wallet | null, + currentWallet: Wallet | null, ): TransactionExplorerData => { const statusInfo = txDetails.status || {}; const vinList = Array.isArray(txDetails.inputs) ? txDetails.inputs : txDetails.vin || []; @@ -688,7 +700,7 @@ const buildExplorerData = ( // Some sources provide prevout directly, others provide value/address at the top level. const normalizeVin = vinList.map((vin: NormalizedVinSource) => ({ prevout: vin.prevout || { - value: vin.value ? Math.round(vin.value * SATOSHIS_PER_BTC) : 0, + value: typeof vin.value === 'number' ? Math.round(vin.value * SATOSHIS_PER_BTC) : 0, scriptpubkey_address: vin.address, }, })); @@ -699,10 +711,10 @@ const buildExplorerData = ( const inputValueSats = normalizeVin.reduce((sum, vin) => sum + (vin.prevout?.value ?? 0), 0); const outputValueSats = normalizeVout.reduce((sum, vout) => sum + (vout.value ?? 0), 0); - const feeSats = typeof txDetails.fee === 'number' ? txDetails.fee : (txDetails.fee ?? 0); + const feeSats = txDetails.fee ?? 0; const feeBtc = feeSats / SATOSHIS_PER_BTC; - const addressSet = new Set(userWallet?.addresses ?? []); + const addressSet = getAddressSet(currentWallet?.addresses); const fallbackNetAmountSats = (() => { if (typeof txDetails.amount === 'number') { return Math.round(txDetails.amount * SATOSHIS_PER_BTC); From d7afeb5771f7e36b65f6782de5e13bad91aaa3fd Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 9 Jan 2026 20:17:25 +0000 Subject: [PATCH 3/5] Add missing Wallet import to fix TypeScript error Co-authored-by: jamespepper81 <84083764+jamespepper81@users.noreply.github.com> --- app/transaction-explorer.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/transaction-explorer.tsx b/app/transaction-explorer.tsx index 5d38cd4..4f4a673 100644 --- a/app/transaction-explorer.tsx +++ b/app/transaction-explorer.tsx @@ -3,7 +3,7 @@ import { GradientBackground } from '@/components/GradientBackground'; import { platformStyles } from '@/constants/themes'; import { useWallet } from '@/hooks/wallet-store'; import { getTransactionDetails } from '@/services/esplora-service'; -import { Transaction } from '@/types/wallet'; +import { Transaction, Wallet } from '@/types/wallet'; import * as Clipboard from 'expo-clipboard'; import { router, Stack, useLocalSearchParams } from 'expo-router'; import { From a0dc44614a170d3bdbe5b1b0964e4ce11f719ccc Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 9 Jan 2026 20:18:47 +0000 Subject: [PATCH 4/5] Fix memoization reference check to work correctly The previous implementation compared a normalized array which would always create a new reference. Now comparing the original addresses reference for proper memoization. Co-authored-by: jamespepper81 <84083764+jamespepper81@users.noreply.github.com> --- app/transaction-explorer.tsx | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/transaction-explorer.tsx b/app/transaction-explorer.tsx index 4f4a673..199efc2 100644 --- a/app/transaction-explorer.tsx +++ b/app/transaction-explorer.tsx @@ -55,12 +55,11 @@ let lastAddressesRef: readonly string[] | undefined; let lastAddressSet: Set | undefined; function getAddressSet(addresses: readonly string[] | undefined | null): Set { - const normalized = addresses ?? []; - if (normalized === lastAddressesRef && lastAddressSet) { + if (addresses === lastAddressesRef && lastAddressSet) { return lastAddressSet; } - lastAddressesRef = normalized; - lastAddressSet = new Set(normalized); + lastAddressesRef = addresses ?? undefined; + lastAddressSet = new Set(addresses ?? []); return lastAddressSet; } From 8c4ea52ec386414d2d248b6015cdba960c405d9c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 9 Jan 2026 20:19:53 +0000 Subject: [PATCH 5/5] Fix null/undefined handling in memoization cache Allow the cache to properly handle both null and undefined by storing the exact reference without normalizing to undefined. Co-authored-by: jamespepper81 <84083764+jamespepper81@users.noreply.github.com> --- app/transaction-explorer.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/transaction-explorer.tsx b/app/transaction-explorer.tsx index 199efc2..690bdc6 100644 --- a/app/transaction-explorer.tsx +++ b/app/transaction-explorer.tsx @@ -51,14 +51,14 @@ interface TransactionExplorerData { } // Memoize the Set of wallet addresses to avoid recreating it on every function call. -let lastAddressesRef: readonly string[] | undefined; +let lastAddressesRef: readonly string[] | undefined | null; let lastAddressSet: Set | undefined; function getAddressSet(addresses: readonly string[] | undefined | null): Set { if (addresses === lastAddressesRef && lastAddressSet) { return lastAddressSet; } - lastAddressesRef = addresses ?? undefined; + lastAddressesRef = addresses; lastAddressSet = new Set(addresses ?? []); return lastAddressSet; }