Skip to content

Commit b08efa1

Browse files
committed
Dashboard: Fix Nebula floating chat authToken query cache key (#6932)
<!-- ## title your PR with this format: "[SDK/Dashboard/Portal] Feature/Fix: Concise title for the changes" If you did not copy the branch name from Linear, paste the issue tag here (format is TEAM-0000): ## Notes for the reviewer Anything important to call out? Be sure to also clarify these in your comments. ## How to test Unit tests, playground, etc. --> <!-- start pr-codex --> --- ## PR-Codex overview This PR enhances the `NebulaChatButton` component by adding an `isLoggedIn` prop across various instances, affecting its behavior based on user authentication. It also updates the `useNebulaAuthToken` hook to accept an `isLoggedIn` parameter, improving its functionality. ### Detailed summary - Added `isLoggedIn` prop to `NebulaChatButton` in: - `layout.tsx` for chain page - `page.tsx` for support page - `layout.tsx` for contract page - Updated `NebulaChatButton` to pass `isLoggedIn` to `NebulaChatUIContainer`. - Modified `useNebulaAuthToken` to accept `isLoggedIn` and updated query key accordingly. - Changed loading state check from `isPending` to `isFetching`. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent 6745ba0 commit b08efa1

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/(chainPage)/layout.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ The following is the user's message:
100100
return (
101101
<>
102102
<NebulaChatButton
103+
isLoggedIn={!!authToken}
103104
networks={chain.testnet ? "testnet" : "mainnet"}
104105
isFloating={true}
105106
pageType="chain"

apps/dashboard/src/app/(app)/(dashboard)/(chain)/[chain_id]/[contractAddress]/layout.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ The following is the user's message:`;
111111
client={client}
112112
>
113113
<NebulaChatButton
114+
isLoggedIn={!!accountAddress}
114115
networks={info.chainMetadata.testnet ? "testnet" : "mainnet"}
115116
isFloating={true}
116117
pageType="contract"

apps/dashboard/src/app/(app)/(dashboard)/support/page.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ export default async function SupportPage() {
158158
</p>
159159
<div className="mt-6 flex w-full flex-col items-center gap-3">
160160
<NebulaChatButton
161+
isLoggedIn={!!accountAddress}
161162
networks="all"
162163
isFloating={false}
163164
pageType="support"

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export function NebulaChatButton(props: {
2828
pageType: "chain" | "contract" | "support";
2929
examplePrompts: ExamplePrompt[];
3030
networks: NebulaContext["networks"];
31+
isLoggedIn: boolean;
3132
label: string;
3233
client: ThirdwebClient;
3334
isFloating: boolean;
@@ -94,6 +95,7 @@ export function NebulaChatButton(props: {
9495
</div>
9596

9697
<NebulaChatUIContainer
98+
isLoggedIn={props.isLoggedIn}
9799
networks={props.networks}
98100
onClose={closeModal}
99101
isOpen={isOpen}
@@ -114,6 +116,7 @@ function NebulaChatUIContainer(props: {
114116
examplePrompts: ExamplePrompt[];
115117
pageType: "chain" | "contract" | "support";
116118
client: ThirdwebClient;
119+
isLoggedIn: boolean;
117120
networks: NebulaContext["networks"];
118121
nebulaParams:
119122
| {
@@ -183,6 +186,7 @@ function NebulaChatUIContainer(props: {
183186
<div className="relative flex grow flex-col overflow-hidden">
184187
{shouldRenderChat && (
185188
<ChatContent
189+
isLoggedIn={props.isLoggedIn}
186190
sessionKey={nebulaSessionKey}
187191
networks={props.networks}
188192
client={props.client}
@@ -202,12 +206,13 @@ function ChatContent(
202206
"authToken"
203207
> & {
204208
sessionKey: number;
209+
isLoggedIn: boolean;
205210
},
206211
) {
207-
const { sessionKey, ...restProps } = props;
208-
const nebulaAuthTokenQuery = useNebulaAuthToken();
212+
const { sessionKey, isLoggedIn, ...restProps } = props;
213+
const nebulaAuthTokenQuery = useNebulaAuthToken(isLoggedIn);
209214

210-
if (nebulaAuthTokenQuery.isPending) {
215+
if (nebulaAuthTokenQuery.isFetching) {
211216
return <LoadingScreen />;
212217
}
213218

@@ -259,16 +264,16 @@ function useOutsideClick(onOutsideClick: () => void) {
259264
return ref;
260265
}
261266

262-
function useNebulaAuthToken() {
267+
function useNebulaAuthToken(isLoggedInToDashboard: boolean) {
263268
return useQuery({
264-
queryKey: ["nebula-auth-token"],
269+
queryKey: ["nebula-auth-token", isLoggedInToDashboard],
265270
queryFn: async () => {
266271
const jwt = await getNebulaAuthToken();
267272
return jwt || null;
268273
},
269274
retry: false,
270275
refetchOnWindowFocus: false,
271-
refetchOnMount: false,
276+
refetchOnMount: "always",
272277
refetchOnReconnect: false,
273278
});
274279
}

0 commit comments

Comments
 (0)