diff --git a/src/shared/transactions.js b/src/shared/transactions.js index f926784..dee0d06 100644 --- a/src/shared/transactions.js +++ b/src/shared/transactions.js @@ -9,6 +9,7 @@ const { formatEther, formatUnits } = require("ethers"); const { log, debugFetch } = require("./log"); const { KNOWN_SYMBOLS, TOKEN_BY_ADDRESS } = require("./tokenList"); +const { decodeCalldata } = require("./decodeCalldata"); function formatTxValue(val) { const parts = val.split("."); @@ -23,6 +24,7 @@ function parseTx(tx, addrLower) { const rawWei = tx.value || "0"; const toIsContract = tx.to?.is_contract || false; const method = tx.method || null; + const rawInput = tx.raw_input || null; // For contract calls, produce a meaningful label instead of "0.0000 ETH" let symbol = "ETH"; @@ -32,14 +34,41 @@ function parseTx(tx, addrLower) { let rawUnit = "wei"; let direction = from.toLowerCase() === addrLower ? "sent" : "received"; let directionLabel = direction === "sent" ? "Sent" : "Received"; - if (toIsContract && method && method !== "transfer") { - const token = TOKEN_BY_ADDRESS.get(to.toLowerCase()); - if (token) { - symbol = token.symbol; + let decoded = null; + + if (rawInput && rawInput !== "0x" && rawInput.length >= 10) { + decoded = decodeCalldata(rawInput, to); + if (decoded) { + // Uniswap swaps: show "Swap" with token pair + if (decoded.name && decoded.name.startsWith("Swap")) { + direction = "contract"; + directionLabel = decoded.name; + value = ""; + exactValue = ""; + rawAmount = ""; + rawUnit = ""; + } else if (decoded.name === "Token Approval") { + direction = "contract"; + directionLabel = "Approve"; + value = ""; + exactValue = ""; + rawAmount = ""; + rawUnit = ""; + } + // Token Transfer: keep as Sent/Received (handled by token transfer overlay) + } else if (toIsContract && method && method !== "transfer") { + // Unknown contract call + direction = "contract"; + directionLabel = "Contract Call"; + value = ""; + exactValue = ""; + rawAmount = ""; + rawUnit = ""; } - const label = method.charAt(0).toUpperCase() + method.slice(1); + } else if (toIsContract && method && method !== "transfer") { + // Contract call without raw input data direction = "contract"; - directionLabel = label; + directionLabel = "Contract Call"; value = ""; exactValue = ""; rawAmount = ""; @@ -65,6 +94,8 @@ function parseTx(tx, addrLower) { holders: null, isContractCall: toIsContract, method: method, + rawInput: rawInput, + decoded: decoded, }; }