import { TOKEN_MIGRATIONS } from '@config' ; import { Asset , ITxReceipt , ITxStatus , ITxType , StoreAccount , StoreAsset , TUuid } from '@types' ; import { bigify , convertToFiatFromAsset } from '@utils' ; import { getTotalByAsset } from './Asset' ; export const getTxsFromAccount = ( accounts ) : ITxReceipt [ ] => { return accounts . filter ( Boolean ) . flatMap ( ( { transactions : txs } ) => txs ) ; } ; export const txIsPending = ( { status } ) => status === ITxStatus . PENDING ; export const txIsSuccessful = ( { status } ) => status === ITxStatus . SUCCESS ; export const txIsFailed = ( { status } ) => status === ITxStatus . FAILED ; export const isNotExcludedAsset = ( excludedAssetUuids ) => ( asset ) : boolean => ! ( excludedAssetUuids || [ ] ) . includes ( asset . uuid ) ; export const isExcludedAsset = ( excludedAssetUuids ) => ( asset ) : boolean => ( excludedAssetUuids || [ ] ) . includes ( asset . uuid ) ; export const isTokenMigration = ( type ) => TOKEN_MIGRATIONS . includes ( type ) ; export const getAccountsAssets = ( accounts ) => accounts . flatMap ( ( a ) => a . assets ) ; export const calculateTotals = ( accounts ) => Object . values ( getTotalByAsset ( getAccountsAssets ( accounts ) ) ) ; export const calculateTotalFiat = ( accounts ) => ( getAssetRate ) => calculateTotals ( accounts ) . reduce ( ( sum , asset ) => sum . plus ( bigify ( convertToFiatFromAsset ( asset , getAssetRate ( asset ) ) ) ) , bigify ( 0 ) ) ;