aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components
diff options
context:
space:
mode:
authorThomas Huang <tmashuang@users.noreply.github.com>2017-06-29 01:07:49 +0800
committerGitHub <noreply@github.com>2017-06-29 01:07:49 +0800
commitffd3773ef3c400c89c362580e7ae3969d00ae20c (patch)
tree13cc622a66025476bdcb8840c316c05c0146a533 /ui/app/components
parentddba2af4152668a5767ce874a4727873c72bac72 (diff)
parent8642feee09f57d5756c682a053434a196cff4af3 (diff)
downloadtangerine-wallet-browser-ffd3773ef3c400c89c362580e7ae3969d00ae20c.tar
tangerine-wallet-browser-ffd3773ef3c400c89c362580e7ae3969d00ae20c.tar.gz
tangerine-wallet-browser-ffd3773ef3c400c89c362580e7ae3969d00ae20c.tar.bz2
tangerine-wallet-browser-ffd3773ef3c400c89c362580e7ae3969d00ae20c.tar.lz
tangerine-wallet-browser-ffd3773ef3c400c89c362580e7ae3969d00ae20c.tar.xz
tangerine-wallet-browser-ffd3773ef3c400c89c362580e7ae3969d00ae20c.tar.zst
tangerine-wallet-browser-ffd3773ef3c400c89c362580e7ae3969d00ae20c.zip
Merge pull request #1620 from MetaMask/i1616-AddTokenAdding
Add ability to add tokens to token list
Diffstat (limited to 'ui/app/components')
-rw-r--r--ui/app/components/token-cell.js4
-rw-r--r--ui/app/components/token-list.js106
2 files changed, 78 insertions, 32 deletions
diff --git a/ui/app/components/token-cell.js b/ui/app/components/token-cell.js
index d3a895d36..4d2cacb01 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
@@ -41,6 +42,7 @@ function navigateTo (url) {
}
function urlFor (tokenAddress, address, network) {
- return `https://etherscan.io/token/${tokenAddress}?a=${address}`
+ const prefix = prefixForNetwork(network)
+ return `https://${prefix}etherscan.io/token/${tokenAddress}?a=${address}`
}
diff --git a/ui/app/components/token-list.js b/ui/app/components/token-list.js
index 633d3ccfe..ac7ab8309 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,15 +19,18 @@ module.exports = TokenList
inherits(TokenList, Component)
function TokenList () {
- this.state = { tokens, isLoading: true, network: null }
+ this.state = {
+ tokens: [],
+ isLoading: true,
+ network: null,
+ }
Component.call(this)
}
TokenList.prototype.render = function () {
const state = this.state
const { tokens, isLoading, error } = state
-
- const { userAddress } = this.props
+ const { userAddress, network } = this.props
if (isLoading) {
return this.message('Loading')
@@ -37,40 +41,65 @@ TokenList.prototype.render = function () {
return this.message('There was a problem loading your token balances.')
}
- const network = this.props.network
-
const tokenViews = tokens.map((tokenData) => {
tokenData.network = network
tokenData.userAddress = userAddress
return h(TokenCell, tokenData)
})
- return (
+ return h('div', [
h('ol', {
style: {
- height: '302px',
+ height: '260px',
overflowY: 'auto',
+ display: 'flex',
+ flexDirection: 'column',
},
- }, [h('style', `
-
- li.token-cell {
- display: flex;
- flex-direction: row;
- align-items: center;
- padding: 10px;
- }
-
- li.token-cell > h3 {
- margin-left: 12px;
- }
-
- li.token-cell:hover {
- background: white;
- cursor: pointer;
- }
+ }, [
+ h('style', `
+
+ li.token-cell {
+ display: flex;
+ flex-direction: row;
+ align-items: center;
+ padding: 10px;
+ }
+
+ li.token-cell > h3 {
+ margin-left: 12px;
+ }
+
+ li.token-cell:hover {
+ background: white;
+ cursor: pointer;
+ }
+
+ `),
+ ...tokenViews,
+ tokenViews.length ? null : this.message('No Tokens Found.'),
+ ]),
+ this.addTokenButtonElement(),
+ ])
+}
- `)].concat(tokenViews.length ? tokenViews : this.message('No Tokens Found.')))
- )
+TokenList.prototype.addTokenButtonElement = function () {
+ return h('div', [
+ h('div.footer.hover-white.pointer', {
+ key: 'reveal-account-bar',
+ onClick: () => {
+ this.props.addToken()
+ },
+ style: {
+ display: 'flex',
+ height: '40px',
+ padding: '10px',
+ justifyContent: 'center',
+ alignItems: 'center',
+ },
+ }, [
+ h('i.fa.fa-plus.fa-lg'),
+ ]),
+ ])
}
TokenList.prototype.message = function (body) {
@@ -101,7 +130,7 @@ TokenList.prototype.createFreshTokenTracker = function () {
this.tracker = new TokenTracker({
userAddress,
provider: global.ethereumProvider,
- tokens: tokens,
+ tokens: uniqueMergeTokens(defaultTokens, this.props.tokens),
pollingInterval: 8000,
})
@@ -135,8 +164,10 @@ TokenList.prototype.componentWillUpdate = function (nextProps) {
}
}
-TokenList.prototype.updateBalances = function (tokenData) {
- const heldTokens = tokenData.filter(token => token.balance !== '0' && token.string !== '0.000')
+TokenList.prototype.updateBalances = function (tokens) {
+ const heldTokens = tokens.filter(token => {
+ return token.balance !== '0' && token.string !== '0.000'
+ })
this.setState({ tokens: heldTokens, isLoading: false })
}
@@ -145,3 +176,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
+}
+