-
Notifications
You must be signed in to change notification settings - Fork 6
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
Header
component adjustements
#357
Changes from all commits
5d8343a
06596ba
c0b0df3
0c707f7
a06c1de
e54282f
5cedbf2
dec2bcc
bc41b76
5d25c89
b02de09
7ce1664
78b0814
5ff78eb
66fc680
0548299
cc68712
bea88fc
4ffdb22
2a9b31a
856e70a
5393743
d286b0f
689154b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,22 @@ | ||
import React from "react" | ||
import { Button, HStack, Icon, Tooltip } from "@chakra-ui/react" | ||
import { useWallet } from "#/hooks" | ||
import { useIsHomeRouteActive, useWallet, useWalletContext } from "#/hooks" | ||
import { CurrencyBalance } from "#/components/shared/CurrencyBalance" | ||
import { TextMd } from "#/components/shared/Typography" | ||
import { BitcoinIcon, EthereumIcon } from "#/assets/icons" | ||
import { BitcoinIcon } from "#/assets/icons" | ||
import { Account } from "@ledgerhq/wallet-api-client" | ||
import { CURRENCY_ID_BITCOIN } from "#/constants" | ||
import { | ||
isSupportedBTCAddressType, | ||
logPromiseFailure, | ||
truncateAddress, | ||
} from "#/utils" | ||
import { AnimatePresence, motion, Variants } from "framer-motion" | ||
|
||
const containerVariants: Variants = { | ||
hidden: { opacity: 0, y: -48 }, | ||
visible: { opacity: 1, y: 0 }, | ||
} | ||
|
||
const getCustomDataByAccount = ( | ||
account?: Account, | ||
|
@@ -28,53 +34,54 @@ const getCustomDataByAccount = ( | |
export default function ConnectWallet() { | ||
const { | ||
bitcoin: { account: btcAccount, requestAccount: requestBitcoinAccount }, | ||
ethereum: { account: ethAccount, requestAccount: requestEthereumAccount }, | ||
} = useWallet() | ||
// TODO: Move `isConnected` to useWallet hook | ||
const { isConnected } = useWalletContext() | ||
|
||
const customDataBtcAccount = getCustomDataByAccount(btcAccount) | ||
const customDataEthAccount = getCustomDataByAccount(ethAccount) | ||
|
||
const isHomeRoute = useIsHomeRouteActive() | ||
|
||
const handleConnectBitcoinAccount = () => { | ||
logPromiseFailure(requestBitcoinAccount()) | ||
} | ||
|
||
const handleConnectEthereumAccount = () => { | ||
logPromiseFailure(requestEthereumAccount()) | ||
} | ||
|
||
return ( | ||
<HStack spacing={4}> | ||
<HStack display={{ base: "none", md: "flex" }}> | ||
<TextMd color="grey.500">Balance</TextMd> | ||
<CurrencyBalance | ||
currency="bitcoin" | ||
amount={btcAccount?.balance.toString()} | ||
/> | ||
</HStack> | ||
<Tooltip | ||
label="Currently, we support only Legacy or Native SegWit addresses. Please try connecting another address." | ||
placement="top" | ||
isDisabled={ | ||
!(btcAccount && !isSupportedBTCAddressType(btcAccount.address)) | ||
} | ||
> | ||
<Button | ||
variant="card" | ||
colorScheme={customDataBtcAccount.colorScheme} | ||
leftIcon={<Icon as={BitcoinIcon} boxSize={6} />} | ||
onClick={handleConnectBitcoinAccount} | ||
<AnimatePresence initial={false}> | ||
{(isConnected || !isHomeRoute) && ( | ||
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. Generally, in such cases, we set the condition higher and return 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. It's not true with 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. Ok, so let's create 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. Not sure why, it's pointless. It will cause the code to shadow. |
||
<HStack | ||
as={motion.div} | ||
variants={containerVariants} | ||
initial="hidden" | ||
animate="visible" | ||
exit="hidden" | ||
spacing={4} | ||
> | ||
{customDataBtcAccount.text} | ||
</Button> | ||
</Tooltip> | ||
<Button | ||
variant="card" | ||
colorScheme={customDataEthAccount.colorScheme} | ||
leftIcon={<Icon as={EthereumIcon} boxSize={6} />} | ||
onClick={handleConnectEthereumAccount} | ||
> | ||
{customDataEthAccount.text} | ||
</Button> | ||
</HStack> | ||
<HStack display={{ base: "none", md: "flex" }}> | ||
<TextMd color="grey.500">Balance</TextMd> | ||
<CurrencyBalance | ||
currency="bitcoin" | ||
amount={btcAccount?.balance.toString()} | ||
/> | ||
</HStack> | ||
<Tooltip | ||
label="Currently, we support only Legacy or Native SegWit addresses. Please try connecting another address." | ||
placement="top" | ||
isDisabled={ | ||
!(btcAccount && !isSupportedBTCAddressType(btcAccount.address)) | ||
} | ||
> | ||
<Button | ||
variant="card" | ||
colorScheme={customDataBtcAccount.colorScheme} | ||
leftIcon={<Icon as={BitcoinIcon} boxSize={6} />} | ||
onClick={handleConnectBitcoinAccount} | ||
> | ||
{customDataBtcAccount.text} | ||
</Button> | ||
</Tooltip> | ||
</HStack> | ||
)} | ||
</AnimatePresence> | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import React from "react" | ||
import { Box, BoxProps, HStack, List } from "@chakra-ui/react" | ||
import { NavigationItemType } from "#/types/navigation" | ||
import NavigationItem from "./NavigationItem" | ||
|
||
type NavigationProps = BoxProps & { | ||
items: NavigationItemType[] | ||
} | ||
|
||
function Navigation(props: NavigationProps) { | ||
const { items, ...restProps } = props | ||
|
||
return ( | ||
<Box as="nav" {...restProps}> | ||
<HStack as={List} spacing={5} ml={12}> | ||
{items.map((item) => ( | ||
<NavigationItem key={item.href} {...item} /> | ||
))} | ||
</HStack> | ||
</Box> | ||
) | ||
} | ||
|
||
export default Navigation |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import React from "react" | ||
import { | ||
Box, | ||
ListItem, | ||
ListItemProps, | ||
useMultiStyleConfig, | ||
} from "@chakra-ui/react" | ||
import { motion } from "framer-motion" | ||
import { NavigationItemType } from "#/types/navigation" | ||
import { NavLink } from "../../shared/NavLink" | ||
|
||
type NavigationItemProps = ListItemProps & NavigationItemType | ||
|
||
function NavigationItem(props: NavigationItemProps) { | ||
const { label, href, ...restProps } = props | ||
const styles = useMultiStyleConfig("Link", { variant: "navigation" }) | ||
|
||
return ( | ||
<ListItem pos="relative" {...restProps}> | ||
<NavLink to={href} sx={styles.container}> | ||
{({ isActive }) => ( | ||
<> | ||
{label} | ||
{isActive && ( | ||
<Box | ||
as={motion.span} | ||
layoutId="active-route-indicator" | ||
sx={styles.indicator} | ||
/> | ||
)} | ||
</> | ||
)} | ||
</NavLink> | ||
</ListItem> | ||
) | ||
} | ||
|
||
export default NavigationItem |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as Navigation } from "./Navigation" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,22 @@ | ||
import React from "react" | ||
import { Flex, HStack, Icon } from "@chakra-ui/react" | ||
import { AcreLogo } from "#/assets/icons" | ||
import { routerPath } from "#/router/path" | ||
import { Flex, HStack, Icon } from "@chakra-ui/react" | ||
import { NavigationItemType } from "#/types/navigation" | ||
import ConnectWallet from "./ConnectWallet" | ||
import { Navigation } from "./Navigation" | ||
|
||
// TODO: To be adjusted after project pivot/cleanup | ||
const NAVIGATION_ITEMS: NavigationItemType[] = [ | ||
{ label: "Season 1", href: routerPath.home }, | ||
{ label: "Dashboard", href: routerPath.dashboard }, | ||
] | ||
|
||
export default function Header() { | ||
return ( | ||
<HStack as="header" p={6}> | ||
<HStack as="header" px={10} py={7}> | ||
<Icon as={AcreLogo} w={20} h={12} /> | ||
<Navigation items={NAVIGATION_ITEMS} /> | ||
r-czajkowski marked this conversation as resolved.
Show resolved
Hide resolved
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. Do we want to pass items props instead of importing navigation items directly in the 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 not. It makes |
||
<Flex ml="auto"> | ||
<ConnectWallet /> | ||
</Flex> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React from "react" | ||
import { | ||
Link as ChakraLink, | ||
LinkProps as ChakraLinkProps, | ||
} from "@chakra-ui/react" | ||
import { | ||
Link as RouterLink, | ||
LinkProps as RouterLinkProps, | ||
} from "react-router-dom" | ||
|
||
type LinkProps = Omit<ChakraLinkProps, "as" | "href"> & | ||
Pick<RouterLinkProps, "to"> | ||
|
||
export function Link(props: LinkProps) { | ||
return <ChakraLink as={RouterLink} {...props} /> | ||
} | ||
Comment on lines
+14
to
+16
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. Let's separate these two components into two files 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. Ref commit: 4ffdb22 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import React from "react" | ||
import { | ||
Link as ChakraLink, | ||
LinkProps as ChakraLinkProps, | ||
} from "@chakra-ui/react" | ||
import { | ||
NavLink as RouterNavLink, | ||
NavLinkProps as RouterNavLinkProps, | ||
} from "react-router-dom" | ||
|
||
type NavLinkProps = Omit<ChakraLinkProps, "as" | "href" | "children"> & | ||
Pick<RouterNavLinkProps, "to" | "children"> | ||
|
||
export function NavLink(props: NavLinkProps) { | ||
const { children, ...restProps } = props | ||
return ( | ||
<ChakraLink as={RouterNavLink} {...restProps}> | ||
{children as React.ReactNode} | ||
</ChakraLink> | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./useIsActiveRoute" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { routerPath } from "#/router/path" | ||
import { useLocation } from "react-router-dom" | ||
|
||
export const useIsActiveRoute = (route: string) => { | ||
const location = useLocation() | ||
|
||
return location.pathname === route | ||
} | ||
|
||
export const useIsHomeRouteActive = () => useIsActiveRoute(routerPath.home) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export type NavigationItemType = { | ||
label: string | ||
href: string | ||
} |
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.
I believe we can move
containerVariants
totheme
dir.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.
I'd like to keep animation related variables coupled together. Will not make it.