2017-07-13 21:02:39 +00:00
|
|
|
// @flow
|
|
|
|
import type { State } from 'reducers';
|
|
|
|
import { BaseWallet } from 'libs/wallet';
|
|
|
|
import { getNetworkConfig } from 'selectors/config';
|
|
|
|
import Big from 'big.js';
|
|
|
|
import type { Token } from 'config/data';
|
|
|
|
|
|
|
|
export function getWalletInst(state: State): ?BaseWallet {
|
|
|
|
return state.wallet.inst;
|
|
|
|
}
|
|
|
|
|
|
|
|
export type TokenBalance = {
|
|
|
|
symbol: string,
|
|
|
|
balance: Big,
|
|
|
|
custom: boolean
|
|
|
|
};
|
|
|
|
|
|
|
|
type MergedToken = Token & {
|
|
|
|
custom: boolean
|
|
|
|
};
|
|
|
|
|
|
|
|
export function getTokens(state: State): MergedToken[] {
|
|
|
|
const tokens: MergedToken[] = (getNetworkConfig(state).tokens: any);
|
2017-07-16 21:02:13 +00:00
|
|
|
return tokens.concat(
|
|
|
|
state.customTokens.map(token => ({ ...token, custom: true }))
|
|
|
|
);
|
2017-07-13 21:02:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function getTokenBalances(state: State): TokenBalance[] {
|
|
|
|
const tokens = getTokens(state);
|
|
|
|
if (!tokens) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
return tokens.map(t => ({
|
|
|
|
symbol: t.symbol,
|
2017-07-16 21:02:13 +00:00
|
|
|
balance: state.wallet.tokens[t.symbol]
|
|
|
|
? state.wallet.tokens[t.symbol]
|
|
|
|
: new Big(0),
|
2017-07-13 21:02:39 +00:00
|
|
|
custom: t.custom
|
|
|
|
}));
|
|
|
|
}
|