From 08f36f8dad0f66bb4bce62aab8da7f1b1179557c Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Tue, 27 Oct 2020 14:59:34 +0300 Subject: [PATCH] Add 10% margin for gas price in case of RSK chains --- app/scripts/metamask-controller.js | 8 ++++++-- test/unit/app/controllers/metamask-controller-test.js | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 225a92660..7487baebc 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -1961,8 +1961,12 @@ module.exports = class MetamaskController extends EventEmitter { const gasPrice = recentBlock && recentBlock.minimumGasPrice && recentBlock.minimumGasPrice.toString() - if (gasPrice !== '0x' && gasPrice !== '0x0' && gasPrice !== '') { - return gasPrice + const gasPriceInt = parseInt(gasPrice, 16) + // https://forum.poa.network/t/gasprice-lower-than-minimumgasprice-in-rsk/4034 + const gasPriceMargin = '0x' + parseInt(gasPriceInt * 1.1).toString(16) + + if (!isNaN(gasPriceInt)) { + return gasPriceMargin } else { return '0x' + GWEI_BN.toString(16) } diff --git a/test/unit/app/controllers/metamask-controller-test.js b/test/unit/app/controllers/metamask-controller-test.js index aab54b8b8..fb5bc4cae 100644 --- a/test/unit/app/controllers/metamask-controller-test.js +++ b/test/unit/app/controllers/metamask-controller-test.js @@ -190,7 +190,7 @@ describe('MetaMaskController', function () { metamaskController.recentBlocksController = recentBlocksController1 const gasPrice = await metamaskController.getGasPrice() - assert.equal(gasPrice, '0x387ee40', 'takes the min gas price from the latest block') + assert.equal(gasPrice, '0x3e252e0', 'takes the min gas price from the latest block') metamaskController.recentBlocksController = realRecentBlocksController })