Skip to content

Commit de92d06

Browse files
fix(mosaic): explain cancelled wallet connections
1 parent 7d8ad23 commit de92d06

5 files changed

Lines changed: 7 additions & 10 deletions

File tree

‎.changeset/quiet-wallet-recovery.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"@clerk/mosaic": patch
33
---
44

5-
Handle rejected wallet requests in UserProfile without showing a generic error, and explain when a request is still pending in the wallet. Ignore late wallet responses after closing the profile so reopening starts a fresh connection flow.
5+
Show a clear cancellation message for rejected wallet requests in UserProfile, and explain when a request is still pending in the wallet. Ignore late wallet responses after closing the profile so reopening starts a fresh connection flow.

‎packages/mosaic/src/features/user-profile/user-profile-web3-wallets-section/__tests__/user-profile-web3-wallets-recovery.feature.test.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ it('handles cancellation in MetaMask without offering a Clerk cancel button and
2727

2828
expect(screen.getByRole('button', { name: 'Connect MetaMask' })).toBeEnabled();
2929
expect(screen.getByRole('button', { name: 'Connect Solana' })).toBeEnabled();
30-
expect(screen.queryByRole('alert')).not.toBeInTheDocument();
30+
expect(screen.getByRole('alert')).toHaveTextContent('Wallet connection was cancelled. Please try again.');
3131
expect(fapi.client.sessions[0]?.user.web3_wallets).toHaveLength(0);
3232
expect(request).not.toHaveBeenCalledWith(expect.objectContaining({ method: 'personal_sign' }));
3333

@@ -40,14 +40,14 @@ it('handles cancellation in MetaMask without offering a Clerk cancel button and
4040
expect(fapi.client.sessions[0]?.user.web3_wallets[0]?.web3_wallet).toBe('0xabcdef1234567890');
4141
});
4242

43-
it('releases a rejected MetaMask connection without displaying an error', async () => {
43+
it('explains a rejected MetaMask connection and releases the pending state', async () => {
4444
const request = vi.fn().mockRejectedValue({ code: 4001, message: 'User rejected the request.' });
4545
vi.stubGlobal('ethereum', { request });
4646
serveFapi(signedInWallets(['web3_metamask_signature']));
4747
await renderWithClerk(<UserProfileWeb3WalletsSection />);
4848
await userEvent.setup().click(await screen.findByRole('button', { name: 'Connect MetaMask' }));
4949
await waitFor(() => expect(screen.getByRole('button', { name: 'Connect MetaMask' })).toBeEnabled());
50-
expect(screen.queryByText('Something went wrong. Please try again.')).not.toBeInTheDocument();
50+
expect(screen.getByRole('alert')).toHaveTextContent('Wallet connection was cancelled. Please try again.');
5151
});
5252

5353
it('explains that an existing MetaMask request needs attention in the wallet', async () => {

‎packages/mosaic/src/features/user-profile/user-profile-web3-wallets-section/user-profile-web3-wallets-section.model.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ function walletUnavailable() {
109109
function rethrowProviderError(cause: unknown): never {
110110
if (typeof cause === 'object' && cause !== null && 'code' in cause) {
111111
if (cause.code === 4001) {
112-
throw new DOMException('Wallet request rejected', 'AbortError');
112+
throw new ClerkRuntimeError('Wallet connection was cancelled.', { code: 'web3_connection_cancelled' });
113113
}
114114
if (cause.code === -32002) {
115115
throw new ClerkRuntimeError('A wallet request is already pending.', { code: 'web3_request_pending' });

‎packages/mosaic/src/hooks/use-pending-action.ts‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,7 @@ export function usePendingAction<TKey extends string = string>({
6969
await action(controller.signal);
7070
return !controller.signal.aborted;
7171
} catch (cause) {
72-
if (
73-
!controller.signal.aborted &&
74-
!isReverificationCancelledError(cause) &&
75-
!(cause instanceof DOMException && cause.name === 'AbortError')
76-
) {
72+
if (!controller.signal.aborted && !isReverificationCancelledError(cause)) {
7773
setFailure({ key, error: toLocalizableError(cause), errorFallback: options.errorFallback });
7874
}
7975
return false;

‎packages/mosaic/src/localization/errors.messages.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ export const errorMessages: { readonly generic: string } & Readonly<Record<strin
9393
too_many_unverified_identifications:
9494
'Too many verifications are pending on this account. Remove an unverified email address, phone number, or wallet you no longer need, or wait a few minutes for an incomplete passkey setup to expire, then try again.',
9595
web3_missing_identifier: 'A Web3 Wallet extension cannot be found. Please install one to continue.',
96+
web3_connection_cancelled: 'Wallet connection was cancelled. Please try again.',
9697
web3_request_pending:
9798
'A request is already pending in your wallet. Open your wallet to complete or reject it, then try again.',
9899
web3_provider_unavailable: 'This wallet provider is unavailable.',

0 commit comments

Comments
 (0)