Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: basic architecture #1

Merged
merged 6 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
NEXT_PUBLIC_API_URL= # Example: https://api.example.com
NEXT_PUBLIC_RPC_URL= # Example: https://localhost:8545
NEXT_PUBLIC_PROJECT_ID= # ProjectID from WalletConnect
NEXT_PUBLIC_ALCHEMY_KEY= # API key from Alchemy
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
echo "NEXT_PUBLIC_RPC_URL=${{ secrets.NEXT_PUBLIC_RPC_URL }}" >> .env
echo "NEXT_PUBLIC_PROJECT_ID=${{ secrets.NEXT_PUBLIC_PROJECT_ID }}" >> .env
echo "NEXT_PUBLIC_ALCHEMY_KEY=${{ secrets.NEXT_PUBLIC_ALCHEMY_KEY }}" >> .env
echo "NEXT_PUBLIC_API_URL=${{ secrets.NEXT_PUBLIC_API_URL }}" >> .env

- name: run Cypress and Jest
uses: cypress-io/github-action@v6
Expand Down
18 changes: 18 additions & 0 deletions src/components/CustomHead.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Head from 'next/head';

interface MetadataProps {
title: string;
description?: string;
image?: string;
type?: string;
}

export const CustomHead = ({ title }: MetadataProps) => {
return (
<Head>
<title>{`${title} - ZKchainHub`}</title>
<meta property='og:title' content={`${title} - ZKchainHub`} />
<meta name='twitter:title' content={`${title} - ZKchainHub`} />
</Head>
);
};
1 change: 1 addition & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './Theme';
export * from './Disclaimer';
export * from './CustomHead';
2 changes: 2 additions & 0 deletions src/config/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ export const getEnv = (): Env => {
const NEXT_PUBLIC_RPC_URL = process.env.NEXT_PUBLIC_RPC_URL;
const NEXT_PUBLIC_PROJECT_ID = process.env.NEXT_PUBLIC_PROJECT_ID;
const NEXT_PUBLIC_ALCHEMY_KEY = process.env.NEXT_PUBLIC_ALCHEMY_KEY;
const NEXT_PUBLIC_API_URL = process.env.NEXT_PUBLIC_API_BASE_URL;

return {
RPC_URL: NEXT_PUBLIC_RPC_URL as string,
PROJECT_ID: NEXT_PUBLIC_PROJECT_ID as string,
ALCHEMY_KEY: NEXT_PUBLIC_ALCHEMY_KEY as string,
API_URL: NEXT_PUBLIC_API_URL as string,
};
};
2 changes: 1 addition & 1 deletion src/containers/Footer/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { styled } from '@mui/material/styles';
import { useCustomTheme } from '~/hooks/useTheme';
import { useCustomTheme } from '~/hooks/useContext/useTheme';

import { FOOTER_HEIGHT } from '~/utils';

Expand Down
2 changes: 1 addition & 1 deletion src/containers/Header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { IconButton } from '@mui/material';
import LightModeIcon from '@mui/icons-material/LightMode';
import DarkModeIcon from '@mui/icons-material/DarkMode';

import { useCustomTheme } from '~/hooks/useTheme';
import { useCustomTheme } from '~/hooks/useContext/useTheme';
import { zIndex, HEADER_HEIGHT } from '~/utils';

export const Header = () => {
Expand Down
60 changes: 60 additions & 0 deletions src/data/chainMockData.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
[
{
"name": "ZKSync Era",
"chainId": 324,
"website": "https://example.com",
"explorer": "https://example.com",
"launchDate": "2023-12-05",
"environment": "Production",
"nativeToken": "ETH",
"chainType": "ZKRollup",
"lastBlock": 123456789,
"lastBlockVerified": 123456788,
"transactionsPerSecond": 15,
"totalBatchesCommitted": 1234567890,
"totalBatchesExecuted": 1234567890,
"totalBatchesVerified": 123456788,
"averageBlockTime": 100000,
"tvl": {
"ETH": {
"value": 500000000,
"address": "0x79db...d692"
},
"USDT": {
"value": 100000000,
"address": "0x79db...d692"
},
"USDC": {
"value": 50000000,
"address": "0x79db...d692"
},
"WBTC": {
"value": 30000000,
"address": "0x79db...d692"
}
},
"rpcs": [
{
"status": "Active",
"url": "https://lrpc.com"
},
{
"status": "Active",
"url": "https://blastapi.com"
},
{
"status": "Inactive",
"url": "https://llamarpc.com"
},
{
"status": "Active",
"url": "https://alchemy.com"
}
],
"feeParams": {
"batchOverheadL1Gas": 1234567890,
"computeOverheadPart": 1234567890,
"maxGasPerBatch": 123456788
}
}
]
91 changes: 91 additions & 0 deletions src/data/ecosystemMockData.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{
"chains": [
{
"name": "zkSync Era",
"id": 324,
"nativeToken": "ETH",
"tvl": 1000000,
"type": "ZKRollup"
},
{
"name": "Teva Chain",
"id": 100,
"nativeToken": "ETH",
"tvl": 1000000,
"type": "ZKRollup"
},
{
"name": "Cronos zkEVM",
"id": 101,
"nativeToken": "ETH",
"tvl": 1000000,
"type": "Validium"
},
{
"name": "GRVT",
"id": 102,
"nativeToken": "ETH",
"tvl": 1000000,
"type": "Validium"
},
{
"name": "Lens",
"id": 103,
"nativeToken": "ETH",
"tvl": 1000000,
"type": "Validium"
},
{
"name": "ZKChain 104",
"id": 104,
"nativeToken": "ETH",
"tvl": 1000000,
"type": "ZKRollup"
},
{
"name": "ZKChain 105",
"id": 105,
"nativeToken": "ETH",
"tvl": 1000000,
"type": "Validium"
}
],
"tvl": [
{
"token": "ETH",
"value": 557596566
},
{
"token": "USDC",
"value": 90091851
},
{
"token": "KOI",
"value": 32757850
},
{
"token": "USDT",
"value": 18021853
},
{
"token": "WBTC",
"value": 12620248
},
{
"token": "wstETH",
"value": 3552439
},
{
"token": "MUTE",
"value": 2071481
},
{
"token": "rETH",
"value": 1404096
},
{
"token": "DAI",
"value": 1080375
}
]
}
19 changes: 0 additions & 19 deletions src/hooks/ScrollToTop.tsx

This file was deleted.

3 changes: 1 addition & 2 deletions src/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from './ScrollToTop';
export * from './useStateContext';
export * from './useContext';
1 change: 1 addition & 0 deletions src/hooks/useContext/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './useStateContext';
13 changes: 13 additions & 0 deletions src/hooks/useContext/useData.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { useContext } from 'react';

import { DataContext } from '~/providers/DataProvider';

export const useData = () => {
const context = useContext(DataContext);

if (context === undefined) {
throw new Error('useData must be used within a StateProvider');
}

return context;
};
File renamed without changes.
File renamed without changes.
14 changes: 14 additions & 0 deletions src/pages/[chain]/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { CustomHead } from '~/components';

const Chain = () => {
const title = 'Chain placeholder';

return (
<>
<CustomHead title={title} />
{/* TODO: Add chain page containers */}
</>
);
};

export default Chain;
5 changes: 5 additions & 0 deletions src/pages/error.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const ErrorPage = () => {
return <div>Sorry, something went wrong.</div>;
};

export default ErrorPage;
6 changes: 3 additions & 3 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import Head from 'next/head';

import { Landing } from '~/containers';

const Home = () => {
const Ecosystem = () => {
return (
<>
<Head>
<title>Web3 Boilerplate</title>
<title>ZKchainHub</title>
</Head>
<Landing />
</>
);
};

export default Home;
export default Ecosystem;
75 changes: 75 additions & 0 deletions src/providers/DataProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { createContext, useState, useEffect } from 'react';
import { useQuery } from '@tanstack/react-query';
import { useRouter } from 'next/router';

import { ChainData, EcosystemData } from '~/types';
import { fetchEcosystemData, fetchChainData } from '~/utils';

type ContextType = {
selectedChain?: ChainData;
setSelectedChain: (val: ChainData) => void;

isEcosystemLoading: boolean;
isChainLoading: boolean;

ecosystemData: EcosystemData;
chainData: ChainData;
};

interface DataProps {
children: React.ReactElement;
}

export const DataContext = createContext({} as ContextType);

export const DataProvider = ({ children }: DataProps) => {
const [selectedChain, setSelectedChain] = useState<ChainData>();
const router = useRouter();

const {
isLoading: isEcosystemLoading,
data: ecosystemData,
isError: isEcosystemError,
} = useQuery({
queryKey: ['ecosystem'],
queryFn: fetchEcosystemData,
});

const {
isLoading: isChainLoading,
data: chainData,
isError: isChainError,
refetch: refetchChainData,
} = useQuery({
queryKey: ['chainData', selectedChain?.chainId],
queryFn: () => fetchChainData(selectedChain!.chainId!),
enabled: !!selectedChain?.chainId,
});

useEffect(() => {
if (selectedChain) {
refetchChainData();
}
}, [selectedChain, refetchChainData]);
0xArdy marked this conversation as resolved.
Show resolved Hide resolved

useEffect(() => {
if (isEcosystemError || isChainError) {
router.push('/error');
}
}, [isEcosystemError, isChainError, router]);

return (
<DataContext.Provider
value={{
selectedChain,
setSelectedChain,
isEcosystemLoading,
isChainLoading,
ecosystemData,
chainData,
}}
>
{children}
</DataContext.Provider>
);
};
Loading
Loading