aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkumavis <kumavis@users.noreply.github.com>2018-01-09 07:35:58 +0800
committerGitHub <noreply@github.com>2018-01-09 07:35:58 +0800
commitf12ad0d4d54e0fb783b0e66c1a2b26250e8d5fef (patch)
treebee5a9463b6dc0069fe789d94652b1887fb135a7
parentf42a808bea16873386afad1002dc0f0ffba06d15 (diff)
parent943befef91cd725579c4bf4e7024734f02ef98f5 (diff)
downloadtangerine-wallet-browser-f12ad0d4d54e0fb783b0e66c1a2b26250e8d5fef.tar
tangerine-wallet-browser-f12ad0d4d54e0fb783b0e66c1a2b26250e8d5fef.tar.gz
tangerine-wallet-browser-f12ad0d4d54e0fb783b0e66c1a2b26250e8d5fef.tar.bz2
tangerine-wallet-browser-f12ad0d4d54e0fb783b0e66c1a2b26250e8d5fef.tar.lz
tangerine-wallet-browser-f12ad0d4d54e0fb783b0e66c1a2b26250e8d5fef.tar.xz
tangerine-wallet-browser-f12ad0d4d54e0fb783b0e66c1a2b26250e8d5fef.tar.zst
tangerine-wallet-browser-f12ad0d4d54e0fb783b0e66c1a2b26250e8d5fef.zip
Merge pull request #2901 from MetaMask/DefaultToOneGwei
Default gas estimate to 1 gwei for networks with no block activity
-rw-r--r--app/scripts/metamask-controller.js6
-rw-r--r--test/unit/metamask-controller-test.js19
2 files changed, 25 insertions, 0 deletions
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js
index aa2dddf3d..6ed0fd467 100644
--- a/app/scripts/metamask-controller.js
+++ b/app/scripts/metamask-controller.js
@@ -490,6 +490,12 @@ module.exports = class MetamaskController extends EventEmitter {
getGasPrice () {
const { recentBlocksController } = this
const { recentBlocks } = recentBlocksController.store.getState()
+
+ // Return 1 gwei if no blocks have been observed:
+ if (recentBlocks.length === 0) {
+ return '0x' + GWEI_BN.toString(16)
+ }
+
const lowestPrices = recentBlocks.map((block) => {
if (!block.gasPrices) {
return GWEI_BN
diff --git a/test/unit/metamask-controller-test.js b/test/unit/metamask-controller-test.js
index 9ec7cd0af..3fc7f9a98 100644
--- a/test/unit/metamask-controller-test.js
+++ b/test/unit/metamask-controller-test.js
@@ -72,6 +72,25 @@ describe('MetaMaskController', function () {
metamaskController.recentBlocksController = realRecentBlocksController
})
+
+ it('gives the 1 gwei price if no blocks have been seen.', async function () {
+ const realRecentBlocksController = metamaskController.recentBlocksController
+ metamaskController.recentBlocksController = {
+ store: {
+ getState: () => {
+ return {
+ recentBlocks: []
+ }
+ }
+ }
+ }
+
+ const gasPrice = metamaskController.getGasPrice()
+ assert.equal(gasPrice, '0x' + GWEI_BN.toString(16), 'defaults to 1 gwei')
+
+ metamaskController.recentBlocksController = realRecentBlocksController
+ })
+
})
describe('#createNewVaultAndKeychain', function () {