Refresh token balance on network change

feature/default_network_editable
Dan Finlay 8 years ago
parent b7b9e0c1ac
commit 6fda78cd2b
  1. 1
      app/scripts/controllers/transactions.js
  2. 2
      package.json
  3. 27
      ui/app/components/token-list.js

@ -389,7 +389,6 @@ module.exports = class TransactionController extends EventEmitter {
this.emit(`${txMeta.id}:${status}`, txId)
if (status === 'submitted' || status === 'rejected') {
this.emit(`${txMeta.id}:finished`, txMeta)
}
this.updateTx(txMeta)
this.emit('updateBadge')

@ -67,7 +67,7 @@
"eth-query": "^2.1.1",
"eth-sig-util": "^1.1.1",
"eth-simple-keyring": "^1.1.1",
"eth-token-tracker": "^1.0.6",
"eth-token-tracker": "^1.0.7",
"ethereumjs-tx": "^1.3.0",
"ethereumjs-util": "ethereumjs/ethereumjs-util#ac5d0908536b447083ea422b435da27f26615de9",
"ethereumjs-wallet": "^0.6.0",

@ -7,7 +7,7 @@ const contracts = require('eth-contract-metadata')
const Loading = require('./loading')
const tokens = []
for (let address in contracts) {
for (const address in contracts) {
const contract = contracts[address]
if (contract.erc20) {
contract.address = address
@ -19,7 +19,7 @@ module.exports = TokenList
inherits(TokenList, Component)
function TokenList () {
this.state = { tokens, isLoading: true }
this.state = { tokens, isLoading: true, network: null }
Component.call(this)
}
@ -68,17 +68,23 @@ TokenList.prototype.render = function () {
}
TokenList.prototype.componentDidMount = function () {
this.createFreshTokenTracker()
}
TokenList.prototype.createFreshTokenTracker = function () {
if (this.tracker) {
this.tracker.stop()
}
if (!global.ethereumProvider) return
const { userAddress } = this.props
this.tracker = new TokenTracker({
userAddress,
provider: global.ethereumProvider,
tokens: this.state.tokens,
tokens: tokens,
pollingInterval: 8000,
})
this.setState({ tokens: this.tracker.serialize() })
this.tracker.on('update', (tokenData) => {
this.updateBalances(tokenData)
})
@ -92,6 +98,17 @@ TokenList.prototype.componentDidMount = function () {
})
}
TokenList.prototype.componentWillUpdate = function (nextProps) {
if (nextProps.network === 'loading') return
const oldNet = this.props.network
const newNet = nextProps.network
if (oldNet && newNet && newNet !== oldNet) {
this.setState({ isLoading: true })
this.createFreshTokenTracker()
}
}
TokenList.prototype.updateBalances = function (tokenData) {
const heldTokens = tokenData.filter(token => token.balance !== '0' && token.string !== '0.000')
this.setState({ tokens: heldTokens, isLoading: false })

Loading…
Cancel
Save