-
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 pull request #10 from optimism-java/deploy
Deploy
- Loading branch information
Showing
20 changed files
with
227 additions
and
160 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; |
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,37 +1,37 @@ | ||
import { type Config, getClient } from '@wagmi/core' | ||
import { FallbackProvider, JsonRpcProvider } from 'ethers' | ||
import type { Client, Chain, Transport } from 'viem' | ||
import { wagmiConfig } from './useWagmiConfig' | ||
import { useMemo } from 'react' | ||
import { useNetworkConfig } from './useNetworkConfig' | ||
import { mainnet, sepolia } from 'viem/chains' | ||
import { type Config, getClient } from "@wagmi/core"; | ||
import { FallbackProvider, JsonRpcProvider } from "ethers"; | ||
import type { Client, Chain, Transport } from "viem"; | ||
import { wagmiConfig } from "./useWagmiConfig"; | ||
import { useContext, useMemo } from "react"; | ||
import { NetworkConfigContext } from "@/components/NetworkConfigContext"; | ||
import { mainnet, sepolia } from "viem/chains"; | ||
|
||
export function clientToProvider(client: Client<Transport, Chain>) { | ||
const { chain, transport } = client | ||
const { chain, transport } = client; | ||
const network = { | ||
chainId: chain.id, | ||
name: chain.name, | ||
ensAddress: chain.contracts?.ensRegistry?.address, | ||
} | ||
if (transport.type === 'fallback') { | ||
}; | ||
if (transport.type === "fallback") { | ||
const providers = (transport.transports as ReturnType<Transport>[]).map( | ||
({ value }) => new JsonRpcProvider(value?.url, network), | ||
) | ||
if (providers.length === 1) return providers[0] | ||
return new FallbackProvider(providers) | ||
({ value }) => new JsonRpcProvider(value?.url, network) | ||
); | ||
if (providers.length === 1) return providers[0]; | ||
return new FallbackProvider(providers); | ||
} | ||
return new JsonRpcProvider(transport.url, network) | ||
return new JsonRpcProvider(transport.url, network); | ||
} | ||
|
||
/** Action to convert a viem Client to an ethers.js Provider. */ | ||
export function useEthersProvider() { | ||
const { network } = useNetworkConfig() | ||
const { network } = useContext(NetworkConfigContext); | ||
const chainId = useMemo(() => { | ||
return network === 'mainnet' ? mainnet.id : sepolia.id | ||
}, [network]) | ||
const client = useMemo(() => getClient(wagmiConfig, { chainId }), [chainId]) | ||
return network === "mainnet" ? mainnet.id : sepolia.id; | ||
}, [network]); | ||
const client = useMemo(() => getClient(wagmiConfig, { chainId }), [chainId]); | ||
return useMemo(() => { | ||
if (!client) return | ||
return clientToProvider(client) | ||
}, [client]) | ||
} | ||
if (!client) return; | ||
return clientToProvider(client); | ||
}, [client]); | ||
} |
Oops, something went wrong.