aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/pending-tx/index.js
diff options
context:
space:
mode:
authorChi Kei Chan <chikeichan@gmail.com>2017-09-23 05:34:56 +0800
committerChi Kei Chan <chikeichan@gmail.com>2017-09-23 05:38:17 +0800
commite1077836ce916e2bd788451e3f365324024a1c0c (patch)
tree77954f105cc7c693a57ac8790c928286bed5d384 /ui/app/components/pending-tx/index.js
parent13f22ff6b087f3865f84a0672a9013ada88be61a (diff)
downloadtangerine-wallet-browser-e1077836ce916e2bd788451e3f365324024a1c0c.tar.gz
tangerine-wallet-browser-e1077836ce916e2bd788451e3f365324024a1c0c.tar.zst
tangerine-wallet-browser-e1077836ce916e2bd788451e3f365324024a1c0c.zip
Add Confirm Send token screen
Diffstat (limited to 'ui/app/components/pending-tx/index.js')
-rw-r--r--ui/app/components/pending-tx/index.js73
1 files changed, 56 insertions, 17 deletions
diff --git a/ui/app/components/pending-tx/index.js b/ui/app/components/pending-tx/index.js
index 3797b5642..915319958 100644
--- a/ui/app/components/pending-tx/index.js
+++ b/ui/app/components/pending-tx/index.js
@@ -9,6 +9,7 @@ const inherits = require('util').inherits
const actions = require('../../actions')
const util = require('../../util')
const ConfirmSendEther = require('./confirm-send-ether')
+const ConfirmSendToken = require('./confirm-send-token')
const TX_TYPES = {
DEPLOY_CONTRACT: 'deploy_contract',
@@ -46,33 +47,51 @@ function PendingTx () {
this.state = {
isFetching: true,
transactionType: '',
+ tokenAddress: '',
+ tokenSymbol: '',
+ tokenDecimals: '',
}
}
-PendingTx.prototype.componentWillMount = function () {
+PendingTx.prototype.componentWillMount = async function () {
const txMeta = this.gatherTxMeta()
const txParams = txMeta.txParams || {}
this.props.setCurrentCurrencyToUSD()
- if (txParams.to) {
+ if (!txParams.to) {
+ return this.setState({
+ transactionType: TX_TYPES.DEPLOY_CONTRACT,
+ isFetching: false,
+ })
+ }
+
+ try {
const token = util.getContractAtAddress(txParams.to)
- token
- .symbol()
- .then(result => {
- const symbol = result[0] || null
+ const results = await Promise.all([
+ token.symbol(),
+ token.decimals(),
+ ])
+
+ const [ symbol, decimals ] = results
+
+ if (symbol[0] && decimals[0]) {
this.setState({
- transactionType: symbol ? TX_TYPES.SEND_TOKEN : TX_TYPES.SEND_ETHER,
+ transactionType: TX_TYPES.SEND_TOKEN,
+ tokenAddress: txParams.to,
+ tokenSymbol: symbol[0],
+ tokenDecimals: decimals[0],
isFetching: false,
})
- })
- .catch(() => this.setState({
- transactionType: TX_TYPES.SEND_ETHER,
- isFetching: false,
- }))
- } else {
+ } else {
+ this.setState({
+ transactionType: TX_TYPES.SEND_ETHER,
+ isFetching: false,
+ })
+ }
+ } catch (e) {
this.setState({
- transactionType: TX_TYPES.DEPLOY_CONTRACT,
+ transactionType: TX_TYPES.SEND_ETHER,
isFetching: false,
})
}
@@ -87,16 +106,36 @@ PendingTx.prototype.gatherTxMeta = function () {
}
PendingTx.prototype.render = function () {
- const { isFetching, transactionType } = this.state
+ const {
+ isFetching,
+ transactionType,
+ tokenAddress,
+ tokenSymbol,
+ tokenDecimals,
+ } = this.state
+
+ const { sendTransaction } = this.props
if (isFetching) {
return h('noscript')
}
-
switch (transactionType) {
case TX_TYPES.SEND_ETHER:
- return h(ConfirmSendEther, { txData: this.gatherTxMeta() })
+ return h(ConfirmSendEther, {
+ txData: this.gatherTxMeta(),
+ sendTransaction,
+ })
+ case TX_TYPES.SEND_TOKEN:
+ return h(ConfirmSendToken, {
+ txData: this.gatherTxMeta(),
+ sendTransaction,
+ token: {
+ address: tokenAddress,
+ symbol: tokenSymbol,
+ decimals: tokenDecimals,
+ },
+ })
default:
return h('noscript')
}