This commit is contained in:
Yana
2023-11-15 12:48:38 +00:00
parent c0cc019b97
commit abbcfbb6c2
2 changed files with 68 additions and 52 deletions
@@ -23,13 +23,7 @@ const sandboxContractAddress = 'n1xr3rq8yvd7qplsw5yx90ftsr2zdhg4e9z60h5duusgxpv7
export const DelegateModal: FCWithChildren<{
open: boolean;
onClose: () => void;
onOk?: (
mixId: number,
identityKey: string,
amount: DecCoin,
tokenPool: TPoolOption,
fee?: FeeDetails,
) => Promise<void>;
onOk?: () => void;
identityKey?: string;
onIdentityKeyChanged?: (identityKey: string) => void;
onAmountChanged?: (amount: string) => void;
@@ -54,14 +48,8 @@ export const DelegateModal: FCWithChildren<{
header,
buttonText,
identityKey: initialIdentityKey,
rewardInterval,
// accountBalance,
estimatedReward,
denom,
profitMarginPercentage,
nodeUptimePercentage,
initialAmount,
hasVestingContract,
sx,
backdropProps,
}) => {
@@ -70,7 +58,6 @@ export const DelegateModal: FCWithChildren<{
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>();
@@ -108,9 +95,6 @@ export const DelegateModal: FCWithChildren<{
isWalletConnected && getClient();
}, [isWalletConnected]);
console.log('cosmWasmSignerClient :>> ', cosmWasmSignerClient);
console.log('isWalletConnected :>> ', isWalletConnected);
useEffect(() => {
const getBalance = async (walletAddress: string) => {
const account = await getCosmWasmClient();
@@ -166,18 +150,6 @@ export const DelegateModal: FCWithChildren<{
setValidated(newValidatedValue);
};
// 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();
// console.log('SCWClient :>> ', SCWClient);
// };
const delegateToMixnode = async (
{
mixId,
@@ -186,13 +158,14 @@ export const DelegateModal: FCWithChildren<{
},
fee: number | StdFee | 'auto' = 'auto',
memo?: string,
_funds?: DecCoin[],
funds?: DecCoin[],
): Promise<ExecuteResult> => {
console.log('cosmWasmSignerClient :>> ', cosmWasmSignerClient);
const amount = (Number(funds![0].amount) * 1000000).toString();
const uNymFunds = [{ amount: amount, denom: 'unym' }];
return await cosmWasmSignerClient.execute(
address,
MIXNET_CONTRACT_ADDRESS,
//sandboxContractAddress,
{
delegate_to_mixnode: {
mix_id: mixId,
@@ -200,17 +173,23 @@ export const DelegateModal: FCWithChildren<{
},
fee,
memo,
_funds,
uNymFunds,
);
};
const handleConfirm = async () => {
const memo: string = 'test delegation';
const fee = { gas: '1000000', amount: [{ amount: '100000', denom: 'unym' }] };
const fee = { gas: '1000000', amount: [{ amount: '25000', denom: 'unym' }] };
if (mixId && amount) {
if (mixId && amount && onOk && cosmWasmSignerClient) {
console.log('trying to delegate :>> ');
await delegateToMixnode({ mixId }, fee, memo, [amount]);
console.log('balance.data :>> ', balance.data);
onOk();
console.log('amount :>> ', amount);
console.log('fee :>> ', fee);
await delegateToMixnode({ mixId }, fee, memo, [amount])
.then((res) => console.log('res :>> ', res))
.catch((err) => console.log('err :>> ', err));
}
};
@@ -284,7 +263,7 @@ export const DelegateModal: FCWithChildren<{
onOk={async () => handleConfirm()}
header={header || 'Delegate'}
okLabel={buttonText || 'Delegate stake'}
okDisabled={isValidated}
okDisabled={!isValidated}
sx={sx}
backdropProps={backdropProps}
>
+53 -16
View File
@@ -7,6 +7,7 @@ import { DelegateModal } from './Delegations/components/DelegateModal';
import { ChainProvider } from '@cosmos-kit/react';
import { assets, chains } from 'chain-registry';
import { wallets as keplr } from '@cosmos-kit/keplr';
import { CurrencyDenom, FeeDetails, DecCoin, decimalToFloatApproximation, Coin } from '@nymproject/types';
const fieldsHeight = '42.25px';
@@ -19,6 +20,17 @@ type TableToolBarProps = {
childrenBefore?: React.ReactNode;
childrenAfter?: React.ReactNode;
};
type ActionType = 'delegate' | 'undelegate' | 'redeem' | 'redeem-all' | 'compound';
type DelegationModalProps = {
status: 'loading' | 'success' | 'error';
action: ActionType;
message?: string;
transactions?: {
url: string;
hash: string;
}[];
};
export const TableToolbar: FCWithChildren<TableToolBarProps> = ({
searchTerm,
@@ -30,6 +42,7 @@ export const TableToolbar: FCWithChildren<TableToolBarProps> = ({
withFilters,
}) => {
const [showNewDelegationModal, setShowNewDelegationModal] = useState<boolean>(false);
const [confirmationModalProps, setConfirmationModalProps] = useState<DelegationModalProps | undefined>();
const assetsFixedUp = useMemo(() => {
const nyx = assets.find((a) => a.chain_name === 'sandbox');
@@ -59,22 +72,43 @@ export const TableToolbar: FCWithChildren<TableToolBarProps> = ({
return chains;
}, [chains]);
// SANDBOX
// const chainsFixedUp = useMemo(() => {
// const nyx = chains.find((c) => c.chain_id === 'sandbox');
// if (nyx) {
// if (!nyx.staking) {
// nyx.staking = {
// staking_tokens: [{ denom: 'unyx' }],
// lock_duration: {
// blocks: 10000,
// },
// };
// if (nyx.apis) nyx.apis.rpc = [{ address: 'https://sandbox-validator1.nymtech.net', provider: 'nym' }];
// }
// }
// return chains;
// }, [chains]);
const handleNewDelegation = () => {
// setConfirmationModalProps({
// status: 'loading',
// action: 'delegate',
// });
setShowNewDelegationModal(false);
// setCurrentDelegationListActionItem(undefined);
// try {
// const tx = await addDelegation(
// {
// mix_id,
// amount,
// },
// tokenPool,
// fee,
// );
// const balances = await getAllBalances();
// setConfirmationModalProps({
// status: 'success',
// action: 'delegate',
// message: 'This operation can take up to one hour to process',
// ...balances,
// transactions: [
// { url: `${urls(network).blockExplorer}/transaction/${tx.transaction_hash}`, hash: tx.transaction_hash },
// ],
// });
// } catch (e) {
// Console.error('Failed to addDelegation', e);
// setConfirmationModalProps({
// status: 'error',
// action: 'delegate',
// message: (e as Error).message,
// });
// }
};
const isMobile = useIsMobile();
return (
@@ -166,6 +200,9 @@ export const TableToolbar: FCWithChildren<TableToolBarProps> = ({
header="Delegate"
buttonText="Delegate stake"
denom={'nym'} // clientDetails?.display_mix_denom || 'nym'}
onOk={handleNewDelegation}
// accountBalance={balance?.printable_balance}
{...confirmationModalProps}
/>
</ChainProvider>
)}