Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support switching to degen and mainnet #33

Merged
merged 1 commit into from
Feb 12, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/components/Demo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
import { config } from "~/components/providers/WagmiProvider";
import { Button } from "~/components/ui/Button";
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 { useSession } from "next-auth/react"
import { createStore } from 'mipd'
Expand Down Expand Up @@ -84,8 +84,20 @@ export default function Demo(
isPending: isSwitchChainPending,
} = 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(() => {
switchChain({ chainId: chainId === base.id ? optimism.id : base.id });
switchChain({ chainId: nextChain.id });
}, [switchChain, chainId]);

useEffect(() => {
Expand Down Expand Up @@ -470,7 +482,7 @@ store.subscribe(providerDetails => {
disabled={isSwitchChainPending}
isLoading={isSwitchChainPending}
>
Switch to {chainId === base.id ? "Optimism" : "Base"}
Switch to {nextChain.name}
</Button>
{isSwitchChainError && renderError(switchChainError)}
</div>
Expand Down