-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f403f31
commit 5db5c19
Showing
14 changed files
with
345 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
apps/web/src/components/Onboarding/AdvancedAccountSettings/AdvancedAccountSettings.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { Button } from "@chakra-ui/react"; | ||
import { type Curves } from "@taquito/signer"; | ||
import { defaultDerivationPathTemplate } from "@umami/tezos"; | ||
import { FormProvider, useForm } from "react-hook-form"; | ||
|
||
import { AdvancedAccountSettings, CURVES } from "./AdvancedAccountSettings"; | ||
import { act, fireEvent, render, screen, userEvent, waitFor } from "../../../testUtils"; | ||
|
||
const TestComponent = ({ onSubmit }: { onSubmit: () => void }) => { | ||
const form = useForm<{ derivationPath: string; curve: Curves }>({ | ||
mode: "onBlur", | ||
defaultValues: { | ||
derivationPath: defaultDerivationPathTemplate, | ||
curve: "ed25519", | ||
}, | ||
}); | ||
|
||
return ( | ||
<FormProvider {...form}> | ||
<form onSubmit={form.handleSubmit(onSubmit)}> | ||
<AdvancedAccountSettings /> | ||
<Button type="submit">Submit</Button> | ||
</form> | ||
</FormProvider> | ||
); | ||
}; | ||
|
||
describe("<AdvancedAccountSettings />", () => { | ||
it("requires a derivation path", async () => { | ||
const user = userEvent.setup(); | ||
render(<TestComponent onSubmit={() => {}} />); | ||
|
||
await act(() => user.click(screen.getByText("Advanced"))); | ||
const input = screen.getByLabelText("Derivation Path"); | ||
await act(() => user.clear(input)); | ||
fireEvent.blur(input); | ||
|
||
await waitFor(() => expect(screen.getByText("Derivation path is required")).toBeVisible()); | ||
}); | ||
|
||
it.each(CURVES)("has %s curve option", async curve => { | ||
const user = userEvent.setup(); | ||
|
||
render(<TestComponent onSubmit={() => {}} />); | ||
|
||
await act(() => user.click(screen.getByText("Advanced"))); | ||
|
||
await waitFor(() => expect(screen.getByRole("button", { name: curve })).toBeVisible()); | ||
}); | ||
|
||
it("restores the default derivation on reset click", async () => { | ||
const user = userEvent.setup(); | ||
render(<TestComponent onSubmit={() => {}} />); | ||
|
||
const input = screen.getByLabelText("Derivation Path"); | ||
await act(() => user.clear(input)); | ||
await act(() => user.click(screen.getByText("Reset"))); | ||
|
||
await waitFor(() => expect(input).toHaveValue("44'/1729'/?'/0'")); | ||
}); | ||
}); |
87 changes: 87 additions & 0 deletions
87
apps/web/src/components/Onboarding/AdvancedAccountSettings/AdvancedAccountSettings.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { | ||
Accordion, | ||
AccordionButton, | ||
AccordionIcon, | ||
AccordionItem, | ||
AccordionPanel, | ||
Button, | ||
Flex, | ||
FormControl, | ||
FormErrorMessage, | ||
FormLabel, | ||
Heading, | ||
Input, | ||
InputGroup, | ||
InputRightElement, | ||
} from "@chakra-ui/react"; | ||
import { type Curves } from "@taquito/signer"; | ||
import { useFormContext } from "react-hook-form"; | ||
|
||
import { useColor } from "../../../styles/useColor"; | ||
import { RadioButtons } from "../../RadioButtons"; | ||
|
||
export const CURVES = ["ed25519", "secp256k1", "p256"]; | ||
|
||
export const AdvancedAccountSettings = () => { | ||
const color = useColor(); | ||
|
||
const form = useFormContext<{ derivationPath: string; curve: Curves }>(); | ||
|
||
const { | ||
formState: { errors }, | ||
register, | ||
resetField, | ||
} = form; | ||
|
||
return ( | ||
<Accordion marginTop="6px" allowToggle data-testid="advanced-section"> | ||
<AccordionItem> | ||
<AccordionButton justifyContent="center" color={color("900")}> | ||
<Heading size="md">Advanced</Heading> | ||
<AccordionIcon /> | ||
</AccordionButton> | ||
|
||
<AccordionPanel> | ||
<Flex flexDirection="column" gap="24px"> | ||
<FormControl isInvalid={!!errors.curve}> | ||
<FormLabel>Elliptic Curve</FormLabel> | ||
<Flex gap="8px"> | ||
<RadioButtons fontSize="sm" fontWeight="400" inputName="curve" options={CURVES} /> | ||
</Flex> | ||
</FormControl> | ||
|
||
<FormControl isInvalid={!!errors.derivationPath}> | ||
<FormLabel>Derivation Path</FormLabel> | ||
|
||
<InputGroup> | ||
<Input | ||
{...register("derivationPath", { | ||
required: "Derivation path is required", | ||
})} | ||
placeholder="m/44'/1729'/?'/0' (default)" | ||
/> | ||
<InputRightElement> | ||
<Button | ||
marginRight="10px" | ||
color={color("200")} | ||
fontWeight="600" | ||
background={color("black")} | ||
borderRadius="4px" | ||
_hover={{ background: color("400") }} | ||
onClick={() => resetField("derivationPath")} | ||
size="sm" | ||
> | ||
Reset | ||
</Button> | ||
</InputRightElement> | ||
</InputGroup> | ||
{errors.derivationPath && ( | ||
<FormErrorMessage>{errors.derivationPath.message}</FormErrorMessage> | ||
)} | ||
</FormControl> | ||
</Flex> | ||
</AccordionPanel> | ||
</AccordionItem> | ||
</Accordion> | ||
); | ||
}; |
1 change: 1 addition & 0 deletions
1
apps/web/src/components/Onboarding/AdvancedAccountSettings/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./AdvancedAccountSettings"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
5db5c19
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.