aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/conf-tx.js
diff options
context:
space:
mode:
authorDan Finlay <somniac@me.com>2016-09-16 06:00:42 +0800
committerGitHub <noreply@github.com>2016-09-16 06:00:42 +0800
commita5e45820cc7359491d1d7b06a5358d99b9c97305 (patch)
tree521c1baf581454c29b05c53a6598d5ec6fe8caa4 /ui/app/conf-tx.js
parent06b9adf172010600c7ac1127ff2ee76a7433e97b (diff)
parentcf484d735fab021a0dfe509243b957e8c6278532 (diff)
downloadtangerine-wallet-browser-a5e45820cc7359491d1d7b06a5358d99b9c97305.tar
tangerine-wallet-browser-a5e45820cc7359491d1d7b06a5358d99b9c97305.tar.gz
tangerine-wallet-browser-a5e45820cc7359491d1d7b06a5358d99b9c97305.tar.bz2
tangerine-wallet-browser-a5e45820cc7359491d1d7b06a5358d99b9c97305.tar.lz
tangerine-wallet-browser-a5e45820cc7359491d1d7b06a5358d99b9c97305.tar.xz
tangerine-wallet-browser-a5e45820cc7359491d1d7b06a5358d99b9c97305.tar.zst
tangerine-wallet-browser-a5e45820cc7359491d1d7b06a5358d99b9c97305.zip
Merge pull request #673 from MetaMask/i#519buyButtonTxConf
Drop the buy button in if tx is more then account balance
Diffstat (limited to 'ui/app/conf-tx.js')
-rw-r--r--ui/app/conf-tx.js27
1 files changed, 27 insertions, 0 deletions
diff --git a/ui/app/conf-tx.js b/ui/app/conf-tx.js
index f02b6be78..f4ca52860 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')
@@ -39,6 +41,7 @@ ConfirmTxScreen.prototype.render = function () {
var unconfTxList = txHelper(unconfTxs, unconfMsgs, network)
var index = state.index !== undefined ? state.index : 0
var txData = unconfTxList[index] || unconfTxList[0] || {}
+ var txParams = txData.txParams || {}
var isNotification = isPopupOrNotification() === 'notification'
return (
@@ -90,7 +93,9 @@ ConfirmTxScreen.prototype.render = function () {
selectedAddress: state.selectedAddress,
accounts: state.accounts,
identities: state.identities,
+ insufficientBalance: this.checkBalnceAgainstTx(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),
@@ -111,6 +116,28 @@ function currentTxView (opts) {
return h(PendingMsg, opts)
}
}
+ConfirmTxScreen.prototype.checkBalnceAgainstTx = function (txData) {
+ 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)
+ 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()