aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components
diff options
context:
space:
mode:
authorDan Finlay <dan@danfinlay.com>2017-06-16 07:22:53 +0800
committerDan Finlay <dan@danfinlay.com>2017-06-16 07:22:53 +0800
commit48789f2a3df2c820b61902fb49057f9f7b6cbd8c (patch)
tree944ddfc812be289c1e7d50f08032e46242776152 /ui/app/components
parent711a4def86d9e8c626ee554a976d9eab6abdcbee (diff)
downloadtangerine-wallet-browser-48789f2a3df2c820b61902fb49057f9f7b6cbd8c.tar
tangerine-wallet-browser-48789f2a3df2c820b61902fb49057f9f7b6cbd8c.tar.gz
tangerine-wallet-browser-48789f2a3df2c820b61902fb49057f9f7b6cbd8c.tar.bz2
tangerine-wallet-browser-48789f2a3df2c820b61902fb49057f9f7b6cbd8c.tar.lz
tangerine-wallet-browser-48789f2a3df2c820b61902fb49057f9f7b6cbd8c.tar.xz
tangerine-wallet-browser-48789f2a3df2c820b61902fb49057f9f7b6cbd8c.tar.zst
tangerine-wallet-browser-48789f2a3df2c820b61902fb49057f9f7b6cbd8c.zip
Add ability to add tokens to token list
Fiex #1616
Diffstat (limited to 'ui/app/components')
-rw-r--r--ui/app/components/token-list.js40
1 files changed, 30 insertions, 10 deletions
diff --git a/ui/app/components/token-list.js b/ui/app/components/token-list.js
index d230ce74a..100e596ed 100644
--- a/ui/app/components/token-list.js
+++ b/ui/app/components/token-list.js
@@ -4,13 +4,14 @@ const inherits = require('util').inherits
const TokenTracker = require('eth-token-tracker')
const TokenCell = require('./token-cell.js')
const contracts = require('eth-contract-metadata')
+const normalizeAddress = require('eth-sig-util').normalize
-const tokens = []
+const defaultTokens = []
for (const address in contracts) {
const contract = contracts[address]
if (contract.erc20) {
contract.address = address
- tokens.push(contract)
+ defaultTokens.push(contract)
}
}
@@ -18,22 +19,23 @@ module.exports = TokenList
inherits(TokenList, Component)
function TokenList () {
- this.state = { tokens, isLoading: true, network: null }
+ this.state = {
+ tokens: null,
+ isLoading: true,
+ network: null,
+ }
Component.call(this)
}
TokenList.prototype.render = function () {
const state = this.state
- const { tokens, isLoading } = state
-
- const { userAddress } = this.props
+ const { isLoading, tokens } = state
+ const { userAddress, network } = this.props
if (isLoading) {
return this.message('Loading')
}
- const network = this.props.network
-
const tokenViews = tokens.map((tokenData) => {
tokenData.network = network
tokenData.userAddress = userAddress
@@ -120,7 +122,7 @@ TokenList.prototype.createFreshTokenTracker = function () {
this.tracker = new TokenTracker({
userAddress,
provider: global.ethereumProvider,
- tokens: tokens,
+ tokens: uniqueMergeTokens(defaultTokens, this.props.tokens),
pollingInterval: 8000,
})
@@ -149,7 +151,12 @@ TokenList.prototype.componentWillUpdate = function (nextProps) {
}
TokenList.prototype.updateBalances = function (tokenData) {
- const heldTokens = tokenData.filter(token => token.balance !== '0' && token.string !== '0.000')
+ const desired = this.props.tokens.map(token => token.address)
+ const heldTokens = tokenData.filter(token => {
+ const held = token.balance !== '0' && token.string !== '0.000'
+ const preferred = desired.includes(normalizeAddress(token.address))
+ return held || preferred
+ })
this.setState({ tokens: heldTokens, isLoading: false })
}
@@ -158,3 +165,16 @@ TokenList.prototype.componentWillUnmount = function () {
this.tracker.stop()
}
+function uniqueMergeTokens (tokensA, tokensB) {
+ const uniqueAddresses = []
+ const result = []
+ tokensA.concat(tokensB).forEach((token) => {
+ const normal = normalizeAddress(token.address)
+ if (!uniqueAddresses.includes(normal)) {
+ uniqueAddresses.push(normal)
+ result.push(token)
+ }
+ })
+ return result
+}
+