From 5cbea92ad6fb8b11e74770ea88a7db8562a2e2d9 Mon Sep 17 00:00:00 2001 From: aTreeFrog Date: Fri, 19 Jul 2024 16:02:57 -0700 Subject: [PATCH] for testing --- src/app/[netname]/bounty/[id]/layout.tsx | 39 +++++------- src/store/chainStatus.store.ts | 78 ++++++++++++++++-------- 2 files changed, 68 insertions(+), 49 deletions(-) diff --git a/src/app/[netname]/bounty/[id]/layout.tsx b/src/app/[netname]/bounty/[id]/layout.tsx index 982851b4..28c7003d 100644 --- a/src/app/[netname]/bounty/[id]/layout.tsx +++ b/src/app/[netname]/bounty/[id]/layout.tsx @@ -2,6 +2,7 @@ import { Metadata } from 'next'; import * as React from 'react'; import { fetchBountyById } from '@/app/context/web3'; import chainStatusStore from '@/store/chainStatus.store'; +import Head from 'next/head'; import '@/styles/colors.css'; @@ -16,42 +17,26 @@ function weiToEther(weiValue: string | number | bigint): string { export async function generateMetadata({ params }: Props): Promise { try { - // read route params const id = params?.id; - let token = null; - try { - token = params.netname; - } catch (error) { - console.log('params?.netname open graph error: ', error); - return {}; - } - let currency = 'degen'; + const token = params?.netname || null; + let currency = 'degen'; let netName = 'base'; - if ( - token && - (token === 'base' || token === 'degen' || token === 'arbitrum') - ) { + + if (token && ['base', 'degen', 'arbitrum'].includes(token)) { netName = token; } - if ( - !netName || - netName === '' || - netName == 'arbitrum' || - netName == 'base' - ) { + if (!netName || netName === 'arbitrum' || netName === 'base') { currency = 'eth'; } - // fetch data - chainStatusStore.setCurrentChainFromNetwork(netName); + await chainStatusStore.setCurrentChainFromNetwork(netName, true); const bountyData = await fetchBountyById(id); return { title: bountyData?.name || '', description: bountyData?.description || '', - openGraph: { title: bountyData?.name || '', description: bountyData?.description || '', @@ -73,11 +58,17 @@ export async function generateMetadata({ params }: Props): Promise { } } -// Ensure that the layout component is correctly exporting the children export default function BountyLayout({ children, }: { children: React.ReactNode; }) { - return <>{children}; + return ( + <> + + <> {/* Ensure Head has children */} + + {children} + + ); } diff --git a/src/store/chainStatus.store.ts b/src/store/chainStatus.store.ts index f893a1a3..65e2357a 100644 --- a/src/store/chainStatus.store.ts +++ b/src/store/chainStatus.store.ts @@ -1,34 +1,62 @@ -import { action,makeObservable, observable } from "mobx"; - +import { action, makeObservable, observable } from 'mobx'; import chains from '../app/context/config'; class ChainStatusStore { - currentChain = chains.base; + currentChain = chains.base; - constructor() { - makeObservable(this, { - currentChain: observable, - setCurrentChain: action, - }) - } + constructor() { + makeObservable(this, { + currentChain: observable, + setCurrentChain: action, + }); + } - setCurrentChain(chain: any) { - this.currentChain = chain; - } + setCurrentChain(chain: any) { + this.currentChain = chain; + } + + async setCurrentChainFromNetwork( + network?: string, + asyncMode: boolean = false + ) { + const setChain = (chain: any) => { + this.setCurrentChain(chain); + }; - setCurrentChainFromNetwork(network?: string) { - switch (network) { - case 'degen': - this.setCurrentChain(chains.degen); - break; - case 'base': - this.setCurrentChain(chains.base); - break; - case 'arbitrum': - this.setCurrentChain(chains.arbitrum); - break; - } + if (asyncMode) { + switch (network) { + case 'degen': + return new Promise((resolve) => { + setChain(chains.degen); + resolve(); + }); + case 'base': + return new Promise((resolve) => { + setChain(chains.base); + resolve(); + }); + case 'arbitrum': + return new Promise((resolve) => { + setChain(chains.arbitrum); + resolve(); + }); + default: + return Promise.resolve(); + } + } else { + switch (network) { + case 'degen': + setChain(chains.degen); + break; + case 'base': + setChain(chains.base); + break; + case 'arbitrum': + setChain(chains.arbitrum); + break; + } } + } } -export default new ChainStatusStore(); \ No newline at end of file +export default new ChainStatusStore();