add disabled state

This commit is contained in:
Sasha 2023-11-07 01:26:09 +01:00
parent 3d11fc67bf
commit 24db1bce1c
No known key found for this signature in database
5 changed files with 24 additions and 6 deletions

View File

@ -6,7 +6,7 @@ import { useRLN, useStore } from "@/hooks";
import { useKeystore } from "@/hooks/useKeystore"; import { useKeystore } from "@/hooks/useKeystore";
export const Keystore: React.FunctionComponent<{}> = () => { export const Keystore: React.FunctionComponent<{}> = () => {
const { keystoreCredentials } = useStore(); const { walletConnected, keystoreCredentials } = useStore();
const { onReadCredentials, onRegisterCredentials } = useKeystore(); const { onReadCredentials, onRegisterCredentials } = useKeystore();
const { password, onPasswordChanged } = usePassword(); const { password, onPasswordChanged } = usePassword();
@ -64,7 +64,11 @@ export const Keystore: React.FunctionComponent<{}> = () => {
<Block className="mt-4"> <Block className="mt-4">
<p className="text-s mb-2">Generate new credentials from wallet and register on chain</p> <p className="text-s mb-2">Generate new credentials from wallet and register on chain</p>
<Button onClick={() => onRegisterCredentials(password)}> <Button
disabled={!walletConnected}
onClick={() => onRegisterCredentials(password)}
className={walletConnected ? "" : "cursor-not-allowed"}
>
Register new credentials Register new credentials
</Button> </Button>
</Block> </Block>

View File

@ -2,7 +2,9 @@ import React from "react";
import { Block } from "@/components/Block"; import { Block } from "@/components/Block";
import { Subtitle } from "@/components/Subtitle"; import { Subtitle } from "@/components/Subtitle";
import { Button } from "@/components/Button"; import { Button } from "@/components/Button";
import { Status } from "@/components/Status";
import { MessageContent, useWaku } from "@/hooks"; import { MessageContent, useWaku } from "@/hooks";
import { CONTENT_TOPIC } from "@/constants";
export const Waku: React.FunctionComponent<{}> = () => { export const Waku: React.FunctionComponent<{}> = () => {
const { onSend, messages } = useWaku(); const { onSend, messages } = useWaku();
@ -20,9 +22,12 @@ export const Waku: React.FunctionComponent<{}> = () => {
return ( return (
<Block className="mt-10"> <Block className="mt-10">
<Subtitle> <Block>
Waku <Subtitle>
</Subtitle> Waku
</Subtitle>
<p className="text-sm">Content topic: {CONTENT_TOPIC}</p>
</Block>
<Block className="mt-4"> <Block className="mt-4">
<label <label

View File

@ -1,12 +1,14 @@
type ButtonProps = { type ButtonProps = {
children: any; children: any;
className?: string; className?: string;
disabled?: boolean;
onClick?: (e?: any) => void; onClick?: (e?: any) => void;
}; };
export const Button: React.FunctionComponent<ButtonProps> = (props) => { export const Button: React.FunctionComponent<ButtonProps> = (props) => {
return ( return (
<button <button
disabled={props.disabled}
onClick={props.onClick} onClick={props.onClick}
className={`${ className={`${
props.className || "" props.className || ""

View File

@ -22,6 +22,9 @@ type StoreResult = {
wakuStatus: string; wakuStatus: string;
setWakuStatus: (v: string) => void; setWakuStatus: (v: string) => void;
walletConnected: boolean;
setWalletConnected: () => void;
}; };
const DEFAULT_VALUE = "none"; const DEFAULT_VALUE = "none";
@ -41,6 +44,9 @@ export const useStore = create<StoreResult>((set) => {
credentials: undefined, credentials: undefined,
setCredentials: (v: undefined | IdentityCredential) => setCredentials: (v: undefined | IdentityCredential) =>
set((state) => ({ ...state, credentials: v })), set((state) => ({ ...state, credentials: v })),
walletConnected: false,
setWalletConnected: () => set((state) => ({ ...state, walletConnected: true })),
}; };
const wakuModule = { const wakuModule = {

View File

@ -9,7 +9,7 @@ type UseWalletResult = {
export const useWallet = (): UseWalletResult => { export const useWallet = (): UseWalletResult => {
const { rln } = useRLN(); const { rln } = useRLN();
const { setEthAccount, setChainID } = useStore(); const { setEthAccount, setChainID, setWalletConnected } = useStore();
React.useEffect(() => { React.useEffect(() => {
const ethereum = window.ethereum; const ethereum = window.ethereum;
@ -51,6 +51,7 @@ export const useWallet = (): UseWalletResult => {
try { try {
await window.ethereum.request({ method: 'eth_requestAccounts' }); await window.ethereum.request({ method: 'eth_requestAccounts' });
await rln.initRLNContract(rln.rlnInstance); await rln.initRLNContract(rln.rlnInstance);
setWalletConnected();
} catch(error) { } catch(error) {
console.error("Failed to conenct to wallet."); console.error("Failed to conenct to wallet.");
} }