|
|
|
@ -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,22 @@ module.exports = class MetamaskController extends EventEmitter { |
|
|
|
|
this.emit('update', this.getState()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
getGasPrice () { |
|
|
|
|
const { recentBlocksController } = this |
|
|
|
|
console.dir(recentBlocksController) |
|
|
|
|
const { recentBlocks } = recentBlocksController.store.getState() |
|
|
|
|
console.dir(recentBlocks) |
|
|
|
|
const lowestPrices = recentBlocks.map((block) => { |
|
|
|
|
return block.transactions |
|
|
|
|
.sort((a, b) => { |
|
|
|
|
return a.gt(b) ? 1 : -1 |
|
|
|
|
})[0] |
|
|
|
|
}) |
|
|
|
|
.map(number => number.div(GWEI_BN).toNumber()) |
|
|
|
|
console.dir({ lowestPrices }) |
|
|
|
|
return percentile(50, lowestPrices) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Vault Management
|
|
|
|
|
//
|
|
|
|
|