diff options
author | Frankie <frankie.pangilinan@consensys.net> | 2016-09-16 01:24:05 +0800 |
---|---|---|
committer | Frankie <frankie.pangilinan@consensys.net> | 2016-09-16 01:24:05 +0800 |
commit | ef0b535d94d97827b4bfc471e4d950d90d637fa3 (patch) | |
tree | 1f59298dffe5992e3e1552b0460dd442aa3412c9 /ui/app/conf-tx.js | |
parent | 17eb53cfcd77b3832f92533a53d82726d1e152e7 (diff) | |
download | tangerine-wallet-browser-ef0b535d94d97827b4bfc471e4d950d90d637fa3.tar tangerine-wallet-browser-ef0b535d94d97827b4bfc471e4d950d90d637fa3.tar.gz tangerine-wallet-browser-ef0b535d94d97827b4bfc471e4d950d90d637fa3.tar.bz2 tangerine-wallet-browser-ef0b535d94d97827b4bfc471e4d950d90d637fa3.tar.lz tangerine-wallet-browser-ef0b535d94d97827b4bfc471e4d950d90d637fa3.tar.xz tangerine-wallet-browser-ef0b535d94d97827b4bfc471e4d950d90d637fa3.tar.zst tangerine-wallet-browser-ef0b535d94d97827b4bfc471e4d950d90d637fa3.zip |
Drop the buy button in the confTx view if account does not have enough eth
Diffstat (limited to 'ui/app/conf-tx.js')
-rw-r--r-- | ui/app/conf-tx.js | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/ui/app/conf-tx.js b/ui/app/conf-tx.js index 99b4bc9f1..0c3e32cea 100644 --- a/ui/app/conf-tx.js +++ b/ui/app/conf-tx.js @@ -6,6 +6,8 @@ const connect = require('react-redux').connect const actions = require('./actions') 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') @@ -113,8 +115,26 @@ function currentTxView (opts) { } ConfirmTxScreen.prototype.sendTransaction = function (txData, event) { + var state = this.props + + var txParams = txData.txParams || {} + var address = txParams.from || state.selectedAddress + var account = state.accounts[address] + var balance = account ? account.balance : '0x0' + + var gasCost = new BN(ethUtil.stripHexPrefix(txParams.gas || txData.estimatedGas), 16) + var gasPrice = new BN(ethUtil.stripHexPrefix(txParams.gasPrice || '0x4a817c800'), 16) + var txFee = gasCost.mul(gasPrice) + var txValue = new BN(ethUtil.stripHexPrefix(txParams.value || '0x0'), 16) + var maxCost = txValue.add(txFee) + + var balanceBn = new BN(ethUtil.stripHexPrefix(balance), 16) event.stopPropagation() - this.props.dispatch(actions.sendTx(txData)) + if (maxCost.gt(balanceBn)) { + this.props.dispatch(actions.buyEthView(address)) + } else { + this.props.dispatch(actions.sendTx(txData)) + } } ConfirmTxScreen.prototype.cancelTransaction = function (txData, event) { |