Skip to content

Commit 9c69898

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

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ export function ChatPageContent(props: {
9696
const setContextFilters = useCallback((v: NebulaContext | undefined) => {
9797
_setContextFilters(v);
9898
setHasUserUpdatedContextFilters(true);
99+
saveLastUsedChainIds(v?.chainIds || undefined);
99100
}, []);
100101

101102
const isNewSession = !props.session;
@@ -118,7 +119,21 @@ export function ChatPageContent(props: {
118119
walletAddress: null,
119120
};
120121

122+
// Only set wallet address from connected wallet
121123
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
122137
updatedContextFilters.chainIds = activeChain
123138
? [activeChain.id.toString()]
124139
: [];
@@ -493,3 +508,31 @@ function WalletDisconnectedDialog(props: {
493508
</Dialog>
494509
);
495510
}
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

Comments
 (0)