-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add remove account group #1871
Merged
OKendigelyan
merged 2 commits into
add-account-derivation-for-mnemonic-users
from
add-remove-account-group
Sep 12, 2024
Merged
Add remove account group #1871
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,13 @@ import { | |
mockMnemonicAccount, | ||
mockSocialAccount, | ||
} from "@umami/core"; | ||
import { type UmamiStore, accountsActions, addTestAccounts, makeStore } from "@umami/state"; | ||
import { | ||
type UmamiStore, | ||
accountsActions, | ||
addTestAccount, | ||
addTestAccounts, | ||
makeStore, | ||
} from "@umami/state"; | ||
|
||
import { AccountSelectorModal } from "./AccountSelectorModal"; | ||
import { DeriveMnemonicAccountModal } from "./DeriveMnemonicAccountModal"; | ||
|
@@ -58,6 +64,87 @@ describe("<AccountSelectorModal />", () => { | |
} | ||
); | ||
|
||
describe("when clicking 'Remove account group' button", () => { | ||
it.each([ | ||
["mnemonic", mockMnemonicAccount(0)], | ||
["ledger", mockLedgerAccount(1)], | ||
["social", mockSocialAccount(2)], | ||
])( | ||
"opens confirmation modal when clicking remove button for %s accounts", | ||
async (_, account) => { | ||
const user = userEvent.setup(); | ||
await renderInModal(<AccountSelectorModal />, store); | ||
const accountLabel = getAccountGroupLabel(account); | ||
|
||
const removeButton = screen.getByLabelText(`Remove ${accountLabel} accounts`); | ||
await act(() => user.click(removeButton)); | ||
|
||
expect(screen.getByText("Remove All Accounts")).toBeInTheDocument(); | ||
|
||
await waitFor(() => | ||
expect( | ||
screen.getByText(`Are you sure you want to remove all of your ${accountLabel}?`) | ||
).toBeVisible() | ||
); | ||
} | ||
); | ||
|
||
it("removes mnemonic accounts when confirmed", async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this test is not grouped with ledger & social? |
||
const user = userEvent.setup(); | ||
await renderInModal(<AccountSelectorModal />, store); | ||
const account = mockMnemonicAccount(0); | ||
const accountLabel = getAccountGroupLabel(account); | ||
const removeButton = screen.getByLabelText(`Remove ${accountLabel} accounts`); | ||
await act(() => user.click(removeButton)); | ||
|
||
const confirmButton = screen.getByText("Remove"); | ||
await act(() => user.click(confirmButton)); | ||
|
||
expect(store.getState().accounts.seedPhrases[account.seedFingerPrint]).toBe(undefined); | ||
expect(store.getState().accounts.items.length).toBe(2); | ||
}); | ||
|
||
it.each([ | ||
["ledger", mockLedgerAccount(1)], | ||
["social", mockSocialAccount(2)], | ||
])("removes %s accounts when confirmed", async (_, account) => { | ||
const user = userEvent.setup(); | ||
await renderInModal(<AccountSelectorModal />, store); | ||
const accountLabel = getAccountGroupLabel(account); | ||
const accounts = store.getState().accounts.items; | ||
|
||
const removeButton = screen.getByLabelText(`Remove ${accountLabel} accounts`); | ||
await act(() => user.click(removeButton)); | ||
|
||
const confirmButton = screen.getByText("Remove"); | ||
await act(() => user.click(confirmButton)); | ||
|
||
expect(store.getState().accounts.items.length).toBe(accounts.length - 1); | ||
}); | ||
|
||
it('shows "Remove & Off-board" message when removing last group of accounts', async () => { | ||
store.dispatch(accountsActions.reset()); | ||
addTestAccount(store, mockSocialAccount(0)); | ||
|
||
const user = userEvent.setup(); | ||
const accountLabel = getAccountGroupLabel(mockSocialAccount(0)); | ||
await renderInModal(<AccountSelectorModal />, store); | ||
|
||
const removeButton = screen.getByLabelText(`Remove ${accountLabel} accounts`); | ||
await act(() => user.click(removeButton)); | ||
|
||
expect(screen.getByText("Remove & Off-board")).toBeInTheDocument(); | ||
|
||
await waitFor(() => | ||
expect( | ||
screen.getByText( | ||
"Removing all your accounts will off-board you from Umami. This will remove or reset all customized settings to their defaults. Personal data (including saved contacts, password and accounts) won't be affected." | ||
) | ||
).toBeVisible() | ||
); | ||
}); | ||
}); | ||
|
||
it("opens appropriate modal when clicking 'Add Account' button", async () => { | ||
const user = userEvent.setup(); | ||
const { openWith } = dynamicModalContextMock; | ||
|
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
64 changes: 64 additions & 0 deletions
64
apps/web/src/components/ConfirmationModal/ConfirmationModal.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,64 @@ | ||
import { | ||
Button, | ||
Center, | ||
Heading, | ||
ModalBody, | ||
ModalContent, | ||
ModalFooter, | ||
ModalHeader, | ||
Text, | ||
} from "@chakra-ui/react"; | ||
import { useDynamicModalContext } from "@umami/components"; | ||
|
||
import { useColor } from "../../styles/useColor"; | ||
import { ModalBackButton } from "../BackButton"; | ||
import { ModalCloseButton } from "../CloseButton"; | ||
|
||
export const ConfirmationModal = ({ | ||
title, | ||
description, | ||
buttonLabel, | ||
onSubmit, | ||
}: { | ||
title: string; | ||
buttonLabel: string; | ||
description?: string; | ||
onSubmit: () => void; | ||
}) => { | ||
const { onClose } = useDynamicModalContext(); | ||
const onClick = () => { | ||
onSubmit(); | ||
onClose(); | ||
}; | ||
|
||
const color = useColor(); | ||
|
||
return ( | ||
<ModalContent> | ||
<ModalHeader> | ||
<Heading size="xl">{title}</Heading> | ||
<ModalBackButton /> | ||
<ModalCloseButton /> | ||
</ModalHeader> | ||
<ModalBody> | ||
<Center> | ||
<Text | ||
width="full" | ||
maxWidth="340px" | ||
color={color("700")} | ||
fontWeight="400" | ||
textAlign="center" | ||
size="md" | ||
> | ||
{description} | ||
</Text> | ||
</Center> | ||
</ModalBody> | ||
<ModalFooter> | ||
<Button width="full" onClick={onClick} size="lg" variant="alert"> | ||
{buttonLabel} | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { ConfirmationModal } from "./ConfirmationModal"; |
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 |
---|---|---|
@@ -1,48 +1,13 @@ | ||
import { | ||
Button, | ||
Center, | ||
Heading, | ||
ModalBody, | ||
ModalContent, | ||
ModalFooter, | ||
ModalHeader, | ||
Text, | ||
} from "@chakra-ui/react"; | ||
import { logout } from "@umami/state"; | ||
|
||
import { useColor } from "../../styles/useColor"; | ||
import { persistor } from "../../utils/persistor"; | ||
import { ModalCloseButton } from "../CloseButton"; | ||
import { ConfirmationModal } from "../ConfirmationModal"; | ||
|
||
export const LogoutModal = () => { | ||
const color = useColor(); | ||
|
||
return ( | ||
<ModalContent> | ||
<ModalHeader> | ||
<Heading size="xl">Logout</Heading> | ||
<ModalCloseButton /> | ||
</ModalHeader> | ||
<ModalBody> | ||
<Center> | ||
<Text | ||
width="full" | ||
maxWidth="340px" | ||
color={color("700")} | ||
fontWeight="400" | ||
textAlign="center" | ||
size="md" | ||
> | ||
Before logging out, make sure your mnemonic phrase is securely saved. Losing this phrase | ||
could result in permanent loss of access to your data. | ||
</Text> | ||
</Center> | ||
</ModalBody> | ||
<ModalFooter> | ||
<Button width="full" onClick={() => logout(persistor)} size="lg" variant="alert"> | ||
Logout | ||
</Button> | ||
</ModalFooter> | ||
</ModalContent> | ||
); | ||
}; | ||
export const LogoutModal = () => ( | ||
<ConfirmationModal | ||
buttonLabel="Logout" | ||
description="Before logging out, make sure your mnemonic phrase is securely saved. Losing this phrase could result in permanent loss of access to your data." | ||
onSubmit={() => logout(persistor)} | ||
title="Logout" | ||
/> | ||
); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
nit:
accountLabel
->groupLabel
maybe?Same for other tests here