diff --git a/src/logic/tokens/store/actions/fetchTokenBalances.js b/src/logic/tokens/store/actions/fetchTokenBalances.js index 0588ad58..d8a6ec1e 100644 --- a/src/logic/tokens/store/actions/fetchTokenBalances.js +++ b/src/logic/tokens/store/actions/fetchTokenBalances.js @@ -7,7 +7,7 @@ import { type Token } from '~/logic/tokens/store/model/token' import { ETH_ADDRESS } from '~/logic/tokens/utils/tokenHelpers' import { getBalanceInEtherOf } from '~/logic/wallets/getWeb3' import { getStandardTokenContract } from './fetchTokens' -import { addTokens } from './saveTokens' +import saveTokens from './saveTokens' export const calculateBalanceOf = async (tokenAddress: string, safeAddress: string, decimals: number = 18) => { if (tokenAddress === ETH_ADDRESS) { @@ -37,14 +37,14 @@ const fetchTokenBalances = (safeAddress: string, tokens: List) => async ( try { const withBalances = await Promise.all( - tokens.map(async token => token.set('funds', await calculateBalanceOf(token.address, safeAddress, token.decimals))), + tokens.map(async token => token.set('balance', await calculateBalanceOf(token.address, safeAddress, token.decimals))), ) const tokensMap = Map().withMutations((map) => { withBalances.forEach(token => map.set(token.address, token)) }) - dispatch(addTokens(safeAddress, tokensMap)) + dispatch(saveTokens(safeAddress, tokensMap)) } catch (err) { // eslint-disable-next-line console.error('Error while loading active tokens from storage:', err) diff --git a/src/logic/tokens/store/actions/saveTokens.js b/src/logic/tokens/store/actions/saveTokens.js index 0fca88b8..36a3ed3b 100644 --- a/src/logic/tokens/store/actions/saveTokens.js +++ b/src/logic/tokens/store/actions/saveTokens.js @@ -15,7 +15,7 @@ type TokenProps = { tokens: Map, } -export const addTokens = createAction( +const addTokens = createAction( ADD_TOKENS, (safeAddress: string, tokens: Map): TokenProps => ({ safeAddress, diff --git a/src/logic/tokens/store/selectors/index.js b/src/logic/tokens/store/selectors/index.js index 4798469a..30ab6b48 100644 --- a/src/logic/tokens/store/selectors/index.js +++ b/src/logic/tokens/store/selectors/index.js @@ -1,27 +1,15 @@ // @flow import { List, Map } from 'immutable' import { createSelector, type Selector } from 'reselect' -import { safeParamAddressSelector, type RouterProps } from '~/routes/safe/store/selectors' +import { type RouterProps } from '~/routes/safe/store/selectors' import { type GlobalState } from '~/store' import { TOKEN_REDUCER_ID } from '~/logic/tokens/store/reducer/tokens' import { type Token } from '~/logic/tokens/store/model/token' -const tokensStateSelector = (state: GlobalState) => state[TOKEN_REDUCER_ID] - -export const tokensSelector: Selector> = createSelector( - tokensStateSelector, - safeParamAddressSelector, - (tokens: Map>, address: string) => { - if (!address) { - return Map() - } - - return tokens.get(address) || Map() - }, -) +export const tokensSelector = (state: GlobalState) => state[TOKEN_REDUCER_ID] export const tokenListSelector: Selector, List> = createSelector( - tokensStateSelector, + tokensSelector, (tokens: Map) => tokens.toList(), ) @@ -29,12 +17,3 @@ export const orderedTokenListSelector: Selector) => tokens.sortBy((token: Token) => token.get('symbol')), ) - -export const tokenAddressesSelector: Selector> = createSelector( - tokenListSelector, - (tokens: List) => { - const addresses = List().withMutations(list => tokens.map(token => list.push(token.address))) - - return addresses - }, -) diff --git a/src/routes/safe/component/Balances/dataFetcher.js b/src/routes/safe/component/Balances/dataFetcher.js index ecb60fe2..f54ffd83 100644 --- a/src/routes/safe/component/Balances/dataFetcher.js +++ b/src/routes/safe/component/Balances/dataFetcher.js @@ -17,9 +17,9 @@ export type BalanceRow = SortRow export const getBalanceData = (activeTokens: List): Array => { const rows = activeTokens.map((token: Token) => ({ - [BALANCE_TABLE_ASSET_ID]: token.get('name'), - [BALANCE_TABLE_BALANCE_ID]: `${token.get('funds')} ${token.get('symbol')}`, - [buildOrderFieldFrom(BALANCE_TABLE_BALANCE_ID)]: Number(token.get('funds')), + [BALANCE_TABLE_ASSET_ID]: token.name, + [BALANCE_TABLE_BALANCE_ID]: `${token.balance} ${token.symbol}`, + [buildOrderFieldFrom(BALANCE_TABLE_BALANCE_ID)]: Number(token.balance), [FIXED]: token.get('symbol') === 'ETH', })) diff --git a/src/routes/safe/container/selector.js b/src/routes/safe/container/selector.js index 8bfa9dbb..c62d905b 100644 --- a/src/routes/safe/container/selector.js +++ b/src/routes/safe/container/selector.js @@ -47,11 +47,15 @@ export const grantedSelector: Selector = crea }, ) +type UserToken = { + address: string, + balance: string, +} + const extendedSafeTokensSelector: Selector> = createSelector( safeTokensSelector, tokensSelector, - (safeTokens: Map, tokensList: Map) => { - // const extendedTokens = safeTokens.map(token => tokensList.get(token.address).set('balance', token.balance)) + (safeTokens: List, tokensList: Map) => { const extendedTokens = Map().withMutations((map) => { safeTokens.forEach((token: { address: string, balance: string }) => { const baseToken = tokensList.get(token.address) @@ -62,7 +66,7 @@ const extendedSafeTokensSelector: Selector }) }) - return extendedTokens + return extendedTokens.toList() }, )