feat(auth-dapp): adds hasInitialized logic

This commit is contained in:
Ben Kremer 2022-09-17 11:35:03 +02:00
parent e8c7bf9c0c
commit 9344954415
2 changed files with 15 additions and 5 deletions

View File

@ -11,6 +11,7 @@ console.log(`AuthClient@${version}`);
const Home: NextPage = () => { const Home: NextPage = () => {
const [client, setClient] = useState<AuthClient | null>(); const [client, setClient] = useState<AuthClient | null>();
const [hasInitialized, setHasInitialized] = useState(false);
const [uri, setUri] = useState<string>(""); const [uri, setUri] = useState<string>("");
const [address, setAddress] = useState<string>(""); const [address, setAddress] = useState<string>("");
@ -42,9 +43,10 @@ const Home: NextPage = () => {
}) })
.then((authClient) => { .then((authClient) => {
setClient(authClient); setClient(authClient);
setHasInitialized(true);
}) })
.catch(console.log); .catch(console.error);
}, [setClient]); }, []);
useEffect(() => { useEffect(() => {
if (!client) return; if (!client) return;
@ -73,7 +75,9 @@ const Home: NextPage = () => {
return ( return (
<Box width="100%" height="100%"> <Box width="100%" height="100%">
{view === "default" && <DefaultView onClick={onSignIn} />} {view === "default" && (
<DefaultView onClick={onSignIn} hasInitialized={hasInitialized} />
)}
{view === "qr" && <QrView uri={uri} />} {view === "qr" && <QrView uri={uri} />}
{view === "signedIn" && <SignedInView address={address} />} {view === "signedIn" && <SignedInView address={address} />}
</Box> </Box>

View File

@ -1,6 +1,9 @@
import { Box, Button, Flex, Heading, Image, position } from "@chakra-ui/react"; 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 ( return (
<Box> <Box>
<Box position={{ position: "relative" }}> <Box position={{ position: "relative" }}>
@ -37,10 +40,13 @@ const DefaultView: React.FC<{ onClick: () => void }> = ({ onClick }) => {
onClick={onClick} onClick={onClick}
borderRadius={"16px"} borderRadius={"16px"}
background="#3396FF" background="#3396FF"
disabled={!hasInitialized}
> >
<Flex gap="1em"> <Flex gap="1em">
<Image src="/wc.png" fit="scale-down" alt="WC" /> <Image src="/wc.png" fit="scale-down" alt="WC" />
<span style={{ color: "white" }}>WalletConnect</span> <span style={{ color: "white" }}>
{hasInitialized ? "WalletConnect" : "Initializing..."}
</span>
</Flex> </Flex>
</Button> </Button>
</Flex> </Flex>