diff --git a/apps/web/src/components/AccountSelectorModal/DeriveMnemonicAccountModal/DeriveMnemonicAccountModal.test.tsx b/apps/web/src/components/AccountSelectorModal/DeriveMnemonicAccountModal/DeriveMnemonicAccountModal.test.tsx index 0976c667b6..4a3e61a79c 100644 --- a/apps/web/src/components/AccountSelectorModal/DeriveMnemonicAccountModal/DeriveMnemonicAccountModal.test.tsx +++ b/apps/web/src/components/AccountSelectorModal/DeriveMnemonicAccountModal/DeriveMnemonicAccountModal.test.tsx @@ -39,7 +39,7 @@ describe("", () => { const account = mockMnemonicAccount(0); await renderInModal(, store); - await act(() => user.type(screen.getByLabelText("Account name"), "Test Account")); + await act(() => user.type(screen.getByLabelText("Account name (Optional)"), "Test Account")); await act(() => user.click(screen.getByRole("button", { name: "Continue" }))); await waitFor(() => { @@ -53,7 +53,7 @@ describe("", () => { const account = mockMnemonicAccount(0); await renderInModal(, store); - await act(() => user.type(screen.getByLabelText("Account name"), "Test Account")); + await act(() => user.type(screen.getByLabelText("Account name (Optional)"), "Test Account")); await act(() => user.click(screen.getByRole("button", { name: "Continue" }))); await act(() => user.type(screen.getByLabelText("Password"), "test-password")); await act(() => user.click(screen.getByRole("button", { name: "Submit" }))); diff --git a/apps/web/src/components/Menu/AdvancedMenu/AdvancedMenu.test.tsx b/apps/web/src/components/Menu/AdvancedMenu/AdvancedMenu.test.tsx index 701930960f..eed3e7152e 100644 --- a/apps/web/src/components/Menu/AdvancedMenu/AdvancedMenu.test.tsx +++ b/apps/web/src/components/Menu/AdvancedMenu/AdvancedMenu.test.tsx @@ -19,7 +19,7 @@ beforeEach(() => { describe("", () => { describe("when user is verified", () => { it("renders advanced menu items correctly", async () => { - await renderInDrawer(); + await renderInDrawer(, store); expect(screen.getByText("Change Password")).toBeVisible(); expect(screen.getByText("Network")).toBeVisible(); @@ -33,7 +33,7 @@ describe("", () => { ])("opens %label menu", async (label, Component) => { const { openWith } = dynamicDrawerContextMock; - await renderInDrawer(); + await renderInDrawer(, store); await userEvent.click(screen.getByText(label)); expect(openWith).toHaveBeenCalledWith(); diff --git a/apps/web/src/components/Menu/Menu.test.tsx b/apps/web/src/components/Menu/Menu.test.tsx index e95c031ab5..d889d8214c 100644 --- a/apps/web/src/components/Menu/Menu.test.tsx +++ b/apps/web/src/components/Menu/Menu.test.tsx @@ -20,6 +20,7 @@ import { screen, userEvent, } from "../../testUtils"; +import { OnboardOptionsModal } from "../Onboarding/OnboardOptions"; jest.mock("@chakra-ui/system", () => ({ ...jest.requireActual("@chakra-ui/system"), @@ -51,7 +52,7 @@ describe("", () => { describe("when user is verified", () => { it("renders menu items correctly", async () => { - await renderInDrawer(); + await renderInDrawer(, store); expect(screen.getByText("Advanced")).toBeVisible(); expect(screen.getByText("Address Book")).toBeVisible(); @@ -70,7 +71,7 @@ describe("", () => { const user = userEvent.setup(); const { openWith } = dynamicDrawerContextMock; - await renderInDrawer(); + await renderInDrawer(, store); await user.click(screen.getByText(label)); expect(openWith).toHaveBeenCalledWith(); @@ -80,7 +81,7 @@ describe("", () => { const user = userEvent.setup(); const { openWith } = dynamicModalContextMock; - await renderInDrawer(); + await renderInDrawer(, store); await user.click(screen.getByText("Logout")); expect(openWith).toHaveBeenCalledWith(); @@ -88,7 +89,7 @@ describe("", () => { it("calls downloadBackupFile function when Save Backup is clicked", async () => { const user = userEvent.setup(); - await renderInDrawer(); + await renderInDrawer(, store); await user.click(screen.getByText("Save Backup")); @@ -97,22 +98,22 @@ describe("", () => { it("calls toggleColorMode function when Light mode is clicked", async () => { const user = userEvent.setup(); - await renderInDrawer(); + await renderInDrawer(, store); await user.click(screen.getByText("Light mode")); expect(useColorMode().toggleColorMode).toHaveBeenCalled(); }); - // TODO: add when Add Account logic is ready - // it("opens Add Account modal when Add Account button is clicked", async () => { - // const user = userEvent.setup(); - // await renderInDrawer(); + it("opens Add Account modal when Add Account button is clicked", async () => { + const { openWith } = dynamicModalContextMock; + const user = userEvent.setup(); + await renderInDrawer(, store); - // await user.click(screen.getByText("Add Account")); + await user.click(screen.getByText("Add Account")); - // expect(useOnboardingModal().onOpen).toHaveBeenCalled(); - // }); + expect(openWith).toHaveBeenCalledWith(); + }); }); describe("when user is unverified", () => { diff --git a/apps/web/src/components/NameAccountModal/NameAccountModal.test.tsx b/apps/web/src/components/NameAccountModal/NameAccountModal.test.tsx index 8c4d88ce9c..93b9712435 100644 --- a/apps/web/src/components/NameAccountModal/NameAccountModal.test.tsx +++ b/apps/web/src/components/NameAccountModal/NameAccountModal.test.tsx @@ -1,3 +1,5 @@ +import { defaultDerivationPathTemplate } from "@umami/tezos"; + import { NameAccountModal } from "./NameAccountModal"; import { act, renderInModal, screen, userEvent, waitFor } from "../../testUtils"; @@ -13,6 +15,7 @@ describe("NameAccountModal", () => { expect(screen.getByText("Custom Title")).toBeVisible(); }); expect(screen.getByText("Custom Subtitle")).toBeVisible(); + expect(screen.queryByTestId("advanced-section")).not.toBeInTheDocument(); }); it("calls onSubmit with form data when submitted", async () => { @@ -20,9 +23,34 @@ describe("NameAccountModal", () => { await renderInModal(); - await act(() => user.type(screen.getByLabelText("Account name"), "Test Account")); + await act(() => user.type(screen.getByLabelText("Account name (Optional)"), "Test Account")); await act(() => user.click(screen.getByRole("button", { name: "Continue" }))); expect(mockOnSubmit).toHaveBeenCalled(); }); + + it("renders advanced settings when enabled", async () => { + await renderInModal(); + + expect(screen.getByTestId("advanced-section")).toBeVisible(); + }); + + it("submits the form with advanced settings when enabled", async () => { + const user = userEvent.setup(); + await renderInModal(); + + const input = screen.getByTestId("accountName"); + const submitButton = screen.getByRole("button", { name: "Continue" }); + + await user.type(input, "My Advanced Account"); + await user.click(submitButton); + + expect(mockOnSubmit).toHaveBeenCalledWith( + expect.objectContaining({ + accountName: "My Advanced Account", + derivationPath: defaultDerivationPathTemplate, + curve: "ed25519", + }) + ); + }); }); diff --git a/apps/web/src/components/NameAccountModal/NameAccountModal.tsx b/apps/web/src/components/NameAccountModal/NameAccountModal.tsx index c4e907803b..86b736554e 100644 --- a/apps/web/src/components/NameAccountModal/NameAccountModal.tsx +++ b/apps/web/src/components/NameAccountModal/NameAccountModal.tsx @@ -13,22 +13,29 @@ import { Text, } from "@chakra-ui/react"; import { useMultiForm } from "@umami/components"; +import { defaultDerivationPathTemplate } from "@umami/tezos"; +import { FormProvider } from "react-hook-form"; import { UserIcon } from "../../assets/icons"; import { useColor } from "../../styles/useColor"; import { ModalBackButton } from "../BackButton"; import { ModalCloseButton } from "../CloseButton"; +import { AdvancedAccountSettings } from "../Onboarding/AdvancedAccountSettings"; type NameAccountModalProps = { title?: string; subtitle?: string; onSubmit: (values: { accountName: string }) => void; + withAdvancedSettings?: boolean; + buttonLabel?: string; }; export const NameAccountModal = ({ title = "Name Your Account", subtitle, onSubmit, + withAdvancedSettings = false, + buttonLabel = "Continue", }: NameAccountModalProps) => { const color = useColor(); @@ -36,6 +43,10 @@ export const NameAccountModal = ({ mode: "onBlur", defaultValues: { accountName: "", + ...(withAdvancedSettings && { + derivationPath: defaultDerivationPathTemplate, + curve: "ed25519", + }), }, }); @@ -50,32 +61,43 @@ export const NameAccountModal = ({ {title} {subtitle && ( - + {subtitle} )} -
- - - Account name - - - - - - -
+ +
+ + + Account name (Optional) + + + {withAdvancedSettings && } + + + + +
+
); }; diff --git a/apps/web/src/components/Onboarding/AdvancedAccountSettings/AdvancedAccountSettings.tsx b/apps/web/src/components/Onboarding/AdvancedAccountSettings/AdvancedAccountSettings.tsx index 7a84d3394a..717fef4606 100644 --- a/apps/web/src/components/Onboarding/AdvancedAccountSettings/AdvancedAccountSettings.tsx +++ b/apps/web/src/components/Onboarding/AdvancedAccountSettings/AdvancedAccountSettings.tsx @@ -63,13 +63,10 @@ export const AdvancedAccountSettings = () => { diff --git a/apps/web/src/components/Onboarding/OnboardOptions/OnboardOptions.tsx b/apps/web/src/components/Onboarding/OnboardOptions/OnboardOptions.tsx index fd192d7ed7..82e19951b6 100644 --- a/apps/web/src/components/Onboarding/OnboardOptions/OnboardOptions.tsx +++ b/apps/web/src/components/Onboarding/OnboardOptions/OnboardOptions.tsx @@ -8,13 +8,31 @@ import { OnboardWithRedditButton } from "./OnboardWithRedditButton"; import { OnboardWithTwitterButton } from "./OnboardWithTwitterButton"; import { useColor } from "../../../styles/useColor"; import { AccountTileWrapper } from "../../AccountTile"; +import { NameAccountModal } from "../../NameAccountModal"; import { ImportWallet } from "../ImportWallet"; import { SetupPassword } from "../SetupPassword"; +import { useIsAccountVerified } from "../VerificationFlow"; export const OnboardOptions = ({ children }: PropsWithChildren) => { const color = useColor(); - const { openWith } = useDynamicModalContext(); + const isAccountVerified = useIsAccountVerified(); + + const handleCreateNewWallet = () => { + if (isAccountVerified) { + return openWith( + openWith()} + subtitle={"Name your account or edit your\n account name later."} + title="Create Account" + withAdvancedSettings + /> + ); + } else { + return openWith(); + } + }; return ( @@ -50,12 +68,7 @@ export const OnboardOptions = ({ children }: PropsWithChildren) => { -