Skip to content

Commit

Permalink
Merge pull request #209 from G7DAO/feat/network-toggle
Browse files Browse the repository at this point in the history
Feat/network toggle
  • Loading branch information
elclandestin0 authored Nov 25, 2024
2 parents 27d1102 + 5a7f75b commit e4f835f
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const Navbar: React.FC<NavbarProps> = ({ navbarOpen, smallView, setIsNavbarOpen,
<div
key={index}
className={item.name === 'Home' ? styles.navbarItemHome : styles.navbarItem}
onClick={() => navigateLink(item)}
onClick={() => {navigateLink(item)}}
>
{item.name}
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,73 +1,77 @@
import React from 'react';
import styles from './Landing.module.css';
import { useNavigate } from 'react-router-dom';
import React from 'react'
import { useNavigate } from 'react-router-dom'
import styles from './Landing.module.css'
import { NetworkType, useBlockchainContext } from '@/contexts/BlockchainContext'

interface NetworkEssentialsProps {
smallView: boolean;
startBuilding: () => void;
smallView: boolean
startBuilding: () => void
}

const essentials = [
{
title: "Faucet",
description: "Get testnet tokens to start building on G7 Sepolia",
imageClass: styles.networkEssentialFaucet,
onClick: (navigate: (path: string) => void) => navigate('/faucet'),
},
{
title: "Bridge",
description: "Bridge tokens between Ethereum, Arbitrum and the G7 network",
imageClass: styles.networkEssentialBridge,
onClick: (navigate: (path: string) => void) => navigate('/bridge'),
},
{
title: "Block explorer",
description: "Track and interact directly with your smart contracts",
imageClass: styles.networkEssentialExplorer,
onClick: () => window.open('https://testnet.game7.io/', '_blank'),
},
{
title: "Docs",
description: "Get more information about building on the G7 Network",
imageClass: styles.networkEssentialDocs,
onClick: () => window.open('https://wiki.game7.io/g7-developer-resource/', '_blank'),
},
{
title: "Discord",
description: "Join our community of builders on Discord",
imageClass: styles.networkEssentialDiscord,
onClick: () => window.open('https://discord.com/invite/g7dao', '_blank'),
},
];
{
title: 'Faucet',
description: 'Get testnet tokens to start building on G7 Sepolia',
imageClass: styles.networkEssentialFaucet,
onClick: (navigate: (path: string) => void, setSelectedNetworkType: (type: NetworkType) => void) => {
setSelectedNetworkType('Testnet')
navigate('/faucet')
}
},
{
title: 'Bridge',
description: 'Bridge tokens between Ethereum, Arbitrum and the G7 network',
imageClass: styles.networkEssentialBridge,
onClick: (navigate: (path: string) => void) => navigate('/bridge')
},
{
title: 'Block explorer',
description: 'Track and interact directly with your smart contracts',
imageClass: styles.networkEssentialExplorer,
onClick: () => window.open('https://testnet.game7.io/', '_blank')
},
{
title: 'Docs',
description: 'Get more information about building on the G7 Network',
imageClass: styles.networkEssentialDocs,
onClick: () => window.open('https://wiki.game7.io/g7-developer-resource/', '_blank')
},
{
title: 'Discord',
description: 'Join our community of builders on Discord',
imageClass: styles.networkEssentialDiscord,
onClick: () => window.open('https://discord.com/invite/g7dao', '_blank')
}
]

const NetworkEssentials: React.FC<NetworkEssentialsProps> = ({ smallView, startBuilding }) => {
const navigate = useNavigate();

return (
<div className={styles.contentContainer}>
<div className={styles.sectionTitle}>Start building with the network essentials</div>
<div className={styles.networkEssentialCards}>
{essentials.map((essential, index) => (
<div
className={styles.networkEssentialCard}
onClick={() => essential.onClick(navigate)}
key={index}
>
<div className={`${styles.networkEssentialCardImage} ${essential.imageClass}`} />
<div className={styles.networkEssentialCardText}>
<div className={styles.networkEssentialCardTitle}>{essential.title}</div>
<div className={styles.networkEssentialCardDescription}>{essential.description}</div>
</div>
</div>
))}
</div>
{!smallView && (
<div className={styles.startBuildingCTA} onClick={startBuilding}>
Start building
</div>
)}
const navigate = useNavigate()
const { setSelectedNetworkType } = useBlockchainContext()
return (
<div className={styles.contentContainer}>
<div className={styles.sectionTitle}>Start building with the network essentials</div>
<div className={styles.networkEssentialCards}>
{essentials.map((essential, index) => (
<div
className={styles.networkEssentialCard}
onClick={() => essential.onClick(navigate, setSelectedNetworkType)}
key={index}
>
<div className={`${styles.networkEssentialCardImage} ${essential.imageClass}`} />
<div className={styles.networkEssentialCardText}>
<div className={styles.networkEssentialCardTitle}>{essential.title}</div>,
<div className={styles.networkEssentialCardDescription}>{essential.description}</div>
</div>
);
};
</div>
))}
</div>
{!smallView && (
<div className={styles.startBuildingCTA} onClick={startBuilding}>
Start building
</div>
)}
</div>
)
}

export default NetworkEssentials;
export default NetworkEssentials
Original file line number Diff line number Diff line change
Expand Up @@ -295,12 +295,11 @@ export const useNotifications = (
): UseQueryResult<BridgeNotification[]> => {
const { selectedNetworkType } = useBlockchainContext()
return useQuery(
['notifications', connectedAccount, offset, limit],
['notifications', connectedAccount, offset, limit, selectedNetworkType],
async () => {
if (!connectedAccount) {
return []
}
// const { selectedNetworkType } = useBlockchainContext()
const transactionsString = localStorage.getItem(`bridge-${connectedAccount}-transactions-${selectedNetworkType}`)
let transactions
if (!transactionsString) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import React, { ReactNode } from 'react'
import { useLocation, useNavigate } from 'react-router-dom'
import styles from './MainLayout.module.css'
import { Tooltip } from 'summon-ui/mantine'
import IconExternalLink from '@/assets/IconExternalLink'
import IconInfoCircle from '@/assets/IconInfoCircle'
import IconLock from '@/assets/IconLock'
import IconLogout from '@/assets/IconLogout'
import NetworkToggle from '@/components/commonComponents/networkToggle/NetworkToggle'
import { useBlockchainContext } from '@/contexts/BlockchainContext'
Expand Down Expand Up @@ -45,14 +42,6 @@ const DesktopSidebar: React.FC<DesktopSidebarProps> = ({ navigationItems }) => {
<div style={{ display: 'flex' }}>
{item.name === 'documentation' || item.name === 'explorer' ? (
<IconExternalLink className={styles.icon} />
) : item.name === 'faucet' && selectedNetworkType === 'Testnet' ? (
<Tooltip arrowSize={8} radius={'8px'} label={'Only available on Testnet'} withArrow>
<IconInfoCircle stroke='#fff' />
</Tooltip>
) : item.name === 'faucet' && selectedNetworkType === 'Mainnet' ? (
<Tooltip arrowSize={8} radius={'8px'} label={'Only available on Testnet'} withArrow>
<IconLock stroke='#fff' />
</Tooltip>
) : (
<></>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const MainLayout: React.FC<MainLayoutProps> = ({}) => {
const location = useLocation()
const { selectedNetworkType } = useBlockchainContext()

const NAVIGATION_ITEMS = [
const TESTNET_NAVIGATION_ITEMS = [
{
name: 'faucet',
navigateTo: '/faucet',
Expand All @@ -42,6 +42,9 @@ const MainLayout: React.FC<MainLayoutProps> = ({}) => {
}
]

const MAINNET_NAVIGATION_ITEMS = TESTNET_NAVIGATION_ITEMS.slice(1, TESTNET_NAVIGATION_ITEMS.length)
const NAVIGATION_ITEMS = selectedNetworkType === 'Testnet' ? TESTNET_NAVIGATION_ITEMS : MAINNET_NAVIGATION_ITEMS

const smallView = useMediaQuery('(max-width: 1199px)')
return (
<div className={styles.container}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ import React, { ReactNode, useState } from 'react'
import { useLocation, useNavigate } from 'react-router-dom'
import parentStyles from './MainLayout.module.css'
import styles from './MobileSidebar.module.css'
import { Tooltip } from 'summon-ui/mantine'
import IconExternalLink from '@/assets/IconExternalLink'
import IconHamburgerLanding from '@/assets/IconHamburgerLanding'
import IconInfoCircle from '@/assets/IconInfoCircle'
import IconLock from '@/assets/IconLock'
import IconLogoutLarge from '@/assets/IconLogoutLarge'
import NetworkToggle from '@/components/commonComponents/networkToggle/NetworkToggle'
import { useBlockchainContext } from '@/contexts/BlockchainContext'
Expand Down Expand Up @@ -68,14 +65,6 @@ const MobileSidebar: React.FC<MobileSidebarProps> = ({ navigationItems }) => {
<div style={{ display: 'flex' }}>
{item.name === 'documentation' || item.name === 'explorer' ? (
<IconExternalLink className={styles.icon} />
) : item.name === 'faucet' && selectedNetworkType === 'Testnet' ? (
<Tooltip arrowSize={8} radius={'8px'} label={'Only available on Testnet'} withArrow>
<IconInfoCircle stroke='#fff' />
</Tooltip>
) : item.name === 'faucet' && selectedNetworkType === 'Mainnet' ? (
<Tooltip arrowSize={8} radius={'8px'} label={'Only available on Testnet'} withArrow>
<IconLock stroke='#fff' />
</Tooltip>
) : (
<></>
)}
Expand Down
102 changes: 58 additions & 44 deletions webapps/world-builder-dashboard/src/pages/LandingPage/LandingPage.tsx
Original file line number Diff line number Diff line change
@@ -1,52 +1,65 @@
// LandingPage.tsx
import React, { useState } from 'react';
import { useNavigate } from 'react-router-dom';
import styles from './LandingPage.module.css';
import { useMediaQuery } from 'summon-ui/mantine';
import MainSection from "@/components/landing/MainSection";
import BenefitsSection from "@/components/landing/BenefitsSection";
import AlliesSection from "@/components/landing/AlliesSection";
import NetworkEssentials from "@/components/landing/NetworksEssentials";
import Navbar from "@/components/landing/Navbar";
import Container from "@/components/landing/Container";
import { useBlockchainContext } from '@/contexts/BlockchainContext';
import React, { useState } from 'react'
import { useNavigate } from 'react-router-dom'
import styles from './LandingPage.module.css'
import { useMediaQuery } from 'summon-ui/mantine'
import AlliesSection from '@/components/landing/AlliesSection'
import BenefitsSection from '@/components/landing/BenefitsSection'
import Container from '@/components/landing/Container'
import MainSection from '@/components/landing/MainSection'
import Navbar from '@/components/landing/Navbar'
import NetworkEssentials from '@/components/landing/NetworksEssentials'
import { useBlockchainContext } from '@/contexts/BlockchainContext'

const LandingPage: React.FC = () => {
const navigate = useNavigate();
const {setSelectedNetworkType} = useBlockchainContext()
const [navbarOpen, setNavBarOpen] = useState<boolean>(false);
const smallView = useMediaQuery('(max-width: 750px)');
const isLargeView = useMediaQuery('(min-width: 1440px)');
const navigate = useNavigate()
const { setSelectedNetworkType } = useBlockchainContext()
const [navbarOpen, setNavBarOpen] = useState<boolean>(false)
const smallView = useMediaQuery('(max-width: 750px)')
const isLargeView = useMediaQuery('(min-width: 1440px)')

const startBuilding = () => {
setSelectedNetworkType('Testnet')
navigate('/faucet');
};
navigate('/faucet')
}

const navigateLink = (item: any) => {
item.name !== 'Docs' && item.name !== 'Community'
? navigate(`/${item.link}`)
: window.open(item.link, '_blank');
};
if (item.name === 'Faucet') {
setSelectedNetworkType('Testnet')
navigate(`/${item.link}`)
} else if (item.name !== 'Docs' && item.name !== 'Community') {
navigate(`/${item.link}`)
} else {
window.open(item.link, '_blank')
}
}

const slides = [
<MainSection key="main" smallView={!!smallView} startBuilding={startBuilding} />,
<BenefitsSection key="benefits" />,
<AlliesSection key="allies" />,
<NetworkEssentials smallView={!!smallView} startBuilding={startBuilding} key="essentials" />
];
<MainSection key='main' smallView={!!smallView} startBuilding={startBuilding} />,
<BenefitsSection key='benefits' />,
<AlliesSection key='allies' />,
<NetworkEssentials smallView={!!smallView} startBuilding={startBuilding} key='essentials' />
]

return (
<>
{isLargeView ? <Container components={slides} isNavbarOpen={navbarOpen} setIsNavbarOpen={setNavBarOpen} isSmallView={!!smallView} startBuilding={startBuilding} navigateLink={navigateLink}/> : (

<div className={`${styles.layout} ${navbarOpen && styles.layoutBlur}`}>
<>
{isLargeView ? (
<Container
components={slides}
isNavbarOpen={navbarOpen}
setIsNavbarOpen={setNavBarOpen}
isSmallView={!!smallView}
startBuilding={startBuilding}
navigateLink={navigateLink}
/>
) : (
<div className={`${styles.layout} ${navbarOpen && styles.layoutBlur}`}>
<Navbar
navbarOpen={navbarOpen}
smallView={!!smallView}
setIsNavbarOpen={setNavBarOpen}
startBuilding={startBuilding}
navigateLink={navigateLink}
navbarOpen={navbarOpen}
smallView={!!smallView}
setIsNavbarOpen={setNavBarOpen}
startBuilding={startBuilding}
navigateLink={navigateLink}
/>

<div className={`${styles.mainLayout} ${navbarOpen ? styles.layoutDarkened : ''}`}>
Expand All @@ -57,13 +70,14 @@ const LandingPage: React.FC = () => {
</div>

{smallView && (
<div className={styles.startBuildingCTA} onClick={startBuilding}>
Start building
</div>
<div className={styles.startBuildingCTA} onClick={startBuilding}>
Start building
</div>
)}
</div>)}
</>
);
};
</div>
)}
</>
)
}

export default LandingPage;
export default LandingPage

0 comments on commit e4f835f

Please sign in to comment.