Calculate transaction fee and adjust transfer amount accordingly
This commit is contained in:
parent
5666fe5d34
commit
a5ebc25567
17
index.html
17
index.html
@ -2453,17 +2453,20 @@
|
||||
}
|
||||
console.log("Transaction details:", tx);
|
||||
|
||||
// Extract transaction information
|
||||
const value =
|
||||
tx.meta?.postBalances && tx.meta?.preBalances
|
||||
? Math.abs(tx.meta.postBalances[0] - tx.meta.preBalances[0]) /
|
||||
solanaWeb3.LAMPORTS_PER_SOL
|
||||
: 0;
|
||||
|
||||
// Calculate fee first
|
||||
const fee = tx.meta?.fee
|
||||
? tx.meta.fee / solanaWeb3.LAMPORTS_PER_SOL
|
||||
: 0;
|
||||
|
||||
// Extract transaction information
|
||||
// Sender's balance change includes both transfer amount and fee
|
||||
// So we subtract the fee to get just the transfer amount
|
||||
const value =
|
||||
tx.meta?.postBalances && tx.meta?.preBalances
|
||||
? (Math.abs(tx.meta.postBalances[0] - tx.meta.preBalances[0]) /
|
||||
solanaWeb3.LAMPORTS_PER_SOL) - fee
|
||||
: 0;
|
||||
|
||||
const timestamp = tx.blockTime
|
||||
? getFormattedTime(tx.blockTime)
|
||||
: "Pending";
|
||||
|
||||
Loading…
Reference in New Issue
Block a user