Skip to content

Commit 22aabf2

Browse files
authored
Merge pull request #17 from hyperweb-io/fix/chain-admin
Customize chain-admin for Hyperweb
2 parents 9072645 + 38686c7 commit 22aabf2

File tree

23 files changed

+264
-195
lines changed

23 files changed

+264
-195
lines changed

templates/chain-admin/components/common/Footer.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const TextDivider = () => {
4545
const socialLinks = [
4646
{
4747
icon: <Icon name="github" color="$blackAlpha600" />,
48-
href: 'https://github.com/cosmology-tech',
48+
href: 'https://github.com/hyperweb-io',
4949
},
5050
{
5151
icon: <Icon name="discord" color="$blackAlpha600" />,
@@ -57,7 +57,7 @@ const socialLinks = [
5757
<FaXTwitter size="16px" />
5858
</Box>
5959
),
60-
href: 'https://x.com/cosmology_tech',
60+
href: 'https://x.com/Hyperweb_',
6161
},
6262
{
6363
icon: <Icon name="youtube" color="$blackAlpha600" />,

templates/chain-admin/components/common/Header/ChainDropdown.tsx

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,25 @@
11
import Image from 'next/image';
2-
import { useEffect, useState } from 'react';
2+
import { useState } from 'react';
33
import { useChain, useManager } from '@cosmos-kit/react';
44
import { Box, Combobox, Skeleton, Stack, Text } from '@interchain-ui/react';
55

66
import { useStarshipChains, useDetectBreakpoints } from '@/hooks';
77
import { chainStore, useChainStore } from '@/contexts';
8-
import { chainOptions } from '@/config';
9-
import { getSignerOptions } from '@/utils';
108

119
export const ChainDropdown = () => {
1210
const { selectedChain } = useChainStore();
1311
const { chain } = useChain(selectedChain);
1412
const [input, setInput] = useState<string>(chain.pretty_name);
15-
const { isMobile } = useDetectBreakpoints();
16-
const { data: starshipChains, refetch } = useStarshipChains();
17-
18-
const [isChainsAdded, setIsChainsAdded] = useState(false);
19-
const { addChains, getChainLogo } = useManager();
20-
21-
useEffect(() => {
22-
if (
23-
starshipChains?.chains.length &&
24-
starshipChains?.assets.length &&
25-
!isChainsAdded
26-
) {
27-
addChains(
28-
starshipChains.chains,
29-
starshipChains.assets,
30-
getSignerOptions()
31-
);
32-
setIsChainsAdded(true);
33-
}
34-
}, [starshipChains, isChainsAdded]);
13+
const { data: starshipChains } = useStarshipChains();
14+
const { getChainLogo } = useManager();
3515

36-
const onOpenChange = (isOpen: boolean) => {
37-
if (isOpen && !isChainsAdded) {
38-
refetch();
39-
}
40-
};
41-
42-
const chains = isChainsAdded
43-
? chainOptions.concat(starshipChains?.chains ?? [])
44-
: chainOptions;
16+
const { isMobile } = useDetectBreakpoints();
4517

4618
return (
4719
<Combobox
4820
onInputChange={(input) => {
4921
setInput(input);
5022
}}
51-
onOpenChange={onOpenChange}
5223
selectedKey={selectedChain}
5324
onSelectionChange={(key) => {
5425
const chainName = key as string | null;
@@ -77,7 +48,7 @@ export const ChainDropdown = () => {
7748
width: isMobile ? '130px' : '260px',
7849
}}
7950
>
80-
{chains.map((c) => (
51+
{(starshipChains?.chains ?? []).map((c) => (
8152
<Combobox.Item key={c.chain_name} textValue={c.pretty_name}>
8253
<Stack
8354
direction="horizontal"

templates/chain-admin/components/common/Header/Header.tsx

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { RxHamburgerMenu } from 'react-icons/rx';
55

66
import { ChainDropdown } from './ChainDropdown';
77
import { Button } from '../Button';
8-
import { useDetectBreakpoints } from '@/hooks';
8+
import { useDetectBreakpoints, useAddHyperwebChain } from '@/hooks';
99
import { AddressButton } from './AddressButton';
1010

1111
interface HeaderProps {
@@ -15,16 +15,14 @@ interface HeaderProps {
1515
export const Header = ({ onOpenSidebar }: HeaderProps) => {
1616
const { theme, setTheme } = useTheme();
1717
const { isDesktop, isMobile } = useDetectBreakpoints();
18+
const { isHyperwebAdded } = useAddHyperwebChain();
1819

1920
const brandLogo = useColorModeValue(
20-
'/logos/brand-logo.svg',
21-
'/logos/brand-logo-dark.svg'
21+
'/logos/hyperweb-logo.svg',
22+
'/logos/hyperweb-logo-dark.svg'
2223
);
2324

24-
const brandLogoSm = useColorModeValue(
25-
'/logos/brand-logo-sm.svg',
26-
'/logos/brand-logo-sm-dark.svg'
27-
);
25+
const brandLogoSm = '/logos/hyperweb-logo-sm.svg';
2826

2927
return (
3028
<Box
@@ -40,13 +38,13 @@ export const Header = ({ onOpenSidebar }: HeaderProps) => {
4038
alt="your logo"
4139
width="0"
4240
height="0"
43-
style={{ width: isMobile ? '40px' : '180px', height: 'auto' }}
41+
style={{ width: isMobile ? '30px' : '150px', height: 'auto' }}
4442
/>
4543
</Link>
4644
)}
4745
<Box display="flex" alignItems="center" gap="10px">
48-
<AddressButton />
49-
<ChainDropdown />
46+
{isHyperwebAdded && <AddressButton />}
47+
{isHyperwebAdded && <ChainDropdown />}
5048
<Button
5149
leftIcon={theme === 'dark' ? 'moonLine' : 'sunLine'}
5250
px="10px"

templates/chain-admin/components/common/Layout.tsx

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,73 @@
11
import Head from 'next/head';
2-
import { Box, useColorModeValue } from '@interchain-ui/react';
2+
import { useRouter } from 'next/router';
3+
import {
4+
Box,
5+
Callout,
6+
Icon,
7+
Text,
8+
useColorModeValue,
9+
} from '@interchain-ui/react';
10+
import { useMemo } from 'react';
311

412
import { Header } from './Header';
513
import { Footer } from './Footer';
614
import { Sidebar } from './Sidebar';
7-
import { useDisclosure } from '@/hooks';
15+
import { useDisclosure, useAddHyperwebChain, useStarshipChains } from '@/hooks';
816
import styles from '@/styles/layout.module.css';
17+
import { Button } from './Button';
18+
import { ROUTES } from './Sidebar';
919

1020
export function Layout({ children }: { children: React.ReactNode }) {
1121
const { isOpen, onOpen, onClose } = useDisclosure();
22+
const { isLoading } = useStarshipChains();
23+
const { isHyperwebAdded, refetchAndAddChain } = useAddHyperwebChain();
24+
const router = useRouter();
25+
26+
const showNotAddedWarning = !isLoading && !isHyperwebAdded;
27+
28+
const notRunningWarning = (
29+
<Callout
30+
title="Hyperweb is not running"
31+
attributes={{
32+
maxWidth: '400px',
33+
position: 'absolute',
34+
top: '20px',
35+
left: '50%',
36+
transform: 'translateX(-50%)',
37+
display: showNotAddedWarning ? 'block' : 'none',
38+
}}
39+
iconRender={<Icon name="errorWarningLine" size="$xl" />}
40+
intent="error"
41+
>
42+
<Box display="flex" alignItems="center" gap="$4">
43+
<Text>Please run `yarn starship start` and try again.</Text>
44+
<Button
45+
variant="text"
46+
size="sm"
47+
color="$text"
48+
textDecoration="underline"
49+
height="$min"
50+
px="0"
51+
py="0"
52+
onClick={refetchAndAddChain}
53+
>
54+
Refresh
55+
</Button>
56+
</Box>
57+
</Callout>
58+
);
59+
60+
const renderContent = useMemo(() => {
61+
if (router.pathname === ROUTES.HOME)
62+
return (
63+
<>
64+
{notRunningWarning}
65+
{children}
66+
</>
67+
);
68+
if (router.pathname === ROUTES.DOCS || isHyperwebAdded) return children;
69+
return notRunningWarning;
70+
}, [router.pathname, isHyperwebAdded, notRunningWarning, children]);
1271

1372
return (
1473
<Box
@@ -30,7 +89,9 @@ export function Layout({ children }: { children: React.ReactNode }) {
3089
flexDirection="column"
3190
>
3291
<Header onOpenSidebar={onOpen} />
33-
<Box flex="1">{children}</Box>
92+
<Box flex="1" position="relative">
93+
{renderContent}
94+
</Box>
3495
<Footer />
3596
</Box>
3697
</Box>

templates/chain-admin/components/common/Sidebar/NavItems.tsx

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,41 +13,51 @@ type NavItem = {
1313
href: string;
1414
};
1515

16+
export const ROUTES = {
17+
HOME: '/',
18+
STAKING: '/staking',
19+
GOVERNANCE: '/governance',
20+
ASSET_LIST: '/asset-list',
21+
FAUCET: '/faucet',
22+
CONTRACT: '/contract',
23+
DOCS: '/docs',
24+
} as const;
25+
1626
const navItems: NavItem[] = [
1727
{
1828
icon: <RiHome7Line size="20px" />,
1929
label: 'Home',
20-
href: '/',
30+
href: ROUTES.HOME,
2131
},
2232
{
2333
icon: <RiStackLine size="20px" />,
2434
label: 'Staking',
25-
href: '/staking',
35+
href: ROUTES.STAKING,
2636
},
2737
{
2838
icon: <MdOutlineHowToVote size="20px" />,
2939
label: 'Governance',
30-
href: '/governance',
40+
href: ROUTES.GOVERNANCE,
3141
},
3242
{
3343
icon: 'coinsLine',
3444
label: 'Asset List',
35-
href: '/asset-list',
45+
href: ROUTES.ASSET_LIST,
3646
},
3747
{
3848
icon: <MdOutlineWaterDrop size="20px" />,
3949
label: 'Faucet',
40-
href: '/faucet',
50+
href: ROUTES.FAUCET,
4151
},
4252
{
4353
icon: <LuFileJson size="20px" />,
4454
label: 'Contract',
45-
href: '/contract',
55+
href: ROUTES.CONTRACT,
4656
},
4757
{
4858
icon: 'document',
4959
label: 'Docs',
50-
href: '/docs',
60+
href: ROUTES.DOCS,
5161
},
5262
];
5363

templates/chain-admin/components/common/Sidebar/Sidebar.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ export const Sidebar = ({ isOpen, onClose }: SidebarProps) => {
1616
const { isDesktop } = useDetectBreakpoints();
1717

1818
const brandLogoSrc = useColorModeValue(
19-
'/logos/brand-logo.svg',
20-
'/logos/brand-logo-dark.svg'
19+
'/logos/hyperweb-logo.svg',
20+
'/logos/hyperweb-logo-dark.svg'
2121
);
2222

2323
const desktopSidebar = (
2424
<Box
25-
width="240px"
25+
width="$fit"
26+
minWidth="240px"
2627
px="30px"
2728
pt="30px"
2829
pb="24px"
@@ -37,13 +38,13 @@ export const Sidebar = ({ isOpen, onClose }: SidebarProps) => {
3738
borderRightWidth="1px"
3839
borderRightStyle="solid"
3940
>
40-
<Link href="/" style={{ marginBottom: '50px' }}>
41+
<Link href="/" style={{ marginBottom: '40px' }}>
4142
<Image
4243
src={brandLogoSrc}
4344
alt="your logo"
4445
width="0"
4546
height="0"
46-
style={{ width: '180px', height: 'auto' }}
47+
style={{ width: '150px', height: 'auto' }}
4748
/>
4849
</Link>
4950
<SidebarContent onClose={onClose} />

0 commit comments

Comments
 (0)