Skip to content

Commit

Permalink
Display actual gas paid in transaction fee summary (#663)
Browse files Browse the repository at this point in the history
  • Loading branch information
mholtzman committed Dec 8, 2021
1 parent 5843cb6 commit ac4f0db
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions app/App/Panel/Main/Account/Requests/TransactionRequest/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,17 +227,20 @@ class TransactionRequest extends React.Component {
// if (layer === 'rollup') metaChainClass += ' requestMetaChainRollup'
// if (layer === 'mainnet') metaChainClass += ' requestMetaChainMainnet'

let feeAtTime
let feeAtTime = '?.??'

if (req && req.tx && req.tx.receipt && nativeUSD) {
const { gasUsed } = req.tx.receipt
const { type, maxFeePerGas, gasPrice } = req.data
const feePerGas = type === '0x2' ? maxFeePerGas : gasPrice
const feeInWei = parseInt(gasUsed, 'hex') * parseInt(feePerGas, 'hex')
const feeInEth = feeInWei / 1e18
const feeInUsd = feeInEth * nativeUSD
feeAtTime = (Math.round(feeInUsd * 100) / 100).toFixed(2)
} else {
feeAtTime = '?.??'
const { gasUsed, effectiveGasPrice } = req.tx.receipt
const { type, gasPrice } = req.data

const paidGas = effectiveGasPrice || (parseInt(type) < 2 ? gasPrice : null)

if (paidGas) {
const feeInWei = parseInt(gasUsed, 'hex') * parseInt(paidGas, 'hex')
const feeInEth = feeInWei / 1e18
const feeInUsd = feeInEth * nativeUSD
feeAtTime = (Math.round(feeInUsd * 100) / 100).toFixed(2)
}
}

return (
Expand Down

0 comments on commit ac4f0db

Please sign in to comment.