|
1 | 1 | import { SequenceConnect, useOpenConnectModal } from "@0xsequence/connect"; |
2 | 2 | import { getAccount, getChainId, signMessage, switchChain } from "@wagmi/core"; |
3 | 3 | import { useLayoutEffect, useRef } from "react"; |
| 4 | +import { useAccount, useDisconnect } from "wagmi"; |
4 | 5 |
|
5 | 6 | import hostExaApp from "./hostExaApp"; // host SDK: expose APIs to the iframe |
6 | 7 | import { connectConfig, wagmiConfig } from "./sequence"; |
7 | 8 |
|
8 | 9 | function App() { |
| 10 | + const { disconnect } = useDisconnect(); |
9 | 11 | const { setOpenConnectModal } = useOpenConnectModal(); |
| 12 | + const { isConnected, isConnecting } = useAccount(); |
10 | 13 | const exaApp = useRef<HTMLIFrameElement>(null); // hold iframe element reference |
11 | 14 |
|
12 | 15 | useLayoutEffect(() => { |
@@ -39,22 +42,29 @@ function App() { |
39 | 42 | throw new Error(`${method} not supported`); |
40 | 43 | } |
41 | 44 | }, |
42 | | - ready: () => { |
43 | | - if (wagmiConfig.state.status !== "connected") setOpenConnectModal(true); |
44 | | - }, |
45 | 45 | }); |
46 | 46 |
|
47 | 47 | return () => host.cleanup(); // teardown host SDK on unmount |
48 | 48 | }, [setOpenConnectModal]); // run once on mount |
49 | 49 |
|
50 | 50 | return ( |
51 | | - <iframe |
52 | | - ref={exaApp} |
53 | | - title="Exa App" |
54 | | - src="https://sandbox.exactly.app" // sandbox origin; replace with https://web.exactly.app in production |
55 | | - allow="clipboard-read; clipboard-write; camera" // address UX: copy/paste addresses; scan address QR codes |
56 | | - loading="eager" // load immediately; primary content |
57 | | - /> |
| 51 | + <> |
| 52 | + <iframe |
| 53 | + ref={exaApp} |
| 54 | + title="Exa App" |
| 55 | + src="https://sandbox.exactly.app" // sandbox origin; replace with https://web.exactly.app in production |
| 56 | + allow="clipboard-read; clipboard-write; camera" // address UX: copy/paste addresses; scan address QR codes |
| 57 | + loading="eager" // load immediately; primary content |
| 58 | + className={isConnected ? undefined : "closed"} |
| 59 | + /> |
| 60 | + <button |
| 61 | + type="button" |
| 62 | + disabled={isConnecting} |
| 63 | + onClick={() => (isConnected ? disconnect() : setOpenConnectModal(true))} |
| 64 | + > |
| 65 | + {isConnected ? "Sign Out" : "Sign In"} |
| 66 | + </button> |
| 67 | + </> |
58 | 68 | ); |
59 | 69 | } |
60 | 70 |
|
|
0 commit comments