diff --git a/src/components/ui/cards/DAONodeInfoCard.tsx b/src/components/ui/cards/DAONodeInfoCard.tsx index 508add2b9..52e3a1abe 100644 --- a/src/components/ui/cards/DAONodeInfoCard.tsx +++ b/src/components/ui/cards/DAONodeInfoCard.tsx @@ -96,7 +96,6 @@ export function DAONodeInfoCard(props: { > {/* Convert multisig badge casing here since it's already been cached to avoid another migration */} {type === 'MULTISIG' ? `${type[0]}${type.slice(1).toLocaleLowerCase()}` : type} - {type} ))} diff --git a/src/components/ui/modals/WrapToken.tsx b/src/components/ui/modals/WrapToken.tsx deleted file mode 100644 index 2b078f8e8..000000000 --- a/src/components/ui/modals/WrapToken.tsx +++ /dev/null @@ -1,205 +0,0 @@ -import { Button, Flex, Input } from '@chakra-ui/react'; -import { abis } from '@fractal-framework/fractal-contracts'; -import { Formik, FormikProps } from 'formik'; -import { useCallback, useEffect, useState } from 'react'; -import { useTranslation } from 'react-i18next'; -import { erc20Abi, getContract } from 'viem'; -import { useAccount, usePublicClient, useWalletClient } from 'wagmi'; -import * as Yup from 'yup'; -import { logError } from '../../../helpers/errorLogging'; -import { useERC20LinearToken } from '../../../hooks/DAO/loaders/governance/useERC20LinearToken'; -import useApproval from '../../../hooks/utils/useApproval'; -import { useFormHelpers } from '../../../hooks/utils/useFormHelpers'; -import { useTransaction } from '../../../hooks/utils/useTransaction'; -import { useFractal } from '../../../providers/App/AppProvider'; -import { AzoriusGovernance, BigIntValuePair } from '../../../types'; -import { formatCoin } from '../../../utils'; -import { BigIntInput } from '../forms/BigIntInput'; -import LabelWrapper from '../forms/LabelWrapper'; - -export function WrapToken({ close }: { close: () => void }) { - const { governance, governanceContracts } = useFractal(); - const azoriusGovernance = governance as AzoriusGovernance; - const { data: walletClient } = useWalletClient(); - const publicClient = usePublicClient(); - const { address: account } = useAccount(); - const [userBalance, setUserBalance] = useState({ - value: '', - bigintValue: 0n, - }); - - const { loadERC20TokenAccountData } = useERC20LinearToken({ onMount: false }); - const [contractCall, pending] = useTransaction(); - const { - approved, - approveTransaction, - pending: approvalPending, - } = useApproval( - governanceContracts.underlyingTokenAddress, - azoriusGovernance.votesToken?.address, - userBalance.bigintValue, - ); - - const { t } = useTranslation(['modals', 'treasury']); - const { restrictChars } = useFormHelpers(); - - const getUserUnderlyingTokenBalance = useCallback(async () => { - if ( - !azoriusGovernance.votesToken?.decimals || - !azoriusGovernance.votesToken.underlyingTokenData || - !publicClient || - !account - ) - return; - const baseTokenContract = getContract({ - address: azoriusGovernance.votesToken.underlyingTokenData.address, - abi: erc20Abi, - client: publicClient, - }); - try { - const [balance, decimals] = await Promise.all([ - baseTokenContract.read.balanceOf([account]), - baseTokenContract.read.decimals(), - ]); - setUserBalance({ - value: formatCoin( - balance, - false, - decimals, - azoriusGovernance.votesToken?.underlyingTokenData?.symbol, - ), - bigintValue: balance, - }); - } catch (e) { - logError(e); - return; - } - }, [account, azoriusGovernance.votesToken, publicClient]); - - useEffect(() => { - getUserUnderlyingTokenBalance(); - }, [getUserUnderlyingTokenBalance]); - - const handleFormSubmit = useCallback( - (amount: BigIntValuePair) => { - const { votesTokenAddress } = governanceContracts; - if (!votesTokenAddress || !account || !walletClient) return; - - const wrapperTokenContract = getContract({ - abi: abis.VotesERC20Wrapper, - address: votesTokenAddress, - client: walletClient, - }); - - contractCall({ - contractFn: () => wrapperTokenContract.write.depositFor([account, amount.bigintValue!]), - pendingMessage: t('wrapTokenPendingMessage'), - failedMessage: t('wrapTokenFailedMessage'), - successMessage: t('wrapTokenSuccessMessage'), - successCallback: async () => { - await loadERC20TokenAccountData(); - }, - completedCallback: () => { - close(); - }, - }); - }, - [account, contractCall, governanceContracts, close, t, loadERC20TokenAccountData, walletClient], - ); - - // @dev next couple of lines are written like this, to keep typing equivalent during the conversion from BN to bigint - const userBalanceBigIntValue = userBalance.bigintValue; - const userBalanceBigIntValueIsZero = userBalanceBigIntValue - ? userBalanceBigIntValue === 0n - : undefined; - - if ( - !azoriusGovernance.votesToken?.decimals || - !azoriusGovernance.votesToken.underlyingTokenData || - userBalanceBigIntValueIsZero - ) { - return null; - } - - return ( - { - const { amount } = values; - handleFormSubmit(amount); - }} - validationSchema={Yup.object().shape({ - amount: Yup.object({ - value: Yup.string().required(), - bigintValue: Yup.mixed().required(), - }).test({ - name: 'Wrap Token Validation', - message: t('wrapTokenError'), - test: amount => { - const amountBN = amount.bigintValue as bigint; - if (!amount) return false; - - if (amountBN === 0n) return false; - if (userBalance.bigintValue! === 0n) return false; - if (amountBN > userBalance.bigintValue!) return false; - return true; - }, - }), - })} - > - {({ handleSubmit, values, setFieldValue, errors }: FormikProps) => { - return ( -
- - - - - - - setFieldValue('amount', valuePair)} - data-testid="wrapToken-amount" - onKeyDown={restrictChars} - maxValue={userBalance.bigintValue} - /> - - - {approved ? ( - - ) : ( - - )} - -
- ); - }} -
- ); -}