import { AirGapWallet } from '@airgap/coinlib-core' ; import { MnemonicSecret } from '../../models/secret' ; import { isWalletMigrated } from '../../utils/migration' ; import { GroupMigrationStatus , MigrationStatus , MigrationWallet } from './migration.types' ; export function getWalletMigrationStatus ( wallet , options ) { if ( wallet . publicKey === options . currentlyHandled ) { return 'migrating' ; } if ( options . alreadyHandled . has ( wallet . publicKey ) ) { return isWalletMigrated ( wallet ) ? 'migrated' : 'skipped' ; } return 'waiting' ; } export function getWalletGroupMigrationStatus ( secret , wallets , options ) { const statusCounter = { waiting : 0 , migrating : 0 , migrated : 0 , skipped : 0 } ; wallets . forEach ( ( wallet ) => { statusCounter [ wallet . status ] ++ ; } ) ; if ( secret . id === options . currentlyHandled ) { return 'migrating' ; } else if ( statusCounter . migrated === wallets . length ) { return 'migrated' ; } else if ( statusCounter . skipped === wallets . length ) { return 'skipped' ; } else if ( statusCounter . waiting === wallets . length ) { return 'waiting' ; } else if ( statusCounter . migrating > 0 ) { return 'migrating' ; } else if ( statusCounter . migrated + statusCounter . skipped === wallets . length ) { return 'partiallyMigrated' ; } else { return 'waiting' ; } } export function shortenAddress ( address ) { return address . length > 12 ? `${ address . slice ( 0 , 5 ) }...${ address . slice ( - 5 ) }` : address ; }