Ensure gas costs are accounted for when calculating the amount of eth received in a swap (#9494)

feature/default_network_editable
Dan J Miller 4 years ago committed by GitHub
parent 46bcba2d63
commit 534ac25a93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      ui/app/pages/swaps/swaps.util.js

@ -366,10 +366,16 @@ export function quotesToRenderableData (quotes, gasPrice, conversionRate, curren
export function getSwapsTokensReceivedFromTxMeta (tokenSymbol, txMeta, tokenAddress, accountAddress, tokenDecimals) {
if (tokenSymbol === 'ETH') {
if (!txMeta?.postTxBalance || !txMeta?.preTxBalance) {
if (!txMeta || !txMeta.postTxBalance || !txMeta.preTxBalance) {
return null
}
const ethReceived = subtractCurrencies(txMeta.postTxBalance, txMeta.preTxBalance, {
const gasCost = calcGasTotal(txMeta.txParams.gas, txMeta.txParams.gasPrice)
const preTxBalanceLessGasCost = subtractCurrencies(txMeta.preTxBalance, gasCost, {
aBase: 16,
bBase: 16,
toNumericBase: 'hex',
})
const ethReceived = subtractCurrencies(txMeta.postTxBalance, preTxBalanceLessGasCost, {
aBase: 16,
bBase: 16,
fromDenomination: 'WEI',

Loading…
Cancel
Save