Skip to content

Commit 106ca3c

Browse files
[Dashboard] more robust engine cloud FTUX (#6980)
1 parent 76a718c commit 106ca3c

File tree

4 files changed

+45
-8
lines changed

4 files changed

+45
-8
lines changed

apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/engine/cloud/analytics/ftux.client.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import CreateServerWallet from "../server-wallets/components/create-server-walle
88
import type { Wallet } from "../server-wallets/wallet-table/types";
99
import CreateVaultAccountButton from "../vault/components/create-vault-account.client";
1010
import { SendTestTransaction } from "./send-test-tx.client";
11+
import { deleteUserAccessToken } from "./utils";
1112

1213
interface Props {
1314
managementAccessToken: string | undefined;
@@ -78,6 +79,11 @@ export const EngineChecklist: React.FC<Props> = (props) => {
7879
props.teamSlug,
7980
]);
8081

82+
const isComplete = useMemo(
83+
() => finalSteps.every((step) => step.completed),
84+
[finalSteps],
85+
);
86+
8187
if (props.testTxWithWallet) {
8288
return (
8389
<SendTestTransaction
@@ -90,10 +96,11 @@ export const EngineChecklist: React.FC<Props> = (props) => {
9096
);
9197
}
9298

93-
if (finalSteps.length === 1) {
99+
if (finalSteps.length === 0 || isComplete) {
100+
// clear token from local storage after FTUX is complete
101+
deleteUserAccessToken(props.project.id);
94102
return null;
95103
}
96-
97104
return (
98105
<StepsCard title="Setup Your Engine" steps={finalSteps} delay={1000} />
99106
);

apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/engine/cloud/analytics/send-test-tx.client.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { CopyTextButton } from "../../../../../../../../@/components/ui/CopyText
3030
import { useTrack } from "../../../../../../../../hooks/analytics/useTrack";
3131
import type { Wallet } from "../server-wallets/wallet-table/types";
3232
import { SmartAccountCell } from "../server-wallets/wallet-table/wallet-table-ui.client";
33+
import { deleteUserAccessToken, getUserAccessToken } from "./utils";
3334

3435
const formSchema = z.object({
3536
accessToken: z.string().min(1, "Access token is required"),
@@ -53,10 +54,13 @@ export function SendTestTransaction(props: {
5354
const router = useDashboardRouter();
5455
const trackEvent = useTrack();
5556

57+
const userAccessToken =
58+
props.userAccessToken ?? getUserAccessToken(props.project.id) ?? "";
59+
5660
const form = useForm<FormValues>({
5761
resolver: zodResolver(formSchema),
5862
defaultValues: {
59-
accessToken: props.userAccessToken ?? "",
63+
accessToken: userAccessToken,
6064
walletIndex:
6165
props.wallets && props.walletId
6266
? props.wallets
@@ -147,7 +151,7 @@ export function SendTestTransaction(props: {
147151
)}
148152
<p className="flex items-center gap-2 text-sm text-warning-text">
149153
<LockIcon className="h-4 w-4" />
150-
{props.userAccessToken
154+
{userAccessToken
151155
? "Copy your Vault access token, you'll need it for every HTTP call to Engine."
152156
: "Every wallet action requires your Vault access token."}
153157
</p>
@@ -157,12 +161,12 @@ export function SendTestTransaction(props: {
157161
<div className="flex-grow">
158162
<div className="flex flex-col gap-2">
159163
<p className="text-sm">Vault Access Token</p>
160-
{props.userAccessToken ? (
164+
{userAccessToken ? (
161165
<div className="flex flex-col gap-2 ">
162166
<CopyTextButton
163167
copyIconPosition="right"
164-
textToCopy={props.userAccessToken}
165-
textToShow={props.userAccessToken}
168+
textToCopy={userAccessToken}
169+
textToShow={userAccessToken}
166170
tooltip="Copy Vault Access Token"
167171
className="!h-auto w-full justify-between bg-background px-3 py-3 font-mono text-xs"
168172
/>
@@ -175,7 +179,7 @@ export function SendTestTransaction(props: {
175179
) : (
176180
<Input
177181
id="access-token"
178-
type={props.userAccessToken ? "text" : "password"}
182+
type={userAccessToken ? "text" : "password"}
179183
placeholder="vt_act_1234....ABCD"
180184
{...form.register("accessToken")}
181185
disabled={isLoading}
@@ -287,6 +291,8 @@ export function SendTestTransaction(props: {
287291
} else {
288292
router.refresh();
289293
}
294+
// clear token from local storage after FTUX is complete
295+
deleteUserAccessToken(props.project.id);
290296
}}
291297
>
292298
{props.walletId ? "Close" : "Complete Setup"}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
export function storeUserAccessToken(projectId: string, accessToken: string) {
2+
localStorage.setItem(
3+
`thirdweb:engine-cloud-user-access-token-${projectId}`,
4+
accessToken,
5+
);
6+
}
7+
8+
export function getUserAccessToken(projectId: string) {
9+
return localStorage.getItem(
10+
`thirdweb:engine-cloud-user-access-token-${projectId}`,
11+
);
12+
}
13+
14+
export function deleteUserAccessToken(projectId: string) {
15+
localStorage.removeItem(
16+
`thirdweb:engine-cloud-user-access-token-${projectId}`,
17+
);
18+
}

apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/engine/cloud/vault/components/create-vault-account.client.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { CheckIcon, DownloadIcon, Loader2Icon, LockIcon } from "lucide-react";
1919
import { useState } from "react";
2020
import { toast } from "sonner";
2121
import { useTrack } from "../../../../../../../../../hooks/analytics/useTrack";
22+
import { storeUserAccessToken } from "../../analytics/utils";
2223
import {
2324
createManagementAccessToken,
2425
createWalletAccessToken,
@@ -86,6 +87,11 @@ export default function CreateVaultAccountButton(props: {
8687
throw new Error("Failed to create access token");
8788
}
8889

90+
// save in local storage in case the user refreshes the page during FTUX
91+
storeUserAccessToken(
92+
props.project.id,
93+
userAccessTokenRes.data.accessToken,
94+
);
8995
props.onUserAccessTokenCreated?.(userAccessTokenRes.data.accessToken);
9096

9197
return {

0 commit comments

Comments
 (0)