Display tx according to role of onboarded participant
This commit is contained in:
parent
1fff7bf0a6
commit
93cca64505
@ -1,27 +1,30 @@
|
|||||||
import { Box, MenuItem, Select, Typography } from '@mui/material'
|
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 { enqueueSnackbar } from 'notistack';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
|
||||||
import { MsgCreateValidatorEncodeObject } from '@cosmjs/stargate';
|
import { MsgCreateValidatorEncodeObject } from '@cosmjs/stargate';
|
||||||
import { fromBech32, toBech32 } from '@cosmjs/encoding';
|
import { fromBech32, toBech32 } from '@cosmjs/encoding';
|
||||||
import { LoadingButton } from '@mui/lab';
|
import { LoadingButton } from '@mui/lab';
|
||||||
|
import { encodePubkey } from '@cosmjs/proto-signing';
|
||||||
|
import { Registry } from '@cerc-io/registry-sdk';
|
||||||
|
|
||||||
import { useWalletConnectContext } from '../context/WalletConnectContext'
|
import { useWalletConnectContext } from '../context/WalletConnectContext'
|
||||||
import { encodePubkey } from '@cosmjs/proto-signing';
|
import { Participant } from '../types';
|
||||||
|
|
||||||
const CreateValidator = () => {
|
const CreateValidator = () => {
|
||||||
const {session, signClient} = useWalletConnectContext();
|
const {session, signClient} = useWalletConnectContext();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
// TODO: Handle
|
|
||||||
const [cosmosAddress, setCosmosAddress] = useState('');
|
const [cosmosAddress, setCosmosAddress] = useState('');
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
const [pubkey, setPubkey] = useState('');
|
const [pubkey, setPubkey] = useState('d5aOEYaCIHaDn6kG0tAg699D7sLgAgkJI5reTMl0o5U=');
|
||||||
|
const [participant, setParticipant] = useState<Participant | null>(null);
|
||||||
|
|
||||||
if (!session){
|
if (!session){
|
||||||
navigate("/connect-wallet")
|
navigate("/connect-wallet")
|
||||||
}
|
}
|
||||||
|
|
||||||
const changePrefix = (address: string, newPrefix: string): string => {
|
const changePrefix = (address: string, newPrefix: string): string => {
|
||||||
return toBech32(newPrefix, fromBech32(address).data);
|
return toBech32(newPrefix, fromBech32(address).data);
|
||||||
}
|
}
|
||||||
@ -45,7 +48,8 @@ const CreateValidator = () => {
|
|||||||
},
|
},
|
||||||
minSelfDelegation: "1",
|
minSelfDelegation: "1",
|
||||||
delegatorAddress: cosmosAddress,
|
delegatorAddress: cosmosAddress,
|
||||||
validatorAddress: changePrefix(cosmosAddress, "laconicvaloper"),
|
// validatorAddress: changePrefix(cosmosAddress, "laconicvaloper"),
|
||||||
|
validatorAddress: "laconicvaloper1ru0s5tu0cj3xmt8zdfrmz74p0c6lj73nqfpt2q",
|
||||||
pubkey: encodePubkey({
|
pubkey: encodePubkey({
|
||||||
type: "tendermint/PubKeyEd25519",
|
type: "tendermint/PubKeyEd25519",
|
||||||
value: pubkey,
|
value: pubkey,
|
||||||
@ -61,7 +65,6 @@ const CreateValidator = () => {
|
|||||||
const sendTransaction = async (
|
const sendTransaction = async (
|
||||||
transactionMessage: MsgCreateValidatorEncodeObject
|
transactionMessage: MsgCreateValidatorEncodeObject
|
||||||
) => {
|
) => {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
setIsLoading(true);
|
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 (
|
return (
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
@ -105,6 +136,9 @@ const CreateValidator = () => {
|
|||||||
<Typography variant="h5">Create a validator</Typography>
|
<Typography variant="h5">Create a validator</Typography>
|
||||||
<Typography variant="body1">Select Laconic account:</Typography>
|
<Typography variant="body1">Select Laconic account:</Typography>
|
||||||
<Select
|
<Select
|
||||||
|
sx={{
|
||||||
|
marginBottom: 2
|
||||||
|
}}
|
||||||
labelId="demo-simple-select-label"
|
labelId="demo-simple-select-label"
|
||||||
id="demo-simple-select"
|
id="demo-simple-select"
|
||||||
value={cosmosAddress}
|
value={cosmosAddress}
|
||||||
@ -119,8 +153,38 @@ const CreateValidator = () => {
|
|||||||
</MenuItem>
|
</MenuItem>
|
||||||
))}
|
))}
|
||||||
</Select>
|
</Select>
|
||||||
|
|
||||||
{Boolean(cosmosAddress) && (
|
{Boolean(cosmosAddress) && (
|
||||||
<div>
|
<div>
|
||||||
|
{participant === null ? (
|
||||||
|
<Typography >No participant found</Typography>
|
||||||
|
) : (
|
||||||
|
<Typography >Onboarded participant</Typography>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
backgroundColor: participant === null? "white": "lightgray",
|
||||||
|
padding: 3,
|
||||||
|
wordWrap: "break-word",
|
||||||
|
marginBottom: 3,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{participant && (
|
||||||
|
<pre style={{ whiteSpace: "pre-wrap", margin: 0 }}>
|
||||||
|
<div>
|
||||||
|
Cosmos Address: {participant.cosmosAddress} <br />
|
||||||
|
Nitro Address: {participant.nitroAddress} <br />
|
||||||
|
Role: {participant.role} <br />
|
||||||
|
KYC ID: {participant.kycId} <br />
|
||||||
|
</div>
|
||||||
|
</pre>
|
||||||
|
)}
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
{participant && participant.role === "validator" && (
|
||||||
|
<>
|
||||||
|
<Typography >Send transaction to chain</Typography>
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
backgroundColor: "lightgray",
|
backgroundColor: "lightgray",
|
||||||
@ -129,13 +193,10 @@ const CreateValidator = () => {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<pre style={{ whiteSpace: "pre-wrap", margin: 0 }}>
|
<pre style={{ whiteSpace: "pre-wrap", margin: 0 }}>
|
||||||
{/* TODO: Use replacer for Uint8 array */}
|
{JSON.stringify(createValidatorMessage, null, 2)}
|
||||||
{JSON.stringify(createValidatorMessage, null, 2)}{" "}
|
|
||||||
</pre>
|
</pre>
|
||||||
</Box>
|
</Box>
|
||||||
<Box
|
<Box marginTop={1}>
|
||||||
marginTop={1}
|
|
||||||
>
|
|
||||||
<LoadingButton
|
<LoadingButton
|
||||||
variant="contained"
|
variant="contained"
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
@ -146,10 +207,11 @@ const CreateValidator = () => {
|
|||||||
Send transaction
|
Send transaction
|
||||||
</LoadingButton>
|
</LoadingButton>
|
||||||
</Box>
|
</Box>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,13 +9,7 @@ import { MessageHandler } from "@sumsub/websdk";
|
|||||||
|
|
||||||
import { config, fetchAccessToken, getAccessTokenExpirationHandler, options } from "../utils/sumsub";
|
import { config, fetchAccessToken, getAccessTokenExpirationHandler, options } from "../utils/sumsub";
|
||||||
import { ENABLE_KYC } from "../constants";
|
import { ENABLE_KYC } from "../constants";
|
||||||
|
import { Participant } from "../types";
|
||||||
interface Participant {
|
|
||||||
cosmosAddress: string;
|
|
||||||
nitroAddress: string;
|
|
||||||
role: string;
|
|
||||||
kycId: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
const registry = new Registry(
|
const registry = new Registry(
|
||||||
process.env.REACT_APP_REGISTRY_GQL_ENDPOINT!
|
process.env.REACT_APP_REGISTRY_GQL_ENDPOINT!
|
||||||
|
6
src/types.ts
Normal file
6
src/types.ts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
export interface Participant {
|
||||||
|
cosmosAddress: string;
|
||||||
|
nitroAddress: string;
|
||||||
|
role: string;
|
||||||
|
kycId: string;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user