From 8166d5057860cc11e03342e37e9a64a9647cb61c Mon Sep 17 00:00:00 2001 From: Daniel <80175477+dan437@users.noreply.github.com> Date: Tue, 8 Feb 2022 19:14:50 +0100 Subject: [PATCH] Resolve a BigNumber issue (#13555) * Do not call `decimalToHex` for `minimumGasLimit`, which is already in hex * Add `0x` prefix when returning a gas estimate * Fix UTs Co-authored-by: Dan J Miller --- app/scripts/controllers/swaps.js | 2 +- app/scripts/controllers/swaps.test.js | 6 ++++-- ui/hooks/gasFeeInput/useGasEstimates.js | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/scripts/controllers/swaps.js b/app/scripts/controllers/swaps.js index 5e8fb6990..e3d0198e4 100644 --- a/app/scripts/controllers/swaps.js +++ b/app/scripts/controllers/swaps.js @@ -55,7 +55,7 @@ function calculateGasEstimateWithRefund( const gasEstimateWithRefund = !isMaxGasMinusRefundNegative && maxGasMinusRefund.lt(estimatedGas, 16) - ? maxGasMinusRefund.toString(16) + ? `0x${maxGasMinusRefund.toString(16)}` : estimatedGas; return gasEstimateWithRefund; diff --git a/app/scripts/controllers/swaps.test.js b/app/scripts/controllers/swaps.test.js index 3bc5b4e0d..85890eeb2 100644 --- a/app/scripts/controllers/swaps.test.js +++ b/app/scripts/controllers/swaps.test.js @@ -372,7 +372,9 @@ describe('SwapsController', function () { assert.strictEqual(gasEstimate, bufferedGasLimit); assert.strictEqual( gasEstimateWithRefund, - new BigNumber(maxGas, 10).minus(estimatedRefund, 10).toString(16), + `0x${new BigNumber(maxGas, 10) + .minus(estimatedRefund, 10) + .toString(16)}`, ); }); @@ -690,7 +692,7 @@ describe('SwapsController', function () { isBestQuote: true, // TODO: find a way to calculate these values dynamically gasEstimate: 2000000, - gasEstimateWithRefund: 'b8cae', + gasEstimateWithRefund: '0xb8cae', savings: { fee: '0', metaMaskFee: '0.5050505050505050505', diff --git a/ui/hooks/gasFeeInput/useGasEstimates.js b/ui/hooks/gasFeeInput/useGasEstimates.js index 5466ec584..0eb0c65e9 100644 --- a/ui/hooks/gasFeeInput/useGasEstimates.js +++ b/ui/hooks/gasFeeInput/useGasEstimates.js @@ -111,7 +111,7 @@ export function useGasEstimates({ const maximumCostInHexWei = getMaximumGasTotalInHexWei(gasSettings); if (editGasMode === EDIT_GAS_MODES.SWAPS) { - gasSettings = { ...gasSettings, gasLimit: decimalToHex(minimumGasLimit) }; + gasSettings = { ...gasSettings, gasLimit: minimumGasLimit }; } // The minimum amount this transaction will cost