@@ -96,6 +96,7 @@ export function ChatPageContent(props: {
96
96
const setContextFilters = useCallback ( ( v : NebulaContext | undefined ) => {
97
97
_setContextFilters ( v ) ;
98
98
setHasUserUpdatedContextFilters ( true ) ;
99
+ saveLastUsedChainIds ( v ?. chainIds || undefined ) ;
99
100
} , [ ] ) ;
100
101
101
102
const isNewSession = ! props . session ;
@@ -118,7 +119,21 @@ export function ChatPageContent(props: {
118
119
walletAddress : null ,
119
120
} ;
120
121
122
+ // Only set wallet address from connected wallet
121
123
updatedContextFilters . walletAddress = address || null ;
124
+
125
+ // if we have last used chains in storage, continue using them
126
+ try {
127
+ const lastUsedChainIds = getLastUsedChainIds ( ) ;
128
+ if ( lastUsedChainIds ) {
129
+ updatedContextFilters . chainIds = lastUsedChainIds ;
130
+ return updatedContextFilters ;
131
+ }
132
+ } catch {
133
+ // ignore local storage errors
134
+ }
135
+
136
+ // else - use the active chain
122
137
updatedContextFilters . chainIds = activeChain
123
138
? [ activeChain . id . toString ( ) ]
124
139
: [ ] ;
@@ -493,3 +508,31 @@ function WalletDisconnectedDialog(props: {
493
508
</ Dialog >
494
509
) ;
495
510
}
511
+
512
+ const NEBULA_LAST_USED_CHAIN_IDS_KEY = "nebula-last-used-chain-ids" ;
513
+
514
+ function saveLastUsedChainIds ( chainIds : string [ ] | undefined ) {
515
+ try {
516
+ if ( chainIds && chainIds . length > 0 ) {
517
+ localStorage . setItem (
518
+ NEBULA_LAST_USED_CHAIN_IDS_KEY ,
519
+ JSON . stringify ( chainIds ) ,
520
+ ) ;
521
+ } else {
522
+ localStorage . removeItem ( NEBULA_LAST_USED_CHAIN_IDS_KEY ) ;
523
+ }
524
+ } catch {
525
+ // ignore local storage errors
526
+ }
527
+ }
528
+
529
+ function getLastUsedChainIds ( ) : string [ ] | null {
530
+ try {
531
+ const lastUsedChainIdsStr = localStorage . getItem (
532
+ NEBULA_LAST_USED_CHAIN_IDS_KEY ,
533
+ ) ;
534
+ return lastUsedChainIdsStr ? JSON . parse ( lastUsedChainIdsStr ) : null ;
535
+ } catch {
536
+ return null ;
537
+ }
538
+ }
0 commit comments