Skip to content

Improve type safety and code clarity in transaction explorer#437

Merged
jamespepper81 merged 9 commits into
devfrom
copilot/rename-current-wallet-parameter
Jan 9, 2026
Merged

Improve type safety and code clarity in transaction explorer#437
jamespepper81 merged 9 commits into
devfrom
copilot/rename-current-wallet-parameter

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 9, 2026

Applied type safety improvements and removed ambiguous naming from the transaction explorer's data transformation logic.

Changes

  • Type interfaces: Added NormalizedVinSource, NormalizedVoutSource, and ExtendedTransactionDetails to replace any types and type assertions
  • Named constant: Defined SATOSHIS_PER_BTC = 1e8 to replace magic number
  • Parameter naming: Renamed currentWallet to userWallet in buildExplorerData for clarity

Before/After

// Before
const normalizeVin = vinList.map((vin: any) => ({
  prevout: vin.prevout || {
    value: vin.value ? Math.round(vin.value * 1e8) : 0,
    scriptpubkey_address: vin.address,
  },
}));

const feePerVB = (txDetails as any).vsize ? feeSats / (txDetails as any).vsize : 0;

// After
const normalizeVin = vinList.map((vin: NormalizedVinSource) => ({
  prevout: vin.prevout || {
    value: vin.value ? Math.round(vin.value * SATOSHIS_PER_BTC) : 0,
    scriptpubkey_address: vin.address,
  },
}));

const extendedTxDetails = txDetails as ExtendedTransactionDetails;
const feePerVB = extendedTxDetails.vsize ? feeSats / extendedTxDetails.vsize : 0;
Original prompt
Please apply the following diffs and create a pull request.
Once the PR is ready, give it a title based on the messages of the fixes being applied.

[{"message":"[nitpick] The parameter name 'currentWallet' is ambiguous. Consider renaming it to 'wallet' or 'userWallet' for better clarity.","fixFiles":[{"filePath":"app/transaction-explorer.tsx","diff":"diff --git a/app/transaction-explorer.tsx b/app/transaction-explorer.tsx\n--- a/app/transaction-explorer.tsx\n+++ b/app/transaction-explorer.tsx\n@@ -646,7 +646,7 @@\n const buildExplorerData = (\n   txDetails: Transaction,\n   bitcoinPrice: { usd?: number } | null,\n-  currentWallet: Wallet | null,\n+  userWallet: Wallet | null,\n ): TransactionExplorerData => {\n   const statusInfo = txDetails.status || {};\n   const vinList = Array.isArray(txDetails.inputs) ? txDetails.inputs : txDetails.vin || [];\n@@ -668,7 +668,7 @@\n   const feeSats = typeof txDetails.fee === 'number' ? txDetails.fee : (txDetails.fee ?? 0);\n   const feeBtc = feeSats / 1e8;\n \n-  const addressSet = new Set(currentWallet?.addresses ?? []);\n+  const addressSet = new Set(userWallet?.addresses ?? []);\n   const fallbackNetAmountSats = (() => {\n     if (typeof txDetails.amount === 'number') {\n       return Math.round(txDetails.amount * 1e8);\n"}]},{"message":"Using 'any' type reduces type safety. Consider defining a proper interface for vin objects to improve type checking and code maintainability.","fixFiles":[{"filePath":"app/transaction-explorer.tsx","diff":"diff --git a/app/transaction-explorer.tsx b/app/transaction-explorer.tsx\n--- a/app/transaction-explorer.tsx\n+++ b/app/transaction-explorer.tsx\n@@ -643,6 +643,15 @@\n   },\n });\n \n+interface NormalizedVinSource {\n+  prevout?: {\n+    value?: number;\n+    scriptpubkey_address?: string;\n+  };\n+  value?: number;\n+  address?: string;\n+}\n+\n const buildExplorerData = (\n   txDetails: Transaction,\n   bitcoinPrice: { usd?: number } | null,\n@@ -652,7 +661,7 @@\n   const vinList = Array.isArray(txDetails.inputs) ? txDetails.inputs : txDetails.vin || [];\n   const voutList = Array.isArray(txDetails.outputs) ? txDetails.outputs : txDetails.vout || [];\n \n-  const normalizeVin = vinList.map((vin: any) => ({\n+  const normalizeVin = vinList.map((vin: NormalizedVinSource) => ({\n     prevout: vin.prevout || {\n       value: vin.value ? Math.round(vin.value * 1e8) : 0,\n       scriptpubkey_address: vin.address,\n"}]},{"message":"Using 'any' type reduces type safety. Consider defining a proper interface for vout objects to improve type checking and code maintainability.","fixFiles":[{"filePath":"app/transaction-explorer.tsx","diff":"diff --git a/app/transaction-explorer.tsx b/app/transaction-explorer.tsx\n--- a/app/transaction-explorer.tsx\n+++ b/app/transaction-explorer.tsx\n@@ -50,6 +50,13 @@\n   }[];\n }\n \n+interface NormalizedVoutSource {\n+  value?: number;\n+  amount?: number;\n+  address?: string;\n+  scriptpubkey_address?: string;\n+}\n+\n export default function TransactionExplorerScreen() {\n   const { txid } = useLocalSearchParams<{ txid: string }>();\n   const { theme, transactions, bitcoinPrice, currentWallet, formatCurrency } = useWallet();\n@@ -658,7 +665,7 @@\n       scriptpubkey_address: vin.address,\n     },\n   }));\n-  const normalizeVout = voutList.map((vout: any) => ({\n+  const normalizeVout = voutList.map((vout: NormalizedVoutSource) => ({\n     value: typeof vout.value === 'number' ? vout.value : Math.round((vout.amount ?? 0) * 1e8),\n     scriptpubkey_address: vout.address ?? vout.scriptpubkey_address,\n   }));\n"}]},{"message":"Magic number 1e8 is used multiple times without explanation. Consider defining a constant like 'SATOSHIS_PER_BTC = 1e8' to improve code readability and maintainability.","fixFiles":[{"filePath":"app/transaction-explorer.tsx","diff":"diff --git a/app/transaction-explorer.tsx b/app/transaction-explorer.tsx\n--- a/app/transaction-explorer.tsx\n+++ b/app/transaction-explorer.tsx\n@@ -50,6 +50,8 @@\n   }[];\n }\n \n+const SATOSHIS_PER_BTC = 1e8;\n+\n export default function TransactionExplorerScreen() {\n   const { txid } = useLocalSearchParams<{ txid: string }>();\n   const { theme, transactions, bitcoinPrice, currentWallet, formatCurrency } = useWallet();\n@@ -654,24 +656,24 @@\n \n   const normalizeVin = vinList.map((vin: any) => ({\n     prevout: vin.prevout || {\n-      value: vin.value ? Math.round(vin.value * 1e8) : 0,\n+      value: vin.value ? Math.round(vin.value * SATOSHIS_PER_BTC) : 0,\n       scriptpubkey_address: vin.address,\n     },\n   }));\n   const normalizeVout = voutList.map((vout: any) => ({\n-    value: typeof vout.value === 'number' ? vout.value : Math.round((vout.amount ?? 0) * 1e8),\n+    value: typeof vout.value === 'number' ? vout.value : Math.round((vout.amount ?? 0) * SATOSHIS_PER_BTC),\n     scriptpubkey_address: vout.address ?? vout.scriptpubkey_address,\n   }));\n \n   const inputValueSats = normalizeVin.reduce((sum, vin) => sum + (vin.p...

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

jamespepper81 and others added 7 commits January 8, 2026 17:17
Potential fix for code scanning alert no. 2: Replacement of a substring with itself
Add GitHub issue and PR templates and update SECURITY
Remove Firebase configuration files from repository
Add additional Firebase configuration files to .gitignore
Copilot AI and others added 2 commits January 9, 2026 19:50
- Rename currentWallet to userWallet for clarity
- Add NormalizedVinSource interface for type safety
- Add NormalizedVoutSource interface for type safety
- Add SATOSHIS_PER_BTC constant to replace magic number
- Add ExtendedTransactionDetails interface to replace type assertions

Co-authored-by: jamespepper81 <84083764+jamespepper81@users.noreply.github.com>
Co-authored-by: jamespepper81 <84083764+jamespepper81@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix ambiguous parameter name in transaction explorer Improve type safety and code clarity in transaction explorer Jan 9, 2026
Copilot AI requested a review from jamespepper81 January 9, 2026 19:54
@jamespepper81 jamespepper81 marked this pull request as ready for review January 9, 2026 20:02
@jamespepper81 jamespepper81 merged commit 17b9e92 into dev Jan 9, 2026
2 checks passed
@jamespepper81 jamespepper81 deleted the copilot/rename-current-wallet-parameter branch January 9, 2026 20:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants