diff --git a/index.html b/index.html index 354dffe..a6ee76a 100644 --- a/index.html +++ b/index.html @@ -1539,15 +1539,34 @@ const amount = calculateTransactionAmount(tx, address); - // Extract from and to addresses with proper null checks + // Extract from and to addresses - prioritize parsed instructions let fromAddress = "N/A"; let toAddress = "N/A"; - // Add null checks before accessing transaction properties - if (tx?.transaction?.message?.accountKeys) { + // First, try to get from parsed instructions (most reliable) + if (tx?.transaction?.message?.instructions) { + for (const ix of tx.transaction.message.instructions) { + if (ix.parsed && ix.parsed.info) { + // System transfer + if (ix.parsed.type === "transfer" && ix.parsed.info.source && ix.parsed.info.destination) { + fromAddress = ix.parsed.info.source; + toAddress = ix.parsed.info.destination; + break; + } + // Token transfer + if (ix.parsed.info.authority && ix.parsed.info.destination) { + fromAddress = ix.parsed.info.authority; + toAddress = ix.parsed.info.destination; + break; + } + } + } + } + + // Fallback: use account keys if parsed instructions not available + if (fromAddress === "N/A" && tx?.transaction?.message?.accountKeys) { const keys = tx.transaction.message.accountKeys; - fromAddress = - keys[0]?.pubkey?.toString() || String(keys[0]) || "N/A"; + fromAddress = keys[0]?.pubkey?.toString() || String(keys[0]) || "N/A"; toAddress = keys[1]?.pubkey?.toString() || String(keys[1]) || "N/A"; } @@ -1576,6 +1595,49 @@ } txid = String(txid); + // Detect transaction type + let transactionType = "transfer"; + const logMessages = tx.meta?.logMessages || []; + + // Check for NFT mint + const isNFTMint = logMessages.some(log => + log.includes("MintToCollectionV1") || + log.includes("MintV1") || + log.includes("Bubblegum") || + (log.includes("Instruction: Mint") && !log.includes("MintTo") && !log.includes("JUP")) + ); + + if (isNFTMint) { + transactionType = "nft_mint"; + } + // Check for token swap + else if (tx.meta?.preTokenBalances && tx.meta?.postTokenBalances) { + const preTokens = tx.meta.preTokenBalances; + const postTokens = tx.meta.postTokenBalances; + + let hasTokenSent = false; + let hasTokenReceived = false; + + for (const preTok of preTokens) { + const postTok = postTokens.find(p => p.accountIndex === preTok.accountIndex); + if (postTok) { + const preAmount = parseFloat(preTok.uiTokenAmount.amount); + const postAmount = parseFloat(postTok.uiTokenAmount.amount); + + if (preAmount > postAmount && (preAmount - postAmount) > 0.000001) { + hasTokenSent = true; + } + if (postAmount > preAmount && (postAmount - preAmount) > 0.000001) { + hasTokenReceived = true; + } + } + } + + if (hasTokenSent && hasTokenReceived) { + transactionType = "swap"; + } + } + return { txid: txid, time: tx.blockTime ? getFormattedTime(tx.blockTime) : "Unknown", @@ -1586,6 +1648,9 @@ sender: fromAddress, receiver: toAddress, address: address, + transactionType: transactionType, + typeLabel: transactionType === "swap" ? "Swap" : transactionType === "nft_mint" ? "NFT Mint" : "Transfer", + }; } catch (err) { console.error("Error in formatTransaction:", err); @@ -1837,13 +1902,14 @@