aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/send-v2.js
diff options
context:
space:
mode:
authorAlexander Tseung <alextsg@gmail.com>2018-01-17 08:08:42 +0800
committerChi Kei Chan <chikeichan@gmail.com>2018-01-17 09:26:34 +0800
commitccb80594be3000488b7c73f9fd5e56168e0d5042 (patch)
tree80642abbd7ad78ba5f13027fd8638811203d4ea9 /ui/app/send-v2.js
parent668aab11d1aa94111252fee3d2abd20c207be71b (diff)
downloadtangerine-wallet-browser-ccb80594be3000488b7c73f9fd5e56168e0d5042.tar
tangerine-wallet-browser-ccb80594be3000488b7c73f9fd5e56168e0d5042.tar.gz
tangerine-wallet-browser-ccb80594be3000488b7c73f9fd5e56168e0d5042.tar.bz2
tangerine-wallet-browser-ccb80594be3000488b7c73f9fd5e56168e0d5042.tar.lz
tangerine-wallet-browser-ccb80594be3000488b7c73f9fd5e56168e0d5042.tar.xz
tangerine-wallet-browser-ccb80594be3000488b7c73f9fd5e56168e0d5042.tar.zst
tangerine-wallet-browser-ccb80594be3000488b7c73f9fd5e56168e0d5042.zip
Readjust gas fees when switching networks on the send screen
Diffstat (limited to 'ui/app/send-v2.js')
-rw-r--r--ui/app/send-v2.js65
1 files changed, 43 insertions, 22 deletions
diff --git a/ui/app/send-v2.js b/ui/app/send-v2.js
index ca73fa5ea..d9187fd80 100644
--- a/ui/app/send-v2.js
+++ b/ui/app/send-v2.js
@@ -85,6 +85,20 @@ SendTransactionScreen.prototype.componentWillMount = function () {
const {
updateTokenExchangeRate,
selectedToken = {},
+ } = this.props
+
+ const { symbol } = selectedToken || {}
+
+ if (symbol) {
+ updateTokenExchangeRate(symbol)
+ }
+
+ this.updateGas()
+}
+
+SendTransactionScreen.prototype.updateGas = function () {
+ const {
+ selectedToken = {},
getGasPrice,
estimateGas,
selectedAddress,
@@ -96,17 +110,16 @@ SendTransactionScreen.prototype.componentWillMount = function () {
gasPrice,
gasLimit,
} = this.props
- const { symbol } = selectedToken || {}
- if (symbol) {
- updateTokenExchangeRate(symbol)
- }
+ const { symbol } = selectedToken || {}
- const estimateGasParams = getParamsForGasEstimate(selectedAddress, symbol, data)
+ const tokenBalancePromise = tokenContract
+ ? tokenContract.balanceOf(from.address)
+ : Promise.resolve()
- const tokenBalancePromise = tokenContract && tokenContract.balanceOf(from.address)
- let newGasTotal
if (!editingTransactionId) {
+ const estimateGasParams = getParamsForGasEstimate(selectedAddress, symbol, data)
+
Promise
.all([
getGasPrice(),
@@ -114,27 +127,26 @@ SendTransactionScreen.prototype.componentWillMount = function () {
tokenBalancePromise,
])
.then(([gasPrice, gas, usersToken]) => {
-
- const newGasTotal = multiplyCurrencies(gas, gasPrice, {
- toNumericBase: 'hex',
- multiplicandBase: 16,
- multiplierBase: 16,
- })
+ const newGasTotal = this.getGasTotal(gas, gasPrice)
updateGasTotal(newGasTotal)
this.updateSendTokenBalance(usersToken)
})
} else {
- newGasTotal = multiplyCurrencies(gasLimit, gasPrice, {
- toNumericBase: 'hex',
- multiplicandBase: 16,
- multiplierBase: 16,
- })
+ const newGasTotal = this.getGasTotal(gasLimit, gasPrice)
updateGasTotal(newGasTotal)
- tokenBalancePromise && tokenBalancePromise.then(
- usersToken => this.updateSendTokenBalance(usersToken))
+ tokenBalancePromise
+ .then(usersToken => this.updateSendTokenBalance(usersToken))
}
}
+SendTransactionScreen.prototype.getGasTotal = function (gasLimit, gasPrice) {
+ return multiplyCurrencies(gasLimit, gasPrice, {
+ toNumericBase: 'hex',
+ multiplicandBase: 16,
+ multiplierBase: 16,
+ })
+}
+
SendTransactionScreen.prototype.componentDidUpdate = function (prevProps) {
const {
from: { balance },
@@ -142,11 +154,14 @@ SendTransactionScreen.prototype.componentDidUpdate = function (prevProps) {
tokenBalance,
amount,
selectedToken,
+ network,
} = this.props
+
const {
from: { balance: prevBalance },
gasTotal: prevGasTotal,
tokenBalance: prevTokenBalance,
+ network: prevNetwork,
} = prevProps
const notFirstRender = [prevBalance, prevGasTotal].every(n => n !== null)
@@ -156,8 +171,14 @@ SendTransactionScreen.prototype.componentDidUpdate = function (prevProps) {
const tokenBalanceHasChanged = selectedToken && tokenBalance !== prevTokenBalance
const amountValidationChange = balanceHasChanged || gasTotalHasChange || tokenBalanceHasChanged
- if (notFirstRender && amountValidationChange) {
- this.validateAmount(amount)
+ if (notFirstRender) {
+ if (amountValidationChange) {
+ this.validateAmount(amount)
+ }
+
+ if (network !== prevNetwork && network !== 'loading') {
+ this.updateGas()
+ }
}
}