Skip to content

Commit 89b5752

Browse files
committed
[NEB-113] Save context chains in local storage
1 parent 6911102 commit 89b5752

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

apps/dashboard/src/app/nebula-app/(app)/components/ChatPageContent.tsx

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import { type ChatMessage, Chats } from "./Chats";
2424
import ContextFiltersButton, { ContextFiltersForm } from "./ContextFilters";
2525
import { EmptyStateChatPageContent } from "./EmptyStateChatPageContent";
2626

27+
const NEBULA_LAST_USED_CHAIN_IDS_KEY = "nebula-last-used-chain-ids";
28+
2729
export function ChatPageContent(props: {
2830
session: SessionInfo | undefined;
2931
authToken: string;
@@ -96,6 +98,20 @@ export function ChatPageContent(props: {
9698
const setContextFilters = useCallback((v: NebulaContext | undefined) => {
9799
_setContextFilters(v);
98100
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+
}
99115
}, []);
100116

101117
const isNewSession = !props.session;
@@ -118,7 +134,28 @@ export function ChatPageContent(props: {
118134
walletAddress: null,
119135
};
120136

137+
// Only set wallet address from connected wallet
121138
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
122159
updatedContextFilters.chainIds = activeChain
123160
? [activeChain.id.toString()]
124161
: [];

0 commit comments

Comments
 (0)