mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-26 20:39:08 +01:00
Ensure gas costs are accounted for when calculating the amount of eth received in a swap (#9494)
This commit is contained in:
parent
46bcba2d63
commit
534ac25a93
@ -366,10 +366,16 @@ export function quotesToRenderableData (quotes, gasPrice, conversionRate, curren
|
|||||||
|
|
||||||
export function getSwapsTokensReceivedFromTxMeta (tokenSymbol, txMeta, tokenAddress, accountAddress, tokenDecimals) {
|
export function getSwapsTokensReceivedFromTxMeta (tokenSymbol, txMeta, tokenAddress, accountAddress, tokenDecimals) {
|
||||||
if (tokenSymbol === 'ETH') {
|
if (tokenSymbol === 'ETH') {
|
||||||
if (!txMeta?.postTxBalance || !txMeta?.preTxBalance) {
|
if (!txMeta || !txMeta.postTxBalance || !txMeta.preTxBalance) {
|
||||||
return null
|
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,
|
aBase: 16,
|
||||||
bBase: 16,
|
bBase: 16,
|
||||||
fromDenomination: 'WEI',
|
fromDenomination: 'WEI',
|
||||||
|
Loading…
Reference in New Issue
Block a user