From 7ee66afdcfbf7f8b328dfd48a39002405e1edc69 Mon Sep 17 00:00:00 2001 From: kingsleydon <10992364+kingsleydon@users.noreply.github.com> Date: Fri, 10 Jan 2025 04:28:48 +0800 Subject: [PATCH] fix chain --- apps/app/components/SwitchChainButton.tsx | 10 ++++------ apps/app/components/Web3Provider.tsx | 5 +++-- apps/app/config.ts | 3 +++ apps/app/hooks/useAutoSwitchChain.ts | 8 +++----- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/apps/app/components/SwitchChainButton.tsx b/apps/app/components/SwitchChainButton.tsx index 3ba0bbfc..83ed7832 100644 --- a/apps/app/components/SwitchChainButton.tsx +++ b/apps/app/components/SwitchChainButton.tsx @@ -1,13 +1,11 @@ +import {ethChain} from '@/config' import {LoadingButton} from '@mui/lab' -import {mainnet, sepolia} from 'viem/chains' import {useAccount, useSwitchChain} from 'wagmi' -const targetChain = process.env.VERCEL_ENV === 'production' ? mainnet : sepolia - const SwitchChainButton = ({children}: {children: React.ReactNode}) => { const {chain} = useAccount() const {switchChain, isPending} = useSwitchChain() - if (chain == null || chain.id === targetChain.id) { + if (chain == null || chain.id === ethChain.id) { return children } return ( @@ -15,9 +13,9 @@ const SwitchChainButton = ({children}: {children: React.ReactNode}) => { loading={isPending} fullWidth color="warning" - onClick={() => switchChain({chainId: targetChain.id})} + onClick={() => switchChain({chainId: ethChain.id})} > - Switch to {targetChain.name} + Switch to {ethChain.name} ) } diff --git a/apps/app/components/Web3Provider.tsx b/apps/app/components/Web3Provider.tsx index 8f42943a..d04d0623 100644 --- a/apps/app/components/Web3Provider.tsx +++ b/apps/app/components/Web3Provider.tsx @@ -1,5 +1,7 @@ +import {ethChain} from '@/config' import {ConnectKitProvider, getDefaultConfig} from 'connectkit' import type {ReactNode} from 'react' +import type {Chain} from 'viem' import { WagmiProvider, cookieStorage, @@ -7,9 +9,8 @@ import { createConfig, createStorage, } from 'wagmi' -import {type Chain, sepolia} from 'wagmi/chains' -const chains: [Chain, ...Chain[]] = [sepolia] +const chains: [Chain, ...Chain[]] = [ethChain] const config = createConfig( getDefaultConfig({ diff --git a/apps/app/config.ts b/apps/app/config.ts index 2c38d41a..65486be8 100644 --- a/apps/app/config.ts +++ b/apps/app/config.ts @@ -1,4 +1,5 @@ import {GraphQLClient} from 'graphql-request' +import {sepolia} from 'viem/chains' export const PHALA_ENDPOINTS = [ 'wss://phala-rpc.dwellir.com', @@ -10,3 +11,5 @@ export const subsquidClient = new GraphQLClient( ) export const WPHA_ASSET_ID = 10000 + +export const ethChain = sepolia diff --git a/apps/app/hooks/useAutoSwitchChain.ts b/apps/app/hooks/useAutoSwitchChain.ts index c2ba8b0f..d0d785dc 100644 --- a/apps/app/hooks/useAutoSwitchChain.ts +++ b/apps/app/hooks/useAutoSwitchChain.ts @@ -1,16 +1,14 @@ +import {ethChain} from '@/config' import {useEffect} from 'react' -import {mainnet, sepolia} from 'viem/chains' import {useSwitchChain} from 'wagmi' import {useAccount} from 'wagmi' -const targetChain = process.env.VERCEL_ENV === 'production' ? mainnet : sepolia - export const useAutoSwitchChain = () => { const {chain} = useAccount() const {switchChain} = useSwitchChain() useEffect(() => { - if (chain != null && chain.id !== targetChain.id) { - switchChain({chainId: targetChain.id}) + if (chain?.id !== ethChain.id) { + switchChain({chainId: ethChain.id}) } }, [chain, switchChain]) }