diff options
Diffstat (limited to 'ui/app/selectors.js')
-rw-r--r-- | ui/app/selectors.js | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/ui/app/selectors.js b/ui/app/selectors.js index fdbc5fcde..951161510 100644 --- a/ui/app/selectors.js +++ b/ui/app/selectors.js @@ -5,14 +5,16 @@ const selectors = { getSelectedIdentity, getSelectedAccount, getSelectedToken, + getSelectedTokenExchangeRate, conversionRateSelector, transactionsSelector, + accountsWithSendEtherInfoSelector, + getCurrentAccountWithSendEtherInfo, } module.exports = selectors function getSelectedAddress (state) { - // TODO: accounts is not defined. Is it needed? const selectedAddress = state.metamask.selectedAddress || Object.keys(state.metamask.accounts)[0] return selectedAddress @@ -40,10 +42,41 @@ function getSelectedToken (state) { return selectedToken || null } +function getSelectedTokenExchangeRate (state) { + const tokenExchangeRates = state.metamask.tokenExchangeRates + const selectedToken = getSelectedToken(state) || {} + const { symbol = '' } = selectedToken + + const pair = `${symbol.toLowerCase()}_eth` + const { rate: tokenExchangeRate = 0 } = tokenExchangeRates[pair] || {} + + return tokenExchangeRate +} + function conversionRateSelector (state) { return state.metamask.conversionRate } +function accountsWithSendEtherInfoSelector (state) { + const { + accounts, + identities, + } = state.metamask + + const accountsWithSendEtherInfo = Object.entries(accounts).map(([key, account]) => { + return Object.assign({}, account, identities[key]) + }) + + return accountsWithSendEtherInfo +} + +function getCurrentAccountWithSendEtherInfo (state) { + const currentAddress = getSelectedAddress(state) + const accounts = accountsWithSendEtherInfoSelector(state) + + return accounts.find(({ address }) => address === currentAddress) +} + function transactionsSelector (state) { const { network, selectedTokenAddress } = state.metamask const unapprovedMsgs = valuesFor(state.metamask.unapprovedMsgs) |