Skip to content

Commit

Permalink
Add address book menu (#1743)
Browse files Browse the repository at this point in the history
  • Loading branch information
OKendigelyan authored Aug 19, 2024
1 parent 0a89d73 commit c8cbbf5
Show file tree
Hide file tree
Showing 27 changed files with 752 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe("<AdvancedSettingsAccordion />", () => {
});

it("updates fee value on change", async () => {
const user = userEvent;
const user = userEvent.setup();
render(<TestComponent />);

await act(() => user.click(screen.getByRole("button", { name: "Advanced" })));
Expand All @@ -58,7 +58,7 @@ describe("<AdvancedSettingsAccordion />", () => {
});

it("updates gas limit value on change", async () => {
const user = userEvent;
const user = userEvent.setup();
render(<TestComponent />);
await act(() => user.click(screen.getByRole("button", { name: "Advanced" })));

Expand All @@ -70,7 +70,7 @@ describe("<AdvancedSettingsAccordion />", () => {
});

it("updates storage limit value on change", async () => {
const user = userEvent;
const user = userEvent.setup();
render(<TestComponent />);
await act(() => user.click(screen.getByRole("button", { name: "Advanced" })));

Expand Down
24 changes: 12 additions & 12 deletions apps/desktop/src/components/UpsertContactModal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe("<UpsertContactModal />", () => {
});

it("validates updated address", async () => {
const user = userEvent;
const user = userEvent.setup();
render(modalComponent, { store });

const addressInput = screen.getByLabelText("Address");
Expand All @@ -68,7 +68,7 @@ describe("<UpsertContactModal />", () => {
});

it("checks the name is unique", async () => {
const user = userEvent;
const user = userEvent.setup();
store.dispatch(contactsActions.upsert(contact2));
render(modalComponent, { store });

Expand All @@ -86,7 +86,7 @@ describe("<UpsertContactModal />", () => {
});

it("adds contact to address book", async () => {
const user = userEvent;
const user = userEvent.setup();
store.dispatch(contactsActions.upsert(contact2));
render(modalComponent, { store });

Expand Down Expand Up @@ -116,7 +116,7 @@ describe("<UpsertContactModal />", () => {
jest
.mocked(getNetworksForContracts)
.mockResolvedValue(new Map([[contractPkh, "ghostnet"]]));
const user = userEvent;
const user = userEvent.setup();
render(modalComponent, { store });

// Set name
Expand All @@ -143,7 +143,7 @@ describe("<UpsertContactModal />", () => {

it("shows error toast on unknown network for contract addresses", async () => {
jest.mocked(getNetworksForContracts).mockResolvedValue(new Map());
const user = userEvent;
const user = userEvent.setup();
render(modalComponent, { store });

// Set name
Expand Down Expand Up @@ -182,7 +182,7 @@ describe("<UpsertContactModal />", () => {
});

it("validates initial address field", async () => {
const user = userEvent;
const user = userEvent.setup();
render(
<UpsertContactModal
contact={{
Expand All @@ -203,7 +203,7 @@ describe("<UpsertContactModal />", () => {
});

it("adds contact to address book with pre-filled address", async () => {
const user = userEvent;
const user = userEvent.setup();
store.dispatch(contactsActions.upsert(contact2));
render(
<UpsertContactModal
Expand Down Expand Up @@ -237,7 +237,7 @@ describe("<UpsertContactModal />", () => {
jest
.mocked(getNetworksForContracts)
.mockResolvedValue(new Map([[contractPkh, "ghostnet"]]));
const user = userEvent;
const user = userEvent.setup();
render(
<UpsertContactModal
contact={{
Expand Down Expand Up @@ -268,7 +268,7 @@ describe("<UpsertContactModal />", () => {

it("shows error toast on unknown network for contract addresses", async () => {
jest.mocked(getNetworksForContracts).mockResolvedValue(new Map());
const user = userEvent;
const user = userEvent.setup();
render(
<UpsertContactModal
contact={{
Expand Down Expand Up @@ -316,7 +316,7 @@ describe("<UpsertContactModal />", () => {
});

it("checks the name was updated", async () => {
const user = userEvent;
const user = userEvent.setup();
render(<UpsertContactModal contact={contact1} />, { store });

await act(() => user.click(screen.getByLabelText("Name")));
Expand All @@ -329,7 +329,7 @@ describe("<UpsertContactModal />", () => {
});

it("checks the name is unique", async () => {
const user = userEvent;
const user = userEvent.setup();
store.dispatch(contactsActions.upsert(contact2));
render(<UpsertContactModal contact={contact1} />, { store });

Expand All @@ -347,7 +347,7 @@ describe("<UpsertContactModal />", () => {
});

it("updates contact in address book", async () => {
const user = userEvent;
const user = userEvent.setup();
store.dispatch(contactsActions.upsert(contact2));
render(<UpsertContactModal contact={contact1} />, { store });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const AccountSelectorPopover = ({ account }: AccountSelectorPopoverProps)
variant="dropdownOption"
>
<ExternalLinkIcon />
<Text color={color("900")} fontWeight="600">
<Text color={color("900")} fontWeight="600" size="lg">
View in TzKT
</Text>
</Link>
Expand Down
10 changes: 4 additions & 6 deletions apps/web/src/components/ActionsDropdown/ActionsDropdown.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Popover, PopoverBody, PopoverContent, PopoverTrigger, Portal } from "@chakra-ui/react";
import { Popover, PopoverBody, PopoverContent, PopoverTrigger } from "@chakra-ui/react";
import { type PropsWithChildren, type ReactNode } from "react";

import { useColor } from "../../styles/useColor";
Expand All @@ -13,11 +13,9 @@ export const ActionsDropdown = ({ actions, children }: PropsWithChildren<Actions
return (
<Popover variant="dropdown">
<PopoverTrigger>{children}</PopoverTrigger>
<Portal>
<PopoverContent maxWidth="204px" data-testid="popover-content">
<PopoverBody color={color("400")}>{actions}</PopoverBody>
</PopoverContent>
</Portal>
<PopoverContent maxWidth="204px" data-testid="popover-content">
<PopoverBody color={color("400")}>{actions}</PopoverBody>
</PopoverContent>
</Popover>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe("<AdvancedSettingsAccordion />", () => {
});

it("updates fee value on change", async () => {
const user = userEvent;
const user = userEvent.setup();
render(<TestComponent />);

await act(() => user.click(screen.getByRole("button", { name: "Advanced" })));
Expand All @@ -58,7 +58,7 @@ describe("<AdvancedSettingsAccordion />", () => {
});

it("updates gas limit value on change", async () => {
const user = userEvent;
const user = userEvent.setup();
render(<TestComponent />);
await act(() => user.click(screen.getByRole("button", { name: "Advanced" })));

Expand All @@ -70,7 +70,7 @@ describe("<AdvancedSettingsAccordion />", () => {
});

it("updates storage limit value on change", async () => {
const user = userEvent;
const user = userEvent.setup();
render(<TestComponent />);
await act(() => user.click(screen.getByRole("button", { name: "Advanced" })));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ export const CopyAddressButton = memo(

return (
<CopyButton
left="-8px"
height="auto"
padding="4px 8px"
aria-label="Copy Address"
variant="unstyled"
variant="ghost"
{...props}
value={address}
>
Expand Down
14 changes: 0 additions & 14 deletions apps/web/src/components/Menu/AddressBookMenu.tsx

This file was deleted.

127 changes: 127 additions & 0 deletions apps/web/src/components/Menu/AddressBookMenu/AddressBookMenu.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import {
Box,
Button,
Center,
Divider,
Flex,
Heading,
IconButton,
Text,
VStack,
useBreakpointValue,
} from "@chakra-ui/react";
import { useDynamicDrawerContext, useDynamicModalContext } from "@umami/components";
import { type Contact } from "@umami/core";
import { useSortedContacts } from "@umami/state";

import { DeleteContactModal } from "./DeleteContactModal";
import { EditContactMenu } from "./EditContactMenu";
import { EditIcon, ThreeDotsIcon, TrashIcon } from "../../../assets/icons";
import { useColor } from "../../../styles/useColor";
import { ActionsDropdown } from "../../ActionsDropdown";
import { CopyAddressButton } from "../../CopyAddressButton";
import { EmptyMessage } from "../../EmptyMessage";
import { DrawerContentWrapper } from "../DrawerContentWrapper";

type ContactItemProps = {
contact: Contact;
};

const ContactItem = ({ contact }: ContactItemProps) => {
const { openWith: openDrawer } = useDynamicDrawerContext();
const { openWith: openModal } = useDynamicModalContext();
const color = useColor();

const isLongAddress = useBreakpointValue({ base: false, md: true });

const actions = (
<Box>
<Button
data-testid="edit-network"
onClick={e => {
e.stopPropagation();
return openDrawer(<EditContactMenu contact={contact} />);
}}
variant="dropdownOption"
>
<EditIcon />
<Text color={color("900")} fontWeight="600">
Edit
</Text>
</Button>
<Button
data-testid="remove-network"
onClick={() => openModal(<DeleteContactModal contact={contact} />)}
variant="dropdownOption"
>
<TrashIcon />
<Text color={color("900")} fontWeight="600">
Remove
</Text>
</Button>
</Box>
);

return (
<Center
key={contact.pkh}
alignItems="center"
justifyContent="space-between"
width="full"
height="60px"
data-testid="peer-row"
>
<Flex height="100%">
<Center alignItems="flex-start" flexDirection="column" gap="6px">
<Heading color={color("900")} size="lg">
{contact.name}
</Heading>
<CopyAddressButton address={contact.pkh} isLong={isLongAddress} />
</Center>
</Flex>
<ActionsDropdown actions={actions}>
<IconButton color={color("500")} aria-label="Remove Peer" icon={<ThreeDotsIcon />} />
</ActionsDropdown>
</Center>
);
};

export const AddressBookMenu = () => {
const { openWith } = useDynamicDrawerContext();
const contacts = useSortedContacts();

return (
<DrawerContentWrapper title="Address book">
<Button
width="fit-content"
marginTop="18px"
padding="0 24px"
onClick={() => openWith(<EditContactMenu />)}
variant="secondary"
>
Add Contact
</Button>
<Divider marginTop={{ base: "36px", lg: "40px" }} />
{contacts.length ? (
<VStack
alignItems="flex-start"
gap="24px"
marginTop="24px"
divider={<Divider />}
spacing="0"
>
{contacts.map(contact => (
<ContactItem key={contact.pkh} contact={contact} />
))}
</VStack>
) : (
<EmptyMessage
alignItems="flex-start"
marginTop="40px"
subtitle="Contacts"
title="Contacts"
/>
)}
</DrawerContentWrapper>
);
};
Loading

1 comment on commit c8cbbf5

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Title Lines Statements Branches Functions
apps/desktop Coverage: 84%
84.06% (1825/2171) 79.11% (860/1087) 78.79% (457/580)
apps/web Coverage: 84%
84.06% (1825/2171) 79.11% (860/1087) 78.79% (457/580)
packages/components Coverage: 96%
95% (114/120) 100% (48/48) 77.14% (27/35)
packages/core Coverage: 81%
82.46% (174/211) 70.75% (75/106) 81.13% (43/53)
packages/crypto Coverage: 100%
100% (28/28) 100% (3/3) 100% (5/5)
packages/data-polling Coverage: 98%
96.55% (140/145) 95.45% (21/22) 92.85% (39/42)
packages/multisig Coverage: 98%
98.4% (123/125) 89.47% (17/19) 100% (33/33)
packages/social-auth Coverage: 100%
100% (22/22) 100% (11/11) 100% (4/4)
packages/state Coverage: 84%
84.32% (769/912) 80.4% (160/199) 79.61% (289/363)
packages/tezos Coverage: 86%
85.1% (80/94) 92.85% (13/14) 82.14% (23/28)
packages/tzkt Coverage: 86%
84.05% (58/69) 81.25% (13/16) 76.92% (30/39)

Please sign in to comment.