mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
fix some minor spelling mistakes and clean up code
This commit is contained in:
parent
9e1c90eafc
commit
fde69ea0ba
@ -97,7 +97,7 @@ function setupControllerConnection (stream) {
|
|||||||
// plugin badge text
|
// plugin badge text
|
||||||
//
|
//
|
||||||
|
|
||||||
txManager.on('update', updateBadge)
|
txManager.on('updateBadge', updateBadge)
|
||||||
|
|
||||||
function updateBadge () {
|
function updateBadge () {
|
||||||
var label = ''
|
var label = ''
|
||||||
|
@ -21,7 +21,6 @@ module.exports = class MetamaskController {
|
|||||||
this.configManager = new ConfigManager(opts)
|
this.configManager = new ConfigManager(opts)
|
||||||
this.keyringController = new KeyringController({
|
this.keyringController = new KeyringController({
|
||||||
configManager: this.configManager,
|
configManager: this.configManager,
|
||||||
txManager: this.txManager,
|
|
||||||
getNetwork: this.getStateNetwork.bind(this),
|
getNetwork: this.getStateNetwork.bind(this),
|
||||||
})
|
})
|
||||||
// notices
|
// notices
|
||||||
@ -40,6 +39,7 @@ module.exports = class MetamaskController {
|
|||||||
txList: this.configManager.getTxList(),
|
txList: this.configManager.getTxList(),
|
||||||
txHistoryLimit: 40,
|
txHistoryLimit: 40,
|
||||||
setTxList: this.configManager.setTxList.bind(this.configManager),
|
setTxList: this.configManager.setTxList.bind(this.configManager),
|
||||||
|
getSelectedAccount: this.configManager.getSelectedAccount.bind(this.configManager),
|
||||||
getGasMultiplier: this.configManager.getGasMultiplier.bind(this.configManager),
|
getGasMultiplier: this.configManager.getGasMultiplier.bind(this.configManager),
|
||||||
getNetwork: this.getStateNetwork.bind(this),
|
getNetwork: this.getStateNetwork.bind(this),
|
||||||
provider: this.provider,
|
provider: this.provider,
|
||||||
@ -47,8 +47,6 @@ module.exports = class MetamaskController {
|
|||||||
})
|
})
|
||||||
this.publicConfigStore = this.initPublicConfigStore()
|
this.publicConfigStore = this.initPublicConfigStore()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var currentFiat = this.configManager.getCurrentFiat() || 'USD'
|
var currentFiat = this.configManager.getCurrentFiat() || 'USD'
|
||||||
this.configManager.setCurrentFiat(currentFiat)
|
this.configManager.setCurrentFiat(currentFiat)
|
||||||
this.configManager.updateConversionRate()
|
this.configManager.updateConversionRate()
|
||||||
@ -105,9 +103,6 @@ module.exports = class MetamaskController {
|
|||||||
signMessage: keyringController.signMessage.bind(keyringController),
|
signMessage: keyringController.signMessage.bind(keyringController),
|
||||||
cancelMessage: keyringController.cancelMessage.bind(keyringController),
|
cancelMessage: keyringController.cancelMessage.bind(keyringController),
|
||||||
|
|
||||||
// forward directly to txManager
|
|
||||||
getUnapprovedTxList: txManager.getUnapprovedTxList.bind(txManager),
|
|
||||||
getFilteredTxList: txManager.getFilteredTxList.bind(txManager),
|
|
||||||
// coinbase
|
// coinbase
|
||||||
buyEth: this.buyEth.bind(this),
|
buyEth: this.buyEth.bind(this),
|
||||||
// shapeshift
|
// shapeshift
|
||||||
@ -251,11 +246,10 @@ module.exports = class MetamaskController {
|
|||||||
setupSigningListners (txParams) {
|
setupSigningListners (txParams) {
|
||||||
var txId = txParams.metamaskId
|
var txId = txParams.metamaskId
|
||||||
// apply event listeners for signing and formating events
|
// apply event listeners for signing and formating events
|
||||||
this.txManager.once(`${txId}:formated`, this.keyringController.signTransaction.bind(this.keyringController))
|
this.txManager.once(`${txId}:formatted`, this.keyringController.signTransaction.bind(this.keyringController))
|
||||||
this.keyringController.once(`${txId}:signed`, this.txManager.resolveSignedTransaction.bind(this.txManager))
|
this.keyringController.once(`${txId}:signed`, this.txManager.resolveSignedTransaction.bind(this.txManager))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
enforceTxValidations (txParams) {
|
enforceTxValidations (txParams) {
|
||||||
if (('value' in txParams) && txParams.value.indexOf('-') === 0) {
|
if (('value' in txParams) && txParams.value.indexOf('-') === 0) {
|
||||||
const msg = `Invalid transaction value of ${txParams.value} not a positive number.`
|
const msg = `Invalid transaction value of ${txParams.value} not a positive number.`
|
||||||
|
@ -12,10 +12,8 @@ module.exports = class TransactionManager extends EventEmitter {
|
|||||||
super()
|
super()
|
||||||
this.txList = opts.txList || []
|
this.txList = opts.txList || []
|
||||||
this._setTxList = opts.setTxList
|
this._setTxList = opts.setTxList
|
||||||
this._unconfTxCbs = {}
|
|
||||||
this.txHistoryLimit = opts.txHistoryLimit
|
this.txHistoryLimit = opts.txHistoryLimit
|
||||||
// txManager :: tx approvals and rejection cb's
|
this.getSelectedAccount = opts.getSelectedAccount
|
||||||
|
|
||||||
this.provider = opts.provider
|
this.provider = opts.provider
|
||||||
this.blockTracker = opts.blockTracker
|
this.blockTracker = opts.blockTracker
|
||||||
this.txProviderUtils = new TxProviderUtil(this.provider)
|
this.txProviderUtils = new TxProviderUtil(this.provider)
|
||||||
@ -25,9 +23,11 @@ module.exports = class TransactionManager extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getState () {
|
getState () {
|
||||||
|
var selectedAccount = this.getSelectedAccount()
|
||||||
return {
|
return {
|
||||||
transactions: this.getTxList(),
|
transactions: this.getTxList(),
|
||||||
unconfTxs: this.getUnapprovedTxList(),
|
unconfTxs: this.getUnapprovedTxList(),
|
||||||
|
selectedAccountTxList: this.getFilteredTxList({metamaskNetworkId: this.getNetwork(), from: selectedAccount}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,14 +37,21 @@ module.exports = class TransactionManager extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Adds a tx to the txlist
|
// Adds a tx to the txlist
|
||||||
addTx (txMeta, onTxDoneCb = noop) {
|
addTx (txMeta, onTxDoneCb = warn) {
|
||||||
var txList = this.getTxList()
|
var txList = this.getTxList()
|
||||||
var txHistoryLimit = this.txHistoryLimit
|
var txHistoryLimit = this.txHistoryLimit
|
||||||
|
|
||||||
|
// checks if the length of th tx history is
|
||||||
|
// longer then desired persistence limit
|
||||||
|
// and then if it is removes only confirmed
|
||||||
|
// or rejected tx's.
|
||||||
|
// not tx's that are pending or unapproved
|
||||||
if (txList.length > txHistoryLimit - 1) {
|
if (txList.length > txHistoryLimit - 1) {
|
||||||
var index = txList.findIndex((metaTx) => metaTx.status === 'confirmed' || metaTx.status === 'rejected')
|
var index = txList.findIndex((metaTx) => metaTx.status === 'confirmed' || metaTx.status === 'rejected')
|
||||||
index ? txList.splice(index, index) : txList.shift()
|
txList.splice(index, 1)
|
||||||
}
|
}
|
||||||
txList.push(txMeta)
|
txList.push(txMeta)
|
||||||
|
|
||||||
this._saveTxList(txList)
|
this._saveTxList(txList)
|
||||||
// keep the onTxDoneCb around in a listener
|
// keep the onTxDoneCb around in a listener
|
||||||
// for after approval/denial (requires user interaction)
|
// for after approval/denial (requires user interaction)
|
||||||
@ -58,14 +65,14 @@ module.exports = class TransactionManager extends EventEmitter {
|
|||||||
onTxDoneCb(null, false)
|
onTxDoneCb(null, false)
|
||||||
})
|
})
|
||||||
|
|
||||||
this.emit('update')
|
this.emit('updateBadge')
|
||||||
this.emit(`${txMeta.id}:unapproved`, txMeta)
|
this.emit(`${txMeta.id}:unapproved`, txMeta)
|
||||||
}
|
}
|
||||||
|
|
||||||
// gets tx by Id and returns it
|
// gets tx by Id and returns it
|
||||||
getTx (txId, cb) {
|
getTx (txId, cb) {
|
||||||
var txList = this.getTxList()
|
var txList = this.getTxList()
|
||||||
var txMeta = txList.find((txData) => txData.id === txId)
|
var txMeta = txList.find(txData => txData.id === txId)
|
||||||
return cb ? cb(txMeta) : txMeta
|
return cb ? cb(txMeta) : txMeta
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,7 +80,7 @@ module.exports = class TransactionManager extends EventEmitter {
|
|||||||
updateTx (txMeta) {
|
updateTx (txMeta) {
|
||||||
var txId = txMeta.id
|
var txId = txMeta.id
|
||||||
var txList = this.getTxList()
|
var txList = this.getTxList()
|
||||||
var index = txList.findIndex((txData) => txData.id === txId)
|
var index = txList.findIndex(txData => txData.id === txId)
|
||||||
txList[index] = txMeta
|
txList[index] = txMeta
|
||||||
this._saveTxList(txList)
|
this._saveTxList(txList)
|
||||||
}
|
}
|
||||||
@ -119,16 +126,14 @@ module.exports = class TransactionManager extends EventEmitter {
|
|||||||
}, {})
|
}, {})
|
||||||
}
|
}
|
||||||
|
|
||||||
approveTransaction (txId, cb) {
|
approveTransaction (txId, cb = warn) {
|
||||||
this.setTxStatusSigned(txId)
|
this.setTxStatusSigned(txId)
|
||||||
cb()
|
cb()
|
||||||
}
|
}
|
||||||
|
|
||||||
cancelTransaction (txId, cb) {
|
cancelTransaction (txId, cb = warn) {
|
||||||
this.setTxStatusRejected(txId)
|
this.setTxStatusRejected(txId)
|
||||||
if (cb && typeof cb === 'function') {
|
cb()
|
||||||
cb()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// formats txParams so the keyringController can sign it
|
// formats txParams so the keyringController can sign it
|
||||||
@ -148,15 +153,14 @@ module.exports = class TransactionManager extends EventEmitter {
|
|||||||
txParams.gasLimit = normalize(txParams.gasLimit || txParams.gas)
|
txParams.gasLimit = normalize(txParams.gasLimit || txParams.gas)
|
||||||
txParams.nonce = normalize(txParams.nonce)
|
txParams.nonce = normalize(txParams.nonce)
|
||||||
const ethTx = new Transaction(txParams)
|
const ethTx = new Transaction(txParams)
|
||||||
// this.updateTxParams(txParams.metamaskId, ethTx)
|
|
||||||
|
|
||||||
// listener is assigned in metamaskController
|
// listener is assigned in metamaskController
|
||||||
this.emit(`${txParams.metamaskId}:formated`, ethTx, address, txParams.metamaskId, cb)
|
this.emit(`${txParams.metamaskId}:formatted`, ethTx, address, txParams.metamaskId, cb)
|
||||||
}
|
}
|
||||||
|
|
||||||
// receives a signed tx object and updates the tx hash
|
// receives a signed tx object and updates the tx hash
|
||||||
// and pass it to the cb to be sent off
|
// and pass it to the cb to be sent off
|
||||||
resolveSignedTransaction ({tx, txId, cb}) {
|
resolveSignedTransaction ({tx, txId, cb = warn}) {
|
||||||
// Add the tx hash to the persisted meta-tx object
|
// Add the tx hash to the persisted meta-tx object
|
||||||
var txHash = ethUtil.bufferToHex(tx.hash())
|
var txHash = ethUtil.bufferToHex(tx.hash())
|
||||||
var metaTx = this.getTx(txId)
|
var metaTx = this.getTx(txId)
|
||||||
@ -212,13 +216,13 @@ module.exports = class TransactionManager extends EventEmitter {
|
|||||||
// should update the status of the tx to 'signed'.
|
// should update the status of the tx to 'signed'.
|
||||||
setTxStatusSigned (txId) {
|
setTxStatusSigned (txId) {
|
||||||
this._setTxStatus(txId, 'signed')
|
this._setTxStatus(txId, 'signed')
|
||||||
this.emit('update')
|
this.emit('updateBadge')
|
||||||
}
|
}
|
||||||
|
|
||||||
// should update the status of the tx to 'rejected'.
|
// should update the status of the tx to 'rejected'.
|
||||||
setTxStatusRejected (txId) {
|
setTxStatusRejected (txId) {
|
||||||
this._setTxStatus(txId, 'rejected')
|
this._setTxStatus(txId, 'rejected')
|
||||||
this.emit('update')
|
this.emit('updateBadge')
|
||||||
}
|
}
|
||||||
|
|
||||||
setTxStatusConfirmed (txId) {
|
setTxStatusConfirmed (txId) {
|
||||||
@ -281,4 +285,4 @@ module.exports = class TransactionManager extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const noop = () => console.warn('noop was used no cb provided')
|
const warn = () => console.warn('warn was used no cb provided')
|
||||||
|
@ -80,7 +80,7 @@ describe('Transaction Manager', function() {
|
|||||||
}
|
}
|
||||||
var result = txManager.getTxList()
|
var result = txManager.getTxList()
|
||||||
assert.equal(result.length, limit, `limit of ${limit} txs enforced`)
|
assert.equal(result.length, limit, `limit of ${limit} txs enforced`)
|
||||||
assert.equal(result[0].id, 0, 'first tx should still be their')
|
assert.equal(result[0].id, 0, 'first tx should still be there')
|
||||||
assert.equal(result[0].status, 'unapproved', 'first tx should be unapproved')
|
assert.equal(result[0].status, 'unapproved', 'first tx should be unapproved')
|
||||||
assert.equal(result[1].id, 2, 'early txs truncted')
|
assert.equal(result[1].id, 2, 'early txs truncted')
|
||||||
})
|
})
|
||||||
@ -168,15 +168,15 @@ describe('Transaction Manager', function() {
|
|||||||
var foop = 0
|
var foop = 0
|
||||||
var zoop = 0
|
var zoop = 0
|
||||||
for (let i = 0; i < 10; ++i ){
|
for (let i = 0; i < 10; ++i ){
|
||||||
let evryOther = i % 2
|
let everyOther = i % 2
|
||||||
txManager.addTx({ id: i,
|
txManager.addTx({ id: i,
|
||||||
status: evryOther ? 'unapproved' : 'confirmed',
|
status: everyOther ? 'unapproved' : 'confirmed',
|
||||||
txParams: {
|
txParams: {
|
||||||
from: evryOther ? 'foop' : 'zoop',
|
from: everyOther ? 'foop' : 'zoop',
|
||||||
to: evryOther ? 'zoop' : 'foop',
|
to: everyOther ? 'zoop' : 'foop',
|
||||||
}
|
}
|
||||||
}, onTxDoneCb)
|
}, onTxDoneCb)
|
||||||
evryOther ? ++foop : ++zoop
|
everyOther ? ++foop : ++zoop
|
||||||
}
|
}
|
||||||
assert.equal(txManager.getFilteredTxList({status: 'confirmed', from: 'zoop'}).length, zoop)
|
assert.equal(txManager.getFilteredTxList({status: 'confirmed', from: 'zoop'}).length, zoop)
|
||||||
assert.equal(txManager.getFilteredTxList({status: 'confirmed', to: 'foop'}).length, zoop)
|
assert.equal(txManager.getFilteredTxList({status: 'confirmed', to: 'foop'}).length, zoop)
|
||||||
|
Loading…
Reference in New Issue
Block a user