1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-23 03:36:18 +02:00

Merge pull request #2901 from MetaMask/DefaultToOneGwei

Default gas estimate to 1 gwei for networks with no block activity
This commit is contained in:
kumavis 2018-01-08 15:35:58 -08:00 committed by GitHub
commit f12ad0d4d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 0 deletions

View File

@ -490,6 +490,12 @@ module.exports = class MetamaskController extends EventEmitter {
getGasPrice () { getGasPrice () {
const { recentBlocksController } = this const { recentBlocksController } = this
const { recentBlocks } = recentBlocksController.store.getState() 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) => { const lowestPrices = recentBlocks.map((block) => {
if (!block.gasPrices) { if (!block.gasPrices) {
return GWEI_BN return GWEI_BN

View File

@ -72,6 +72,25 @@ describe('MetaMaskController', function () {
metamaskController.recentBlocksController = realRecentBlocksController 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 () { describe('#createNewVaultAndKeychain', function () {