From 3286d05b7f9de72106cf19fcc516d488263a3d25 Mon Sep 17 00:00:00 2001 From: Peterbjx Date: Mon, 6 May 2024 16:42:18 +0800 Subject: [PATCH] feat: change NEXT_PUBLIC_NETWORK_TYPE env use --- src/_components/Footer/index.tsx | 7 ++++--- src/_components/HeaderTop/index.tsx | 3 ++- src/_components/MobileHeaderMenu/index.tsx | 5 ++++- src/_utils/isMainNet.ts | 6 ++---- .../[itemSymbol]/_overview/OverViewDetail.tsx | 4 +++- 5 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/_components/Footer/index.tsx b/src/_components/Footer/index.tsx index c760783d..c046e361 100644 --- a/src/_components/Footer/index.tsx +++ b/src/_components/Footer/index.tsx @@ -11,9 +11,10 @@ import './index.css'; import IconFont from '@_components/IconFont'; import BackToTopButton from '@_components/BackToTopBtn'; import Image from 'next/image'; -import { checkMainNet } from '@_utils/isMainNet'; import { useMobileAll } from '@_hooks/useResponsive'; import { MenuItem } from '@_types'; +import { useEnvContext } from 'next-runtime-env'; +import { checkMainNet } from '@_utils/isMainNet'; const FoorterBgTets = '/image/footer-bg.png'; const clsPrefix = 'footer-container'; interface IProps { @@ -23,6 +24,8 @@ interface IProps { }[]; } export default function Footer({ footerMenuList }: IProps) { + const { NEXT_PUBLIC_NETWORK_TYPE } = useEnvContext(); + const isMainNet = checkMainNet(NEXT_PUBLIC_NETWORK_TYPE); const isMobile = useMobileAll(); const rightLinkCom = footerMenuList.map((ele) => { const item = ele.footerMenu_id; @@ -42,8 +45,6 @@ export default function Footer({ footerMenuList }: IProps) { ); }); - - const isMainNet = checkMainNet(); return (
{!isMainNet && ( diff --git a/src/_components/HeaderTop/index.tsx b/src/_components/HeaderTop/index.tsx index 81792fdf..672ebe3c 100644 --- a/src/_components/HeaderTop/index.tsx +++ b/src/_components/HeaderTop/index.tsx @@ -11,6 +11,7 @@ import { useMobileAll } from '@_hooks/useResponsive'; import { MenuItem, NetworkItem } from '@_types'; import { useEnvContext } from 'next-runtime-env'; import { useParams, useRouter } from 'next/navigation'; +import { checkMainNet } from '@_utils/isMainNet'; // at public file const TopIconMain = '/image/aelf-header-top.svg'; @@ -37,8 +38,8 @@ export default function HeaderTop({ price, range, networkList, headerMenuList }: const finalUrl = networkList.find((ele) => ele.key === networkType)?.path; const { chain } = useParams(); const router = useRouter(); - const isMainNet = true; + const isMainNet = checkMainNet(NEXT_PUBLIC_NETWORK_TYPE); return (
diff --git a/src/_components/MobileHeaderMenu/index.tsx b/src/_components/MobileHeaderMenu/index.tsx index 64944ee0..c7bd878a 100644 --- a/src/_components/MobileHeaderMenu/index.tsx +++ b/src/_components/MobileHeaderMenu/index.tsx @@ -9,6 +9,7 @@ import './index.css'; import { useAppDispatch, useAppSelector } from '@_store'; import { setDefaultChain } from '@_store/features/chainIdSlice'; import { getPathnameFirstSlash } from '@_utils/urlUtils'; +import { useEnvContext } from 'next-runtime-env'; import { checkMainNet } from '@_utils/isMainNet'; interface IProps { headerMenuList: MenuItem[]; @@ -27,6 +28,8 @@ export default function MobileHeaderMenu({ headerMenuList, networkList }: IProps setCurrent(e.key); setShowMobileMenu(false); }; + const { NEXT_PUBLIC_NETWORK_TYPE } = useEnvContext(); + const isMainNet = checkMainNet(NEXT_PUBLIC_NETWORK_TYPE); const pathname = usePathname(); const secondSlashIndex = pathname.slice(1).indexOf('/'); @@ -79,7 +82,7 @@ export default function MobileHeaderMenu({ headerMenuList, networkList }: IProps }), ), ]; - const isMainNet = checkMainNet(); + return (
toggleMenu()} /> diff --git a/src/_utils/isMainNet.ts b/src/_utils/isMainNet.ts index ff0cefea..9f5b61ee 100644 --- a/src/_utils/isMainNet.ts +++ b/src/_utils/isMainNet.ts @@ -1,5 +1,3 @@ -import getEnv from './env'; - -export function checkMainNet() { - return getEnv('NEXT_PUBLIC_NETWORK_TYPE') === 'MAINNET'; +export function checkMainNet(type) { + return type === 'MAINNET'; } diff --git a/src/app/[chain]/nft/[collectionSymbol]/[itemSymbol]/_overview/OverViewDetail.tsx b/src/app/[chain]/nft/[collectionSymbol]/[itemSymbol]/_overview/OverViewDetail.tsx index 171cf4b0..b5e88d61 100644 --- a/src/app/[chain]/nft/[collectionSymbol]/[itemSymbol]/_overview/OverViewDetail.tsx +++ b/src/app/[chain]/nft/[collectionSymbol]/[itemSymbol]/_overview/OverViewDetail.tsx @@ -9,6 +9,7 @@ import { checkMainNet } from '@_utils/isMainNet'; import Link from 'next/link'; import { useParams } from 'next/navigation'; import { CollectionSymbol, ItemSymbol } from 'global'; +import { useEnvContext } from 'next-runtime-env'; export interface OverViewDetailProps { overview: ItemSymbolDetailOverview; @@ -18,7 +19,8 @@ export interface OverViewDetailProps { export default function OverViewDetail(props: OverViewDetailProps) { const params = useParams(); const { overview, onHolderClick } = props; - const isMainNet = checkMainNet(); + const { NEXT_PUBLIC_NETWORK_TYPE } = useEnvContext(); + const isMainNet = checkMainNet(NEXT_PUBLIC_NETWORK_TYPE); return (