import { convert } from '@emeraldplatform/core' ; import { blockchainById , IStoredTransaction , utils } from '@emeraldwallet/core' ; import BigNumber from 'bignumber.js' ; const { toBigNumber } = convert ; deprecated export function storeTransactions ( key , txs ) { if ( localStorage ) { localStorage . setItem ( key , JSON . stringify ( txs ) ) ; } } deprecated export function removeTransactions ( key ) { if ( localStorage ) { localStorage . removeItem ( key ) ; } } deprecated export function loadTransactions ( key , chainId ) { if ( localStorage ) { let txs = [ ] ; const old = localStorage . getItem ( 'trackedTransactions' ) ; if ( old ) { txs = JSON . parse ( old ) ; localStorage . removeItem ( 'trackedTransactions' ) ; } else { const storedTxs = localStorage . getItem ( key ) ; if ( storedTxs ) { txs = JSON . parse ( storedTxs ) ; } } return txs . map ( ( t ) => ( { ... t , chainId : t . chainId || chainId } ) ) . map ( restoreTx ) ; } return [ ] ; } /**
 * Converts parsed JSON object to typed Transaction object
 */ function restoreTx ( tx ) { return { ... tx , value : ( tx . value && typeof tx . value === 'string' ) ? toBigNumber ( tx . value ) : new BigNumber ( 0 ) , gasPrice : ( tx . gasPrice && typeof tx . gasPrice === 'string' ) ? toBigNumber ( tx . gasPrice ) : new BigNumber ( 0 ) , timestamp : utils . parseDate ( tx . timestamp , undefined ) , blockchain : tx . blockchain || ( blockchainById ( tx . chainId ) ? blockchainById ( tx . chainId ) ! . params . code : null ) , since : utils . parseDate ( tx . since , new Date ( ) ) , discarded : tx . discarded || false } ; }