From 12006ecc83734df68c8d18a4562615944aaa4243 Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Thu, 18 Apr 2024 17:30:50 +0100 Subject: [PATCH] fix account button dropdown --- packages/account-kit/src/AccountButton.tsx | 69 ++++++++++--------- .../account-kit/src/bundle/mountButton.tsx | 3 + packages/account-kit/src/ui/FrameConfig.tsx | 22 ------ packages/account-kit/src/ui/Shadow.tsx | 53 +++++++------- 4 files changed, 67 insertions(+), 80 deletions(-) delete mode 100644 packages/account-kit/src/ui/FrameConfig.tsx diff --git a/packages/account-kit/src/AccountButton.tsx b/packages/account-kit/src/AccountButton.tsx index 610e96d35c..90a98ac620 100644 --- a/packages/account-kit/src/AccountButton.tsx +++ b/packages/account-kit/src/AccountButton.tsx @@ -121,43 +121,44 @@ export function AccountButton() { - - - - - Gas tank - - - - Copy address - - - - Switch chain - - + +
disconnect()} > - - Disconnect - - - + + + Gas tank + + + + Copy address + + + + Switch chain + + disconnect()} + > + + Disconnect + +
+
+
); diff --git a/packages/account-kit/src/bundle/mountButton.tsx b/packages/account-kit/src/bundle/mountButton.tsx index 06a277cc11..8f4c2e6b0d 100644 --- a/packages/account-kit/src/bundle/mountButton.tsx +++ b/packages/account-kit/src/bundle/mountButton.tsx @@ -26,6 +26,9 @@ export function mountButton(element: HTMLElement, { wagmiConfig, accountKitConfi const queryClient = new QueryClient(); + // RainbowKit renders an outer
+ // TODO: move to rendering the actual button into a portal as a sibling of the tree + const root = ReactDOM.createRoot(element); root.render( diff --git a/packages/account-kit/src/ui/FrameConfig.tsx b/packages/account-kit/src/ui/FrameConfig.tsx deleted file mode 100644 index 2681d49942..0000000000 --- a/packages/account-kit/src/ui/FrameConfig.tsx +++ /dev/null @@ -1,22 +0,0 @@ -import { useEffect } from "react"; -import { useFrame } from "./FrameProvider"; - -export type Props = { - mode: "modal"; -}; - -export function FrameConfig({ mode }: Props) { - const { frame } = useFrame(); - - useEffect(() => { - if (mode === "modal") { - frame.style.position = "fixed"; - frame.style.inset = "0"; - frame.style.width = "100vw"; - frame.style.height = "100vh"; - frame.style.zIndex = "2147483646"; - } - }, [frame, mode]); - - return <>; -} diff --git a/packages/account-kit/src/ui/Shadow.tsx b/packages/account-kit/src/ui/Shadow.tsx index 19c8becfbc..764e9ea198 100644 --- a/packages/account-kit/src/ui/Shadow.tsx +++ b/packages/account-kit/src/ui/Shadow.tsx @@ -19,12 +19,21 @@ function Resizer({ } & HTMLProps) { const ref = useRef(null); useResizeObserver({ ref, onResize: onSize }); - return
; + return
; } +// TODO: make a container inside the iframe that is at least the size of the window, render content into that so we can correctly measure size relative to window +// otherwise as the iframe shrinks, the measurement will be based on that shrunk value and it'll never get bigger, only smaller + export const Shadow = forwardRef(function Shadow({ mode, children }, forwardedRef) { const frameRef = useRef(null); - const [frameSize, setFrameSize] = useState<{ width: number; height: number } | null>(null); + const [loaded, setLoaded] = useState(false); + const frame = loaded ? frameRef.current : null; + + const [frameSize, setFrameSize] = useState<{ width: number | undefined; height: number | undefined }>({ + width: undefined, + height: undefined, + }); const { theme: initialTheme } = useConfig(); const darkMode = useMediaQuery("(prefers-color-scheme: dark)"); @@ -33,7 +42,7 @@ export const Shadow = forwardRef(function Shadow({ mod const modeStyle: CSSProperties = mode === "modal" ? { display: "block", position: "fixed", inset: "0", width: "100vw", height: "100vh", zIndex: "2147483646" } - : frameSize + : frameSize.width && frameSize.height ? { display: "inline-block", width: `${frameSize.width}px`, height: `${frameSize.height}px` } : { display: "block", @@ -46,29 +55,25 @@ export const Shadow = forwardRef(function Shadow({ mod }; return ( -