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.
closes ZKS-104 Description: - Create a DataProvider that will handle all requests
- Loading branch information
Showing
26 changed files
with
368 additions
and
28 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,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 |
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
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> | ||
); | ||
}; |
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,2 +1,3 @@ | ||
export * from './Theme'; | ||
export * from './Disclaimer'; | ||
export * from './CustomHead'; |
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
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
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 | ||
} | ||
} | ||
] |
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 |
---|---|---|
@@ -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 | ||
} | ||
] | ||
} |
This file was deleted.
Oops, something went wrong.
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,2 +1 @@ | ||
export * from './ScrollToTop'; | ||
export * from './useStateContext'; | ||
export * from './useContext'; |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './useStateContext'; |
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 |
---|---|---|
@@ -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.
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 |
---|---|---|
@@ -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; |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const ErrorPage = () => { | ||
return <div>Sorry, something went wrong.</div>; | ||
}; | ||
|
||
export default ErrorPage; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { createContext, useState, useEffect, ReactNode } from 'react'; | ||
import { useQuery, UseQueryResult } 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; | ||
refetchChainData: (options: { throwOnError: boolean; cancelRefetch: boolean }) => Promise<UseQueryResult>; | ||
|
||
ecosystemData: EcosystemData; | ||
chainData: ChainData; | ||
}; | ||
|
||
interface DataProps { | ||
children: ReactNode; | ||
} | ||
|
||
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 (isEcosystemError || isChainError) { | ||
router.push('/error'); | ||
} | ||
}, [isEcosystemError, isChainError, router]); | ||
|
||
return ( | ||
<DataContext.Provider | ||
value={{ | ||
selectedChain, | ||
setSelectedChain, | ||
isEcosystemLoading, | ||
isChainLoading, | ||
ecosystemData, | ||
chainData, | ||
refetchChainData, | ||
}} | ||
> | ||
{children} | ||
</DataContext.Provider> | ||
); | ||
}; |
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
Oops, something went wrong.