Fix feature to work

feature/default_network_editable
Dan Finlay 7 years ago
parent 447682d1fb
commit aec24ec81e
  1. 3
      app/scripts/controllers/transactions.js
  2. 11
      app/scripts/metamask-controller.js
  3. 8
      test/unit/metamask-controller-test.js

@ -180,7 +180,8 @@ module.exports = class TransactionController extends EventEmitter {
// ensure value // ensure value
txMeta.gasPriceSpecified = Boolean(txParams.gasPrice) txMeta.gasPriceSpecified = Boolean(txParams.gasPrice)
txMeta.nonceSpecified = Boolean(txParams.nonce) txMeta.nonceSpecified = Boolean(txParams.nonce)
const gasPrice = txParams.gasPrice || this.getGasPrice() const gasPrice = txParams.gasPrice || this.getGasPrice ? this.getGasPrice()
: await this.query.gasPrice()
txParams.gasPrice = ethUtil.addHexPrefix(gasPrice.toString(16)) txParams.gasPrice = ethUtil.addHexPrefix(gasPrice.toString(16))
txParams.value = txParams.value || '0x0' txParams.value = txParams.value || '0x0'
// set gasLimit // set gasLimit

@ -491,13 +491,20 @@ module.exports = class MetamaskController extends EventEmitter {
const { recentBlocksController } = this const { recentBlocksController } = this
const { recentBlocks } = recentBlocksController.store.getState() const { recentBlocks } = recentBlocksController.store.getState()
const lowestPrices = recentBlocks.map((block) => { const lowestPrices = recentBlocks.map((block) => {
return block.transactions if (!block.gasPrices) {
return new BN(0)
}
return block.gasPrices
.map(hexPrefix => hexPrefix.substr(2))
.map(hex => new BN(hex, 16))
.sort((a, b) => { .sort((a, b) => {
return a.gt(b) ? 1 : -1 return a.gt(b) ? 1 : -1
})[0] })[0]
}) })
.map(number => number.div(GWEI_BN).toNumber()) .map(number => number.div(GWEI_BN).toNumber())
return percentile(50, lowestPrices) const percentileNum = percentile(50, lowestPrices)
const percentileNumBn = new BN(percentileNum)
return '0x' + percentileNumBn.mul(GWEI_BN).toString(16)
} }
// //

@ -55,8 +55,10 @@ describe('MetaMaskController', function () {
getState: () => { getState: () => {
return { return {
recentBlocks: [ recentBlocks: [
{ transactions: [ new BN('50000000000'), new BN('100000000000') ] }, { gasPrices: [ '0x3b9aca00', '0x174876e800'] },
{ transactions: [ new BN('60000000000'), new BN('100000000000') ] }, { gasPrices: [ '0x3b9aca00', '0x174876e800'] },
{ gasPrices: [ '0x174876e800', '0x174876e800' ]},
{ gasPrices: [ '0x174876e800', '0x174876e800' ]},
] ]
} }
} }
@ -64,7 +66,7 @@ describe('MetaMaskController', function () {
} }
const gasPrice = metamaskController.getGasPrice() const gasPrice = metamaskController.getGasPrice()
assert.equal(gasPrice, 50, 'accurately estimates 50th percentile accepted gas price') assert.equal(gasPrice, '0x3b9aca00', 'accurately estimates 50th percentile accepted gas price')
metamaskController.recentBlocksController = realRecentBlocksController metamaskController.recentBlocksController = realRecentBlocksController
}) })

Loading…
Cancel
Save