From f2cd496eb921a7934b3519a5ea7321352a94e1fa Mon Sep 17 00:00:00 2001 From: Matias Benary Date: Wed, 16 Oct 2024 12:48:13 -0300 Subject: [PATCH 1/4] feat: network selector added --- src/components/sidebar-navigation/Sidebar.tsx | 66 ++++++++++++++++++- .../sidebar-navigation/SmallScreenHeader.tsx | 55 +++++++++++++--- src/components/sidebar-navigation/styles.ts | 6 +- 3 files changed, 113 insertions(+), 14 deletions(-) diff --git a/src/components/sidebar-navigation/Sidebar.tsx b/src/components/sidebar-navigation/Sidebar.tsx index 17bb8abea..2be959590 100644 --- a/src/components/sidebar-navigation/Sidebar.tsx +++ b/src/components/sidebar-navigation/Sidebar.tsx @@ -1,9 +1,12 @@ -import { Tooltip } from '@near-pagoda/ui'; +import { Dropdown, SvgIcon, Tooltip } from '@near-pagoda/ui'; +import { CaretDown } from '@phosphor-icons/react'; import Image from 'next/image'; import { useRouter } from 'next/router'; -import { useCallback, useEffect, useRef } from 'react'; +import { useCallback, useEffect, useRef, useState } from 'react'; import { useContext } from 'react'; +import styled from 'styled-components'; +import { networkId } from '@/config'; import { useSignInRedirect } from '@/hooks/useSignInRedirect'; import { NearContext } from '../wallet-selector/WalletSelector'; @@ -14,6 +17,26 @@ import * as S from './styles'; import { UserDropdownMenu } from './UserDropdownMenu'; import { currentPathMatchesRoute } from './utils'; +const Redirect = styled.a<{ selected?: boolean }>` + text-decoration: none; + color: #444; +`; + +const Badge = styled.div` + display: flex; + align-items: center; + justify-content: center; + padding: 0.25rem 0.5rem; + gap: 4px; + font-size: 0.75rem; + font-weight: 600; + color: ${() => (networkId === 'mainnet' ? '#0072de' : '#d14e00')}; + background-color: ${() => (networkId === 'mainnet' ? '#0084f116' : '#f9900026')}; + text-transform: capitalize; + border-radius: 0.25rem; + letter-spacing: 0.05em; +`; + export const Sidebar = () => { const router = useRouter(); const expandedDrawer = useNavigationStore((store) => store.expandedDrawer); @@ -25,6 +48,13 @@ export const Sidebar = () => { const { signedAccountId } = useContext(NearContext); const { requestAuthentication } = useSignInRedirect(); const inputRef = useRef(null); + const [isOpenNetwork, setIsOpenNetwork] = useState(false); + + const preventRedirect = (network: string) => (e: React.MouseEvent) => { + if (networkId == network) { + e.preventDefault(); + } + }; const handleCreateAccount = () => { requestAuthentication(true); @@ -53,6 +83,38 @@ export const Sidebar = () => { NEAR + + setIsOpenNetwork(open)}> + + + {networkId}{' '} + } + size="xs" + style={{ + marginBottom: '2px', + transform: isOpenNetwork ? 'rotate(180deg)' : 'rotate(0deg)', + transition: 'all 200ms', + }} + /> + + + + + + + Mainnet + + + + + Testnet + + + + + + diff --git a/src/components/sidebar-navigation/SmallScreenHeader.tsx b/src/components/sidebar-navigation/SmallScreenHeader.tsx index 0f40941d7..facf3a5c6 100644 --- a/src/components/sidebar-navigation/SmallScreenHeader.tsx +++ b/src/components/sidebar-navigation/SmallScreenHeader.tsx @@ -1,9 +1,11 @@ -import { Button } from '@near-pagoda/ui'; -import { MagnifyingGlass } from '@phosphor-icons/react'; +import { Button, Dropdown } from '@near-pagoda/ui'; +import { MagnifyingGlass, WifiHigh } from '@phosphor-icons/react'; import Image from 'next/image'; import { useRouter } from 'next/router'; import { useContext } from 'react'; +import styled from 'styled-components'; +import { networkId } from '@/config'; import { useSignInRedirect } from '@/hooks/useSignInRedirect'; import { NearContext } from '../wallet-selector/WalletSelector'; @@ -12,6 +14,11 @@ import { useNavigationStore } from './store'; import * as S from './styles'; import { UserDropdownMenu } from './UserDropdownMenu'; +const Redirect = styled.a<{ selected?: boolean }>` + text-decoration: none; + color: #444; +`; + export const SmallScreenHeader = () => { const router = useRouter(); const redirect = (url: string) => () => router.push(url); @@ -23,6 +30,12 @@ export const SmallScreenHeader = () => { const { signedAccountId } = useContext(NearContext); const { requestAuthentication } = useSignInRedirect(); + const preventRedirect = (network: string) => (e: React.MouseEvent) => { + if (networkId == network) { + e.preventDefault(); + } + }; + const handleCreateAccount = () => { requestAuthentication(true); }; @@ -50,23 +63,45 @@ export const SmallScreenHeader = () => { NEAR )} - {signedAccountId ? (