import { BigNumber } from '@ethersproject/bignumber' ; import { EXCLUDED_ASSETS } from '@config' ; import { translateRaw } from '@translations' ; import { Asset , Contact , IAccount , Network , NetworkId , StoreAccount , StoreAsset , TAddress } from '@types' ; import { isSameAddress } from '@utils' ; const getAccountBaseBalance = ( account ) => { const baseAsset = account . assets . find ( ( as ) => as . type === 'base' ) ; return baseAsset ? baseAsset . balance : BigNumber . from ( 0 ) ; } ; const getAccountTokenBalance = ( account , token ) : BigNumber => { const erc20 = account . assets . find ( ( as ) => as . uuid === token . uuid ) ; return erc20 ? erc20 . balance : BigNumber . from ( 0 ) ; } ; export const getAccountBalance = ( account , token ? ) : BigNumber => token ? getAccountTokenBalance ( account , token ) : getAccountBaseBalance ( account ) ; export const getStoreAccount = ( accounts ) => ( address , networkId ) => accounts . find ( ( a ) => isSameAddress ( a . address , address ) && a . networkId === networkId ) ; export const toStoreAccount = ( account , assets , network , contact ? ) : StoreAccount => { const accountAssets = account . assets . filter ( ( a ) => ! EXCLUDED_ASSETS . includes ( a . uuid ) ) . reduce ( ( acc , asset ) => [ ... acc , { ... asset , balance : BigNumber . from ( asset . balance ) , ... assets . find ( ( a ) => a . uuid === asset . uuid ) ! } ] , [ ] ) ; return { ... account , assets : accountAssets , network , label : contact ?. label || account . label || translateRaw ( 'NO_LABEL' ) } ; } ;