diff --git a/src/shared/transactions.js b/src/shared/transactions.js index 88bb9ef..96fbbe0 100644 --- a/src/shared/transactions.js +++ b/src/shared/transactions.js @@ -94,19 +94,22 @@ async function fetchRecentTransactions(address, blockscoutUrl, count = 25) { const txJson = txResp.ok ? await txResp.json() : {}; const ttJson = ttResp.ok ? await ttResp.json() : {}; - const txs = []; + const txsByHash = new Map(); for (const tx of txJson.items || []) { - txs.push(parseTx(tx, addrLower)); + txsByHash.set(tx.hash, parseTx(tx, addrLower)); } - // Deduplicate: skip token transfers whose tx hash is already present - const seenHashes = new Set(txs.map((t) => t.hash)); + // When a token transfer shares a hash with a normal tx, the normal tx + // is the contract call (0 ETH) and the token transfer has the real + // amount and symbol. Replace the normal tx with the token transfer. for (const tt of ttJson.items || []) { - if (seenHashes.has(tt.transaction_hash)) continue; - txs.push(parseTokenTransfer(tt, addrLower)); + const parsed = parseTokenTransfer(tt, addrLower); + txsByHash.set(parsed.hash, parsed); } + const txs = [...txsByHash.values()]; + txs.sort((a, b) => b.blockNumber - a.blockNumber); const result = txs.slice(0, count); log.debugf("fetchRecentTransactions done, count:", result.length);