aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2017-06-28 06:08:29 +0800
committerDan Finlay <dan@danfinlay.com>2017-06-28 06:08:29 +0800
commit40223687aeb8a5a593ab5af572e617f230f89140 (patch)
treec0e9aa485c8ce2d01b2d649e34d35ef18b50583a
parent58e993ff29ec5bc19abeb34d01c71ded60251b7e (diff)
parent307e967a0c2f059e8e2c742c282ba5b43c311cb0 (diff)
downloadtangerine-wallet-browser-40223687aeb8a5a593ab5af572e617f230f89140.tar
tangerine-wallet-browser-40223687aeb8a5a593ab5af572e617f230f89140.tar.gz
tangerine-wallet-browser-40223687aeb8a5a593ab5af572e617f230f89140.tar.bz2
tangerine-wallet-browser-40223687aeb8a5a593ab5af572e617f230f89140.tar.lz
tangerine-wallet-browser-40223687aeb8a5a593ab5af572e617f230f89140.tar.xz
tangerine-wallet-browser-40223687aeb8a5a593ab5af572e617f230f89140.tar.zst
tangerine-wallet-browser-40223687aeb8a5a593ab5af572e617f230f89140.zip
Merge branch 'i1616-AddTokenAdding' into i784-SendTokenButton
-rw-r--r--ui/app/actions.js4
-rw-r--r--ui/app/add-token.js17
-rw-r--r--ui/app/components/token-cell.js4
-rw-r--r--ui/lib/etherscan-prefix-for-network.js21
-rw-r--r--ui/lib/explorer-link.js21
5 files changed, 45 insertions, 22 deletions
diff --git a/ui/app/actions.js b/ui/app/actions.js
index 6ff28f32f..d99291e46 100644
--- a/ui/app/actions.js
+++ b/ui/app/actions.js
@@ -645,7 +645,9 @@ function addToken (address, symbol, decimals) {
if (err) {
return dispatch(actions.displayWarning(err.message))
}
- dispatch(actions.goHome())
+ setTimeout(() => {
+ dispatch(actions.goHome())
+ }, 250)
})
}
}
diff --git a/ui/app/add-token.js b/ui/app/add-token.js
index 025cfacb5..f21184270 100644
--- a/ui/app/add-token.js
+++ b/ui/app/add-token.js
@@ -31,6 +31,7 @@ function AddTokenScreen () {
AddTokenScreen.prototype.render = function () {
const state = this.state
+ const props = this.props
const { warning, symbol, decimals } = state
return (
@@ -40,7 +41,7 @@ AddTokenScreen.prototype.render = function () {
h('.section-title.flex-row.flex-center', [
h('i.fa.fa-arrow-left.fa-lg.cursor-pointer', {
onClick: (event) => {
- state.dispatch(actions.goHome())
+ props.dispatch(actions.goHome())
},
}),
h('h2.page-subtitle', 'Add Token'),
@@ -141,7 +142,13 @@ AddTokenScreen.prototype.render = function () {
if (!valid) return
const { address, symbol, decimals } = this.state
- this.props.dispatch(actions.addToken(address.trim(), symbol.trim(), decimals))
+ this.checkIfToken(address.trim())
+ .then(() => {
+ this.props.dispatch(actions.addToken(address.trim(), symbol.trim(), decimals))
+ })
+ .catch((reason) => {
+ this.setState({ warning: 'Not a valid token address.' })
+ })
},
}, 'Add'),
]),
@@ -201,6 +208,12 @@ AddTokenScreen.prototype.validateInputs = function () {
return isValid
}
+AddTokenScreen.prototype.checkIfToken = async function (address) {
+ const contract = this.TokenContract.at(address)
+ const result = await contract.balance(address)
+ return result[0].toString()
+}
+
AddTokenScreen.prototype.attemptToAutoFillTokenParams = async function (address) {
const contract = this.TokenContract.at(address)
diff --git a/ui/app/components/token-cell.js b/ui/app/components/token-cell.js
index 67558ad87..48f46934a 100644
--- a/ui/app/components/token-cell.js
+++ b/ui/app/components/token-cell.js
@@ -2,6 +2,7 @@ const Component = require('react').Component
const h = require('react-hyperscript')
const inherits = require('util').inherits
const Identicon = require('./identicon')
+const prefixForNetwork = require('../../lib/etherscan-prefix-for-network')
module.exports = TokenCell
@@ -59,7 +60,8 @@ function navigateTo (url) {
}
function etherscanLinkFor (tokenAddress, address, network) {
- return `https://etherscan.io/token/${tokenAddress}?a=${address}`
+ const prefix = prefixForNetwork(network)
+ return `https://${prefix}etherscan.io/token/${tokenAddress}?a=${address}`
}
function tokenFactoryFor (tokenAddress) {
diff --git a/ui/lib/etherscan-prefix-for-network.js b/ui/lib/etherscan-prefix-for-network.js
new file mode 100644
index 000000000..2c1904f1c
--- /dev/null
+++ b/ui/lib/etherscan-prefix-for-network.js
@@ -0,0 +1,21 @@
+module.exports = function (network) {
+ const net = parseInt(network)
+ let prefix
+ switch (net) {
+ case 1: // main net
+ prefix = ''
+ break
+ case 3: // ropsten test net
+ prefix = 'ropsten.'
+ break
+ case 4: // rinkeby test net
+ prefix = 'rinkeby.'
+ break
+ case 42: // kovan test net
+ prefix = 'kovan.'
+ break
+ default:
+ prefix = ''
+ }
+ return prefix
+}
diff --git a/ui/lib/explorer-link.js b/ui/lib/explorer-link.js
index e11249551..3b82ecd5f 100644
--- a/ui/lib/explorer-link.js
+++ b/ui/lib/explorer-link.js
@@ -1,21 +1,6 @@
+const prefixForNetwork = require('./etherscan-prefix-for-network')
+
module.exports = function (hash, network) {
- const net = parseInt(network)
- let prefix
- switch (net) {
- case 1: // main net
- prefix = ''
- break
- case 3: // ropsten test net
- prefix = 'ropsten.'
- break
- case 4: // rinkeby test net
- prefix = 'rinkeby.'
- break
- case 42: // kovan test net
- prefix = 'kovan.'
- break
- default:
- prefix = ''
- }
+ const prefix = prefixForNetwork(network)
return `http://${prefix}etherscan.io/tx/${hash}`
}