import { isWalletCheckModule } from '../../validation' ; import { WalletCheckModule , WalletCheckInit } from '../../interfaces' ; const defaultChecks = [ 'connect' , 'network' ] ; async function check ( walletChecks , networkId ) { if ( walletChecks ) { const checks = walletChecks . map ( ( checkOrModule ) => { if ( ! isWalletCheckModule ( checkOrModule ) ) { const { checkName , ... otherParams } = checkOrModule ; const module = getModule ( checkName ) ; return ( module && module . then ( ( m ) => m . default ( { ... otherParams , networkId } ) ) ) ; } return Promise . resolve ( checkOrModule ) ; } ) ; return Promise . all ( checks ) ; } return Promise . all ( defaultChecks . map ( ( checkName ) => { const module = getModule ( checkName ) ; return module && module . then ( ( m ) => m . default ( { networkId } ) ) ; } ) ) ; } function getModule ( name ) { switch ( name ) { case 'connect' : return import ( './connect' ) ; case 'network' : return import ( './network' ) ; case 'balance' : return import ( './balance' ) ; case 'accounts' : return import ( './accounts' ) ; case 'derivationPath' : return import ( './derivation-path' ) ; default : throw new Error ( `invalid module name: ${ name }` ) ; } } export default check ;