-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathLoginButton.tsx
42 lines (36 loc) · 989 Bytes
/
LoginButton.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { useAccount, useChainId } from "wagmi";
import Button from "../ui/Button";
import { faCircleNotch } from "@fortawesome/free-solid-svg-icons";
import { isChainIdSupported } from "../../wagmi/is-chain-id-supported";
import { useSiweIdentity } from "ic-use-siwe-identity";
export default function LoginButton() {
const { isConnected } = useAccount();
const chainId = useChainId();
const { login, isLoggingIn, isPreparingLogin } = useSiweIdentity();
const text = () => {
if (isLoggingIn) {
return "Signing in";
}
if (isPreparingLogin) {
return "Preparing";
}
return "Sign in";
};
const icon = isLoggingIn || isPreparingLogin ? faCircleNotch : undefined;
const disabled =
!isChainIdSupported(chainId) ||
isLoggingIn ||
!isConnected ||
isPreparingLogin;
return (
<Button
className="w-44"
disabled={disabled}
icon={icon}
onClick={login}
spin
>
{text()}
</Button>
);
}