From 534ac25a93968688425408f1b313219219e7f131 Mon Sep 17 00:00:00 2001 From: Dan J Miller Date: Tue, 6 Oct 2020 21:38:09 -0230 Subject: [PATCH] Ensure gas costs are accounted for when calculating the amount of eth received in a swap (#9494) --- ui/app/pages/swaps/swaps.util.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ui/app/pages/swaps/swaps.util.js b/ui/app/pages/swaps/swaps.util.js index 679e51929..fb6173101 100644 --- a/ui/app/pages/swaps/swaps.util.js +++ b/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',