1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 18:00:18 +01:00

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

This commit is contained in:
Dan J Miller 2020-10-06 21:38:09 -02:30 committed by GitHub
parent 46bcba2d63
commit 534ac25a93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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',