aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorFrankie <frankie.diamond@gmail.com>2016-12-24 04:34:12 +0800
committerFrankie <frankie.diamond@gmail.com>2016-12-24 04:43:42 +0800
commitfde69ea0baf32b5d2a6932b73f4772e983aef552 (patch)
treed0cc11af3a427e7985ceb03fd9f10e6db4d137ac /app
parent9e1c90eafcace4ac67100ae0a567faba13f9e618 (diff)
downloadtangerine-wallet-browser-fde69ea0baf32b5d2a6932b73f4772e983aef552.tar
tangerine-wallet-browser-fde69ea0baf32b5d2a6932b73f4772e983aef552.tar.gz
tangerine-wallet-browser-fde69ea0baf32b5d2a6932b73f4772e983aef552.tar.bz2
tangerine-wallet-browser-fde69ea0baf32b5d2a6932b73f4772e983aef552.tar.lz
tangerine-wallet-browser-fde69ea0baf32b5d2a6932b73f4772e983aef552.tar.xz
tangerine-wallet-browser-fde69ea0baf32b5d2a6932b73f4772e983aef552.tar.zst
tangerine-wallet-browser-fde69ea0baf32b5d2a6932b73f4772e983aef552.zip
fix some minor spelling mistakes and clean up code
Diffstat (limited to 'app')
-rw-r--r--app/scripts/background.js2
-rw-r--r--app/scripts/metamask-controller.js10
-rw-r--r--app/scripts/transaction-manager.js42
3 files changed, 26 insertions, 28 deletions
diff --git a/app/scripts/background.js b/app/scripts/background.js
index d05ec989f..ca2efc114 100644
--- a/app/scripts/background.js
+++ b/app/scripts/background.js
@@ -97,7 +97,7 @@ function setupControllerConnection (stream) {
// plugin badge text
//
-txManager.on('update', updateBadge)
+txManager.on('updateBadge', updateBadge)
function updateBadge () {
var label = ''
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js
index 6aec825fe..4af5cd78d 100644
--- a/app/scripts/metamask-controller.js
+++ b/app/scripts/metamask-controller.js
@@ -21,7 +21,6 @@ module.exports = class MetamaskController {
this.configManager = new ConfigManager(opts)
this.keyringController = new KeyringController({
configManager: this.configManager,
- txManager: this.txManager,
getNetwork: this.getStateNetwork.bind(this),
})
// notices
@@ -40,6 +39,7 @@ module.exports = class MetamaskController {
txList: this.configManager.getTxList(),
txHistoryLimit: 40,
setTxList: this.configManager.setTxList.bind(this.configManager),
+ getSelectedAccount: this.configManager.getSelectedAccount.bind(this.configManager),
getGasMultiplier: this.configManager.getGasMultiplier.bind(this.configManager),
getNetwork: this.getStateNetwork.bind(this),
provider: this.provider,
@@ -47,8 +47,6 @@ module.exports = class MetamaskController {
})
this.publicConfigStore = this.initPublicConfigStore()
-
-
var currentFiat = this.configManager.getCurrentFiat() || 'USD'
this.configManager.setCurrentFiat(currentFiat)
this.configManager.updateConversionRate()
@@ -105,9 +103,6 @@ module.exports = class MetamaskController {
signMessage: keyringController.signMessage.bind(keyringController),
cancelMessage: keyringController.cancelMessage.bind(keyringController),
- // forward directly to txManager
- getUnapprovedTxList: txManager.getUnapprovedTxList.bind(txManager),
- getFilteredTxList: txManager.getFilteredTxList.bind(txManager),
// coinbase
buyEth: this.buyEth.bind(this),
// shapeshift
@@ -251,11 +246,10 @@ module.exports = class MetamaskController {
setupSigningListners (txParams) {
var txId = txParams.metamaskId
// 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))
}
-
enforceTxValidations (txParams) {
if (('value' in txParams) && txParams.value.indexOf('-') === 0) {
const msg = `Invalid transaction value of ${txParams.value} not a positive number.`
diff --git a/app/scripts/transaction-manager.js b/app/scripts/transaction-manager.js
index 031993424..fd136a51b 100644
--- a/app/scripts/transaction-manager.js
+++ b/app/scripts/transaction-manager.js
@@ -12,10 +12,8 @@ module.exports = class TransactionManager extends EventEmitter {
super()
this.txList = opts.txList || []
this._setTxList = opts.setTxList
- this._unconfTxCbs = {}
this.txHistoryLimit = opts.txHistoryLimit
- // txManager :: tx approvals and rejection cb's
-
+ this.getSelectedAccount = opts.getSelectedAccount
this.provider = opts.provider
this.blockTracker = opts.blockTracker
this.txProviderUtils = new TxProviderUtil(this.provider)
@@ -25,9 +23,11 @@ module.exports = class TransactionManager extends EventEmitter {
}
getState () {
+ var selectedAccount = this.getSelectedAccount()
return {
transactions: this.getTxList(),
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
- addTx (txMeta, onTxDoneCb = noop) {
+ addTx (txMeta, onTxDoneCb = warn) {
var txList = this.getTxList()
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) {
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)
+
this._saveTxList(txList)
// keep the onTxDoneCb around in a listener
// for after approval/denial (requires user interaction)
@@ -58,14 +65,14 @@ module.exports = class TransactionManager extends EventEmitter {
onTxDoneCb(null, false)
})
- this.emit('update')
+ this.emit('updateBadge')
this.emit(`${txMeta.id}:unapproved`, txMeta)
}
// gets tx by Id and returns it
getTx (txId, cb) {
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
}
@@ -73,7 +80,7 @@ module.exports = class TransactionManager extends EventEmitter {
updateTx (txMeta) {
var txId = txMeta.id
var txList = this.getTxList()
- var index = txList.findIndex((txData) => txData.id === txId)
+ var index = txList.findIndex(txData => txData.id === txId)
txList[index] = txMeta
this._saveTxList(txList)
}
@@ -119,16 +126,14 @@ module.exports = class TransactionManager extends EventEmitter {
}, {})
}
- approveTransaction (txId, cb) {
+ approveTransaction (txId, cb = warn) {
this.setTxStatusSigned(txId)
cb()
}
- cancelTransaction (txId, cb) {
+ cancelTransaction (txId, cb = warn) {
this.setTxStatusRejected(txId)
- if (cb && typeof cb === 'function') {
- cb()
- }
+ cb()
}
// 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.nonce = normalize(txParams.nonce)
const ethTx = new Transaction(txParams)
- // this.updateTxParams(txParams.metamaskId, ethTx)
// 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
// 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
var txHash = ethUtil.bufferToHex(tx.hash())
var metaTx = this.getTx(txId)
@@ -212,13 +216,13 @@ module.exports = class TransactionManager extends EventEmitter {
// should update the status of the tx to 'signed'.
setTxStatusSigned (txId) {
this._setTxStatus(txId, 'signed')
- this.emit('update')
+ this.emit('updateBadge')
}
// should update the status of the tx to 'rejected'.
setTxStatusRejected (txId) {
this._setTxStatus(txId, 'rejected')
- this.emit('update')
+ this.emit('updateBadge')
}
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')