Skip to content

Commit

Permalink
Merge pull request #211 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 26, 2024
2 parents a65a3cc + 131953a commit cd1d68f
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 103 deletions.
18 changes: 5 additions & 13 deletions webapps/world-builder-dashboard/src/assets/IconG7T.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
import React from 'react'

const IconG7T: React.FC<React.SVGProps<SVGSVGElement>> = (props) => (
<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' {...props}>
<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 20 20' fill='none' {...props}>
<path
fillRule='evenodd'
clipRule='evenodd'
d='M12.0006 24.0005C18.628 24.0005 24.0006 18.6279 24.0006 12.0005C24.0006 5.37307 18.628 0.000488281 12.0006 0.000488281C5.37319 0.000488281 0.000610352 5.37307 0.000610352 12.0005C0.000610352 18.6279 5.37319 24.0005 12.0006 24.0005Z'
fill='white'
d='M20 10C20 15.5228 15.5228 20 10 20C4.47715 20 0 15.5228 0 10C0 4.47715 4.47715 0 10 0C15.5228 0 20 4.47715 20 10Z'
fill='#FE7071'
/>
<path
d='M4.66064 7.6987L7.6138 11.8754H11.438L10.569 10.6466H13.3268L10.0358 15.3024L11.9469 18.006L19.2331 7.70058L4.66064 7.6987Z'
fill='#4E4E4E'
/>
<path
fillRule='evenodd'
clipRule='evenodd'
d='M12.0026 22.3862C17.7373 22.3862 22.3862 17.7374 22.3862 12.0027C22.3862 6.26805 17.7373 1.61919 12.0026 1.61919C6.26798 1.61919 1.61912 6.26805 1.61912 12.0027C1.61912 17.7374 6.26798 22.3862 12.0026 22.3862ZM12.0026 23.1469C18.1574 23.1469 23.1469 18.1575 23.1469 12.0027C23.1469 5.84792 18.1574 0.858488 12.0026 0.858488C5.84786 0.858488 0.858423 5.84792 0.858423 12.0027C0.858423 18.1575 5.84786 23.1469 12.0026 23.1469Z'
fill='#4E4E4E'
d='M4.33333 6.16667L6.62944 9.76822H9.60412L8.92848 8.70799H11.0727L8.51324 12.7238L10 15.0556L15.6667 6.16667H4.33333Z'
fill='#1B1B1B'
/>
</svg>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import {
} from '../../../../constants'
import styles from './NetworkSelector.module.css'
import { Combobox, Group, InputBase, InputBaseProps, useCombobox } from 'summon-ui/mantine'
import G7LogoBlue from '@/assets/G7LogoBlue'
import G7LogoRed from '@/assets/G7LogoRed'
import IconArbitrumOne from '@/assets/IconArbitrumOne'
import IconCheck from '@/assets/IconCheck'
import IconChevronDown from '@/assets/IconChevronDown'
import IconEthereum from '@/assets/IconEthereum'
import IconG7T from '@/assets/IconG7T'
import { HighNetworkInterface, NetworkInterface, useBlockchainContext } from '@/contexts/BlockchainContext'

type NetworkSelectorProps = {
Expand All @@ -38,8 +39,9 @@ const NetworkSelector = ({ networks, onChange, selectedNetwork, direction }: Net
case L2_MAIN_NETWORK.chainId:
return <IconArbitrumOne />
case L3_NETWORK.chainId:
return <G7LogoBlue />
case L3_MAIN_NETWORK.chainId:
return <IconG7T />
return <G7LogoRed />
default:
return <></>
}
Expand Down Expand Up @@ -76,10 +78,17 @@ const NetworkSelector = ({ networks, onChange, selectedNetwork, direction }: Net
<Combobox.Dropdown className='!bg-dark-900 !rounded-md !border-dark-700'>
<Combobox.Options>
{networks.map((n) => {
const isDisabled = direction === "DEPOSIT" ? selectedHighNetwork.chainId !== n.chainId && selectedHighNetwork.chainId === selectedNetwork.chainId : selectedLowNetwork.chainId !== n.chainId && selectedLowNetwork.chainId === selectedNetwork.chainId
const isDisabled =
direction === 'DEPOSIT'
? selectedHighNetwork.chainId !== n.chainId && selectedHighNetwork.chainId === selectedNetwork.chainId
: selectedLowNetwork.chainId !== n.chainId && selectedLowNetwork.chainId === selectedNetwork.chainId
return (
<Combobox.Option value={String(n.chainId)} key={n.chainId} disabled={isDisabled}
className={isDisabled ? styles.optionDisabled : styles.option} >
<Combobox.Option
value={String(n.chainId)}
key={n.chainId}
disabled={isDisabled}
className={isDisabled ? styles.optionDisabled : styles.option}
>
<Group>
<div
className={
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useState } from 'react'
import React, { useState, useRef, useEffect } from 'react'
import { useSearchParams } from 'react-router-dom'
import styles from './NetworkToggle.module.css'
import IconChevronDownToggle from '@/assets/IconChevronDownToggle'
import { NetworkType, useBlockchainContext } from '@/contexts/BlockchainContext'
Expand All @@ -10,15 +11,37 @@ interface NetworkToggleProps {}
const NetworkToggle: React.FC<NetworkToggleProps> = () => {
const { selectedNetworkType, setSelectedNetworkType } = useBlockchainContext()
const [isDropdownOpen, setDropdownOpen] = useState(false)
const dropdownRef = useRef<HTMLDivElement>(null)
const [searchParams, setSearchParams] = useSearchParams()
const toggleDropdown = () => setDropdownOpen((prev) => !prev)

const toggleDropdown = () => setDropdownOpen(!isDropdownOpen)
useEffect(() => {
const networkType = searchParams.get('network')
setSelectedNetworkType(networkType ? (networkType as NetworkType) : selectedNetworkType ? selectedNetworkType : 'Mainnet')
setSearchParams({ network: networkType ? (networkType as string) : selectedNetworkType ? (selectedNetworkType as string) : 'Mainnet' })
}, [selectedNetworkType])

const handleNetworkSelect = (network: NetworkType) => {
setSelectedNetworkType(network as NetworkType)
setDropdownOpen(false)
setDropdownOpen(!isDropdownOpen)
setSearchParams({ network: network as string })
}

useEffect(() => {
const handleClickOutside = (event: MouseEvent) => {
if (dropdownRef.current && !dropdownRef.current.contains(event.target as Node)) {
setDropdownOpen(false)
}
}

document.addEventListener('click', handleClickOutside)
return () => {
document.removeEventListener('click', handleClickOutside)
}
}, [])

return (
<div className={styles.container} onClick={toggleDropdown}>
<div ref={dropdownRef} className={styles.container} onClick={toggleDropdown}>
<div className={`${styles.toggle} ${selectedNetworkType === 'Testnet' ? styles.testnet : styles.mainnet}`}>
<div className={styles.testnetContainer}>
<div
Expand Down
154 changes: 78 additions & 76 deletions webapps/world-builder-dashboard/src/components/landing/Navbar.tsx
Original file line number Diff line number Diff line change
@@ -1,88 +1,90 @@
// Navbar.tsx
import React from 'react';
import { useNavigate } from 'react-router-dom';
import styles from './Landing.module.css';
import IconGame7Logo from '@/assets/IconGame7Logo';
import IconGame7 from '@/assets/IconGame7';
import IconHamburgerLanding from '@/assets/IconHamburgerLanding';
import React from 'react'
import { useNavigate } from 'react-router-dom'
import styles from './Landing.module.css'
import IconGame7 from '@/assets/IconGame7'
import IconGame7Logo from '@/assets/IconGame7Logo'
import IconHamburgerLanding from '@/assets/IconHamburgerLanding'

interface NavbarProps {
navbarOpen: boolean;
smallView: boolean;
setIsNavbarOpen: React.Dispatch<React.SetStateAction<boolean>>;
startBuilding: () => void;
navigateLink: (item: {name: string, link: string}) => void;
navbarOpen: boolean
smallView: boolean
setIsNavbarOpen: React.Dispatch<React.SetStateAction<boolean>>
startBuilding: () => void
navigateLink: (item: { name: string; link: string }) => void
}

const NAVBAR_ITEMS = [
{ name: 'Home', link: '/' },
{ name: 'Faucet', link: 'faucet' },
{ name: 'Bridge', link: 'bridge' },
{ name: 'Community', link: 'https://discord.com/invite/g7dao' },
{
name: 'Docs',
link: 'https://wiki.game7.io/g7-developer-resource/bWmdEUXVjGpgIbH3H5XT/introducing-the-g7-network/world-builder'
}
];
{ name: 'Home', link: '/' },
{ name: 'Faucet', link: 'faucet' },
{ name: 'Bridge', link: 'bridge' },
{ name: 'Community', link: 'https://discord.com/invite/g7dao' },
{
name: 'Docs',
link: 'https://wiki.game7.io/g7-developer-resource/bWmdEUXVjGpgIbH3H5XT/introducing-the-g7-network/world-builder'
}
]

const Navbar: React.FC<NavbarProps> = ({ navbarOpen, smallView, setIsNavbarOpen, startBuilding, navigateLink }) => {
const navigate = useNavigate();
const navigate = useNavigate()

return (
<>
{/* Main Navbar */}
<div className={styles.navbarContainer}>
<div className={styles.navbar}>
<div className={styles.logoWrapper} onClick={() => navigate('/')}>
<IconGame7Logo />
<IconGame7 />
</div>
<div className={styles.navbarItemsContainer}>
{!smallView ? (
<div className={styles.navbarItems}>
{NAVBAR_ITEMS.map((item, index) => (
<div
key={index}
className={item.name === 'Home' ? styles.navbarItemHome : styles.navbarItem}
onClick={() => {navigateLink(item)}}
>
{item.name}
</div>
))}
<div className={styles.navbarCTA} onClick={startBuilding}>
Start building
</div>
</div>
) : (
<div className={styles.navbarItem}>
<IconHamburgerLanding onClick={() => setIsNavbarOpen(!navbarOpen)} />
</div>
)}
</div>
</div>
</div>

{/* Expanded Navbar for small view */}
{navbarOpen && smallView && (
<div className={styles.navContainer}>
{NAVBAR_ITEMS.map((item, index) => (
<div
key={index}
className={item.name === 'Home' ? styles.navItemHome : styles.navItem}
onClick={() => navigateLink(item)}
>
{item.name}
</div>
))}
<div className={styles.ctaContainer}>
<div className={styles.startBuildingCTA} onClick={startBuilding}>
Start building
</div>
</div>
return (
<>
{/* Main Navbar */}
<div className={styles.navbarContainer}>
<div className={styles.navbar}>
<div className={styles.logoWrapper} onClick={() => navigate('/')}>
<IconGame7Logo />
<IconGame7 />
</div>
<div className={styles.navbarItemsContainer}>
{!smallView ? (
<div className={styles.navbarItems}>
{NAVBAR_ITEMS.map((item, index) => (
<div
key={index}
className={item.name === 'Home' ? styles.navbarItemHome : styles.navbarItem}
onClick={() => {
navigateLink(item)
}}
>
{item.name}
</div>
))}
<div className={styles.navbarCTA} onClick={startBuilding}>
Start building
</div>
</div>
) : (
<div className={styles.navbarItem}>
<IconHamburgerLanding onClick={() => setIsNavbarOpen(!navbarOpen)} />
</div>
)}
</>
);
};
</div>
</div>
</div>

{/* Expanded Navbar for small view */}
{navbarOpen && smallView && (
<div className={styles.navContainer}>
{NAVBAR_ITEMS.map((item, index) => (
<div
key={index}
className={item.name === 'Home' ? styles.navItemHome : styles.navItem}
onClick={() => navigateLink(item)}
>
{item.name}
</div>
))}
<div className={styles.ctaContainer}>
<div className={styles.startBuildingCTA} onClick={startBuilding}>
Start building
</div>
</div>
</div>
)}
</>
)
}

export default Navbar;
export default Navbar
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ const essentials = [
title: 'Bridge',
description: 'Bridge tokens between Ethereum, Arbitrum and the G7 network',
imageClass: styles.networkEssentialBridge,
onClick: (navigate: (path: string) => void) => navigate('/bridge')
onClick: (navigate: (path: string) => void, setSelectedNetworkType: (type: NetworkType) => void) => {
setSelectedNetworkType('Mainnet')
navigate('/bridge')
}
},
{
title: 'Block explorer',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
import { ethers } from 'ethers'
import { getTokensForNetwork, Token } from '@/utils/tokens'


interface BlockchainContextType {
walletProvider?: ethers.providers.Web3Provider
connectedAccount?: string
Expand Down Expand Up @@ -91,7 +90,7 @@ export const BlockchainProvider: React.FC<BlockchainProviderProps> = ({ children
const [selectedBridgeToken, setSelectedBridgeToken] = useState<Token>(
getTokensForNetwork(DEFAULT_LOW_NETWORK.chainId, connectedAccount)[0]
)

const tokenAddress = '0x5f88d811246222F6CB54266C42cc1310510b9feA'

const setSelectedLowNetwork = (network: NetworkInterface) => {
Expand Down Expand Up @@ -156,7 +155,6 @@ export const BlockchainProvider: React.FC<BlockchainProviderProps> = ({ children
} else {
setSelectedLowNetwork(DEFAULT_LOW_MAINNET_NETWORK)
setSelectedHighNetwork(DEFAULT_HIGH_MAINNET_NETWORK)

}
}, [selectedNetworkType])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ const LandingPage: React.FC = () => {
if (item.name === 'Faucet') {
setSelectedNetworkType('Testnet')
navigate(`/${item.link}`)
} else if (item.name !== 'Docs' && item.name !== 'Community') {
} else if (item.name === "Bridge") {
setSelectedNetworkType('Mainnet')
navigate(`/${item.link}`)
} else {
window.open(item.link, '_blank')
Expand Down
1 change: 1 addition & 0 deletions webapps/world-builder-dashboard/src/utils/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import IconG7T from '@/assets/IconG7T'
import IconTokenNoSynbol from '@/assets/IconTokenNoSymbol'
import IconUSDC from '@/assets/IconUSDC'


export interface Token {
name: string
symbol: string
Expand Down

0 comments on commit cd1d68f

Please sign in to comment.