Skip to content

Commit 371856c

Browse files
committed
✨ connect and disconnect
1 parent abf6404 commit 371856c

2 files changed

Lines changed: 51 additions & 10 deletions

File tree

index.html

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,43 @@
4444
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25); /* elevate above page */
4545
outline: 1px solid rgba(0, 0, 0, 0.08); /* subtle border in light mode */
4646
z-index: 1000; /* ensure it stays on top */
47+
transform: translateY(0);
48+
visibility: visible;
49+
pointer-events: auto;
50+
transition:
51+
transform 300ms ease,
52+
visibility 0s;
53+
}
54+
iframe.closed {
55+
transform: translateY(calc(100% + 16px));
56+
visibility: hidden;
57+
pointer-events: none;
58+
transition:
59+
transform 300ms ease,
60+
visibility 0s linear 300ms;
61+
}
62+
button {
63+
position: fixed;
64+
top: 50%;
65+
left: 50%;
66+
transform: translate(-50%, -50%);
67+
padding: 10px 12px;
68+
border-radius: 8px;
69+
border: 1px solid rgba(0, 0, 0, 0.12);
70+
background: #ffffffcc;
71+
color: #111;
72+
cursor: pointer;
4773
}
4874
@media (prefers-color-scheme: dark) {
4975
iframe {
5076
outline-color: rgba(255, 255, 255, 0.08); /* subtle border in dark mode */
5177
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
5278
}
79+
button {
80+
border-color: rgba(255, 255, 255, 0.12);
81+
background: #111111cc;
82+
color: #fff;
83+
}
5384
}
5485
/* #endregion */
5586
</style>

src/App.tsx

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import { SequenceConnect, useOpenConnectModal } from "@0xsequence/connect";
22
import { getAccount, getChainId, signMessage, switchChain } from "@wagmi/core";
33
import { useLayoutEffect, useRef } from "react";
4+
import { useAccount, useDisconnect } from "wagmi";
45

56
import hostExaApp from "./hostExaApp"; // host SDK: expose APIs to the iframe
67
import { connectConfig, wagmiConfig } from "./sequence";
78

89
function App() {
10+
const { disconnect } = useDisconnect();
911
const { setOpenConnectModal } = useOpenConnectModal();
12+
const { isConnected, isConnecting } = useAccount();
1013
const exaApp = useRef<HTMLIFrameElement>(null); // hold iframe element reference
1114

1215
useLayoutEffect(() => {
@@ -39,22 +42,29 @@ function App() {
3942
throw new Error(`${method} not supported`);
4043
}
4144
},
42-
ready: () => {
43-
if (wagmiConfig.state.status !== "connected") setOpenConnectModal(true);
44-
},
4545
});
4646

4747
return () => host.cleanup(); // teardown host SDK on unmount
4848
}, [setOpenConnectModal]); // run once on mount
4949

5050
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+
</>
5868
);
5969
}
6070

0 commit comments

Comments
 (0)