This repository was archived by the owner on Mar 16, 2026. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -22,6 +22,28 @@ const validateNetworkAddress = (address: string): boolean => {
2222
2323export async function connectWallet ( { onCancel } : ConnectWalletOptions ) {
2424 try {
25+ // Clear any existing wallet session data to prevent JSON parse errors
26+ // when switching between different wallet providers (Leather/Xverse)
27+ try {
28+ localStorage . removeItem ( "blockstack-session" ) ;
29+ localStorage . removeItem ( "stacks-connect" ) ;
30+ localStorage . removeItem ( "@stacks/connect" ) ;
31+ localStorage . removeItem ( "STX_PROVIDER" ) ;
32+ // Clear any other stacks-related session data
33+ Object . keys ( localStorage ) . forEach ( ( key ) => {
34+ if (
35+ key . startsWith ( "stacks" ) ||
36+ key . startsWith ( "blockstack" ) ||
37+ key . startsWith ( "@stacks" ) ||
38+ key . startsWith ( "STX" )
39+ ) {
40+ localStorage . removeItem ( key ) ;
41+ }
42+ } ) ;
43+ } catch ( e ) {
44+ console . warn ( "Failed to clear wallet session data:" , e ) ;
45+ }
46+
2547 const response = await connect ( ) ;
2648
2749 // After successful connection, validate the network
You can’t perform that action at this time.
0 commit comments