Skip to content

Commit

Permalink
Unified invalid credentials error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
SVell committed Nov 11, 2024
1 parent 5ebfc5a commit d055f22
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
7 changes: 1 addition & 6 deletions packages/app/src/systems/Unlock/machines/unlockMachine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: <explanation>
} catch (err: any) {
toast.error(err?.message || 'Invalid credentials.');
}
await VaultService.unlock(input);
},
}),
lock: FetchMachine.create<void, void>({
Expand Down
11 changes: 10 additions & 1 deletion packages/app/src/systems/Vault/services/VaultServer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// biome-ignore lint/style/useNodejsImportProtocol: <explanation>
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';
Expand Down Expand Up @@ -126,7 +127,15 @@ export class VaultServer extends EventEmitter {
}

async unlock({ password }: VaultInputs['unlock']): Promise<void> {
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<void> {
Expand Down

0 comments on commit d055f22

Please sign in to comment.