Skip to content

[Dashboard] more robust engine cloud FTUX #6980

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import CreateServerWallet from "../server-wallets/components/create-server-walle
import type { Wallet } from "../server-wallets/wallet-table/types";
import CreateVaultAccountButton from "../vault/components/create-vault-account.client";
import { SendTestTransaction } from "./send-test-tx.client";
import { deleteUserAccessToken } from "./utils";

interface Props {
managementAccessToken: string | undefined;
Expand Down Expand Up @@ -78,6 +79,11 @@ export const EngineChecklist: React.FC<Props> = (props) => {
props.teamSlug,
]);

const isComplete = useMemo(
() => finalSteps.every((step) => step.completed),
[finalSteps],
);

if (props.testTxWithWallet) {
return (
<SendTestTransaction
Expand All @@ -90,10 +96,11 @@ export const EngineChecklist: React.FC<Props> = (props) => {
);
}

if (finalSteps.length === 1) {
if (finalSteps.length === 0 || isComplete) {
// clear token from local storage after FTUX is complete
deleteUserAccessToken(props.project.id);
return null;
}

return (
<StepsCard title="Setup Your Engine" steps={finalSteps} delay={1000} />
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { CopyTextButton } from "../../../../../../../../@/components/ui/CopyText
import { useTrack } from "../../../../../../../../hooks/analytics/useTrack";
import type { Wallet } from "../server-wallets/wallet-table/types";
import { SmartAccountCell } from "../server-wallets/wallet-table/wallet-table-ui.client";
import { deleteUserAccessToken, getUserAccessToken } from "./utils";

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

const userAccessToken =
props.userAccessToken ?? getUserAccessToken(props.project.id) ?? "";

const form = useForm<FormValues>({
resolver: zodResolver(formSchema),
defaultValues: {
accessToken: props.userAccessToken ?? "",
accessToken: userAccessToken,
walletIndex:
props.wallets && props.walletId
? props.wallets
Expand Down Expand Up @@ -147,7 +151,7 @@ export function SendTestTransaction(props: {
)}
<p className="flex items-center gap-2 text-sm text-warning-text">
<LockIcon className="h-4 w-4" />
{props.userAccessToken
{userAccessToken
? "Copy your Vault access token, you'll need it for every HTTP call to Engine."
: "Every wallet action requires your Vault access token."}
</p>
Expand All @@ -157,12 +161,12 @@ export function SendTestTransaction(props: {
<div className="flex-grow">
<div className="flex flex-col gap-2">
<p className="text-sm">Vault Access Token</p>
{props.userAccessToken ? (
{userAccessToken ? (
<div className="flex flex-col gap-2 ">
<CopyTextButton
copyIconPosition="right"
textToCopy={props.userAccessToken}
textToShow={props.userAccessToken}
textToCopy={userAccessToken}
textToShow={userAccessToken}
tooltip="Copy Vault Access Token"
className="!h-auto w-full justify-between bg-background px-3 py-3 font-mono text-xs"
/>
Expand All @@ -175,7 +179,7 @@ export function SendTestTransaction(props: {
) : (
<Input
id="access-token"
type={props.userAccessToken ? "text" : "password"}
type={userAccessToken ? "text" : "password"}
placeholder="vt_act_1234....ABCD"
{...form.register("accessToken")}
disabled={isLoading}
Expand Down Expand Up @@ -287,6 +291,8 @@ export function SendTestTransaction(props: {
} else {
router.refresh();
}
// clear token from local storage after FTUX is complete
deleteUserAccessToken(props.project.id);
}}
>
{props.walletId ? "Close" : "Complete Setup"}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export function storeUserAccessToken(projectId: string, accessToken: string) {
localStorage.setItem(
`thirdweb:engine-cloud-user-access-token-${projectId}`,
accessToken,
);
}

export function getUserAccessToken(projectId: string) {
return localStorage.getItem(
`thirdweb:engine-cloud-user-access-token-${projectId}`,
);
}

export function deleteUserAccessToken(projectId: string) {
localStorage.removeItem(
`thirdweb:engine-cloud-user-access-token-${projectId}`,
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { CheckIcon, DownloadIcon, Loader2Icon, LockIcon } from "lucide-react";
import { useState } from "react";
import { toast } from "sonner";
import { useTrack } from "../../../../../../../../../hooks/analytics/useTrack";
import { storeUserAccessToken } from "../../analytics/utils";
import {
createManagementAccessToken,
createWalletAccessToken,
Expand Down Expand Up @@ -86,6 +87,11 @@ export default function CreateVaultAccountButton(props: {
throw new Error("Failed to create access token");
}

// save in local storage in case the user refreshes the page during FTUX
storeUserAccessToken(
props.project.id,
userAccessTokenRes.data.accessToken,
);
props.onUserAccessTokenCreated?.(userAccessTokenRes.data.accessToken);

return {
Expand Down
Loading