mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
fix class names
This commit is contained in:
parent
e761fb0ef7
commit
a13643bdb5
@ -4,8 +4,8 @@ const clone = require('clone')
|
|||||||
const ObservableStore = require('obs-store')
|
const ObservableStore = require('obs-store')
|
||||||
const ethUtil = require('ethereumjs-util')
|
const ethUtil = require('ethereumjs-util')
|
||||||
const EthQuery = require('ethjs-query')
|
const EthQuery = require('ethjs-query')
|
||||||
const TxProviderUtils = require('../lib/tx-utils')
|
const TxProviderUtil = require('../lib/tx-utils')
|
||||||
const PendingTransactionWatchers = require('../lib/pending-tx-watchers')
|
const PendingTransactionTracker = require('../lib/pending-tx-tracker')
|
||||||
const createId = require('../lib/random-id')
|
const createId = require('../lib/random-id')
|
||||||
const NonceTracker = require('../lib/nonce-tracker')
|
const NonceTracker = require('../lib/nonce-tracker')
|
||||||
|
|
||||||
@ -35,13 +35,17 @@ module.exports = class TransactionController extends EventEmitter {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
this.query = new EthQuery(this.provider)
|
this.query = new EthQuery(this.provider)
|
||||||
this.txProviderUtils = new TxProviderUtils(this.provider)
|
this.txProviderUtil = new TxProviderUtil(this.provider)
|
||||||
|
|
||||||
this.pendingTxWatchers = new PendingTransactionWatchers({
|
this.pendingTxTracker = new PendingTransactionTracker({
|
||||||
provider: this.provider,
|
provider: this.provider,
|
||||||
nonceTracker: this.nonceTracker,
|
nonceTracker: this.nonceTracker,
|
||||||
getBalance: (address) => this.ethStore.getState().accounts[address].balance,
|
getBalance: async (address) => {
|
||||||
publishTransaction: this.txProviderUtils.publishTransaction.bind(this.txProviderUtils),
|
const account = this.ethStore.getState().accounts[address]
|
||||||
|
if (!account) return
|
||||||
|
return account.balance
|
||||||
|
},
|
||||||
|
publishTransaction: this.txProviderUtil.publishTransaction.bind(this.txProviderUtil),
|
||||||
getPendingTransactions: (address) => {
|
getPendingTransactions: (address) => {
|
||||||
return this.getFilteredTxList({
|
return this.getFilteredTxList({
|
||||||
from: address,
|
from: address,
|
||||||
@ -50,16 +54,18 @@ module.exports = class TransactionController extends EventEmitter {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
this.pendingTxWatchers.on('txWarning', this.updateTx.bind(this))
|
this.pendingTxTracker.on('txWarning', this.updateTx.bind(this))
|
||||||
this.pendingTxWatchers.on('txFailed', this.setTxStatusFailed.bind(this))
|
this.pendingTxTracker.on('txFailed', this.setTxStatusFailed.bind(this))
|
||||||
this.pendingTxWatchers.on('txConfirmed', this.setTxStatusConfirmed.bind(this))
|
this.pendingTxTracker.on('txConfirmed', this.setTxStatusConfirmed.bind(this))
|
||||||
|
|
||||||
this.blockTracker.on('rawBlock', this.pendingTxWatchers.checkForTxInBlock.bind(this.pendingTxWatchers))
|
this.blockTracker.on('rawBlock', this.pendingTxTracker.checkForTxInBlock.bind(this.pendingTxTracker))
|
||||||
// this is a little messy but until ethstore has been either
|
// this is a little messy but until ethstore has been either
|
||||||
// removed or redone this is to guard against the race condition
|
// removed or redone this is to guard against the race condition
|
||||||
// where ethStore hasent been populated by the results yet
|
// where ethStore hasent been populated by the results yet
|
||||||
this.blockTracker.once('latest', () => this.blockTracker.on('latest', this.pendingTxWatchers.resubmitPendingTxs.bind(this.pendingTxWatchers)))
|
this.blockTracker.once('latest', () => {
|
||||||
this.blockTracker.on('sync', this.pendingTxWatchers.queryPendingTxs.bind(this.pendingTxWatchers))
|
this.blockTracker.on('latest', this.pendingTxTracker.resubmitPendingTxs.bind(this.pendingTxTracker))
|
||||||
|
})
|
||||||
|
this.blockTracker.on('sync', this.pendingTxTracker.queryPendingTxs.bind(this.pendingTxTracker))
|
||||||
// memstore is computed from a few different stores
|
// memstore is computed from a few different stores
|
||||||
this._updateMemstore()
|
this._updateMemstore()
|
||||||
this.store.subscribe(() => this._updateMemstore())
|
this.store.subscribe(() => this._updateMemstore())
|
||||||
@ -191,7 +197,7 @@ module.exports = class TransactionController extends EventEmitter {
|
|||||||
|
|
||||||
async addUnapprovedTransaction (txParams) {
|
async addUnapprovedTransaction (txParams) {
|
||||||
// validate
|
// validate
|
||||||
await this.txProviderUtils.validateTxParams(txParams)
|
await this.txProviderUtil.validateTxParams(txParams)
|
||||||
// construct txMeta
|
// construct txMeta
|
||||||
const txMeta = {
|
const txMeta = {
|
||||||
id: createId(),
|
id: createId(),
|
||||||
@ -217,7 +223,7 @@ module.exports = class TransactionController extends EventEmitter {
|
|||||||
txParams.gasPrice = gasPrice
|
txParams.gasPrice = gasPrice
|
||||||
}
|
}
|
||||||
// set gasLimit
|
// set gasLimit
|
||||||
return await this.txProviderUtils.analyzeGasUsage(txMeta)
|
return await this.txProviderUtil.analyzeGasUsage(txMeta)
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateAndApproveTransaction (txMeta) {
|
async updateAndApproveTransaction (txMeta) {
|
||||||
@ -260,7 +266,7 @@ module.exports = class TransactionController extends EventEmitter {
|
|||||||
const fromAddress = txParams.from
|
const fromAddress = txParams.from
|
||||||
// add network/chain id
|
// add network/chain id
|
||||||
txParams.chainId = this.getChainId()
|
txParams.chainId = this.getChainId()
|
||||||
const ethTx = this.txProviderUtils.buildEthTxFromParams(txParams)
|
const ethTx = this.txProviderUtil.buildEthTxFromParams(txParams)
|
||||||
await this.signEthTx(ethTx, fromAddress)
|
await this.signEthTx(ethTx, fromAddress)
|
||||||
this.setTxStatusSigned(txMeta.id)
|
this.setTxStatusSigned(txMeta.id)
|
||||||
const rawTx = ethUtil.bufferToHex(ethTx.serialize())
|
const rawTx = ethUtil.bufferToHex(ethTx.serialize())
|
||||||
@ -271,7 +277,7 @@ module.exports = class TransactionController extends EventEmitter {
|
|||||||
const txMeta = this.getTx(txId)
|
const txMeta = this.getTx(txId)
|
||||||
txMeta.rawTx = rawTx
|
txMeta.rawTx = rawTx
|
||||||
this.updateTx(txMeta)
|
this.updateTx(txMeta)
|
||||||
const txHash = await this.txProviderUtils.publishTransaction(rawTx)
|
const txHash = await this.txProviderUtil.publishTransaction(rawTx)
|
||||||
this.setTxHash(txId, txHash)
|
this.setTxHash(txId, txHash)
|
||||||
this.setTxStatusSubmitted(txId)
|
this.setTxStatusSubmitted(txId)
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ const sufficientBalance = require('./util').sufficientBalance
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = class PendingTransactionWatchers extends EventEmitter {
|
module.exports = class PendingTransactionTracker extends EventEmitter {
|
||||||
constructor (config) {
|
constructor (config) {
|
||||||
super()
|
super()
|
||||||
this.query = new EthQuery(config.provider)
|
this.query = new EthQuery(config.provider)
|
||||||
@ -97,6 +97,7 @@ module.exports = class PendingTransactionWatchers extends EventEmitter {
|
|||||||
async _resubmitTx (txMeta) {
|
async _resubmitTx (txMeta) {
|
||||||
const address = txMeta.txParams.from
|
const address = txMeta.txParams.from
|
||||||
const balance = this.getBalance(address)
|
const balance = this.getBalance(address)
|
||||||
|
if (balance === undefined) return
|
||||||
if (!('retryCount' in txMeta)) txMeta.retryCount = 0
|
if (!('retryCount' in txMeta)) txMeta.retryCount = 0
|
||||||
|
|
||||||
// if the value of the transaction is greater then the balance, fail.
|
// if the value of the transaction is greater then the balance, fail.
|
@ -13,7 +13,7 @@ its passed ethquery
|
|||||||
and used to do things like calculate gas of a tx.
|
and used to do things like calculate gas of a tx.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = class txProvideUtils {
|
module.exports = class txProvideUtil {
|
||||||
constructor (provider) {
|
constructor (provider) {
|
||||||
this.query = new EthQuery(provider)
|
this.query = new EthQuery(provider)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user