From d055f22fa60c0fff2a65f61596eb6ada78f17e11 Mon Sep 17 00:00:00 2001 From: Viacheslav Date: Mon, 11 Nov 2024 19:57:00 +0200 Subject: [PATCH] Unified invalid credentials error handling --- .../app/src/systems/Unlock/machines/unlockMachine.tsx | 7 +------ .../app/src/systems/Vault/services/VaultServer.ts | 11 ++++++++++- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/app/src/systems/Unlock/machines/unlockMachine.tsx b/packages/app/src/systems/Unlock/machines/unlockMachine.tsx index 4295f3b0b..c25507aa3 100644 --- a/packages/app/src/systems/Unlock/machines/unlockMachine.tsx +++ b/packages/app/src/systems/Unlock/machines/unlockMachine.tsx @@ -170,12 +170,7 @@ export const unlockMachine = createMachine( if (!input || !input?.password) { throw new Error('Password is required to unlock wallet'); } - try { - await VaultService.unlock(input); - // biome-ignore lint/suspicious/noExplicitAny: - } catch (err: any) { - toast.error(err?.message || 'Invalid credentials.'); - } + await VaultService.unlock(input); }, }), lock: FetchMachine.create({ diff --git a/packages/app/src/systems/Vault/services/VaultServer.ts b/packages/app/src/systems/Vault/services/VaultServer.ts index 8afcc61eb..1144bc3a3 100644 --- a/packages/app/src/systems/Vault/services/VaultServer.ts +++ b/packages/app/src/systems/Vault/services/VaultServer.ts @@ -1,5 +1,6 @@ // biome-ignore lint/style/useNodejsImportProtocol: import EventEmitter from 'events'; +import { toast } from '@fuel-ui/react'; import { createProvider } from '@fuel-wallet/connections'; import { Address, WalletManager, transactionRequestify } from 'fuels'; import { JSONRPCServer } from 'json-rpc-2.0'; @@ -126,7 +127,15 @@ export class VaultServer extends EventEmitter { } async unlock({ password }: VaultInputs['unlock']): Promise { - await this.manager.unlock(password); + try { + await this.manager.unlock(password); + } catch (err: unknown) { + if (err instanceof Error) { + toast.error(err.message || 'Invalid credentials.'); + } else { + toast.error('Invalid credentials.'); + } + } } async lock(): Promise {