@@ -24,6 +24,8 @@ import { type ChatMessage, Chats } from "./Chats";
24
24
import ContextFiltersButton , { ContextFiltersForm } from "./ContextFilters" ;
25
25
import { EmptyStateChatPageContent } from "./EmptyStateChatPageContent" ;
26
26
27
+ const NEBULA_LAST_USED_CHAIN_IDS_KEY = "nebula-last-used-chain-ids" ;
28
+
27
29
export function ChatPageContent ( props : {
28
30
session : SessionInfo | undefined ;
29
31
authToken : string ;
@@ -96,6 +98,20 @@ export function ChatPageContent(props: {
96
98
const setContextFilters = useCallback ( ( v : NebulaContext | undefined ) => {
97
99
_setContextFilters ( v ) ;
98
100
setHasUserUpdatedContextFilters ( true ) ;
101
+
102
+ // save context chains to local storage
103
+ try {
104
+ if ( v ?. chainIds && v . chainIds . length > 0 ) {
105
+ localStorage . setItem (
106
+ NEBULA_LAST_USED_CHAIN_IDS_KEY ,
107
+ JSON . stringify ( v . chainIds ) ,
108
+ ) ;
109
+ } else {
110
+ localStorage . removeItem ( NEBULA_LAST_USED_CHAIN_IDS_KEY ) ;
111
+ }
112
+ } catch {
113
+ // ignore local storage errors
114
+ }
99
115
} , [ ] ) ;
100
116
101
117
const isNewSession = ! props . session ;
@@ -118,7 +134,28 @@ export function ChatPageContent(props: {
118
134
walletAddress : null ,
119
135
} ;
120
136
137
+ // Only set wallet address from connected wallet
121
138
updatedContextFilters . walletAddress = address || null ;
139
+
140
+ // if we have last used chains in storage, continue using them
141
+ try {
142
+ const lastUsedChainIdsStr = localStorage . getItem (
143
+ NEBULA_LAST_USED_CHAIN_IDS_KEY ,
144
+ ) ;
145
+
146
+ if ( lastUsedChainIdsStr ) {
147
+ const lastUsedChainIds = lastUsedChainIdsStr
148
+ ? JSON . parse ( lastUsedChainIdsStr )
149
+ : null ;
150
+
151
+ updatedContextFilters . chainIds = lastUsedChainIds ;
152
+ return updatedContextFilters ;
153
+ }
154
+ } catch {
155
+ // ignore local storage errors
156
+ }
157
+
158
+ // else - use the active chain
122
159
updatedContextFilters . chainIds = activeChain
123
160
? [ activeChain . id . toString ( ) ]
124
161
: [ ] ;
0 commit comments