From 2dac6338739a16c220aaa1c19149adefb407728c Mon Sep 17 00:00:00 2001 From: Yana Date: Tue, 7 Nov 2023 15:06:45 +0000 Subject: [PATCH] WIP --- .../src/components/ConnectKeplrWallet.tsx | 19 +- .../Delegations/components/ConfirmTX.tsx | 48 +++ .../Delegations/components/DelegateModal.tsx | 98 ++++--- .../Delegations/components/FeeWarning.tsx | 35 +++ .../Delegations/components/ModalDivider.tsx | 6 + .../Delegations/components/ModalFee.tsx | 35 +++ .../Delegations/components/styles.ts | 21 ++ .../components/Delegations/context/buy.tsx | 4 +- .../components/Delegations/context/main.tsx | 23 +- .../Delegations/hooks/useCheckOwnership.ts | 4 +- .../Delegations/hooks/useGetBalance.ts | 4 +- .../components/Delegations/hooks/useGetFee.ts | 4 +- .../components/Delegations/typings/FC.d.ts | 1 + .../components/Delegations/typings/jpeg.d.ts | 9 + .../components/Delegations/typings/json.d.ts | 4 + .../components/Delegations/typings/png.d.ts | 4 + .../components/Delegations/typings/svg.d.ts | 4 + .../components/Delegations/utils/common.ts | 273 ++++++++++++++++++ .../components/Delegations/utils/console.ts | 10 + .../Delegations/utils/fireRequests.ts | 22 ++ .../src/components/Delegations/utils/index.ts | 4 + .../src/components/Delegations/utils/sleep.ts | 3 + 22 files changed, 562 insertions(+), 73 deletions(-) create mode 100644 explorer/src/components/Delegations/components/ConfirmTX.tsx create mode 100644 explorer/src/components/Delegations/components/FeeWarning.tsx create mode 100644 explorer/src/components/Delegations/components/ModalDivider.tsx create mode 100644 explorer/src/components/Delegations/components/ModalFee.tsx create mode 100644 explorer/src/components/Delegations/components/styles.ts create mode 100644 explorer/src/components/Delegations/typings/FC.d.ts create mode 100644 explorer/src/components/Delegations/typings/jpeg.d.ts create mode 100644 explorer/src/components/Delegations/typings/json.d.ts create mode 100644 explorer/src/components/Delegations/typings/png.d.ts create mode 100644 explorer/src/components/Delegations/typings/svg.d.ts create mode 100644 explorer/src/components/Delegations/utils/common.ts create mode 100644 explorer/src/components/Delegations/utils/console.ts create mode 100644 explorer/src/components/Delegations/utils/fireRequests.ts create mode 100644 explorer/src/components/Delegations/utils/index.ts create mode 100644 explorer/src/components/Delegations/utils/sleep.ts diff --git a/explorer/src/components/ConnectKeplrWallet.tsx b/explorer/src/components/ConnectKeplrWallet.tsx index 4fab8b8712..766f96059a 100644 --- a/explorer/src/components/ConnectKeplrWallet.tsx +++ b/explorer/src/components/ConnectKeplrWallet.tsx @@ -39,8 +39,17 @@ export const trimAddress = (address = '', trimBy = 6) => { }; export default function ConnectKeplrWallet() { - const { username, connect, disconnect, wallet, openView, address, getCosmWasmClient, isWalletConnected } = - useChain('nyx'); + const { + username, + connect, + disconnect, + wallet, + openView, + address, + getCosmWasmClient, + isWalletConnected, + isWalletConnecting, + } = useChain('nyx'); const isClient = useIsClient(); const theme = useTheme(); @@ -70,9 +79,9 @@ export default function ConnectKeplrWallet() { if (!isClient) return null; const getGlobalbutton = () => { - // if (globalStatus === 'Connecting') { - // return ; - // } + if (isWalletConnecting) { + return ; + } if (isWalletConnected) { return ( diff --git a/explorer/src/components/Delegations/components/ConfirmTX.tsx b/explorer/src/components/Delegations/components/ConfirmTX.tsx new file mode 100644 index 0000000000..e62a86a23c --- /dev/null +++ b/explorer/src/components/Delegations/components/ConfirmTX.tsx @@ -0,0 +1,48 @@ +import React from 'react'; +import { FeeDetails } from '@nymproject/types'; +import { Box } from '@mui/material'; +import { useTheme, Theme } from '@mui/material/styles'; +import { SimpleModal } from './SimpleModal'; +import { ModalFee } from './ModalFee'; +import { ModalDivider } from './ModalDivider'; +import { backDropStyles, modalStyles } from './styles'; + +const storybookStyles = (theme: Theme, isStorybook?: boolean, backdropProps?: object) => + isStorybook + ? { + backdropProps: { ...backDropStyles(theme), ...backdropProps }, + sx: modalStyles(theme), + } + : {}; + +export const ConfirmTx: FCWithChildren<{ + open: boolean; + header: string; + subheader?: string; + fee: FeeDetails; + onConfirm: () => Promise; + onClose?: () => void; + onPrev: () => void; + isStorybook?: boolean; + children?: React.ReactNode; +}> = ({ open, fee, onConfirm, onClose, header, subheader, onPrev, children, isStorybook }) => { + const theme = useTheme(); + return ( + + + {children} + + + + + ); +}; diff --git a/explorer/src/components/Delegations/components/DelegateModal.tsx b/explorer/src/components/Delegations/components/DelegateModal.tsx index eb98c57bac..3828e81857 100644 --- a/explorer/src/components/Delegations/components/DelegateModal.tsx +++ b/explorer/src/components/Delegations/components/DelegateModal.tsx @@ -3,7 +3,7 @@ import { Box, Typography, SxProps } 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 'src/utils/console'; +import { Console } from '../utils/console'; import { useGetFee } from '../hooks/useGetFee'; // import { simulateDelegateToMixnode, simulateVestingDelegateToMixnode, tryConvertIdentityToMixId } from 'src/requests'; import { debounce } from 'lodash'; @@ -12,15 +12,17 @@ import { ModalListItem } from './ModalListItem'; // import { AppContext } from 'src/context'; // import { SimpleModal } from '../Modals/SimpleModal'; // import { ModalListItem } from '../Modals/ModalListItem'; -// import { checkTokenBalance, validateAmount, validateKey } from '../../utils'; +import { TPoolOption, checkTokenBalance, validateAmount, validateKey } from '../utils'; // import { TokenPoolSelector, TPoolOption } from './TokenPoolSelector'; // import { ConfirmTx } from '../ConfirmTX'; // import { getMixnodeStakeSaturation } from '../../requests'; // import { ErrorModal } from '../Modals/ErrorModal'; -// import { BalanceWarning } from '../FeeWarning'; import { useChain } from '@cosmos-kit/react'; -import { uNYMtoNYM } from '../../ConnectKeplrWallet'; +import { uNYMtoNYM } from '../utils'; +import { ErrorModal } from './ErrorModal'; +import { ConfirmTx } from './ConfirmTX'; +import { BalanceWarning } from './FeeWarning'; const MIN_AMOUNT_TO_DELEGATE = 10; @@ -31,7 +33,7 @@ export const DelegateModal: FCWithChildren<{ mixId: number, identityKey: string, amount: DecCoin, - // tokenPool: TPoolOption, + tokenPool: TPoolOption, fee?: FeeDetails, ) => Promise; identityKey?: string; @@ -102,7 +104,6 @@ export const DelegateModal: FCWithChildren<{ getBalance(address); } }, [address, getCosmWasmClient]); - // const { userBalance } = useContext(AppContext); // const handleCheckStakeSaturation = async (newMixId: number) => { // try { @@ -138,10 +139,10 @@ export const DelegateModal: FCWithChildren<{ // } // } - // if (amount && !(await validateAmount(amount, '0'))) { - // newValidatedValue = false; - // errorAmountMessage = 'Please enter a valid amount'; - // } + if (amount && !(await validateAmount(amount, '0'))) { + newValidatedValue = false; + errorAmountMessage = 'Please enter a valid amount'; + } if (amount && Number(amount) < MIN_AMOUNT_TO_DELEGATE) { errorAmountMessage = `Min. delegation amount: ${MIN_AMOUNT_TO_DELEGATE} ${denom.toUpperCase()}`; @@ -166,21 +167,22 @@ export const DelegateModal: FCWithChildren<{ const handleOk = async () => { if (onOk && amount && identityKey && mixId) { - onOk(mixId, identityKey, { amount, denom }, fee); //tokenPool, fee); + onOk(mixId, identityKey, { amount, denom }, 'balance', fee); } }; const handleConfirm = async ({ mixId: id, value }: { mixId: number; value: DecCoin }) => { - const hasEnoughTokens = true; // await checkTokenBalance(tokenPool, value.amount); + const tokenPool = 'balance'; + const hasEnoughTokens = await checkTokenBalance(tokenPool, value.amount); if (!hasEnoughTokens) { setErrorAmount('Not enough funds'); return; } - // if (tokenPool === 'balance') { - // getFee(simulateDelegateToMixnode, { mixId: id, amount: value }); - // } + // if (tokenPool === 'balance') { + // getFee(simulateDelegateToMixnode, { mixId: id, amount: value }); + // } // if (tokenPool === 'locked') { // getFee(simulateVestingDelegateToMixnode, { mixId: id, amount: value }); @@ -217,7 +219,7 @@ export const DelegateModal: FCWithChildren<{ try { // res = await tryConvertIdentityToMixId(idKey); } catch (e) { - // Console.warn(`failed to resolve mix_id for "${idKey}": ${e}`); + Console.warn(`failed to resolve mix_id for "${idKey}": ${e}`); return; } if (res) { @@ -234,38 +236,38 @@ export const DelegateModal: FCWithChildren<{ resolveMixId(identityKey); }, [identityKey]); - // if (fee) { - // return ( - // - // {userBalance.balance?.amount.amount && fee?.amount?.amount && ( - // - // - // - // )} - // - // - // - // ); - // } + if (fee) { + return ( + + {balance.data && fee?.amount?.amount && ( + + + + )} + + + + ); + } - // if (feeError) { - // return ( - // - // ); - // } + if (feeError) { + return ( + + ); + } return ( - +