Skip to content
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 account tile to mobile header #1805

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/web/src/components/AccountCard/AccountCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const AccountCard = () => {
<AccountTile
background={color("50")}
account={currentAccount}
id="account-tile"
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it's better to put it inside account tile component itself?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we need this particular AccoundTile to avoid potential future collisions

onClick={() => openWith(<AccountSelectorModal />)}
>
<IconButton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export const AccountSelectorModal = () => {
aria-label="actions"
icon={<ThreeDotsIcon />}
size="xs"
variant="ghost"
/>
</Center>
{accounts.map(account => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export const AccountSelectorPopover = ({ account }: AccountSelectorPopoverProps)
icon={<ThreeDotsIcon />}
onClick={event => event.stopPropagation()}
size="xs"
variant="ghost"
/>
</ActionsDropdown>
);
Expand Down
37 changes: 26 additions & 11 deletions apps/web/src/components/AccountTile/AccountTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,47 @@ import { CopyAddressButton } from "../CopyAddressButton";
export const AccountTile = ({
account,
children,
size = "sm",
...props
}: PropsWithChildren<{ account: ImplicitAccount }> & FlexProps) => {
}: PropsWithChildren<{ account: ImplicitAccount; size?: "xs" | "sm" }> & FlexProps) => {
const color = useColor();
const address = account.address.pkh;

const sizes = {
xs: 20,
sm: 30,
};

const isSmall = size === "xs";
const copyButtonStyles = isSmall
? {
padding: 0,
left: 0,
}
: {};

return (
<Flex
gap="10px"
paddingLeft="12px"
gap={isSmall ? "6px" : "10px"}
padding={isSmall ? "6px 12px 6px 6px" : "12px 0 12px 16px"}
borderRadius="full"
_hover={{ background: color("100") }}
cursor={props.onClick ? "pointer" : undefined}
data-testid="account-tile"
paddingY="12px"
{...props}
>
<AccountTileWrapper>
<AccountTileIcon account={account} />
<AccountTileWrapper size={size}>
<AccountTileIcon account={account} size={sizes[size]} />
</AccountTileWrapper>

<Flex justifyContent="space-between" width="100%" marginRight="20px">
<Flex justifyContent="space-between" width="100%" marginRight={isSmall ? 0 : "20px"}>
<Flex justifyContent="center" flexDirection="column" gap="2px">
<Heading color={color("900")} size="sm">
{account.label}
</Heading>
<CopyAddressButton address={address} />
{!isSmall && (
<Heading color={color("900")} size="sm">
{account.label}
</Heading>
)}
<CopyAddressButton address={address} isCopyDisabled={isSmall} {...copyButtonStyles} />
</Flex>

{children}
Expand Down
41 changes: 40 additions & 1 deletion apps/web/src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
import { Card, Icon, useBreakpointValue, useColorMode } from "@chakra-ui/react";
import { Card, Icon, SlideFade, useBreakpointValue, useColorMode } from "@chakra-ui/react";
import { mode } from "@chakra-ui/theme-tools";
import { useDynamicModalContext } from "@umami/components";
import { useCurrentAccount } from "@umami/state";
import { useEffect, useState } from "react";

import { Actions } from "./Actions";
import { LogoDarkIcon, LogoLightIcon } from "../../assets/icons";
import { useColor } from "../../styles/useColor";
import { AccountSelectorModal } from "../AccountSelectorModal";
import { AccountTile } from "../AccountTile";

export const Header = () => {
const color = useColor();
const colorMode = useColorMode();
const currentAccount = useCurrentAccount()!;
const { openWith } = useDynamicModalContext();

const [isVisible, setIsVisible] = useState(false);

const size = useBreakpointValue({
base: {
width: "42px",
Expand All @@ -17,6 +29,25 @@ export const Header = () => {
},
});

useEffect(() => {
const accountTile = document.getElementById("account-tile")!;

const observer = new IntersectionObserver(
([entry]) => {
setIsVisible(!entry.isIntersecting);
},
{
threshold: 1,
}
);

observer.observe(accountTile);

return () => {
observer.unobserve(accountTile);
};
}, []);

return (
<Card
justifyContent="space-between"
Expand All @@ -29,6 +60,14 @@ export const Header = () => {
}}
>
{mode(<Icon as={LogoLightIcon} {...size} />, <Icon as={LogoDarkIcon} {...size} />)(colorMode)}
<SlideFade in={isVisible} offsetY="20px">
<AccountTile
background={color("100")}
account={currentAccount}
onClick={() => openWith(<AccountSelectorModal />)}
size="xs"
/>
</SlideFade>
<Actions />
</Card>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,12 @@ const ContactItem = ({ contact }: ContactItemProps) => {
</Center>
</Flex>
<ActionsDropdown actions={actions}>
<IconButton color={color("500")} aria-label="Remove Peer" icon={<ThreeDotsIcon />} />
<IconButton
color={color("500")}
aria-label="Remove Peer"
icon={<ThreeDotsIcon />}
variant="iconButtonSolid"
/>
</ActionsDropdown>
</Center>
);
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/components/beacon/BeaconPeers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const PeerRow = ({ peerInfo }: { peerInfo: ExtendedPeerInfo }) => {
aria-label="Remove Peer"
icon={<TrashIcon />}
onClick={() => removePeer(peerInfo)}
variant="iconButtonSolid"
/>
</Center>
);
Expand Down
6 changes: 6 additions & 0 deletions apps/web/src/setupTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import { TextDecoder, TextEncoder } from "util";
import { mockToast } from "@umami/state";
import { setupJestCanvasMock } from "jest-canvas-mock";

const intersectionObserverMock = () => ({
observe: jest.fn(),
unobserve: jest.fn(),
});

const localStorageMock = () => {
const store: { [key: string]: string } = {};

Expand All @@ -28,6 +33,7 @@ Object.defineProperties(global, {
crypto: { value: webcrypto, writable: true },
TextDecoder: { value: TextDecoder, writable: true },
TextEncoder: { value: TextEncoder, writable: true },
IntersectionObserver: { value: intersectionObserverMock, writable: true, configurable: true },
});

jest.mock("./utils/persistor", () => ({
Expand Down
Loading