generated from defi-wonderland/web3-react-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
65 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,57 @@ | ||
import { GetStaticPaths, GetStaticProps } from 'next'; | ||
import { useEffect } from 'react'; | ||
|
||
import { ecosystemChainData } from '~/types'; | ||
import { CustomHead } from '~/components'; | ||
import { useData } from '~/hooks/useContext/useData'; | ||
import { fetchEcosystemData } from '~/utils'; | ||
|
||
interface ChainProps { | ||
chain: ecosystemChainData; | ||
} | ||
|
||
const Chain = ({ chain }: ChainProps) => { | ||
const { setSelectedChainId } = useData(); | ||
|
||
const Chain = () => { | ||
const title = 'Chain placeholder'; | ||
useEffect(() => { | ||
setSelectedChainId(chain.id); | ||
}, [chain.id, setSelectedChainId]); | ||
|
||
return ( | ||
<> | ||
<CustomHead title={title} /> | ||
<CustomHead title={chain.name} /> | ||
<h1>{chain.name}</h1> | ||
{/* TODO: Add chain page containers */} | ||
</> | ||
); | ||
}; | ||
|
||
export const getStaticPaths: GetStaticPaths = async () => { | ||
const ecosystemData = await fetchEcosystemData(); | ||
const chains = ecosystemData.chains; | ||
|
||
const paths = chains.map((chain: ecosystemChainData) => ({ | ||
params: { chain: chain.id.toString() }, | ||
})); | ||
|
||
return { paths, fallback: false }; | ||
}; | ||
|
||
export const getStaticProps: GetStaticProps = async ({ params }) => { | ||
const ecosystemData = await fetchEcosystemData(); | ||
const chains = ecosystemData.chains; | ||
const chainId = parseInt(params?.chain as string); | ||
const chain = chains.find((chain: ecosystemChainData) => chain.id === chainId); | ||
|
||
if (!chain) { | ||
return { notFound: true }; | ||
} | ||
|
||
return { | ||
props: { | ||
chain, | ||
}, | ||
}; | ||
}; | ||
|
||
export default Chain; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters