diff options
Diffstat (limited to 'ui/app/conf-tx.js')
-rw-r--r-- | ui/app/conf-tx.js | 69 |
1 files changed, 56 insertions, 13 deletions
diff --git a/ui/app/conf-tx.js b/ui/app/conf-tx.js index 43604e8cf..a27219576 100644 --- a/ui/app/conf-tx.js +++ b/ui/app/conf-tx.js @@ -4,7 +4,11 @@ const ReactCSSTransitionGroup = require('react-addons-css-transition-group') const h = require('react-hyperscript') const connect = require('react-redux').connect const actions = require('./actions') +const NetworkIndicator = require('./components/network') const txHelper = require('../lib/tx-helper') +const isPopupOrNotification = require('../../app/scripts/lib/is-popup-or-notification') +const ethUtil = require('ethereumjs-util') +const BN = ethUtil.BN const PendingTx = require('./components/pending-tx') const PendingMsg = require('./components/pending-msg') @@ -16,10 +20,12 @@ function mapStateToProps (state) { identities: state.metamask.identities, accounts: state.metamask.accounts, selectedAddress: state.metamask.selectedAddress, - unconfTxs: state.metamask.unconfTxs, - unconfMsgs: state.metamask.unconfMsgs, + unapprovedTxs: state.metamask.unapprovedTxs, + unapprovedMsgs: state.metamask.unapprovedMsgs, index: state.appState.currentView.context, warning: state.appState.warning, + network: state.metamask.network, + provider: state.metamask.provider, } } @@ -31,11 +37,17 @@ function ConfirmTxScreen () { ConfirmTxScreen.prototype.render = function () { var state = this.props - var unconfTxs = state.unconfTxs - var unconfMsgs = state.unconfMsgs - var unconfTxList = txHelper(unconfTxs, unconfMsgs) - var index = state.index !== undefined ? state.index : 0 - var txData = unconfTxList[index] || unconfTxList[0] || {} + var network = state.network + var provider = state.provider + var unapprovedTxs = state.unapprovedTxs + var unapprovedMsgs = state.unapprovedMsgs + + var unconfTxList = txHelper(unapprovedTxs, unapprovedMsgs, network) + var index = state.index !== undefined && unconfTxList[index] ? state.index : 0 + var txData = unconfTxList[index] || {} + var txParams = txData.params || {} + var isNotification = isPopupOrNotification() === 'notification' + if (unconfTxList.length === 0) return null return ( @@ -43,10 +55,14 @@ ConfirmTxScreen.prototype.render = function () { // subtitle and nav h('.section-title.flex-row.flex-center', [ - h('i.fa.fa-arrow-left.fa-lg.cursor-pointer', { + !isNotification ? h('i.fa.fa-arrow-left.fa-lg.cursor-pointer', { onClick: this.goHome.bind(this), - }), + }) : null, h('h2.page-subtitle', 'Confirm Transaction'), + isNotification ? h(NetworkIndicator, { + network: network, + provider: provider, + }) : null, ]), h('h3', { @@ -86,7 +102,9 @@ ConfirmTxScreen.prototype.render = function () { selectedAddress: state.selectedAddress, accounts: state.accounts, identities: state.identities, + insufficientBalance: this.checkBalanceAgainstTx(txData), // Actions + buyEth: this.buyEth.bind(this, txParams.from || state.selectedAddress), sendTransaction: this.sendTransaction.bind(this, txData), cancelTransaction: this.cancelTransaction.bind(this, txData), signMessage: this.signMessage.bind(this, txData), @@ -99,14 +117,33 @@ ConfirmTxScreen.prototype.render = function () { } function currentTxView (opts) { - if ('txParams' in opts.txData) { + const { txData } = opts + const { txParams, msgParams } = txData + + if (txParams) { // This is a pending transaction return h(PendingTx, opts) - } else if ('msgParams' in opts.txData) { + } else if (msgParams) { // This is a pending message to sign return h(PendingMsg, opts) } } +ConfirmTxScreen.prototype.checkBalanceAgainstTx = function (txData) { + if (!txData.txParams) return false + var state = this.props + var address = txData.txParams.from || state.selectedAddress + var account = state.accounts[address] + var balance = account ? account.balance : '0x0' + var maxCost = new BN(txData.maxCost, 16) + + var balanceBn = new BN(ethUtil.stripHexPrefix(balance), 16) + return maxCost.gt(balanceBn) +} + +ConfirmTxScreen.prototype.buyEth = function (address, event) { + event.stopPropagation() + this.props.dispatch(actions.buyEthView(address)) +} ConfirmTxScreen.prototype.sendTransaction = function (txData, event) { event.stopPropagation() @@ -136,7 +173,13 @@ ConfirmTxScreen.prototype.goHome = function (event) { } function warningIfExists (warning) { - if (warning) { - return h('span.error', { style: { margin: 'auto' } }, warning) + if (warning && + // Do not display user rejections on this screen: + warning.indexOf('User denied transaction signature') === -1) { + return h('.error', { + style: { + margin: 'auto', + }, + }, warning) } } |