Fetching active Tokens and showing them in Balances' Tab #73

This commit is contained in:
apanizo 2018-11-05 09:44:15 +01:00
parent 4e019af2a4
commit 24dfd80122
2 changed files with 15 additions and 35 deletions

View File

@ -1,5 +1,6 @@
// @flow // @flow
import { List } from 'immutable' import { List } from 'immutable'
import { type Token } from '~/routes/tokens/store/model/token'
import { buildOrderFieldFrom, FIXED, type SortRow } from '~/components/Table/sorting' import { buildOrderFieldFrom, FIXED, type SortRow } from '~/components/Table/sorting'
import { type Column } from '~/components/Table/TableHead' import { type Column } from '~/components/Table/TableHead'
@ -14,39 +15,17 @@ type BalanceData = {
export type BalanceRow = SortRow<BalanceData> export type BalanceRow = SortRow<BalanceData>
export const getBalanceData = (): Array<BalanceRow> => [ export const getBalanceData = (activeTokens: List<Token>): Array<BalanceRow> => {
{ const rows = activeTokens.map((token: Token) => ({
[BALANCE_TABLE_ASSET_ID]: 'CVL Journalism', [BALANCE_TABLE_ASSET_ID]: token.get('name'),
[BALANCE_TABLE_BALANCE_ID]: '234 CVL', [BALANCE_TABLE_BALANCE_ID]: `${token.get('funds')} ${token.get('symbol')}`,
[buildOrderFieldFrom(BALANCE_TABLE_BALANCE_ID)]: 234, [buildOrderFieldFrom(BALANCE_TABLE_BALANCE_ID)]: Number(token.get('funds')),
}, [FIXED]: token.get('symbol') === 'ETH',
{ }))
[BALANCE_TABLE_ASSET_ID]: 'ABC Periodico',
[BALANCE_TABLE_BALANCE_ID]: '1.394 ABC', return Array.from(rows)
[buildOrderFieldFrom(BALANCE_TABLE_BALANCE_ID)]: 1.394, }
},
{
[BALANCE_TABLE_ASSET_ID]: 'Ethereum',
[BALANCE_TABLE_BALANCE_ID]: '9.394 ETH',
[buildOrderFieldFrom(BALANCE_TABLE_BALANCE_ID)]: 9.394,
[FIXED]: true,
},
{
[BALANCE_TABLE_ASSET_ID]: 'Gnosis',
[BALANCE_TABLE_BALANCE_ID]: '0.599 GNO',
[buildOrderFieldFrom(BALANCE_TABLE_BALANCE_ID)]: 0.559,
},
{
[BALANCE_TABLE_ASSET_ID]: 'OmiseGO',
[BALANCE_TABLE_BALANCE_ID]: '39.922 OMG',
[buildOrderFieldFrom(BALANCE_TABLE_BALANCE_ID)]: 39.922,
},
{
[BALANCE_TABLE_ASSET_ID]: 'Moe Feo',
[BALANCE_TABLE_BALANCE_ID]: '0 MOE',
[buildOrderFieldFrom(BALANCE_TABLE_BALANCE_ID)]: 0,
},
]
export const generateColumns = () => { export const generateColumns = () => {
const assetRow: Column = { const assetRow: Column = {

View File

@ -33,6 +33,7 @@ type Props = {
classes: Object, classes: Object,
granted: boolean, granted: boolean,
tokens: List<Token>, tokens: List<Token>,
activeTokens: List<Token>,
safeAddress: string, safeAddress: string,
} }
@ -65,7 +66,7 @@ class Balances extends React.Component<Props, State> {
hideZero, showToken, showReceive, showSend, hideZero, showToken, showReceive, showSend,
} = this.state } = this.state
const { const {
classes, granted, tokens, safeAddress, classes, granted, tokens, safeAddress, activeTokens,
} = this.props } = this.props
const columns = generateColumns() const columns = generateColumns()
@ -74,7 +75,7 @@ class Balances extends React.Component<Props, State> {
root: classes.root, root: classes.root,
} }
const filteredData = filterByZero(getBalanceData(), hideZero) const filteredData = filterByZero(getBalanceData(activeTokens), hideZero)
return ( return (
<React.Fragment> <React.Fragment>