Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-sign-in-silent-bail-unsupported-chain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rainbow-me/rainbowkit": patch
---

Show an error in the Sign In screen when the wallet is connected on a chain that is not in the configured chains list. Previously the Sign Message button would silently do nothing in this case, leaving the user stuck with no feedback.
27 changes: 27 additions & 0 deletions packages/rainbowkit/src/components/SignIn/SignIn.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,31 @@ describe('SignIn', () => {

expect(createMessage).toHaveBeenCalledTimes(2);
});

it('shows an error message when the wallet is on an unsupported chain', async () => {
wagmiMocks.useAccount.mockReturnValue({
address,
chain: undefined,
});
const createMessage = vi.fn(() => 'message');
wagmiMocks.signMessageAsync.mockReturnValue(new Promise(() => {}));

renderSignIn({ createMessage });

const button = await screen.findByTestId('rk-auth-message-button');
await waitFor(() => expect(button).toHaveTextContent('Sign message'));

fireEvent.click(button);

await waitFor(() =>
expect(
screen.getByText(
'Your wallet is on an unsupported network. Switch to a supported network and try again.',
),
).toBeInTheDocument(),
);
expect(createMessage).not.toHaveBeenCalled();
expect(wagmiMocks.signMessageAsync).not.toHaveBeenCalled();
expect(button).toHaveTextContent('Sign message');
});
});
13 changes: 12 additions & 1 deletion packages/rainbowkit/src/components/SignIn/SignIn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,21 @@ export function SignIn({
const chainId = activeChain?.id;
const { nonce } = state;

if (!address || !chainId || !nonce) {
if (!address || !nonce) {
return;
}

if (!chainId) {
// The wallet is connected on a chain that is not in the
// configured chains list, so wagmi reports chain as undefined.
// Surface an actionable error rather than bailing silently.
return setState((x) => ({
...x,
errorMessage: i18n.t('sign_in.signature.unsupported_chain_error'),
status: 'idle',
}));
}

setState((x) => ({
...x,
errorMessage: undefined,
Expand Down
3 changes: 2 additions & 1 deletion packages/rainbowkit/src/locales/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"verifying": "Verifying signature...",
"signing_error": "Error signing message, please retry!",
"verifying_error": "Error verifying signature, please retry!",
"oops_error": "Oops, something went wrong!"
"oops_error": "Oops, something went wrong!",
"unsupported_chain_error": "Your wallet is on an unsupported network. Switch to a supported network and try again."
}
},

Expand Down