mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Auto populate token list with popular token balances
Half implements #175 Things to do: - Add ability to add tokens to the list. - Persist the token tab selection (so it is an implicit preference) - Check what's up with the token-tracker polling, it seems like it is not waiting the interval.
This commit is contained in:
parent
de500250c4
commit
108c4ab2c5
@ -39,7 +39,7 @@ function mapStateToProps (state) {
|
|||||||
|
|
||||||
inherits(AccountDetailScreen, Component)
|
inherits(AccountDetailScreen, Component)
|
||||||
function AccountDetailScreen () {
|
function AccountDetailScreen () {
|
||||||
this.state = {}
|
this.state = { tabSelection: 'history' }
|
||||||
Component.call(this)
|
Component.call(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -251,13 +251,7 @@ AccountDetailScreen.prototype.subview = function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
AccountDetailScreen.prototype.tabSections = function () {
|
AccountDetailScreen.prototype.tabSections = function () {
|
||||||
var subview
|
const tabSelection = this.state.tabSelection
|
||||||
try {
|
|
||||||
subview = this.props.accountDetail.subview
|
|
||||||
} catch (e) {
|
|
||||||
subview = null
|
|
||||||
}
|
|
||||||
|
|
||||||
return h('section.tabSection', [
|
return h('section.tabSection', [
|
||||||
|
|
||||||
h(TabBar, {
|
h(TabBar, {
|
||||||
@ -265,7 +259,7 @@ AccountDetailScreen.prototype.tabSections = function () {
|
|||||||
{ content: 'History', key: 'history' },
|
{ content: 'History', key: 'history' },
|
||||||
{ content: 'Tokens', key: 'tokens' },
|
{ content: 'Tokens', key: 'tokens' },
|
||||||
],
|
],
|
||||||
defaultTab: subview || 'history',
|
defaultTab: tabSelection || 'history',
|
||||||
tabSelected: (key) => {
|
tabSelected: (key) => {
|
||||||
this.setState({ tabSelection: key })
|
this.setState({ tabSelection: key })
|
||||||
},
|
},
|
||||||
@ -276,12 +270,13 @@ AccountDetailScreen.prototype.tabSections = function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
AccountDetailScreen.prototype.tabSwitchView = function () {
|
AccountDetailScreen.prototype.tabSwitchView = function () {
|
||||||
const userAddress = this.props.address
|
const props = this.props
|
||||||
|
const { address, network } = props
|
||||||
const tabSelection = this.state.tabSelection || 'history'
|
const tabSelection = this.state.tabSelection || 'history'
|
||||||
|
|
||||||
switch (tabSelection) {
|
switch (tabSelection) {
|
||||||
case 'tokens':
|
case 'tokens':
|
||||||
return h(TokenList, { userAddress })
|
return h(TokenList, { userAddress: address, network })
|
||||||
default:
|
default:
|
||||||
return this.transactionList()
|
return this.transactionList()
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,9 @@ IdenticonComponent.prototype.render = function () {
|
|||||||
h('div', {
|
h('div', {
|
||||||
key: 'identicon-' + this.props.address,
|
key: 'identicon-' + this.props.address,
|
||||||
style: {
|
style: {
|
||||||
display: 'inline-block',
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
height: diameter,
|
height: diameter,
|
||||||
width: diameter,
|
width: diameter,
|
||||||
borderRadius: diameter / 2,
|
borderRadius: diameter / 2,
|
||||||
@ -40,8 +42,8 @@ IdenticonComponent.prototype.componentDidMount = function () {
|
|||||||
if (!address) return
|
if (!address) return
|
||||||
|
|
||||||
var container = findDOMNode(this)
|
var container = findDOMNode(this)
|
||||||
var diameter = props.diameter || this.defaultDiameter
|
|
||||||
|
|
||||||
|
var diameter = props.diameter || this.defaultDiameter
|
||||||
if (!isNode) {
|
if (!isNode) {
|
||||||
var img = iconFactory.iconForAddress(address, diameter)
|
var img = iconFactory.iconForAddress(address, diameter)
|
||||||
container.appendChild(img)
|
container.appendChild(img)
|
||||||
|
@ -33,3 +33,4 @@ TabBar.prototype.render = function () {
|
|||||||
}))
|
}))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,11 +12,19 @@ function TokenCell () {
|
|||||||
|
|
||||||
TokenCell.prototype.render = function () {
|
TokenCell.prototype.render = function () {
|
||||||
const props = this.props
|
const props = this.props
|
||||||
const { address, symbol, string, network } = props
|
const { address, symbol, string, network, userAddress } = props
|
||||||
log.info({ address, symbol, string })
|
log.info({ address, symbol, string, network })
|
||||||
|
|
||||||
return (
|
return (
|
||||||
h('li.token-cell', [
|
h('li.token-cell', {
|
||||||
|
style: { cursor: network === '1' ? 'pointer' : 'default' },
|
||||||
|
onClick: (event) => {
|
||||||
|
const url = urlFor(address, userAddress, network)
|
||||||
|
if (url) {
|
||||||
|
navigateTo(url)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}, [
|
||||||
|
|
||||||
h(Identicon, {
|
h(Identicon, {
|
||||||
diameter: 50,
|
diameter: 50,
|
||||||
@ -29,3 +37,11 @@ TokenCell.prototype.render = function () {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function navigateTo (url) {
|
||||||
|
global.platform.openWindow({ url })
|
||||||
|
}
|
||||||
|
|
||||||
|
function urlFor (tokenAddress, address, network) {
|
||||||
|
return `https://etherscan.io/token/${tokenAddress}?a=${address}`
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -3,35 +3,49 @@ const h = require('react-hyperscript')
|
|||||||
const inherits = require('util').inherits
|
const inherits = require('util').inherits
|
||||||
const TokenTracker = require('eth-token-tracker')
|
const TokenTracker = require('eth-token-tracker')
|
||||||
const TokenCell = require('./token-cell.js')
|
const TokenCell = require('./token-cell.js')
|
||||||
|
const contracts = require('eth-contract-metadata')
|
||||||
|
const Loading = require('./loading')
|
||||||
|
|
||||||
|
const tokens = []
|
||||||
|
for (let address in contracts) {
|
||||||
|
const contract = contracts[address]
|
||||||
|
if (contract.erc20) {
|
||||||
|
contract.address = address
|
||||||
|
tokens.push(contract)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = TokenList
|
module.exports = TokenList
|
||||||
|
|
||||||
inherits(TokenList, Component)
|
inherits(TokenList, Component)
|
||||||
function TokenList () {
|
function TokenList () {
|
||||||
|
this.state = { tokens, isLoading: true }
|
||||||
// Hard coded for development for now:
|
|
||||||
const tokens = [
|
|
||||||
{ address: '0x48c80F1f4D53D5951e5D5438B54Cba84f29F32a5', symbol: 'REP', balance: 'aa'},
|
|
||||||
{ address: '0xc66ea802717bfb9833400264dd12c2bceaa34a6d', symbol: 'MKR', balance: '1000', decimals: 18},
|
|
||||||
{ address: '0xa74476443119A942dE498590Fe1f2454d7D4aC0d', symbol: 'GOL', balance: 'ff'},
|
|
||||||
{ address: '0xaec2e87e0a235266d9c5adc9deb4b2e29b54d009', symbol: 'SNGLS', balance: '0' },
|
|
||||||
]
|
|
||||||
|
|
||||||
this.state = { tokens }
|
|
||||||
Component.call(this)
|
Component.call(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
TokenList.prototype.render = function () {
|
TokenList.prototype.render = function () {
|
||||||
const tokens = this.state.tokens
|
const state = this.state
|
||||||
|
const { tokens, isLoading } = state
|
||||||
|
|
||||||
|
const { userAddress } = this.props
|
||||||
|
|
||||||
|
if (isLoading) return h(Loading, { isLoading })
|
||||||
|
|
||||||
const network = this.props.network
|
const network = this.props.network
|
||||||
|
|
||||||
const tokenViews = tokens.map((tokenData) => {
|
const tokenViews = tokens.map((tokenData) => {
|
||||||
tokenData.network = network
|
tokenData.network = network
|
||||||
|
tokenData.userAddress = userAddress
|
||||||
return h(TokenCell, tokenData)
|
return h(TokenCell, tokenData)
|
||||||
})
|
})
|
||||||
|
|
||||||
return (
|
return (
|
||||||
h('ol', [h('style', `
|
h('ol', {
|
||||||
|
style: {
|
||||||
|
height: '302px',
|
||||||
|
overflowY: 'auto',
|
||||||
|
},
|
||||||
|
}, [h('style', `
|
||||||
|
|
||||||
li.token-cell {
|
li.token-cell {
|
||||||
display: flex;
|
display: flex;
|
||||||
@ -54,19 +68,26 @@ TokenList.prototype.render = function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TokenList.prototype.componentDidMount = function () {
|
TokenList.prototype.componentDidMount = function () {
|
||||||
|
if (!global.ethereumProvider) return
|
||||||
const { userAddress } = this.props
|
const { userAddress } = this.props
|
||||||
|
|
||||||
this.tracker = new TokenTracker({
|
this.tracker = new TokenTracker({
|
||||||
userAddress,
|
userAddress,
|
||||||
provider: web3.currentProvider,
|
provider: global.ethereumProvider,
|
||||||
tokens: this.state.tokens,
|
tokens: this.state.tokens,
|
||||||
|
pollingInterval: 8000,
|
||||||
})
|
})
|
||||||
|
|
||||||
this.setState({ tokens: this.tracker.serialize() })
|
this.setState({ tokens: this.tracker.serialize() })
|
||||||
this.tracker.on('update', (tokenData) => this.setState({ tokens: tokenData }))
|
this.tracker.on('update', (tokenData) => {
|
||||||
|
const heldTokens = tokenData.filter(token => token.balance !== '0' && token.string !== '0.000')
|
||||||
|
this.setState({ tokens: heldTokens, isLoading: false })
|
||||||
|
})
|
||||||
this.tracker.updateBalances()
|
this.tracker.updateBalances()
|
||||||
}
|
}
|
||||||
|
|
||||||
TokenList.prototype.componentWillUnmount = function () {
|
TokenList.prototype.componentWillUnmount = function () {
|
||||||
|
if (!this.tracker) return
|
||||||
this.tracker.stop()
|
this.tracker.stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,3 +155,4 @@ InfoScreen.prototype.render = function () {
|
|||||||
InfoScreen.prototype.navigateTo = function (url) {
|
InfoScreen.prototype.navigateTo = function (url) {
|
||||||
global.platform.openWindow({ url })
|
global.platform.openWindow({ url })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ IconFactory.prototype.generateNewIdenticon = function (address, diameter) {
|
|||||||
// util
|
// util
|
||||||
|
|
||||||
function iconExistsFor (address) {
|
function iconExistsFor (address) {
|
||||||
return (contractMap.address) && isValidAddress(address) && (contractMap[address].logo)
|
return contractMap[address] && isValidAddress(address) && contractMap[address].logo
|
||||||
}
|
}
|
||||||
|
|
||||||
function imageElFor (address) {
|
function imageElFor (address) {
|
||||||
@ -53,7 +53,7 @@ function imageElFor (address) {
|
|||||||
const path = `images/contract/${fileName}`
|
const path = `images/contract/${fileName}`
|
||||||
const img = document.createElement('img')
|
const img = document.createElement('img')
|
||||||
img.src = path
|
img.src = path
|
||||||
img.style.width = '100%'
|
img.style.width = '75%'
|
||||||
return img
|
return img
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user