aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/actions.js
diff options
context:
space:
mode:
authorDan <danjm.com@gmail.com>2018-04-28 03:03:00 +0800
committerDan <danjm.com@gmail.com>2018-04-30 23:35:48 +0800
commit26f965bcceb26ce7cdec9df9f213b44be8d9acac (patch)
tree155bad73750b5c3905f799eac6d298c9dc7305dc /ui/app/actions.js
parent33c16d1bf62133a87d8f24232ee85438a6b6a0e6 (diff)
downloadtangerine-wallet-browser-26f965bcceb26ce7cdec9df9f213b44be8d9acac.tar
tangerine-wallet-browser-26f965bcceb26ce7cdec9df9f213b44be8d9acac.tar.gz
tangerine-wallet-browser-26f965bcceb26ce7cdec9df9f213b44be8d9acac.tar.bz2
tangerine-wallet-browser-26f965bcceb26ce7cdec9df9f213b44be8d9acac.tar.lz
tangerine-wallet-browser-26f965bcceb26ce7cdec9df9f213b44be8d9acac.tar.xz
tangerine-wallet-browser-26f965bcceb26ce7cdec9df9f213b44be8d9acac.tar.zst
tangerine-wallet-browser-26f965bcceb26ce7cdec9df9f213b44be8d9acac.zip
Further refactors; includes refactor of send-v2.js and associated container
Diffstat (limited to 'ui/app/actions.js')
-rw-r--r--ui/app/actions.js70
1 files changed, 60 insertions, 10 deletions
diff --git a/ui/app/actions.js b/ui/app/actions.js
index 674669eed..7b838940a 100644
--- a/ui/app/actions.js
+++ b/ui/app/actions.js
@@ -1,6 +1,11 @@
const abi = require('human-standard-token-abi')
const getBuyEthUrl = require('../../app/scripts/lib/buy-eth-url')
const { getTokenAddressFromTokenObject } = require('./util')
+const {
+ calcGasTotal,
+ getParamsForGasEstimate,
+ calcTokenBalance,
+} = require('./components/send_/send.utils')
const ethUtil = require('ethereumjs-util')
const { fetchLocale } = require('../i18n-helper')
const log = require('loglevel')
@@ -173,14 +178,16 @@ var actions = {
updateGasLimit,
updateGasPrice,
updateGasTotal,
+ setGasTotal,
+ setSendTokenBalance,
updateSendTokenBalance,
updateSendFrom,
updateSendTo,
updateSendAmount,
updateSendMemo,
- updateSendErrors,
setMaxModeTo,
updateSend,
+ updateSendErrors,
clearSend,
setSelectedAddress,
// app messages
@@ -716,14 +723,64 @@ function updateGasPrice (gasPrice) {
}
}
-function updateGasTotal (gasTotal) {
+function setGasTotal (gasTotal) {
return {
type: actions.UPDATE_GAS_TOTAL,
value: gasTotal,
}
}
-function updateSendTokenBalance (tokenBalance) {
+function updateGasTotal ({ selectedAddress, selectedToken, data }) {
+ return (dispatch) => {
+ const { symbol } = selectedToken || {}
+ const estimateGasParams = getParamsForGasEstimate(selectedAddress, symbol, data)
+ return Promise.all([
+ dispatch(actions.getGasPrice()),
+ dispatch(actions.estimateGas(estimateGasParams)),
+ ])
+ .then(([gasPrice, gas]) => {
+ const newGasTotal = calcGasTotal(gas, gasPrice)
+ dispatch(actions.setGasTotal(newGasTotal))
+ dispatch(updateSendErrors({ gasLoadingError: null }))
+ })
+ .catch(err => {
+ log.error(err)
+ dispatch(updateSendErrors({ gasLoadingError: 'gasLoadingError' }))
+ })
+ }
+}
+
+function updateSendTokenBalance ({
+ selectedToken,
+ tokenContract,
+ address,
+}) {
+ return (dispatch) => {
+ const tokenBalancePromise = tokenContract
+ ? tokenContract.balanceOf(address)
+ : Promise.resolve()
+ return tokenBalancePromise
+ .then(usersToken => {
+ if (usersToken) {
+ const newTokenBalance = calcTokenBalance({ selectedToken, usersToken })
+ dispatch(setSendTokenBalance(newTokenBalance))
+ }
+ })
+ .catch(err => {
+ log.error(err)
+ updateSendErrors({ tokenBalance: 'tokenBalanceError' })
+ })
+ }
+}
+
+function updateSendErrors (errorObject) {
+ return {
+ type: actions.UPDATE_SEND_ERRORS,
+ value: errorObject,
+ }
+}
+
+function setSendTokenBalance (tokenBalance) {
return {
type: actions.UPDATE_SEND_TOKEN_BALANCE,
value: tokenBalance,
@@ -758,13 +815,6 @@ function updateSendMemo (memo) {
}
}
-function updateSendErrors (error) {
- return {
- type: actions.UPDATE_SEND_ERRORS,
- value: error,
- }
-}
-
function setMaxModeTo (bool) {
return {
type: actions.UPDATE_MAX_MODE,