From 93449544151a32683d09400c316a107b3ca3e905 Mon Sep 17 00:00:00 2001 From: Ben Kremer Date: Sat, 17 Sep 2022 11:35:03 +0200 Subject: [PATCH] feat(auth-dapp): adds hasInitialized logic --- dapps/react-dapp-auth/pages/index.tsx | 10 +++++++--- dapps/react-dapp-auth/views/DefaultView.tsx | 10 ++++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/dapps/react-dapp-auth/pages/index.tsx b/dapps/react-dapp-auth/pages/index.tsx index 18c9c7f..204a4b7 100644 --- a/dapps/react-dapp-auth/pages/index.tsx +++ b/dapps/react-dapp-auth/pages/index.tsx @@ -11,6 +11,7 @@ console.log(`AuthClient@${version}`); const Home: NextPage = () => { const [client, setClient] = useState(); + const [hasInitialized, setHasInitialized] = useState(false); const [uri, setUri] = useState(""); const [address, setAddress] = useState(""); @@ -42,9 +43,10 @@ const Home: NextPage = () => { }) .then((authClient) => { setClient(authClient); + setHasInitialized(true); }) - .catch(console.log); - }, [setClient]); + .catch(console.error); + }, []); useEffect(() => { if (!client) return; @@ -73,7 +75,9 @@ const Home: NextPage = () => { return ( - {view === "default" && } + {view === "default" && ( + + )} {view === "qr" && } {view === "signedIn" && } diff --git a/dapps/react-dapp-auth/views/DefaultView.tsx b/dapps/react-dapp-auth/views/DefaultView.tsx index 99c41d0..f19f74a 100644 --- a/dapps/react-dapp-auth/views/DefaultView.tsx +++ b/dapps/react-dapp-auth/views/DefaultView.tsx @@ -1,6 +1,9 @@ import { Box, Button, Flex, Heading, Image, position } from "@chakra-ui/react"; -const DefaultView: React.FC<{ onClick: () => void }> = ({ onClick }) => { +const DefaultView: React.FC<{ + onClick: () => void; + hasInitialized: boolean; +}> = ({ onClick, hasInitialized }) => { return ( @@ -37,10 +40,13 @@ const DefaultView: React.FC<{ onClick: () => void }> = ({ onClick }) => { onClick={onClick} borderRadius={"16px"} background="#3396FF" + disabled={!hasInitialized} > WC - WalletConnect + + {hasInitialized ? "WalletConnect" : "Initializing..."} +