diff --git a/src/pages/CreateValidator.tsx b/src/pages/CreateValidator.tsx index cb872b3..06fead2 100644 --- a/src/pages/CreateValidator.tsx +++ b/src/pages/CreateValidator.tsx @@ -1,27 +1,30 @@ import { Box, MenuItem, Select, Typography } from '@mui/material' -import React, { useMemo, useState } from 'react' +import React, { useEffect, useMemo, useState } from 'react' import { enqueueSnackbar } from 'notistack'; import { useNavigate } from 'react-router-dom'; import { MsgCreateValidatorEncodeObject } from '@cosmjs/stargate'; import { fromBech32, toBech32 } from '@cosmjs/encoding'; import { LoadingButton } from '@mui/lab'; +import { encodePubkey } from '@cosmjs/proto-signing'; +import { Registry } from '@cerc-io/registry-sdk'; import { useWalletConnectContext } from '../context/WalletConnectContext' -import { encodePubkey } from '@cosmjs/proto-signing'; +import { Participant } from '../types'; const CreateValidator = () => { const {session, signClient} = useWalletConnectContext(); const navigate = useNavigate(); - // TODO: Handle const [cosmosAddress, setCosmosAddress] = useState(''); const [isLoading, setIsLoading] = useState(false); - const [pubkey, setPubkey] = useState(''); + const [pubkey, setPubkey] = useState('d5aOEYaCIHaDn6kG0tAg699D7sLgAgkJI5reTMl0o5U='); + const [participant, setParticipant] = useState(null); if (!session){ navigate("/connect-wallet") } + const changePrefix = (address: string, newPrefix: string): string => { return toBech32(newPrefix, fromBech32(address).data); } @@ -45,7 +48,8 @@ const CreateValidator = () => { }, minSelfDelegation: "1", delegatorAddress: cosmosAddress, - validatorAddress: changePrefix(cosmosAddress, "laconicvaloper"), + // validatorAddress: changePrefix(cosmosAddress, "laconicvaloper"), + validatorAddress: "laconicvaloper1ru0s5tu0cj3xmt8zdfrmz74p0c6lj73nqfpt2q", pubkey: encodePubkey({ type: "tendermint/PubKeyEd25519", value: pubkey, @@ -61,7 +65,6 @@ const CreateValidator = () => { const sendTransaction = async ( transactionMessage: MsgCreateValidatorEncodeObject ) => { - try { setIsLoading(true); @@ -93,6 +96,34 @@ const CreateValidator = () => { } }; + useEffect(() => { + const registry = new Registry( + process.env.REACT_APP_REGISTRY_GQL_ENDPOINT! + ); + + const fetchParticipant = async () => { + try { + if (!cosmosAddress) { + setParticipant(null); + return; + } + const fetchedParticipant: Participant = await registry.getParticipantByAddress(cosmosAddress); + if (!fetchedParticipant) { + enqueueSnackbar("Participant not found", { variant: "error" }); + setParticipant(null); + return; + } + + setParticipant(fetchedParticipant); + } catch (error) { + console.error("Error fetching participant", error); + setParticipant(null); + } + }; + + fetchParticipant(); + }, [cosmosAddress]); + return ( { Create a validator Select Laconic account: + {Boolean(cosmosAddress) && (
+ {participant === null ? ( + No participant found + ) : ( + Onboarded participant + )} + -
-              {/* TODO: Use replacer for Uint8 array */}
-              {JSON.stringify(createValidatorMessage, null, 2)}{" "}
-            
-
- - { - await sendTransaction(createValidatorMessage); - }} - loading={isLoading} - > - Send transaction - + {participant && ( +
+                
+ Cosmos Address: {participant.cosmosAddress}
+ Nitro Address: {participant.nitroAddress}
+ Role: {participant.role}
+ KYC ID: {participant.kycId}
+
+
+ )}
+ + {participant && participant.role === "validator" && ( + <> + Send transaction to chain + +
+                  {JSON.stringify(createValidatorMessage, null, 2)}
+                
+
+ + { + await sendTransaction(createValidatorMessage); + }} + loading={isLoading} + > + Send transaction + + + + )}
)}
- ) } -export default CreateValidator +export default CreateValidator \ No newline at end of file diff --git a/src/pages/OnboardingSuccess.tsx b/src/pages/OnboardingSuccess.tsx index 30ab8eb..9105403 100644 --- a/src/pages/OnboardingSuccess.tsx +++ b/src/pages/OnboardingSuccess.tsx @@ -9,13 +9,7 @@ import { MessageHandler } from "@sumsub/websdk"; import { config, fetchAccessToken, getAccessTokenExpirationHandler, options } from "../utils/sumsub"; import { ENABLE_KYC } from "../constants"; - -interface Participant { - cosmosAddress: string; - nitroAddress: string; - role: string; - kycId: string; -} +import { Participant } from "../types"; const registry = new Registry( process.env.REACT_APP_REGISTRY_GQL_ENDPOINT! diff --git a/src/types.ts b/src/types.ts new file mode 100644 index 0000000..da7f296 --- /dev/null +++ b/src/types.ts @@ -0,0 +1,6 @@ +export interface Participant { + cosmosAddress: string; + nitroAddress: string; + role: string; + kycId: string; + }