-
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.
Merge branch 'development' of https://github.com/optimism-java/disput…
…e-explorer-frontend into development
- Loading branch information
Showing
20 changed files
with
243 additions
and
156 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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
.yarn/install-state.gz | ||
|
||
# testing | ||
/coverage | ||
|
||
# next.js | ||
/.next/ | ||
/out/ | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
*.pem | ||
|
||
# debug | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# local env files | ||
.env*.local | ||
|
||
# vercel | ||
.vercel |
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
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 |
---|---|---|
@@ -1,12 +1,18 @@ | ||
import { useNetworkConfig } from "@/hooks/useNetworkConfig"; | ||
import { NetworkConfigContext } from "@/components/NetworkConfigContext"; | ||
import Link from "next/link"; | ||
import { useContext } from "react"; | ||
|
||
|
||
const DisputeGameLogo: React.FC<{ className?: string }> = ({ }) => { | ||
const { network } = useNetworkConfig() | ||
return <Link href="/"> | ||
<img src={network === 'base-sepolia' ? '/logo_base.svg' : '/logo.svg'} className="w-48" alt="logo" /> | ||
</Link> | ||
const DisputeGameLogo: React.FC<{ className?: string }> = ({}) => { | ||
const { network } = useContext(NetworkConfigContext); | ||
return ( | ||
<Link href="/"> | ||
<img | ||
src={network === "base-sepolia" ? "/logo_base.svg" : "/logo.svg"} | ||
className="w-48" | ||
alt="logo" | ||
/> | ||
</Link> | ||
); | ||
}; | ||
|
||
export default DisputeGameLogo; |
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 |
---|---|---|
@@ -1,12 +1,16 @@ | ||
import { useNetworkConfig } from "@/hooks/useNetworkConfig"; | ||
import { useTheme } from "next-themes"; | ||
import { NetworkConfigContext } from "@/components/NetworkConfigContext"; | ||
import Link from "next/link"; | ||
import { useContext } from "react"; | ||
|
||
export const Logo: React.FC<{ className?: string }> = ({ className = "" }) => { | ||
const { network } = useNetworkConfig() | ||
const { network } = useContext(NetworkConfigContext); | ||
return ( | ||
<Link href="/"> | ||
<img src={network === 'base-sepolia' ? '/logo_base.svg' : '/logo.svg'} className="w-40" alt="logo" /> | ||
<img | ||
src={network === "base-sepolia" ? "/logo_base.svg" : "/logo.svg"} | ||
className="w-40" | ||
alt="logo" | ||
/> | ||
</Link> | ||
); | ||
} | ||
}; |
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,42 @@ | ||
import { NetworkConfig, networkConfigs, Network } from "@/utils/env"; | ||
import { createContext, ReactNode, useEffect, useState } from "react"; | ||
|
||
const defaultNetwork = networkConfigs["sepolia"]; | ||
export const NetworkConfigContext = | ||
createContext<NetworkConfig>(defaultNetwork); | ||
|
||
export default function NetworkConfigProvider({ | ||
children, | ||
}: { | ||
children: ReactNode; | ||
}) { | ||
const [config, setConfig] = useState<NetworkConfig>(defaultNetwork); | ||
useEffect(() => { | ||
const getChain = async () => { | ||
try { | ||
const res = await fetch("/api/disputegames/chainname"); | ||
const data = await res.json(); | ||
let network = data?.blockchain as string; | ||
if (network) { | ||
if (network.startsWith("eth-")) { | ||
network = network.substring(4); | ||
} | ||
const fetchedConfig = networkConfigs[network as Network]; | ||
if (fetchedConfig) { | ||
setConfig(fetchedConfig); // 更新上下文状态 | ||
} | ||
} | ||
} catch (error) { | ||
console.error("Failed to fetch network:", error); | ||
} | ||
}; | ||
|
||
getChain(); | ||
}, []); | ||
|
||
return ( | ||
<NetworkConfigContext.Provider value={config}> | ||
{children} | ||
</NetworkConfigContext.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,19 @@ | ||
import { useAccount, useSwitchChain } from "wagmi" | ||
import { useNetworkConfig } from "./useNetworkConfig" | ||
import { useEffect } from "react" | ||
import { mainnet, sepolia } from "viem/chains" | ||
|
||
import { useAccount, useSwitchChain } from "wagmi"; | ||
import { useContext, useEffect } from "react"; | ||
import { mainnet, sepolia } from "viem/chains"; | ||
import { NetworkConfigContext } from "@/components/NetworkConfigContext"; | ||
|
||
const useAutoSwitchNetwork = () => { | ||
const { network } = useNetworkConfig() | ||
const { switchChain } = useSwitchChain() | ||
const { isConnected, chain } = useAccount() | ||
const { network } = useContext(NetworkConfigContext); | ||
const { switchChain } = useSwitchChain(); | ||
const { isConnected, chain } = useAccount(); | ||
useEffect(() => { | ||
if (!isConnected || !chain) return; | ||
const targetChainId = network === 'mainnet' ? mainnet.id : sepolia.id; | ||
const targetChainId = network === "mainnet" ? mainnet.id : sepolia.id; | ||
if (chain.id !== targetChainId) { | ||
switchChain({ chainId: targetChainId }) | ||
switchChain({ chainId: targetChainId }); | ||
} | ||
}, [isConnected, network, chain]) | ||
} | ||
}, [isConnected, network, chain]); | ||
}; | ||
|
||
export default useAutoSwitchNetwork | ||
export default useAutoSwitchNetwork; |
Oops, something went wrong.