mirror of
https://github.com/neynarxyz/create-farcaster-mini-app.git
synced 2025-11-17 00:28:56 -05:00
support switching to degen and mainnet
This commit is contained in:
parent
805036bdaf
commit
e88ae7a98d
@ -24,7 +24,7 @@ import {
|
|||||||
import { config } from "~/components/providers/WagmiProvider";
|
import { config } from "~/components/providers/WagmiProvider";
|
||||||
import { Button } from "~/components/ui/Button";
|
import { Button } from "~/components/ui/Button";
|
||||||
import { truncateAddress } from "~/lib/truncateAddress";
|
import { truncateAddress } from "~/lib/truncateAddress";
|
||||||
import { base, optimism } from "wagmi/chains";
|
import { base, degen, mainnet, optimism } from "wagmi/chains";
|
||||||
import { BaseError, UserRejectedRequestError } from "viem";
|
import { BaseError, UserRejectedRequestError } from "viem";
|
||||||
import { useSession } from "next-auth/react"
|
import { useSession } from "next-auth/react"
|
||||||
import { createStore } from 'mipd'
|
import { createStore } from 'mipd'
|
||||||
@ -84,8 +84,20 @@ export default function Demo(
|
|||||||
isPending: isSwitchChainPending,
|
isPending: isSwitchChainPending,
|
||||||
} = useSwitchChain();
|
} = useSwitchChain();
|
||||||
|
|
||||||
|
const nextChain = useMemo(() => {
|
||||||
|
if (chainId === base.id) {
|
||||||
|
return optimism;
|
||||||
|
} else if (chainId === optimism.id) {
|
||||||
|
return degen;
|
||||||
|
} else if (chainId === degen.id) {
|
||||||
|
return mainnet;
|
||||||
|
} else {
|
||||||
|
return base;
|
||||||
|
}
|
||||||
|
}, [chainId]);
|
||||||
|
|
||||||
const handleSwitchChain = useCallback(() => {
|
const handleSwitchChain = useCallback(() => {
|
||||||
switchChain({ chainId: chainId === base.id ? optimism.id : base.id });
|
switchChain({ chainId: nextChain.id });
|
||||||
}, [switchChain, chainId]);
|
}, [switchChain, chainId]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -470,7 +482,7 @@ store.subscribe(providerDetails => {
|
|||||||
disabled={isSwitchChainPending}
|
disabled={isSwitchChainPending}
|
||||||
isLoading={isSwitchChainPending}
|
isLoading={isSwitchChainPending}
|
||||||
>
|
>
|
||||||
Switch to {chainId === base.id ? "Optimism" : "Base"}
|
Switch to {nextChain.name}
|
||||||
</Button>
|
</Button>
|
||||||
{isSwitchChainError && renderError(switchChainError)}
|
{isSwitchChainError && renderError(switchChainError)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user