import { Env , Handler , InternalHandler , Message } from "@keplr-wallet/router" ; import { ChainsService } from "./service" ; import { GetChainInfosMsg , RemoveSuggestedChainInfoMsg , SuggestChainInfoMsg , } from "./messages" ; import { ChainInfo } from "@keplr-wallet/types" ; type Writeable < T > = { - readonly [ P in keyof T ] : T [ P ] ; } ; export const getHandler = ( service ) => { return ( env , msg ) => { switch ( msg . constructor ) { case GetChainInfosMsg : return handleGetChainInfosMsg ( service ) ( env , msg as GetChainInfosMsg ) ; case SuggestChainInfoMsg : return handleSuggestChainInfoMsg ( service ) ( env , msg as SuggestChainInfoMsg ) ; case RemoveSuggestedChainInfoMsg : return handleRemoveSuggestedChainInfoMsg ( service ) ( env , msg as RemoveSuggestedChainInfoMsg ) ; default : throw new Error ( "Unknown msg type" ) ; } } ; } ; const handleGetChainInfosMsg = ( service ) => { return async ( ) => { const chainInfos = await service . getChainInfos ( ) ; return { chainInfos , } ; } ; } ; const handleSuggestChainInfoMsg = ( service ) => { return async ( env , msg ) => { if ( await service . hasChainInfo ( msg . chainInfo . chainId ) ) { return ; } const chainInfo = msg . chainInfo as Writeable < ChainInfo > ; chainInfo . beta = true ; await service . suggestChainInfo ( env , chainInfo , msg . origin ) ; } ; } ; const handleRemoveSuggestedChainInfoMsg = ( service ) => { return async ( _ , msg ) => { await service . removeChainInfo ( msg . chainId ) ; return await service . getChainInfos ( ) ; } ; } ;