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

fix: network menu #647

Merged
merged 3 commits into from
Dec 6, 2023
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Bug fixes

- [#647](https://github.com/alleslabs/celatone-frontend/pull/647) Remove Select network auto select first item
- [#646](https://github.com/alleslabs/celatone-frontend/pull/646) Fix UTC timestamp on block, tx query
- [#644](https://github.com/alleslabs/celatone-frontend/pull/644) Remove relation badge from transaction card in mobile

Expand Down
143 changes: 32 additions & 111 deletions src/lib/layout/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,122 +1,43 @@
import {
Flex,
Menu,
MenuButton,
MenuList,
Text,
MenuItem,
Image,
} from "@chakra-ui/react";
import { Flex, Image } from "@chakra-ui/react";

import { CHAIN_CONFIGS } from "config/chain";
import { CURR_THEME } from "env";
import { AmpEvent, track } from "lib/amplitude";
import { useCelatoneApp, useSelectChain } from "lib/app-provider";
import { AppLink } from "lib/components/AppLink";
import { FaucetBtn } from "lib/components/button";
import { CustomIcon } from "lib/components/icon";
import { WalletSection } from "lib/components/Wallet";

import { NetworkMenu } from "./NetworkMenu";
import Searchbar from "./Searchbar";

const Header = () => {
const { availableChainIds, currentChainId } = useCelatoneApp();
const selectChain = useSelectChain();

return (
<Flex
as="header"
width="100vw"
height="full"
align="center"
justifyContent="space-between"
px={6}
mb={1}
gap={6}
>
<AppLink href="/">
<Image
src={CURR_THEME.branding.logo}
alt="Celatone"
minWidth="152px"
width="152px"
maxWidth="152px"
mr={8}
transition="all 0.25s ease-in-out"
_hover={{ cursor: "pointer", opacity: 0.85 }}
/>
</AppLink>
<Searchbar />
<Flex gap={4}>
<FaucetBtn />
<Menu onOpen={() => track(AmpEvent.USE_SELECT_NETWORK)}>
<MenuButton
pl={4}
pr={2}
py={1}
borderRadius="8px"
borderWidth="1px"
borderColor="gray.600"
_hover={{ bg: "gray.700" }}
transition="all 0.25s ease-in-out"
w="170px"
>
<Flex
alignItems="center"
justifyContent="space-between"
display="flex"
>
<Text
textOverflow="ellipsis"
variant="body2"
overflow="hidden"
whiteSpace="nowrap"
maxW="170px"
>
{currentChainId}
</Text>
<CustomIcon name="chevron-down" color="gray.600" />
</Flex>
</MenuButton>
<MenuList zIndex="dropdown">
{availableChainIds.map((chainId) => {
const noConfig = !(chainId in CHAIN_CONFIGS);
return (
<MenuItem
key={chainId}
onClick={() => {
selectChain(chainId);
}}
flexDirection="column"
alignItems="flex-start"
_hover={{
backgroundColor: "gray.800",
}}
transition="all 0.25s ease-in-out"
isDisabled={noConfig}
>
<Flex justify="space-between" align="center" w="full">
<Flex direction="column">
<Text variant="body2">
{CHAIN_CONFIGS[chainId]?.prettyName || chainId}
</Text>
<Text color="text.dark" variant="body3">
{chainId}
</Text>
</Flex>
{chainId === currentChainId && (
<CustomIcon name="check" boxSize={3} color="gray.600" />
)}
</Flex>
</MenuItem>
);
})}
</MenuList>
</Menu>
<WalletSection />
</Flex>
const Header = () => (
<Flex
as="header"
width="100vw"
height="full"
align="center"
justifyContent="space-between"
px={6}
mb={1}
gap={6}
>
<AppLink href="/">
<Image
src={CURR_THEME.branding.logo}
alt="Celatone"
minWidth="152px"
width="152px"
maxWidth="152px"
mr={8}
transition="all 0.25s ease-in-out"
_hover={{ cursor: "pointer", opacity: 0.85 }}
/>
</AppLink>
<Searchbar />
<Flex gap={4}>
<FaucetBtn />
<NetworkMenu />
<WalletSection />
</Flex>
);
};
</Flex>
);

export default Header;
78 changes: 78 additions & 0 deletions src/lib/layout/NetworkMenu.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { track } from "@amplitude/analytics-browser";
import {
Flex,
Menu,
MenuButton,
MenuItem,
MenuList,
Text,
} from "@chakra-ui/react";

import { CHAIN_CONFIGS } from "config/chain";
import { AmpEvent } from "lib/amplitude";
import { useCelatoneApp, useMobile, useSelectChain } from "lib/app-provider";
import { CustomIcon } from "lib/components/icon";

export const NetworkMenu = () => {
const isMobile = useMobile();
const { currentChainId, availableChainIds } = useCelatoneApp();
const selectChain = useSelectChain();

const width = isMobile ? "220px" : "170px";

return (
<Menu
onOpen={() => track(AmpEvent.USE_SELECT_NETWORK)}
autoSelect={!isMobile}
>
<MenuButton
pl={4}
pr={2}
py={1}
borderRadius="8px"
borderWidth="1px"
borderColor="gray.600"
_hover={{ bg: "gray.700" }}
transition="all 0.25s ease-in-out"
w={width}
>
<Flex alignItems="center" justifyContent="space-between" display="flex">
<Text
textOverflow="ellipsis"
variant="body2"
overflow="hidden"
whiteSpace="nowrap"
maxW={width}
>
{currentChainId}
</Text>
<CustomIcon name="chevron-down" color="gray.600" />
</Flex>
</MenuButton>
<MenuList zIndex="dropdown">
{availableChainIds.map((chainId) => (
<MenuItem
key={chainId}
onClick={() => selectChain(chainId)}
transition="all 0.25s ease-in-out"
isDisabled={!(chainId in CHAIN_CONFIGS)}
>
<Flex justify="space-between" align="center" w="full">
<Flex direction="column">
<Text variant="body2">
{CHAIN_CONFIGS[chainId]?.prettyName || chainId}
</Text>
<Text color="text.dark" variant="body3">
{chainId}
</Text>
</Flex>
{chainId === currentChainId && (
<CustomIcon name="check" boxSize={3} color="gray.600" />
)}
</Flex>
</MenuItem>
))}
</MenuList>
</Menu>
);
};
Loading