Skip to content

Commit

Permalink
Default to cached balance when selecting metamask accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
danjm committed Nov 30, 2018
1 parent 85ba0df commit efa04db
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions ui/app/selectors.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
const abi = require('human-standard-token-abi')

import {
transactionsSelector,
} from './selectors/transactions'

const {
multiplyCurrencies,
} = require('./conversion-util')
Expand Down Expand Up @@ -36,6 +34,7 @@ const selectors = {
getCurrentViewContext,
getTotalUnapprovedCount,
preferencesSelector,
getMetaMaskAccounts,
}

module.exports = selectors
Expand All @@ -54,7 +53,22 @@ function getSelectedIdentity (state) {
}

function getMetaMaskAccounts (state) {
return state.metamask.accounts
const currentAccounts = state.metamask.accounts
const cachedBalances = state.metamask.cachedBalances
const selectedAccounts = {}

Object.keys(currentAccounts).forEach(accountID => {
const account = currentAccounts[accountID]
if (account && account.balance === null || account.balance === undefined) {
selectedAccounts[accountID] = {
...account,
balance: cachedBalances[accountID],
}
} else {
selectedAccounts[accountID] = account
}
})
return selectedAccounts
}

function getSelectedAccount (state) {
Expand Down

0 comments on commit efa04db

Please sign in to comment.