aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/add-token.js
diff options
context:
space:
mode:
authorAlexander Tseung <alextsg@users.noreply.github.com>2017-10-14 05:14:48 +0800
committerDaniel Tsui <szehungdanieltsui@gmail.com>2017-10-14 05:14:48 +0800
commita59972dcabc56c3d92f09ba1b88a2ded70ce8c34 (patch)
tree53bc230ec90946b20f2e57e3d970c9ff7e06cfea /ui/app/add-token.js
parent3fd9c8b57fe46d14772086980e0e92573c1799f2 (diff)
downloadtangerine-wallet-browser-a59972dcabc56c3d92f09ba1b88a2ded70ce8c34.tar
tangerine-wallet-browser-a59972dcabc56c3d92f09ba1b88a2ded70ce8c34.tar.gz
tangerine-wallet-browser-a59972dcabc56c3d92f09ba1b88a2ded70ce8c34.tar.bz2
tangerine-wallet-browser-a59972dcabc56c3d92f09ba1b88a2ded70ce8c34.tar.lz
tangerine-wallet-browser-a59972dcabc56c3d92f09ba1b88a2ded70ce8c34.tar.xz
tangerine-wallet-browser-a59972dcabc56c3d92f09ba1b88a2ded70ce8c34.tar.zst
tangerine-wallet-browser-a59972dcabc56c3d92f09ba1b88a2ded70ce8c34.zip
Prevent adding already added tokens (#2362)
Diffstat (limited to 'ui/app/add-token.js')
-rw-r--r--ui/app/add-token.js28
1 files changed, 25 insertions, 3 deletions
diff --git a/ui/app/add-token.js b/ui/app/add-token.js
index f723ff07c..90edc8de1 100644
--- a/ui/app/add-token.js
+++ b/ui/app/add-token.js
@@ -22,14 +22,17 @@ const ethUtil = require('ethereumjs-util')
const abi = require('human-standard-token-abi')
const Eth = require('ethjs-query')
const EthContract = require('ethjs-contract')
+const R = require('ramda')
const emptyAddr = '0x0000000000000000000000000000000000000000'
module.exports = connect(mapStateToProps, mapDispatchToProps)(AddTokenScreen)
function mapStateToProps (state) {
+ const { identities, tokens } = state.metamask
return {
- identities: state.metamask.identities,
+ identities,
+ tokens,
}
}
@@ -101,6 +104,15 @@ AddTokenScreen.prototype.tokenAddressDidChange = function (e) {
}
}
+AddTokenScreen.prototype.checkExistingAddresses = function (address) {
+ const tokensList = this.props.tokens
+ const matchesAddress = existingToken => {
+ return existingToken.address.toLowerCase() === address.toLowerCase()
+ }
+
+ return R.any(matchesAddress)(tokensList)
+}
+
AddTokenScreen.prototype.validate = function () {
const errors = {}
const identitiesList = Object.keys(this.props.identities)
@@ -128,6 +140,11 @@ AddTokenScreen.prototype.validate = function () {
if (ownAddress) {
errors.customAddress = 'Personal address detected. Input the token contract address.'
}
+
+ const tokenAlreadyAdded = this.checkExistingAddresses(customAddress)
+ if (tokenAlreadyAdded) {
+ errors.customAddress = 'Token has already been added.'
+ }
} else if (
Object.entries(selectedTokens)
.reduce((isEmpty, [ symbol, isSelected ]) => (
@@ -217,12 +234,14 @@ AddTokenScreen.prototype.renderTokenList = function () {
return Array(6).fill(undefined)
.map((_, i) => {
const { logo, symbol, name, address } = results[i] || {}
+ const tokenAlreadyAdded = this.checkExistingAddresses(address)
return Boolean(logo || symbol || name) && (
h('div.add-token__token-wrapper', {
- className: classnames('add-token__token-wrapper', {
+ className: classnames({
'add-token__token-wrapper--selected': selectedTokens[address],
+ 'add-token__token-wrapper--disabled': tokenAlreadyAdded,
}),
- onClick: () => this.toggleToken(address, results[i]),
+ onClick: () => !tokenAlreadyAdded && this.toggleToken(address, results[i]),
}, [
h('div.add-token__token-icon', {
style: {
@@ -233,6 +252,9 @@ AddTokenScreen.prototype.renderTokenList = function () {
h('div.add-token__token-symbol', symbol),
h('div.add-token__token-name', name),
]),
+ tokenAlreadyAdded && (
+ h('div.add-token__token-message', 'Already added')
+ ),
])
)
})