From 15476be0e733000e287b407d1a389756b100feab Mon Sep 17 00:00:00 2001 From: dafuga Date: Sat, 27 Jul 2024 11:13:59 -0700 Subject: [PATCH] enhancement: better error handling when wrong chain definition is passed --- src/index.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index d07da8d..cf10f06 100644 --- a/src/index.ts +++ b/src/index.ts @@ -28,6 +28,7 @@ export class AccountCreationPluginMetamask readonly config: AccountCreationPluginConfig = { requiresChainSelect: true, + supportedChains: [Chains.EOS], } readonly metadata: AccountCreationPluginMetadata = AccountCreationPluginMetadata.from({ @@ -44,8 +45,16 @@ export class AccountCreationPluginMetamask } async create(context: CreateAccountContext) { - if (context.chain?.id !== Chains.EOS.id) { - throw new Error('Only EOS is currently supported by this plugin.') + if (!context.chain) { + throw new Error('Chain not provided') + } + const currenChain = this.config.supportedChains?.find((chain) => + chain.equals(context.chain!) + ) + if (!currenChain) { + throw new Error( + `Chain not supported. This plugin only supports ${this.config.supportedChains}` + ) } const qs = new URLSearchParams() qs.set('supported_chains', String(context.chain))