diff --git a/src/components/Demo.tsx b/src/components/Demo.tsx index 87c4c66..1f406d4 100644 --- a/src/components/Demo.tsx +++ b/src/components/Demo.tsx @@ -1,6 +1,6 @@ "use client"; -import { useEffect, useCallback, useState } from "react"; +import { useEffect, useCallback, useState, useMemo } from "react"; import sdk, { FrameNotificationDetails, type FrameContext, @@ -20,7 +20,7 @@ import { import { config } from "~/components/providers/WagmiProvider"; import { Button } from "~/components/ui/Button"; import { truncateAddress } from "~/lib/truncateAddress"; -import { base } from "wagmi/chains"; +import { base, optimism } from "wagmi/chains"; export default function Demo( { title }: { title?: string } = { title: "Frames v2 Demo" } @@ -59,6 +59,17 @@ export default function Demo( const { disconnect } = useDisconnect(); const { connect } = useConnect(); + const { + switchChain, + error: switchChainError, + isError: isSwitchChainError, + isPending: isSwitchChainPending, + } = useSwitchChain(); + + const handleSwitchChain = useCallback(() => { + switchChain({ chainId: chainId === base.id ? optimism.id : base.id }); + }, [switchChain, chainId]); + useEffect(() => { const load = async () => { setContext(await sdk.context); @@ -139,6 +150,7 @@ export default function Demo( const sendTx = useCallback(() => { sendTransaction( { + // call yoink() on Yoink contract to: "0x4bBFD120d9f352A0BEd7a014bd67913a2007a878", data: "0x9846cd9efc000023c0", }, @@ -155,7 +167,7 @@ export default function Demo( domain: { name: "Frames v2 Demo", version: "1", - chainId: 8453, + chainId, }, types: { Message: [{ name: "content", type: "string" }], @@ -165,7 +177,7 @@ export default function Demo( }, primaryType: "Message", }); - }, [signTypedData]); + }, [chainId, signTypedData]); const toggleContext = useCallback(() => { setIsContextOpen((prev) => !prev); @@ -278,7 +290,7 @@ export default function Demo( {chainId && (
- Chain ID:
{chainId}
+ Chain ID:
{chainId}
)} @@ -293,7 +305,7 @@ export default function Demo( {isConnected ? "Disconnect" : "Connect"} - +
@@ -337,7 +349,14 @@ export default function Demo( {isSignTypedError && renderError(signTypedError)}
- + + {isSwitchChainError && renderError(switchChainError)}
)} @@ -346,34 +365,6 @@ export default function Demo( ); } -function SwitchChain() { - const chainId = useChainId(); - - const { - switchChain, - error: switchChainError, - isError: isSwitchChainError, - isPending: isSwitchChainPending, - } = useSwitchChain(); - - const handleSwitchChain = useCallback(() => { - switchChain({ chainId: chainId === 1 ? 8453 : 1 }); - }, [switchChain, chainId]); - - return ( - <> - - {isSwitchChainError && renderError(switchChainError)} - - ); -} - function SignMessage() { const { isConnected } = useAccount(); const { connectAsync } = useConnect(); @@ -387,16 +378,15 @@ function SignMessage() { const handleSignMessage = useCallback(async () => { if (!isConnected) { - await connectAsync({ - chainId: base.id, - connector: config.connectors[0] - }) + await connectAsync({ + chainId: base.id, + connector: config.connectors[0], + }); } signMessage({ message: "Hello from Frames v2!" }); }, [connectAsync, isConnected, signMessage]); - return ( <>