Add CosmWasmSigningClient
This commit is contained in:
@@ -2,23 +2,23 @@ import React, { useCallback, useContext, useState, useEffect, ChangeEvent } from
|
||||
import { Box, Typography, SxProps, TextField } from '@mui/material';
|
||||
import { IdentityKeyFormField } from '@nymproject/react/mixnodes/IdentityKeyFormField';
|
||||
import { CurrencyFormField } from '@nymproject/react/currency/CurrencyFormField';
|
||||
import { CurrencyDenom, FeeDetails, DecCoin, decimalToFloatApproximation } from '@nymproject/types';
|
||||
import { Console } from '../utils/console';
|
||||
import { useGetFee } from '../hooks/useGetFee';
|
||||
import { debounce } from 'lodash';
|
||||
import { CurrencyDenom, FeeDetails, DecCoin, decimalToFloatApproximation, Coin } from '@nymproject/types';
|
||||
|
||||
import { SimpleModal } from './SimpleModal';
|
||||
import { ModalListItem } from './ModalListItem';
|
||||
|
||||
import { TPoolOption, checkTokenBalance, validateAmount, validateKey } from '../utils';
|
||||
import { TPoolOption, validateAmount } from '../utils';
|
||||
|
||||
import { useChain } from '@cosmos-kit/react';
|
||||
import { StdFee } from '@cosmjs/amino';
|
||||
import { ExecuteResult } from '@cosmjs/cosmwasm-stargate';
|
||||
|
||||
import { uNYMtoNYM } from '../utils';
|
||||
import { ErrorModal } from './ErrorModal';
|
||||
import { ConfirmTx } from './ConfirmTX';
|
||||
import { BalanceWarning } from './FeeWarning';
|
||||
import { getMixnodeStakeSaturation, simulateDelegateToMixnode, tryConvertIdentityToMixId } from '../requests';
|
||||
|
||||
const MIN_AMOUNT_TO_DELEGATE = 10;
|
||||
const MIXNET_CONTRACT_ADDRESS = 'n17srjznxl9dvzdkpwpw24gg668wc73val88a6m5ajg6ankwvz9wtst0cznr';
|
||||
const sandboxContractAddress = 'n1xr3rq8yvd7qplsw5yx90ftsr2zdhg4e9z60h5duusgxpv72hud3sjkxkav';
|
||||
|
||||
export const DelegateModal: FCWithChildren<{
|
||||
open: boolean;
|
||||
@@ -67,14 +67,15 @@ export const DelegateModal: FCWithChildren<{
|
||||
}) => {
|
||||
const [mixId, setMixId] = useState<number | undefined>();
|
||||
const [identityKey, setIdentityKey] = useState<string | undefined>(initialIdentityKey);
|
||||
const [amount, setAmount] = useState<string | undefined>(initialAmount);
|
||||
const [amount, setAmount] = useState<DecCoin | undefined>();
|
||||
const [isValidated, setValidated] = useState<boolean>(false);
|
||||
const [errorAmount, setErrorAmount] = useState<string | undefined>();
|
||||
// const [tokenPool, setTokenPool] = useState<TPoolOption>('balance');
|
||||
const [errorIdentityKey, setErrorIdentityKey] = useState<string>();
|
||||
const [mixIdError, setMixIdError] = useState<string>();
|
||||
const [cosmWasmSignerClient, setCosmWasmSignerClient] = useState<any>();
|
||||
|
||||
const { fee, getFee, resetFeeState, feeError } = useGetFee();
|
||||
// const { fee, getFee, resetFeeState, feeError } = useGetFee();
|
||||
|
||||
const {
|
||||
username,
|
||||
@@ -86,6 +87,7 @@ export const DelegateModal: FCWithChildren<{
|
||||
getCosmWasmClient,
|
||||
isWalletConnected,
|
||||
getSigningCosmWasmClient,
|
||||
estimateFee,
|
||||
} = useChain('nyx');
|
||||
|
||||
const [balance, setBalance] = useState<{
|
||||
@@ -93,6 +95,16 @@ export const DelegateModal: FCWithChildren<{
|
||||
data?: string;
|
||||
}>({ status: 'loading', data: undefined });
|
||||
|
||||
useEffect(() => {
|
||||
const getClient = async () => {
|
||||
await getSigningCosmWasmClient()
|
||||
.then((res) => setCosmWasmSignerClient(res))
|
||||
.catch((e) => console.log('e :>> ', e));
|
||||
};
|
||||
|
||||
getClient();
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const getBalance = async (walletAddress: string) => {
|
||||
const account = await getCosmWasmClient();
|
||||
@@ -117,7 +129,7 @@ export const DelegateModal: FCWithChildren<{
|
||||
errorIdentityKeyMessage = 'Please enter a valid identity key';
|
||||
}
|
||||
|
||||
if (amount && !(await validateAmount(amount, '0'))) {
|
||||
if (amount && !(await validateAmount(amount.amount, '0'))) {
|
||||
newValidatedValue = false;
|
||||
errorAmountMessage = 'Please enter a valid amount';
|
||||
}
|
||||
@@ -127,7 +139,7 @@ export const DelegateModal: FCWithChildren<{
|
||||
newValidatedValue = false;
|
||||
}
|
||||
|
||||
if (!amount?.length) {
|
||||
if (!amount?.amount.length) {
|
||||
newValidatedValue = false;
|
||||
}
|
||||
|
||||
@@ -148,11 +160,11 @@ export const DelegateModal: FCWithChildren<{
|
||||
setValidated(newValidatedValue);
|
||||
};
|
||||
|
||||
const handleOk = async () => {
|
||||
if (onOk && amount && identityKey && mixId) {
|
||||
onOk(mixId, identityKey, { amount, denom }, 'balance', fee);
|
||||
}
|
||||
};
|
||||
// const handleOk = async () => {
|
||||
// if (onOk && amount && identityKey && mixId) {
|
||||
// onOk(mixId, identityKey, { amount }, 'balance', fee);
|
||||
// }
|
||||
// };
|
||||
|
||||
// const handleConfirm = async ({ mixId: id, value }: { mixId: number; value: DecCoin }) => {
|
||||
// const SCWClient = await getSigningCosmWasmClient();
|
||||
@@ -160,10 +172,36 @@ export const DelegateModal: FCWithChildren<{
|
||||
// console.log('SCWClient :>> ', SCWClient);
|
||||
// };
|
||||
|
||||
const handleConfirm = async () => {
|
||||
const SCWClient = await getSigningCosmWasmClient();
|
||||
const delegateToMixnode = async (
|
||||
{
|
||||
mixId,
|
||||
}: {
|
||||
mixId: number;
|
||||
},
|
||||
fee: number | StdFee | 'auto' = 'auto',
|
||||
memo?: string,
|
||||
_funds?: DecCoin[],
|
||||
): Promise<ExecuteResult> => {
|
||||
return await cosmWasmSignerClient.execute(
|
||||
address,
|
||||
MIXNET_CONTRACT_ADDRESS,
|
||||
{
|
||||
delegate_to_mixnode: {
|
||||
mix_id: mixId,
|
||||
},
|
||||
},
|
||||
fee,
|
||||
memo,
|
||||
_funds,
|
||||
);
|
||||
};
|
||||
|
||||
console.log('SCWClient :>> ', SCWClient);
|
||||
const handleConfirm = async () => {
|
||||
const memo: string = 'test delegation';
|
||||
|
||||
if (mixId && amount) {
|
||||
await delegateToMixnode({ mixId }, 'auto', memo, [amount]);
|
||||
}
|
||||
};
|
||||
|
||||
const handleIdentityKeyChanged = (newIdentityKey: string) => {
|
||||
@@ -180,7 +218,7 @@ export const DelegateModal: FCWithChildren<{
|
||||
};
|
||||
|
||||
const handleAmountChanged = (newAmount: DecCoin) => {
|
||||
setAmount(newAmount.amount);
|
||||
setAmount(newAmount);
|
||||
|
||||
if (onAmountChanged) {
|
||||
onAmountChanged(newAmount.amount);
|
||||
|
||||
@@ -53,6 +53,7 @@ export const TableToolbar: FCWithChildren<TableToolBarProps> = ({
|
||||
blocks: 10000,
|
||||
},
|
||||
};
|
||||
if (nyx.apis) nyx.apis.rpc = [{ address: 'https://rpc.nymtech.net', provider: 'nym' }];
|
||||
}
|
||||
}
|
||||
return chains;
|
||||
|
||||
Reference in New Issue
Block a user