-
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.
Add social login 2fa warning (#2234)
- Loading branch information
1 parent
ce58089
commit 4263bbc
Showing
11 changed files
with
356 additions
and
54 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
86 changes: 86 additions & 0 deletions
86
apps/desktop/src/components/SocialLoginWarningModal/SocialLoginWarningModal.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,86 @@ | ||
import { SocialLoginWarningModal } from "./SocialLoginWarningModal"; | ||
import { | ||
act, | ||
dynamicModalContextMock, | ||
render, | ||
screen, | ||
userEvent, | ||
waitFor, | ||
} from "../../mocks/testUtils"; | ||
|
||
beforeEach(() => { | ||
localStorage.clear(); | ||
}); | ||
|
||
describe("<SocialLoginWarningModal />", () => { | ||
it("renders the modal with correct title and content", async () => { | ||
render(<SocialLoginWarningModal />); | ||
|
||
await waitFor(() => { | ||
expect(screen.getByText("Important notice about your social account wallet")).toBeVisible(); | ||
}); | ||
|
||
expect( | ||
screen.getByText( | ||
"Wallets created with social accounts depend on those accounts to function. Losing access to this social account will result in loosing the wallet. Enable two-factor authentication to protect your social accounts." | ||
) | ||
).toBeVisible(); | ||
}); | ||
|
||
it("disables 'Continue' button when checkbox is not checked", () => { | ||
render(<SocialLoginWarningModal />); | ||
|
||
const button = screen.getByRole("button", { name: "Continue" }); | ||
expect(button).toBeDisabled(); | ||
}); | ||
|
||
it("enables 'Continue' button when checkbox is checked", async () => { | ||
const user = userEvent.setup(); | ||
render(<SocialLoginWarningModal />); | ||
|
||
const checkbox = screen.getByRole("checkbox", { | ||
name: "I understand and accept the risks.", | ||
}); | ||
await act(() => user.click(checkbox)); | ||
|
||
const continueButton = screen.getByRole("button", { name: "Continue" }); | ||
expect(continueButton).toBeEnabled(); | ||
}); | ||
|
||
it("sets localStorage and closes modal when 'Continue' is clicked", async () => { | ||
const { onClose } = dynamicModalContextMock; | ||
const user = userEvent.setup(); | ||
render(<SocialLoginWarningModal />); | ||
|
||
const checkbox = screen.getByRole("checkbox", { | ||
name: "I understand and accept the risks.", | ||
}); | ||
await act(() => user.click(checkbox)); | ||
|
||
const continueButton = screen.getByRole("button", { name: "Continue" }); | ||
await act(() => user.click(continueButton)); | ||
|
||
await waitFor(() => { | ||
expect(localStorage.getItem("user:isSocialLoginWarningShown")).toBe("true"); | ||
}); | ||
|
||
expect(onClose).toHaveBeenCalled(); | ||
}); | ||
|
||
it("toggles checkbox state correctly", async () => { | ||
const user = userEvent.setup(); | ||
render(<SocialLoginWarningModal />); | ||
|
||
const checkbox = screen.getByRole("checkbox", { | ||
name: "I understand and accept the risks.", | ||
}); | ||
|
||
expect(checkbox).not.toBeChecked(); | ||
|
||
await act(() => user.click(checkbox)); | ||
expect(checkbox).toBeChecked(); | ||
|
||
await act(() => user.click(checkbox)); | ||
expect(checkbox).not.toBeChecked(); | ||
}); | ||
}); |
68 changes: 68 additions & 0 deletions
68
apps/desktop/src/components/SocialLoginWarningModal/SocialLoginWarningModal.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,68 @@ | ||
import { | ||
Button, | ||
Checkbox, | ||
Flex, | ||
Heading, | ||
Icon, | ||
ModalBody, | ||
ModalContent, | ||
ModalFooter, | ||
ModalHeader, | ||
Text, | ||
} from "@chakra-ui/react"; | ||
import { useDynamicModalContext } from "@umami/components"; | ||
import { useState } from "react"; | ||
|
||
import { WarningIcon } from "../../assets/icons"; | ||
import colors from "../../style/colors"; | ||
|
||
export const SocialLoginWarningModal = () => { | ||
const { onClose } = useDynamicModalContext(); | ||
const [isAgreed, setIsAgreed] = useState(false); | ||
|
||
const handleInform = () => { | ||
localStorage.setItem("user:isSocialLoginWarningShown", "true"); | ||
onClose(); | ||
}; | ||
|
||
return ( | ||
<ModalContent> | ||
<ModalHeader> | ||
<Flex | ||
alignItems="center" | ||
justifyContent="center" | ||
flexDirection="column" | ||
gap="16px" | ||
textAlign="center" | ||
> | ||
<Icon as={WarningIcon} width="22px" stroke={colors.gray[450]} /> | ||
<Heading size="xl">Important notice about your social account wallet</Heading> | ||
</Flex> | ||
</ModalHeader> | ||
<ModalBody marginTop="24px"> | ||
<Flex alignItems="center" flexDirection="column" gap="16px" textAlign="center"> | ||
<Text color={colors.gray[400]} fontSize="md"> | ||
Wallets created with social accounts depend on those accounts to function. Losing access | ||
to this social account will result in loosing the wallet. Enable two-factor | ||
authentication to protect your social accounts. | ||
</Text> | ||
<Checkbox | ||
marginTop="16px" | ||
color={colors.gray[400]} | ||
isChecked={isAgreed} | ||
onChange={e => setIsAgreed(e.target.checked)} | ||
> | ||
<Text fontSize="sm" fontWeight="bold"> | ||
I understand and accept the risks. | ||
</Text> | ||
</Checkbox> | ||
</Flex> | ||
</ModalBody> | ||
<ModalFooter> | ||
<Button width="full" isDisabled={!isAgreed} onClick={handleInform} variant="primary"> | ||
Continue | ||
</Button> | ||
</ModalFooter> | ||
</ModalContent> | ||
); | ||
}; |
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
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.
4263bbc
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.
4263bbc
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.
4263bbc
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.