diff --git a/src/hooks/useContext/index.ts b/src/hooks/useContext/index.ts
index 92f170c..c570b64 100644
--- a/src/hooks/useContext/index.ts
+++ b/src/hooks/useContext/index.ts
@@ -1 +1,3 @@
export * from './useStateContext';
+export * from './useData';
+export * from './useTheme';
diff --git a/src/pages/[chain]/index.tsx b/src/pages/[chain]/index.tsx
index a472e99..34eed58 100644
--- a/src/pages/[chain]/index.tsx
+++ b/src/pages/[chain]/index.tsx
@@ -1,14 +1,57 @@
+import { useEffect } from 'react';
+import { GetStaticPaths, GetStaticProps } from 'next';
+
+import { EcosystemChainData } from '~/types';
import { CustomHead } from '~/components';
+import { useData } from '~/hooks';
+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 (
<>
-
+
+
{chain.name}
{/* 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;
diff --git a/src/providers/DataProvider.tsx b/src/providers/DataProvider.tsx
index f8d02a3..5dc964e 100644
--- a/src/providers/DataProvider.tsx
+++ b/src/providers/DataProvider.tsx
@@ -6,8 +6,8 @@ import { ChainData, EcosystemData } from '~/types';
import { fetchEcosystemData, fetchChainData } from '~/utils';
type ContextType = {
- selectedChain?: ChainData;
- setSelectedChain: (val: ChainData) => void;
+ selectedChainId?: number;
+ setSelectedChainId: (val: number) => void;
isEcosystemLoading: boolean;
isChainLoading: boolean;
@@ -24,7 +24,7 @@ interface DataProps {
export const DataContext = createContext({} as ContextType);
export const DataProvider = ({ children }: DataProps) => {
- const [selectedChain, setSelectedChain] = useState();
+ const [selectedChainId, setSelectedChainId] = useState();
const router = useRouter();
const {
@@ -42,9 +42,9 @@ export const DataProvider = ({ children }: DataProps) => {
isError: isChainError,
refetch: refetchChainData,
} = useQuery({
- queryKey: ['chainData', selectedChain?.chainId],
- queryFn: () => fetchChainData(selectedChain!.chainId!),
- enabled: !!selectedChain?.chainId,
+ queryKey: ['chainData', selectedChainId],
+ queryFn: () => fetchChainData(selectedChainId!),
+ enabled: !!selectedChainId,
});
useEffect(() => {
@@ -56,8 +56,8 @@ export const DataProvider = ({ children }: DataProps) => {
return (