import * as balance from "../actions/balance.action" ; export interface WalletRecord { address : string ; balance : string ; name : string ; loading : boolean ; } export interface State { ETH : WalletRecord ; BTC : WalletRecord ; REP : WalletRecord ; TOKENS : Map < string , WalletRecord > ; } export const initialState = { ETH : undefined , BTC : undefined , REP : undefined , TOKENS : new Map < string , WalletRecord > ( ) , } ; export function reducer ( state = initialState , action ) { switch ( action . type ) { case balance . GET_ETH_BALANCE : { return { ... state , ETH : { ... state . ETH , loading : true , } } ; } case balance . GET_BTC_BALANCE : { return { ... state , BTC : { ... state . BTC , loading : true , } } ; } case balance . GET_REP_BALANCE : { return { ... state , REP : { ... state . REP , loading : true } } ; } case balance . GET_REP_BALANCE_SUCCESS : { return { ... state , REP : { ... state . REP , loading : false , balance : action . payload } } ; } case balance . GET_TOKEN_BALANCE : { const newState = { ... state } ; const token = state . TOKENS [ action . payload . name ] = { } as WalletRecord ; token . loading = true ; return newState ; } case balance . GET_TOKEN_BALANCE_SUCCESS : { const newState = { ... state } ; const token = state . TOKENS [ action . payload . name ] ; token . loading = false ; token . address = action . payload . address ; token . balance = action . payload . balance ; return newState ; } case balance . GET_ETH_BALANCE_SUCCESS : { return { ... state , ETH : { ... state . ETH , balance : action . payload . balance , address : action . payload . address , loading : false } , } ; } case balance . GET_BTC_BALANCE_SUCCESS : { return { ... state , BTC : { ... state . BTC , balance : action . payload . balance , address : action . payload . address , loading : false } , } ; } default : { return state ; } } } export const getEthLoading = ( state ) => state . ETH . loading ; export const getBtcLoading = ( state ) => state . BTC . loading ; export const getRepLoading = ( state ) => state . REP . loading ; export const getTokenLoadingAugur = ( state ) => state . TOKENS [ "augur" ] . loading ; export const getTokenLoadingGolem = ( state ) => state . TOKENS [ "golem" ] . loading ; export const getTokenLoadingGnosis = ( state ) => state . TOKENS [ "gnosis" ] . loading ; export const getTokenLoadingBat = ( state ) => state . TOKENS [ "bat" ] . loading ; export const getTokenLoadingAragon = ( state ) => state . TOKENS [ "aragon" ] . loading ; export const getTokenLoadingEos = ( state ) => state . TOKENS [ "eos" ] . loading ; export const getTokenLoadingSalt = ( state ) => state . TOKENS [ "salt" ] . loading ; export const getETHBalance = ( state ) => state . ETH ; export const getBTCBalance = ( state ) => state . BTC ; export const getREPBalance = ( state ) => state . REP ; export const getTokenBalances = ( state ) => state . TOKENS ; export const getTokenBalanceAugur = ( state ) => state . TOKENS [ "augur" ] ; export const getTokenBalanceGolem = ( state ) => state . TOKENS [ "golem" ] ; export const getTokenBalanceGnosis = ( state ) => state . TOKENS [ "gnosis" ] ; export const getTokenBalanceBat = ( state ) => state . TOKENS [ "bat" ] ; export const getTokenBalanceAragon = ( state ) => state . TOKENS [ "aragon" ] ; export const getTokenBalanceEos = ( state ) => state . TOKENS [ "eos" ] ; export const getTokenBalanceSalt = ( state ) => state . TOKENS [ "salt" ] ; export const getTokenBalanceCivic = ( state ) => state . TOKENS [ "cvc" ] ; export const getTokenBalanceOmiseGo = ( state ) => state . TOKENS [ "omg" ] ; export const getTokenBalanceDistrict0x = ( state ) => state . TOKENS [ "dnt" ] ; export const getTokenBalanceStatusNetwork = ( state ) => state . TOKENS [ "snt" ] ; export const getTokenBalanceSubstratum = ( state ) => state . TOKENS [ "sub" ] ; export const getTokenBalanceTron = ( state ) => state . TOKENS [ "trx" ] ; export const getTokenBalanceBytom = ( state ) => state . TOKENS [ "btm" ] ; export const getTokenBalanceDent = ( state ) => state . TOKENS [ "dent" ] ;