diff options
author | Dan Finlay <542863+danfinlay@users.noreply.github.com> | 2018-01-09 03:21:41 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-09 03:21:41 +0800 |
commit | d11ec81f49328d3f0fee484fba5191d4c29c42ad (patch) | |
tree | 1d888a0e26cb5cf224b8c5a0c1a9bd67e6ae3f1b /app/scripts | |
parent | 39b700bf87f213d2fb06dcde85f4e6173a6ce70c (diff) | |
parent | f6f3f915707a2a4f5c9db43ae51741c7d30cbc69 (diff) | |
download | tangerine-wallet-browser-d11ec81f49328d3f0fee484fba5191d4c29c42ad.tar tangerine-wallet-browser-d11ec81f49328d3f0fee484fba5191d4c29c42ad.tar.gz tangerine-wallet-browser-d11ec81f49328d3f0fee484fba5191d4c29c42ad.tar.bz2 tangerine-wallet-browser-d11ec81f49328d3f0fee484fba5191d4c29c42ad.tar.lz tangerine-wallet-browser-d11ec81f49328d3f0fee484fba5191d4c29c42ad.tar.xz tangerine-wallet-browser-d11ec81f49328d3f0fee484fba5191d4c29c42ad.tar.zst tangerine-wallet-browser-d11ec81f49328d3f0fee484fba5191d4c29c42ad.zip |
Merge branch 'master' into i2621-0xRecipientAddress
Diffstat (limited to 'app/scripts')
-rw-r--r-- | app/scripts/controllers/blacklist.js | 1 | ||||
-rw-r--r-- | app/scripts/controllers/transactions.js | 4 | ||||
-rw-r--r-- | app/scripts/metamask-controller.js | 25 |
3 files changed, 28 insertions, 2 deletions
diff --git a/app/scripts/controllers/blacklist.js b/app/scripts/controllers/blacklist.js index dd671943f..33c31dab9 100644 --- a/app/scripts/controllers/blacklist.js +++ b/app/scripts/controllers/blacklist.js @@ -57,3 +57,4 @@ class BlacklistController { } module.exports = BlacklistController + diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js index 7c7efb84d..469deb670 100644 --- a/app/scripts/controllers/transactions.js +++ b/app/scripts/controllers/transactions.js @@ -32,6 +32,7 @@ module.exports = class TransactionController extends EventEmitter { this.provider = opts.provider this.blockTracker = opts.blockTracker this.signEthTx = opts.signTransaction + this.getGasPrice = opts.getGasPrice this.memStore = new ObservableStore({}) this.query = new EthQuery(this.provider) @@ -179,7 +180,8 @@ module.exports = class TransactionController extends EventEmitter { // ensure value txMeta.gasPriceSpecified = Boolean(txParams.gasPrice) txMeta.nonceSpecified = Boolean(txParams.nonce) - const gasPrice = txParams.gasPrice || await this.query.gasPrice() + const gasPrice = txParams.gasPrice || this.getGasPrice ? this.getGasPrice() + : await this.query.gasPrice() txParams.gasPrice = ethUtil.addHexPrefix(gasPrice.toString(16)) txParams.value = txParams.value || '0x0' // set gasLimit diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 23f2a1598..1b13f6567 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -35,13 +35,15 @@ const accountImporter = require('./account-import-strategies') const getBuyEthUrl = require('./lib/buy-eth-url') const Mutex = require('await-semaphore').Mutex const version = require('../manifest.json').version +const BN = require('ethereumjs-util').BN +const GWEI_BN = new BN('1000000000') +const percentile = require('percentile') module.exports = class MetamaskController extends EventEmitter { constructor (opts) { super() - this.sendUpdate = debounce(this.privateSendUpdate.bind(this), 200) this.opts = opts @@ -139,6 +141,7 @@ module.exports = class MetamaskController extends EventEmitter { provider: this.provider, blockTracker: this.blockTracker, ethQuery: this.ethQuery, + getGasPrice: this.getGasPrice.bind(this), }) this.txController.on('newUnapprovedTx', opts.showUnapprovedTx.bind(opts)) @@ -484,6 +487,26 @@ module.exports = class MetamaskController extends EventEmitter { this.emit('update', this.getState()) } + getGasPrice () { + const { recentBlocksController } = this + const { recentBlocks } = recentBlocksController.store.getState() + const lowestPrices = recentBlocks.map((block) => { + if (!block.gasPrices) { + return new BN(0) + } + return block.gasPrices + .map(hexPrefix => hexPrefix.substr(2)) + .map(hex => new BN(hex, 16)) + .sort((a, b) => { + return a.gt(b) ? 1 : -1 + })[0] + }) + .map(number => number.div(GWEI_BN).toNumber()) + const percentileNum = percentile(50, lowestPrices) + const percentileNumBn = new BN(percentileNum) + return '0x' + percentileNumBn.mul(GWEI_BN).toString(16) + } + // // Vault Management // |