diff --git a/explorer/src/components/Delegations/components/DelegateModal.tsx b/explorer/src/components/Delegations/components/DelegateModal.tsx index 0ecb501981..d4069687b1 100644 --- a/explorer/src/components/Delegations/components/DelegateModal.tsx +++ b/explorer/src/components/Delegations/components/DelegateModal.tsx @@ -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; + 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(); const [isValidated, setValidated] = useState(false); const [errorAmount, setErrorAmount] = useState(); - // const [tokenPool, setTokenPool] = useState('balance'); const [errorIdentityKey, setErrorIdentityKey] = useState(); const [mixIdError, setMixIdError] = useState(); const [cosmWasmSignerClient, setCosmWasmSignerClient] = useState(); @@ -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 => { 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} > diff --git a/explorer/src/components/TableToolbar.tsx b/explorer/src/components/TableToolbar.tsx index dcbf4c6ea2..bdd179ac7c 100644 --- a/explorer/src/components/TableToolbar.tsx +++ b/explorer/src/components/TableToolbar.tsx @@ -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 = ({ searchTerm, @@ -30,6 +42,7 @@ export const TableToolbar: FCWithChildren = ({ withFilters, }) => { const [showNewDelegationModal, setShowNewDelegationModal] = useState(false); + const [confirmationModalProps, setConfirmationModalProps] = useState(); const assetsFixedUp = useMemo(() => { const nyx = assets.find((a) => a.chain_name === 'sandbox'); @@ -59,22 +72,43 @@ export const TableToolbar: FCWithChildren = ({ 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 = ({ header="Delegate" buttonText="Delegate stake" denom={'nym'} // clientDetails?.display_mix_denom || 'nym'} + onOk={handleNewDelegation} + // accountBalance={balance?.printable_balance} + {...confirmationModalProps} /> )}