Skip to content

Comments

fix: resolve Solana connect race condition causing WalletNotSelectedError#163

Open
adonesky1 wants to merge 1 commit intomainfrom
ad/tweak-solana-connection-flow
Open

fix: resolve Solana connect race condition causing WalletNotSelectedError#163
adonesky1 wants to merge 1 commit intomainfrom
ad/tweak-solana-connection-flow

Conversation

@adonesky1
Copy link
Contributor

@adonesky1 adonesky1 commented Feb 4, 2026

Summary

  • Fixes WalletNotSelectedError being thrown when clicking "Connect (Solana)" without the extension installed
  • Resolves timing issue between select() and connect() calls in the Solana wallet adapter

Before

Screen.Recording.2026-02-04.at.2.49.38.PM.mov

After

Screen.Recording.2026-02-04.at.2.51.34.PM.mov

Problem

When connecting to Solana, the previous code called select() followed immediately by connect(). Since select() triggers an async React state update, connect() was executing before the wallet was actually selected, causing WalletNotSelectedError to appear in the console.

Solution

Use an effect-based approach that waits for the wallet to be selected before initiating the connection:

  1. connectSolana() calls select() and sets a solanaPendingConnect flag
  2. A useEffect watches for when both the flag is set and the wallet becomes available
  3. The effect then calls connect(), ensuring proper sequencing

Testing Steps

  • Click "Connect (Solana)" without MetaMask extension installed
  • Verify no WalletNotSelectedError in console
  • Verify QR code modal appears promptly
  • Complete connection flow and verify wallet connects successfully

@adonesky1 adonesky1 requested a review from a team as a code owner February 4, 2026 20:47
@adonesky1 adonesky1 force-pushed the ad/tweak-solana-connection-flow branch from a48be84 to ad76558 Compare February 4, 2026 20:47
…rror

The previous implementation called select() and connect() synchronously,
but connect() executed before React state updated from select(), causing
WalletNotSelectedError. Now uses an effect to wait for wallet selection
before initiating connection.

Co-authored-by: Cursor <cursoragent@cursor.com>
@adonesky1 adonesky1 force-pushed the ad/tweak-solana-connection-flow branch from ad76558 to 25c9f3a Compare February 4, 2026 20:52
Comment on lines 2 to 13
@@ -10,7 +9,6 @@ import { WalletModalProvider } from '@solana/wallet-adapter-react-ui';
import type React from 'react';
import {
createContext,
useCallback,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated cleanup 😅

Copy link
Contributor

@wenfix wenfix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants