import { AddPermissionOrigin , EnableAccessMsg , GetOriginPermittedChainsMsg , GetPermissionOriginsMsg , RemovePermissionOrigin , } from "./messages" ; import { Env , Handler , InternalHandler , Message } from "@keplr-wallet/router" ; import { PermissionService } from "./service" ; export const getHandler = ( service ) => { return ( env , msg ) => { switch ( msg . constructor ) { case EnableAccessMsg : return handleEnableAccessMsg ( service ) ( env , msg as EnableAccessMsg ) ; case GetPermissionOriginsMsg : return handleGetPermissionOriginsMsg ( service ) ( env , msg as GetPermissionOriginsMsg ) ; case GetOriginPermittedChainsMsg : return handleGetOriginPermittedChainsMsg ( service ) ( env , msg as GetOriginPermittedChainsMsg ) ; case AddPermissionOrigin : return handleAddPermissionOrigin ( service ) ( env , msg as RemovePermissionOrigin ) ; case RemovePermissionOrigin : return handleRemovePermissionOrigin ( service ) ( env , msg as RemovePermissionOrigin ) ; default : throw new Error ( "Unknown msg type" ) ; } } ; } ; const handleEnableAccessMsg = ( service ) => { return async ( env , msg ) => { return await service . checkOrGrantBasicAccessPermission ( env , msg . chainIds , msg . origin ) ; } ; } ; const handleGetPermissionOriginsMsg = ( service ) => { return ( _ , msg ) => { return service . getPermissionOrigins ( msg . chainId , msg . permissionType ) ; } ; } ; const handleGetOriginPermittedChainsMsg = ( service ) => { return ( _ , msg ) => { return service . getOriginPermittedChains ( msg . permissionOrigin , msg . permissionType ) ; } ; } ; const handleAddPermissionOrigin = ( service ) => { return async ( _ , msg ) => { await service . addPermission ( [ msg . chainId ] , msg . permissionType , [ msg . permissionOrigin , ] ) ; } ; } ; const handleRemovePermissionOrigin = ( service ) => { return async ( _ , msg ) => { await service . removePermission ( msg . chainId , msg . permissionType , [ msg . permissionOrigin , ] ) ; } ; } ;