aboutsummaryrefslogtreecommitdiffstats
path: root/app/scripts
diff options
context:
space:
mode:
authorFrankie <frankie.diamond@gmail.com>2017-01-11 03:52:25 +0800
committerFrankie <frankie.diamond@gmail.com>2017-01-12 04:16:37 +0800
commit0fae263a9acb1f4023070b37ee1b91815e34de86 (patch)
tree06ce3969f56a2b6d2c5d4316dc6367b79540cb44 /app/scripts
parentaf312bdc90139f99a9a08f9d0f67d63e005e2a20 (diff)
downloadtangerine-wallet-browser-0fae263a9acb1f4023070b37ee1b91815e34de86.tar
tangerine-wallet-browser-0fae263a9acb1f4023070b37ee1b91815e34de86.tar.gz
tangerine-wallet-browser-0fae263a9acb1f4023070b37ee1b91815e34de86.tar.bz2
tangerine-wallet-browser-0fae263a9acb1f4023070b37ee1b91815e34de86.tar.lz
tangerine-wallet-browser-0fae263a9acb1f4023070b37ee1b91815e34de86.tar.xz
tangerine-wallet-browser-0fae263a9acb1f4023070b37ee1b91815e34de86.tar.zst
tangerine-wallet-browser-0fae263a9acb1f4023070b37ee1b91815e34de86.zip
Take some of the tx Logic out of the UI and create a visble state for pending and unaproved transactions
Diffstat (limited to 'app/scripts')
-rw-r--r--app/scripts/background.js1
-rw-r--r--app/scripts/keyring-controller.js2
-rw-r--r--app/scripts/metamask-controller.js1
-rw-r--r--app/scripts/transaction-manager.js33
4 files changed, 28 insertions, 9 deletions
diff --git a/app/scripts/background.js b/app/scripts/background.js
index 6b7926526..3f15488ee 100644
--- a/app/scripts/background.js
+++ b/app/scripts/background.js
@@ -27,7 +27,6 @@ function triggerUi () {
if (!popupIsOpen) notification.show()
}
// On first install, open a window to MetaMask website to how-it-works.
-
extension.runtime.onInstalled.addListener(function (details) {
if ((details.reason === 'install') && (!METAMASK_DEBUG)) {
extension.tabs.create({url: 'https://metamask.io/#how-it-works'})
diff --git a/app/scripts/keyring-controller.js b/app/scripts/keyring-controller.js
index c58be0aae..a457a2560 100644
--- a/app/scripts/keyring-controller.js
+++ b/app/scripts/keyring-controller.js
@@ -95,7 +95,6 @@ module.exports = class KeyringController extends EventEmitter {
isInitialized: (!!wallet || !!vault),
isUnlocked: Boolean(this.password),
isDisclaimerConfirmed: this.configManager.getConfirmedDisclaimer(),
- transactions: this.configManager.getTxList(),
unconfMsgs: messageManager.unconfirmedMsgs(),
messages: messageManager.getMsgList(),
selectedAccount: address,
@@ -273,6 +272,7 @@ module.exports = class KeyringController extends EventEmitter {
setSelectedAccount (address) {
var addr = normalize(address)
this.configManager.setSelectedAccount(addr)
+ this.emit('update')
return Promise.resolve(addr)
}
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js
index 555460f3d..ae7aee9e3 100644
--- a/app/scripts/metamask-controller.js
+++ b/app/scripts/metamask-controller.js
@@ -64,6 +64,7 @@ module.exports = class MetamaskController extends EventEmitter {
this.ethStore.on('update', this.sendUpdate.bind(this))
this.keyringController.on('update', this.sendUpdate.bind(this))
+ this.txManager.on('update', this.sendUpdate.bind(this))
}
getState () {
diff --git a/app/scripts/transaction-manager.js b/app/scripts/transaction-manager.js
index 6becfa6d1..a279ba23a 100644
--- a/app/scripts/transaction-manager.js
+++ b/app/scripts/transaction-manager.js
@@ -25,9 +25,8 @@ 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}),
+ transactions: this.getFilteredTxList({metamaskNetworkId: this.getNetwork(), from: selectedAccount}),
}
}
@@ -113,10 +112,26 @@ module.exports = class TransactionManager extends EventEmitter {
txDidComplete (txMeta, onTxDoneCb, cb, err) {
if (err) return cb(err)
+ var {maxCost, txFee} = this.getMaxTxCostAndFee(txMeta)
+ txMeta.maxCost = maxCost
+ txMeta.txFee = txFee
this.addTx(txMeta, onTxDoneCb)
cb(null, txMeta)
}
+ getMaxTxCostAndFee (txMeta) {
+ var txParams = txMeta.txParams
+
+ var gasMultiplier = txMeta.gasMultiplier
+ var gasCost = new BN(ethUtil.stripHexPrefix(txParams.gas || txMeta.estimatedGas), 16)
+ var gasPrice = new BN(ethUtil.stripHexPrefix(txParams.gasPrice || '0x4a817c800'), 16)
+ gasPrice = gasPrice.mul(new BN(gasMultiplier * 100), 10).div(new BN(100, 10))
+ var txFee = gasCost.mul(gasPrice)
+ var txValue = new BN(ethUtil.stripHexPrefix(txParams.value || '0x0'), 16)
+ var maxCost = txValue.add(txFee)
+ return {maxCost, txFee}
+ }
+
getUnapprovedTxList () {
var txList = this.getTxList()
return txList.filter((txMeta) => txMeta.status === 'unapproved')
@@ -227,6 +242,7 @@ module.exports = class TransactionManager extends EventEmitter {
setTxStatusConfirmed (txId) {
this._setTxStatus(txId, 'confirmed')
+ this.emit('update')
}
// merges txParams obj onto txData.txParams
@@ -240,17 +256,20 @@ module.exports = class TransactionManager extends EventEmitter {
// checks if a signed tx is in a block and
// if included sets the tx status as 'confirmed'
checkForTxInBlock () {
- var signedTxList = this.getFilteredTxList({status: 'signed', err: undefined})
+ var signedTxList = this.getFilteredTxList({status: 'signed'})
if (!signedTxList.length) return
signedTxList.forEach((tx) => {
var txHash = tx.hash
var txId = tx.id
- if (!txHash) return
+ if (!txHash) {
+ tx.err = { errCode: 'No hash was provided', message: 'Tx could possibly have not been submitted or an error accrued during signing'}
+ return this.updateTx(tx)
+ }
this.txProviderUtils.query.getTransactionByHash(txHash, (err, txMeta) => {
- if (err || !txMeta) {
- tx.err = err || 'Tx could possibly have not been submitted'
+ if (err) {
+ tx.err = {errorCode: err, message: 'Tx could possibly have not been submitted to the block chain',}
this.updateTx(tx)
- return txMeta ? console.error(err) : console.debug(`txMeta is ${txMeta} for:`, tx)
+ return console.error(err)
}
if (txMeta.blockNumber) {
this.setTxStatusConfirmed(txId)