Skip to content

Commit

Permalink
Merge pull request #330 from AElfProject/feature/refactor-2.0.0-Block…
Browse files Browse the repository at this point in the history
…chain

feat: change NEXT_PUBLIC_NETWORK_TYPE env use
  • Loading branch information
Peterbjx committed May 6, 2024
2 parents 926b48a + 3286d05 commit bd87746
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 10 deletions.
7 changes: 4 additions & 3 deletions src/_components/Footer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand All @@ -42,8 +45,6 @@ export default function Footer({ footerMenuList }: IProps) {
</div>
);
});

const isMainNet = checkMainNet();
return (
<div className={clsx(clsPrefix, isMainNet && `${clsPrefix}-main`, isMobile && `${clsPrefix}-mobile`)}>
{!isMainNet && (
Expand Down
3 changes: 2 additions & 1 deletion src/_components/HeaderTop/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 (
<div className={clsx(clsPrefix, isMainNet && `${clsPrefix}-main`, isMobile && `${clsPrefix}-mobile`)}>
<div className={clsx(`${clsPrefix}-content`)}>
Expand Down
5 changes: 4 additions & 1 deletion src/_components/MobileHeaderMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand All @@ -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('/');
Expand Down Expand Up @@ -79,7 +82,7 @@ export default function MobileHeaderMenu({ headerMenuList, networkList }: IProps
}),
),
];
const isMainNet = checkMainNet();

return (
<div className={`header-navbar-mobile-more ${isMainNet ? 'header-navbar-main-mobile-more' : ''}`}>
<IconFont type={isMainNet ? 'moremainnet' : 'moretestnet'} onClick={() => toggleMenu()} />
Expand Down
6 changes: 2 additions & 4 deletions src/_utils/isMainNet.ts
Original file line number Diff line number Diff line change
@@ -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';
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -18,7 +19,8 @@ export interface OverViewDetailProps {
export default function OverViewDetail(props: OverViewDetailProps) {
const params = useParams<CollectionSymbol & ItemSymbol>();
const { overview, onHolderClick } = props;
const isMainNet = checkMainNet();
const { NEXT_PUBLIC_NETWORK_TYPE } = useEnvContext();
const isMainNet = checkMainNet(NEXT_PUBLIC_NETWORK_TYPE);
return (
<ul className="nft-detail-ul">
<li className="nft-detail-item">
Expand Down

0 comments on commit bd87746

Please sign in to comment.