import * as ethUtil from 'ethereumjs-util' ; import pageStateCache from '../service/pageStateCache' ; export { default as createPersistStore } from './persisitStore' ; const retrieveValuePath = ( obj ) => { const arr = [ ... Object . entries ( obj ) ] ; const result = { } ; const parentKey = [ ] ; let lastParent ; while ( arr . length ) { const curNode = arr . shift ( ) ; const [ key , value ] = curNode ! ; if ( lastParent && lastParent [ key ] !== value ) { parentKey . pop ( ) ; } if ( typeof value === 'object' ) { arr . unshift ( ... Object . entries ( value ! ) ) ; parentKey . push ( key ) ; lastParent = value ; } else if ( typeof value === 'string' ) { result [ value ] = `${ [ ... parentKey , key ] . join ( '.' ) }` ; } } return result ; } ; export const underline2Camelcase = ( str ) => { return str . replace ( /_(.)/g , ( m , p1 ) => p1 . toUpperCase ( ) ) ; } ; export { retrieveValuePath } ; export { default as PromiseFlow } from './promiseFlow' ; export function normalizeAddress ( input ) { if ( ! input ) { return '' ; } if ( typeof input === 'number' ) { const buffer = ethUtil . toBuffer ( input ) ; input = ethUtil . bufferToHex ( buffer ) ; } if ( typeof input !== 'string' ) { let msg = 'eth-sig-util.normalize() requires hex string or integer input.' ; msg += ` received ${ typeof input }: ${ input }` ; throw new Error ( msg ) ; } return ethUtil . addHexPrefix ( input ) ; } export const wait = ( fn , ms = 1000 ) => { return new Promise ( ( resolve ) => { setTimeout ( ( ) => { fn ( ) ; resolve ( true ) ; } , ms ) ; } ) ; } ; export const setPageStateCacheWhenPopupClose = ( data ) => { const cache = pageStateCache . get ( ) ; if ( cache && cache . path === '/import/wallet-connect' ) { pageStateCache . set ( { ... cache , states : { ... cache . states , data , } , } ) ; } } ; export const hasWalletConnectPageStateCache = ( ) => { const cache = pageStateCache . get ( ) ; if ( cache && cache . path === '/import/wallet-connect' ) { return true ; } return false ; } ; export const isSameAddress = ( a , b ) => { return a . toLowerCase ( ) === b . toLowerCase ( ) ; } ;