Skip to content

Commit

Permalink
enhancement: better error handling when wrong chain definition is passed
Browse files Browse the repository at this point in the history
  • Loading branch information
dafuga committed Jul 27, 2024
1 parent 92ab2b2 commit 15476be
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export class AccountCreationPluginMetamask

readonly config: AccountCreationPluginConfig = {
requiresChainSelect: true,
supportedChains: [Chains.EOS],
}

readonly metadata: AccountCreationPluginMetadata = AccountCreationPluginMetadata.from({
Expand All @@ -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))
Expand Down

0 comments on commit 15476be

Please sign in to comment.