From 93aecc87efab7c26bd135ed289dca9a81e9bd2cb Mon Sep 17 00:00:00 2001 From: clawbot Date: Fri, 27 Feb 2026 12:05:11 -0800 Subject: [PATCH] Use shared decodeCalldata in approval view Replace the local decodeCalldata function in approval.js with an import from the new shared module. --- src/popup/views/approval.js | 87 +------------------------------------ 1 file changed, 2 insertions(+), 85 deletions(-) diff --git a/src/popup/views/approval.js b/src/popup/views/approval.js index 359b506..7bce818 100644 --- a/src/popup/views/approval.js +++ b/src/popup/views/approval.js @@ -3,6 +3,7 @@ const { state, saveState } = require("../../shared/state"); const { formatEther, formatUnits, Interface, toUtf8String } = require("ethers"); const { ERC20_ABI } = require("../../shared/constants"); const { TOKEN_BY_ADDRESS } = require("../../shared/tokenList"); +const { decodeCalldata } = require("../../shared/decodeCalldata"); const txStatus = require("./txStatus"); const uniswap = require("../../shared/uniswap"); @@ -41,91 +42,7 @@ function etherscanTokenLink(address) { return `https://etherscan.io/token/${address}`; } -// Try to decode calldata using known ABIs. -// Returns { name, description, details } or null. -function decodeCalldata(data, toAddress) { - if (!data || data === "0x" || data.length < 10) return null; - - // Try ERC-20 (approve / transfer) - try { - const parsed = erc20Iface.parseTransaction({ data }); - if (parsed) { - const token = TOKEN_BY_ADDRESS.get(toAddress.toLowerCase()); - const tokenSymbol = token ? token.symbol : null; - const tokenDecimals = token ? token.decimals : 18; - const contractLabel = tokenSymbol - ? tokenSymbol + " (" + toAddress + ")" - : toAddress; - - if (parsed.name === "approve") { - const spender = parsed.args[0]; - const rawAmount = parsed.args[1]; - const maxUint = BigInt( - "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", - ); - const isUnlimited = rawAmount === maxUint; - const amountStr = isUnlimited - ? "Unlimited" - : formatTxValue(formatUnits(rawAmount, tokenDecimals)) + - (tokenSymbol ? " " + tokenSymbol : ""); - - return { - name: "Token Approval", - description: tokenSymbol - ? "Approve spending of your " + tokenSymbol - : "Approve spending of an ERC-20 token", - details: [ - { - label: "Token", - value: contractLabel, - address: toAddress, - isToken: true, - }, - { - label: "Spender", - value: spender, - address: spender, - }, - { label: "Amount", value: amountStr }, - ], - }; - } - - if (parsed.name === "transfer") { - const to = parsed.args[0]; - const rawAmount = parsed.args[1]; - const amountStr = - formatTxValue(formatUnits(rawAmount, tokenDecimals)) + - (tokenSymbol ? " " + tokenSymbol : ""); - - return { - name: "Token Transfer", - description: tokenSymbol - ? "Transfer " + tokenSymbol - : "Transfer ERC-20 token", - details: [ - { - label: "Token", - value: contractLabel, - address: toAddress, - isToken: true, - }, - { label: "Recipient", value: to, address: to }, - { label: "Amount", value: amountStr }, - ], - }; - } - } - } catch { - // Not ERC-20 — fall through - } - - // Try Uniswap Universal Router - const routerResult = uniswap.decode(data, toAddress); - if (routerResult) return routerResult; - - return null; -} +// decodeCalldata is now in ../../shared/decodeCalldata.js function showTxApproval(details) { const toAddr = details.txParams.to;