From ddd7e7415060ad419f02e2504b5d6c3901790a67 Mon Sep 17 00:00:00 2001 From: Adam Gall Date: Mon, 8 Apr 2024 01:58:36 -0400 Subject: [PATCH 01/16] Replace BigNumber with bigint --- netlify/functions/tokenPrices.mts | 8 +- .../ProposalTemplateDetails.tsx | 4 +- .../ProposalTemplateTransaction.tsx | 6 +- .../ProposalTemplateTransactions.tsx | 4 +- .../CreateProposalTemplate/constants.ts | 2 +- src/components/DaoCreator/constants.ts | 23 ++-- .../formComponents/AzoriusGovernance.tsx | 22 ++-- .../formComponents/AzoriusNFTDetail.tsx | 8 +- .../formComponents/AzoriusNFTDetails.tsx | 12 +- .../formComponents/AzoriusTokenAllocation.tsx | 7 +- .../AzoriusTokenAllocations.tsx | 18 ++- .../formComponents/AzoriusTokenDetails.tsx | 13 +- .../formComponents/GuardDetails.tsx | 54 ++++---- .../formComponents/VotesTokenImport.tsx | 2 +- .../formComponents/VotesTokenNew.tsx | 6 +- .../DaoCreator/hooks/usePrepareFormData.ts | 52 ++++---- src/components/ProposalCreate/Transaction.tsx | 6 +- .../ProposalCreate/Transactions.tsx | 4 +- src/components/ProposalCreate/constants.ts | 3 +- .../MultisigProposalDetails/TxActions.tsx | 2 +- .../Proposals/ProposalActions/CastVote.tsx | 2 +- .../ProposalActions/ProposalAction.tsx | 4 +- src/components/Proposals/ProposalSummary.tsx | 38 +++--- .../ProposalVotes/ProposalERC20VoteItem.tsx | 3 +- .../ProposalVotes/ProposalERC721VoteItem.tsx | 4 +- .../ProposalVotes/context/VoteContext.tsx | 8 +- .../Proposals/ProposalVotes/index.tsx | 13 +- .../pages/DAOTreasury/components/Assets.tsx | 8 +- .../DAOTreasury/hooks/useFormatCoins.tsx | 18 +-- .../pages/DAOTreasury/hooks/useSendAssets.ts | 6 +- .../DAOTreasury/hooks/useTreasuryTotalBN.tsx | 5 +- .../Activities/ActivityFreeze.tsx | 6 +- .../pages/DaoDashboard/Activities/index.tsx | 4 +- .../pages/DaoDashboard/ERC20Claim.tsx | 7 +- .../pages/DaoHierarchy/useFetchNodes.tsx | 10 +- .../components/ERC721Token/index.tsx | 2 +- .../DaoSettings/components/Metadata/index.tsx | 7 +- .../DaoSettings/components/Modules/index.tsx | 4 +- .../components/Signers/hooks/useAddSigner.ts | 9 +- .../Signers/hooks/useRemoveSigner.ts | 5 +- src/components/ui/badges/QuorumBadge.tsx | 30 ++--- .../{BigNumberInput.tsx => BigIntInput.tsx} | 59 ++++----- src/components/ui/forms/InputComponent.tsx | 10 +- .../ui/links/EtherscanLinkERC20.tsx | 6 +- .../ui/menus/ManageDAO/ManageDAOMenu.tsx | 3 +- src/components/ui/modals/DelegateModal.tsx | 120 +++++++++--------- .../ui/modals/ProposalTemplateModal.tsx | 16 +-- src/components/ui/modals/SendAssetsModal.tsx | 25 ++-- src/components/ui/modals/Stake.tsx | 19 ++- src/components/ui/modals/UnwrapToken.tsx | 35 ++--- src/components/ui/modals/WrapToken.tsx | 46 ++++--- .../ui/proposal/useProposalCountdown.tsx | 5 +- src/helpers/crypto.ts | 15 ++- src/helpers/freezePeriodHelpers.ts | 40 +++--- .../loaders/governance/useAzoriusListeners.ts | 17 +-- .../loaders/governance/useAzoriusProposals.ts | 9 +- .../governance/useERC20LinearStrategy.ts | 15 +-- .../loaders/governance/useERC20LinearToken.ts | 6 +- .../governance/useERC721LinearStrategy.ts | 11 +- .../DAO/loaders/governance/useERC721Tokens.ts | 10 +- .../DAO/loaders/governance/useLockRelease.ts | 8 +- src/hooks/DAO/loaders/useFavorites.ts | 4 +- src/hooks/DAO/loaders/useFractalFreeze.ts | 41 +++--- .../DAO/proposal/useCreateProposalTemplate.ts | 3 +- src/hooks/DAO/proposal/useExecuteProposal.ts | 3 +- src/hooks/DAO/proposal/usePrepareProposal.ts | 2 +- .../DAO/proposal/useRemoveProposalTemplate.ts | 3 +- src/hooks/DAO/proposal/useSubmitProposal.ts | 8 +- .../DAO/proposal/useUpdateProposalState.ts | 3 +- .../DAO/proposal/useUserERC721VotingTokens.ts | 8 +- src/hooks/DAO/useClawBack.ts | 2 +- src/hooks/DAO/useCreateSubDAOProposal.ts | 3 +- src/hooks/DAO/useDeployAzorius.ts | 3 +- .../schemas/DAOCreate/useDAOCreateSchema.ts | 15 +-- .../schemas/DAOCreate/useDAOCreateTests.ts | 27 ++-- src/hooks/stake/lido/useLidoStaking.ts | 9 +- src/hooks/utils/useAddress.ts | 6 +- src/hooks/utils/useApproval.tsx | 12 +- src/hooks/utils/useSafeTransactions.ts | 48 +++---- src/i18n/locales/en/common.json | 2 +- src/models/AzoriusTxBuilder.ts | 30 ++--- src/models/DaoTxBuilder.ts | 9 +- src/models/helpers/safeData.ts | 11 +- src/pages/create/index.tsx | 3 +- .../proposal-templates/new/index.tsx | 3 +- .../daos/[daoAddress]/proposals/index.tsx | 10 +- .../daos/[daoAddress]/treasury/index.tsx | 2 +- src/providers/App/combinedReducer.ts | 3 +- src/providers/App/governance/action.ts | 11 +- src/providers/App/guard/action.ts | 5 +- src/providers/App/guard/reducer.ts | 2 +- src/providers/App/useReadOnlyValues.ts | 16 +-- src/types/account.ts | 12 +- src/types/common.ts | 6 +- src/types/createDAO.ts | 27 ++-- src/types/createProposal.ts | 4 +- src/types/createProposalTemplate.ts | 4 +- src/types/daoGuard.ts | 3 +- src/types/daoProposal.ts | 15 +-- src/types/daoTreasury.ts | 11 +- src/types/fractal.ts | 21 ++- src/types/transaction.ts | 12 +- src/types/votingFungibleToken.ts | 17 ++- src/utils/azorius.ts | 85 +++++++------ src/utils/contract.ts | 9 +- src/utils/currency.ts | 6 +- src/utils/numberFormats.ts | 26 ++-- src/utils/percentFormat.spec.ts | 27 ++-- src/utils/safeData.ts | 18 +-- src/utils/shutter.ts | 4 +- src/utils/signatures.ts | 6 +- 111 files changed, 753 insertions(+), 791 deletions(-) rename src/components/ui/forms/{BigNumberInput.tsx => BigIntInput.tsx} (74%) diff --git a/netlify/functions/tokenPrices.mts b/netlify/functions/tokenPrices.mts index 530399cf55..4b335a3a51 100644 --- a/netlify/functions/tokenPrices.mts +++ b/netlify/functions/tokenPrices.mts @@ -1,6 +1,6 @@ -// eslint-disable-next-line import/named -import { Store, getStore } from '@netlify/blobs'; -import { ethers } from 'ethers'; +import { getStore } from '@netlify/blobs'; +import type { Store } from '@netlify/blobs'; +import { isAddress } from 'viem'; const PUBLIC_DEMO_API_BASE_URL = 'https://api.coingecko.com/api/v3/'; const AUTH_QUERY_PARAM = `?x_cg_demo_api_key=${process.env.COINGECKO_API_KEY}`; @@ -27,7 +27,7 @@ type SupportedNetworks = (typeof SUPPORTED_NETWORKS)[number]; function sanitizeUserInput(tokensString: string, network: SupportedNetworks) { const rawTokenAddresses = tokensString.split(','); const needNativeAsset = rawTokenAddresses.map(address => address.toLowerCase()).includes(network); - const validTokenAddresses = rawTokenAddresses.filter(address => ethers.utils.isAddress(address)); + const validTokenAddresses = rawTokenAddresses.filter(address => isAddress(address)); const lowerCaseTokenAddresses = validTokenAddresses.map(address => address.toLowerCase()); const tokens = [...new Set(lowerCaseTokenAddresses)]; if (needNativeAsset) tokens.push(network); diff --git a/src/components/CreateProposalTemplate/ProposalTemplateDetails.tsx b/src/components/CreateProposalTemplate/ProposalTemplateDetails.tsx index a470459623..851bf4c0b0 100644 --- a/src/components/CreateProposalTemplate/ProposalTemplateDetails.tsx +++ b/src/components/CreateProposalTemplate/ProposalTemplateDetails.tsx @@ -73,8 +73,8 @@ export default function ProposalTemplateDetails({ {transactions.map((transaction, i) => { - const valueBiggerThanZero = transaction.ethValue.bigNumberValue - ? transaction.ethValue.bigNumberValue.gt(0) + const valueBiggerThanZero = transaction.ethValue.bigintValue + ? transaction.ethValue.bigintValue > 0n : false; return ( diff --git a/src/components/CreateProposalTemplate/ProposalTemplateTransaction.tsx b/src/components/CreateProposalTemplate/ProposalTemplateTransaction.tsx index 33e5c5bdd5..ed3c1c85e6 100644 --- a/src/components/CreateProposalTemplate/ProposalTemplateTransaction.tsx +++ b/src/components/CreateProposalTemplate/ProposalTemplateTransaction.tsx @@ -5,7 +5,7 @@ import { useTranslation } from 'react-i18next'; import { CreateProposalTemplateTransaction } from '../../types/createProposalTemplate'; import ABISelector, { ABIElement } from '../ui/forms/ABISelector'; import ExampleLabel from '../ui/forms/ExampleLabel'; -import { BigNumberComponent, InputComponent } from '../ui/forms/InputComponent'; +import { BigIntComponent, InputComponent } from '../ui/forms/InputComponent'; import { DEFAULT_PROPOSAL_TEMPLATE_TRANSACTION } from './constants'; interface ProposalTemplateTransactionProps { @@ -268,7 +268,7 @@ export default function ProposalTemplateTransaction({ mt={6} pl={10} > - } errorMessage={undefined} - value={transaction.ethValue.bigNumberValue} + value={transaction.ethValue.bigintValue} onChange={e => { setFieldValue(`transactions.${transactionIndex}.ethValue`, e); }} diff --git a/src/components/CreateProposalTemplate/ProposalTemplateTransactions.tsx b/src/components/CreateProposalTemplate/ProposalTemplateTransactions.tsx index 1b4c5b4849..6c7a794c8a 100644 --- a/src/components/CreateProposalTemplate/ProposalTemplateTransactions.tsx +++ b/src/components/CreateProposalTemplate/ProposalTemplateTransactions.tsx @@ -11,7 +11,7 @@ import { ArrowDown, ArrowRight, Minus } from '@decent-org/fractal-ui'; import { FormikErrors, FormikProps } from 'formik'; import { Dispatch, SetStateAction } from 'react'; import { useTranslation } from 'react-i18next'; -import { BigNumberValuePair } from '../../types'; +import { BigIntValuePair } from '../../types'; import { CreateProposalTemplateForm, CreateProposalTemplateTransaction, @@ -46,7 +46,7 @@ export default function ProposalTemplateTransactions({ > {transactions.map((_, index) => { const txErrors = errors?.transactions?.[index] as - | FormikErrors> + | FormikErrors> | undefined; const txAddressError = txErrors?.targetAddress; const txFunctionError = txErrors?.functionName; diff --git a/src/components/CreateProposalTemplate/constants.ts b/src/components/CreateProposalTemplate/constants.ts index 4c7930e184..f309684a4a 100644 --- a/src/components/CreateProposalTemplate/constants.ts +++ b/src/components/CreateProposalTemplate/constants.ts @@ -2,7 +2,7 @@ import { CreateProposalTemplateTransaction } from '../../types/createProposalTem export const DEFAULT_PROPOSAL_TEMPLATE_TRANSACTION: CreateProposalTemplateTransaction = { targetAddress: '', - ethValue: { value: '', bigNumberValue: undefined }, + ethValue: { value: '', bigintValue: undefined }, functionName: '', parameters: [ { diff --git a/src/components/DaoCreator/constants.ts b/src/components/DaoCreator/constants.ts index 399b83af86..196ad440ed 100644 --- a/src/components/DaoCreator/constants.ts +++ b/src/components/DaoCreator/constants.ts @@ -1,4 +1,3 @@ -import { BigNumber } from 'ethers'; import { CreatorFormState, GovernanceType, @@ -8,6 +7,8 @@ import { export const DEFAULT_TOKEN_DECIMALS = 18; +// @todo make the time lengths dynamic for whatever real-life values we're targeting here + export const initialState: CreatorFormState = { essentials: { daoName: '', @@ -45,7 +46,7 @@ export const initialState: CreatorFormState = { ], quorumThreshold: { value: '10', - bigNumberValue: BigNumber.from(10), + bigintValue: 10n, }, }, /** @@ -58,42 +59,42 @@ export const initialState: CreatorFormState = { azorius: { quorumPercentage: { value: '4', - bigNumberValue: BigNumber.from(4), + bigintValue: 4n, }, timelock: { value: '1440', - bigNumberValue: BigNumber.from(1440), + bigintValue: 1440n, }, votingPeriod: { value: '10080', - bigNumberValue: BigNumber.from(10080), + bigintValue: 10080n, }, executionPeriod: { value: '2880', - bigNumberValue: BigNumber.from(2880), + bigintValue: 2880n, }, votingStrategyType: VotingStrategyType.LINEAR_ERC20, }, freeze: { executionPeriod: { value: '2880', - bigNumberValue: BigNumber.from(2880), + bigintValue: 2880n, }, timelockPeriod: { value: '1440', - bigNumberValue: BigNumber.from(1440), + bigintValue: 1440n, }, freezeVotesThreshold: { value: '1', - bigNumberValue: BigNumber.from(1), + bigintValue: 1n, }, freezeProposalPeriod: { value: '10080', - bigNumberValue: BigNumber.from(10080), + bigintValue: 10080n, }, freezePeriod: { value: '10080', - bigNumberValue: BigNumber.from(10080), + bigintValue: 10080n, }, }, multisig: { diff --git a/src/components/DaoCreator/formComponents/AzoriusGovernance.tsx b/src/components/DaoCreator/formComponents/AzoriusGovernance.tsx index 5f02a6f0bb..bea29eaca5 100644 --- a/src/components/DaoCreator/formComponents/AzoriusGovernance.tsx +++ b/src/components/DaoCreator/formComponents/AzoriusGovernance.tsx @@ -11,7 +11,7 @@ import { Info } from '@decent-org/fractal-ui'; import { useTranslation } from 'react-i18next'; import { ICreationStepProps, CreatorSteps, VotingStrategyType } from '../../../types'; import ContentBoxTitle from '../../ui/containers/ContentBox/ContentBoxTitle'; -import { BigNumberInput } from '../../ui/forms/BigNumberInput'; +import { BigIntInput } from '../../ui/forms/BigIntInput'; import { LabelComponent } from '../../ui/forms/InputComponent'; import { StepButtons } from '../StepButtons'; import { StepWrapper } from '../StepWrapper'; @@ -39,8 +39,8 @@ export function AzoriusGovernance(props: ICreationStepProps) { isRequired > - setFieldValue('azorius.votingPeriod', valuePair)} decimalPlaces={0} min="1" @@ -63,8 +63,8 @@ export function AzoriusGovernance(props: ICreationStepProps) { isRequired > - setFieldValue('azorius.quorumPercentage', valuePair)} max="100" decimalPlaces={0} @@ -79,8 +79,8 @@ export function AzoriusGovernance(props: ICreationStepProps) { helper={t('helperQuorumThreshold')} isRequired > - setFieldValue('erc721Token.quorumThreshold', valuePair)} decimalPlaces={0} min="1" @@ -94,8 +94,8 @@ export function AzoriusGovernance(props: ICreationStepProps) { isRequired > - setFieldValue('azorius.timelock', valuePair)} decimalPlaces={0} data-testid="govConfig-timelock" @@ -116,8 +116,8 @@ export function AzoriusGovernance(props: ICreationStepProps) { isRequired > - setFieldValue('azorius.executionPeriod', valuePair)} decimalPlaces={0} min="1" diff --git a/src/components/DaoCreator/formComponents/AzoriusNFTDetail.tsx b/src/components/DaoCreator/formComponents/AzoriusNFTDetail.tsx index 1d02982bd4..2e1cdf6485 100644 --- a/src/components/DaoCreator/formComponents/AzoriusNFTDetail.tsx +++ b/src/components/DaoCreator/formComponents/AzoriusNFTDetail.tsx @@ -2,10 +2,10 @@ import { Flex, Box, Text } from '@chakra-ui/react'; import { ethers } from 'ethers'; import { useState, useEffect } from 'react'; import { useTranslation } from 'react-i18next'; -import { erc721Abi } from 'viem'; +import { erc721Abi, isAddress } from 'viem'; import useDisplayName from '../../../hooks/utils/useDisplayName'; import { useEthersProvider } from '../../../providers/Ethers/hooks/useEthersProvider'; -import { BigNumberValuePair, ERC721TokenConfig } from '../../../types'; +import { BigIntValuePair, ERC721TokenConfig } from '../../../types'; import { BarLoader } from '../../ui/loaders/BarLoader'; type TokenDetails = { @@ -18,7 +18,7 @@ export default function AzoriusNFTDetail({ nft, hasAddressError, }: { - nft: ERC721TokenConfig; + nft: ERC721TokenConfig; hasAddressError: boolean; }) { const [loading, setLoading] = useState(); @@ -36,7 +36,7 @@ export default function AzoriusNFTDetail({ setLoading(true); try { - if (nft.tokenAddress && ethers.utils.isAddress(nft.tokenAddress)) { + if (nft.tokenAddress && isAddress(nft.tokenAddress)) { const tokenContract = new ethers.Contract(nft.tokenAddress, erc721Abi, provider); const [name, symbol] = await Promise.all([tokenContract.name(), tokenContract.symbol()]); setTokenDetails({ diff --git a/src/components/DaoCreator/formComponents/AzoriusNFTDetails.tsx b/src/components/DaoCreator/formComponents/AzoriusNFTDetails.tsx index fb4b62ec8c..909bf51096 100644 --- a/src/components/DaoCreator/formComponents/AzoriusNFTDetails.tsx +++ b/src/components/DaoCreator/formComponents/AzoriusNFTDetails.tsx @@ -8,10 +8,10 @@ import { ICreationStepProps, CreatorSteps, ERC721TokenConfig, - BigNumberValuePair, + BigIntValuePair, } from '../../../types'; import ContentBoxTitle from '../../ui/containers/ContentBox/ContentBoxTitle'; -import { BigNumberInput } from '../../ui/forms/BigNumberInput'; +import { BigIntInput } from '../../ui/forms/BigIntInput'; import { LabelComponent } from '../../ui/forms/InputComponent'; import { StepButtons } from '../StepButtons'; import { StepWrapper } from '../StepWrapper'; @@ -70,7 +70,7 @@ export default function AzoriusNFTDetails(props: ICreationStepProps) { {values.erc721Token.nfts.map((nft, i) => { const nftError = ( errors?.erc721Token?.nfts as FormikErrors< - ERC721TokenConfig[] | undefined + ERC721TokenConfig[] | undefined > )?.[i]; const addressErrorMessage = @@ -135,8 +135,8 @@ export default function AzoriusNFTDetails(props: ICreationStepProps) { }} > - setFieldValue(`erc721Token.nfts.${i}.tokenWeight`, valuePair) } @@ -198,7 +198,7 @@ export default function AzoriusNFTDetails(props: ICreationStepProps) { {values.erc721Token.nfts.map((nft, i) => { const nftError = ( errors?.erc721Token?.nfts as FormikErrors< - ERC721TokenConfig[] | undefined + ERC721TokenConfig[] | undefined > )?.[i]; const addressErrorMessage = diff --git a/src/components/DaoCreator/formComponents/AzoriusTokenAllocation.tsx b/src/components/DaoCreator/formComponents/AzoriusTokenAllocation.tsx index c066bdda74..67d484c7d3 100644 --- a/src/components/DaoCreator/formComponents/AzoriusTokenAllocation.tsx +++ b/src/components/DaoCreator/formComponents/AzoriusTokenAllocation.tsx @@ -1,9 +1,8 @@ import { IconButton, Box } from '@chakra-ui/react'; import { LabelWrapper, Minus } from '@decent-org/fractal-ui'; -import { BigNumber } from 'ethers'; import { Field, FieldAttributes } from 'formik'; import { useFormHelpers } from '../../../hooks/utils/useFormHelpers'; -import { BigNumberInput } from '../../ui/forms/BigNumberInput'; +import { BigIntInput } from '../../ui/forms/BigIntInput'; import { AddressInput } from '../../ui/forms/EthAddressInput'; interface ITokenAllocations { index: number; @@ -11,7 +10,7 @@ interface ITokenAllocations { setFieldValue: (field: string, value: any) => void; addressErrorMessage: string | null; amountErrorMessage: string | null; - amountInputValue: BigNumber | undefined; + amountInputValue: bigint | undefined; allocationLength: number; } @@ -39,7 +38,7 @@ export function AzoriusTokenAllocation({ - setFieldValue(`erc20Token.tokenAllocations.${index}.amount`, valuePair) diff --git a/src/components/DaoCreator/formComponents/AzoriusTokenAllocations.tsx b/src/components/DaoCreator/formComponents/AzoriusTokenAllocations.tsx index 72279a143d..64ff8f4076 100644 --- a/src/components/DaoCreator/formComponents/AzoriusTokenAllocations.tsx +++ b/src/components/DaoCreator/formComponents/AzoriusTokenAllocations.tsx @@ -15,12 +15,12 @@ import { BACKGROUND_SEMI_TRANSPARENT } from '../../../constants/common'; import { useFractal } from '../../../providers/App/AppProvider'; import { AzoriusGovernance, - BigNumberValuePair, + BigIntValuePair, ICreationStepProps, TokenAllocation, } from '../../../types'; import ContentBoxTitle from '../../ui/containers/ContentBox/ContentBoxTitle'; -import { BigNumberInput } from '../../ui/forms/BigNumberInput'; +import { BigIntInput } from '../../ui/forms/BigIntInput'; import { LabelComponent } from '../../ui/forms/InputComponent'; import { AzoriusTokenAllocation } from './AzoriusTokenAllocation'; @@ -60,7 +60,7 @@ export function AzoriusTokenAllocations(props: ICreationStepProps) { {values.erc20Token.tokenAllocations.map((tokenAllocation, index) => { const tokenAllocationError = ( errors?.erc20Token?.tokenAllocations as FormikErrors< - TokenAllocation[] | undefined + TokenAllocation[] | undefined > )?.[index]; @@ -72,7 +72,7 @@ export function AzoriusTokenAllocations(props: ICreationStepProps) { const amountErrorMessage = values.erc20Token.tokenSupply.value && tokenAllocationError?.amount?.value && - !tokenAllocation.amount.bigNumberValue?.isZero() + !(tokenAllocation.amount.bigintValue ?? 0n === 0n) ? tokenAllocationError.amount.value : null; @@ -83,9 +83,7 @@ export function AzoriusTokenAllocations(props: ICreationStepProps) { remove={remove} addressErrorMessage={addressErrorMessage} amountErrorMessage={amountErrorMessage} - amountInputValue={ - values.erc20Token.tokenAllocations[index].amount.bigNumberValue - } + amountInputValue={values.erc20Token.tokenAllocations[index].amount.bigintValue} allocationLength={values.erc20Token.tokenAllocations.length} {...props} /> @@ -140,14 +138,14 @@ export function AzoriusTokenAllocations(props: ICreationStepProps) { - setFieldValue('erc20Token.parentAllocationAmount', valuePair) } diff --git a/src/components/DaoCreator/formComponents/AzoriusTokenDetails.tsx b/src/components/DaoCreator/formComponents/AzoriusTokenDetails.tsx index 27787e9495..c549f01035 100644 --- a/src/components/DaoCreator/formComponents/AzoriusTokenDetails.tsx +++ b/src/components/DaoCreator/formComponents/AzoriusTokenDetails.tsx @@ -1,9 +1,9 @@ import { Box, Flex, Input, RadioGroup, Text } from '@chakra-ui/react'; import { LabelWrapper } from '@decent-org/fractal-ui'; -import { BigNumber, constants, ethers, utils } from 'ethers'; +import { ethers } from 'ethers'; import { useCallback, useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; -import { erc20Abi } from 'viem'; +import { erc20Abi, isAddress, zeroAddress } from 'viem'; import { BACKGROUND_SEMI_TRANSPARENT } from '../../../constants/common'; import { createAccountSubstring } from '../../../hooks/utils/useDisplayName'; import { useEthersProvider } from '../../../providers/Ethers/hooks/useEthersProvider'; @@ -49,18 +49,21 @@ export function AzoriusTokenDetails(props: ICreationStepProps) { const updateImportFields = useCallback(async () => { const importAddress = values.erc20Token.tokenImportAddress; const importError = errors?.erc20Token?.tokenImportAddress; - if (importAddress && !importError && utils.isAddress(importAddress)) { + if (importAddress && !importError && isAddress(importAddress)) { const isVotesToken = await checkVotesToken(importAddress); const tokenContract = new ethers.Contract(importAddress, erc20Abi, provider); const name: string = await tokenContract.name(); const symbol: string = await tokenContract.symbol(); const decimals: number = await tokenContract.decimals(); + + // @todo yo what is going on here const totalSupply: number = (await tokenContract.totalSupply()) / 10 ** decimals; + setFieldValue( 'erc20Token.tokenSupply', { value: totalSupply, - bigNumberValue: BigNumber.from(totalSupply), + bigintValue: BigInt(totalSupply), }, true, ); @@ -156,7 +159,7 @@ export function AzoriusTokenDetails(props: ICreationStepProps) { name="erc20Token.tokenImportAddress" onChange={handleChange} value={values.erc20Token.tokenImportAddress} - placeholder={createAccountSubstring(constants.AddressZero)} + placeholder={createAccountSubstring(zeroAddress)} /> {!isImportedVotesToken && !errors.erc20Token?.tokenImportAddress && ( diff --git a/src/components/DaoCreator/formComponents/GuardDetails.tsx b/src/components/DaoCreator/formComponents/GuardDetails.tsx index f042cda381..13fda496fe 100644 --- a/src/components/DaoCreator/formComponents/GuardDetails.tsx +++ b/src/components/DaoCreator/formComponents/GuardDetails.tsx @@ -8,20 +8,20 @@ import { Divider, } from '@chakra-ui/react'; import { Info } from '@decent-org/fractal-ui'; -import { BigNumber, ethers } from 'ethers'; import { useEffect, useState, useCallback } from 'react'; import { useTranslation } from 'react-i18next'; +import { formatUnits } from 'viem'; import { useFractal } from '../../../providers/App/AppProvider'; import { ICreationStepProps, - BigNumberValuePair, + BigIntValuePair, GovernanceType, CreatorSteps, AzoriusGovernance, } from '../../../types'; -import { formatBigNumberDisplay } from '../../../utils/numberFormats'; +import { formatBigIntDisplay } from '../../../utils/numberFormats'; import ContentBoxTitle from '../../ui/containers/ContentBox/ContentBoxTitle'; -import { BigNumberInput } from '../../ui/forms/BigNumberInput'; +import { BigIntInput } from '../../ui/forms/BigIntInput'; import { CustomNonceInput } from '../../ui/forms/CustomNonceInput'; import { LabelComponent } from '../../ui/forms/InputComponent'; import { StepButtons } from '../StepButtons'; @@ -38,7 +38,7 @@ function GuardDetails(props: ICreationStepProps) { } = useFractal(); const { type } = governance; const [showCustomNonce, setShowCustomNonce] = useState(); - const [totalParentVotes, setTotalParentVotes] = useState(); + const [totalParentVotes, setTotalParentVotes] = useState(); const { t } = useTranslation(['daoCreate', 'common', 'proposal']); const minutes = t('minutes', { ns: 'common' }); const azoriusGovernance = governance as AzoriusGovernance; @@ -63,7 +63,7 @@ function GuardDetails(props: ICreationStepProps) { if (!totalParentVotes) { if (!type) return; - let parentVotes: BigNumber; + let parentVotes: bigint; switch (type) { case GovernanceType.AZORIUS_ERC20: @@ -74,38 +74,38 @@ function GuardDetails(props: ICreationStepProps) { ) return; if (azoriusGovernance.votesToken) { - const normalized = ethers.utils.formatUnits( + const normalized = formatUnits( azoriusGovernance.votesToken.totalSupply, azoriusGovernance.votesToken.decimals, ); - parentVotes = BigNumber.from(normalized.substring(0, normalized.indexOf('.'))); + parentVotes = BigInt(normalized.substring(0, normalized.indexOf('.'))); } else if (azoriusGovernance.erc721Tokens) { parentVotes = azoriusGovernance.erc721Tokens!.reduce( - (prev, curr) => curr.votingWeight.mul(curr.totalSupply || 1).add(prev), - BigNumber.from(0), + (prev, curr) => curr.votingWeight * (curr.totalSupply || 1n) + prev, + 0n, ); } else { - parentVotes = BigNumber.from(1); + parentVotes = 1n; } break; case GovernanceType.MULTISIG: default: if (!safe) return; - parentVotes = BigNumber.from(safe.owners.length); + parentVotes = BigInt(safe.owners.length); } - let thresholdDefault: BigNumberValuePair; + let thresholdDefault: BigIntValuePair; - if (parentVotes.eq(1)) { + if (parentVotes === 1n) { thresholdDefault = { value: '1', - bigNumberValue: parentVotes, + bigintValue: parentVotes, }; } else { thresholdDefault = { value: parentVotes.toString(), - bigNumberValue: parentVotes.div(2), + bigintValue: parentVotes / 2n, }; } @@ -122,7 +122,7 @@ function GuardDetails(props: ICreationStepProps) { ]); const freezeHelper = totalParentVotes - ? t('helperFreezeVotesThreshold', { totalVotes: formatBigNumberDisplay(totalParentVotes) }) + ? t('helperFreezeVotesThreshold', { totalVotes: formatBigIntDisplay(totalParentVotes) }) : null; return ( @@ -145,8 +145,8 @@ function GuardDetails(props: ICreationStepProps) { isRequired > - setFieldValue('freeze.timelockPeriod', valuePair)} decimalPlaces={0} min="1" @@ -168,8 +168,8 @@ function GuardDetails(props: ICreationStepProps) { isRequired > - setFieldValue('freeze.executionPeriod', valuePair)} decimalPlaces={0} min="1" @@ -193,8 +193,8 @@ function GuardDetails(props: ICreationStepProps) { helper={freezeHelper || ''} isRequired > - setFieldValue('freeze.freezeVotesThreshold', valuePair)} decimalPlaces={0} data-testid="guardConfig-freezeVotesThreshold" @@ -206,8 +206,8 @@ function GuardDetails(props: ICreationStepProps) { isRequired > - setFieldValue('freeze.freezeProposalPeriod', valuePair)} decimalPlaces={0} min="1" @@ -229,8 +229,8 @@ function GuardDetails(props: ICreationStepProps) { isRequired > - setFieldValue('freeze.freezePeriod', valuePair)} decimalPlaces={0} min="1" diff --git a/src/components/DaoCreator/formComponents/VotesTokenImport.tsx b/src/components/DaoCreator/formComponents/VotesTokenImport.tsx index 27d22d38ad..64cb0901ef 100644 --- a/src/components/DaoCreator/formComponents/VotesTokenImport.tsx +++ b/src/components/DaoCreator/formComponents/VotesTokenImport.tsx @@ -53,7 +53,7 @@ export function VotesTokenImport(props: ICreationStepProps) { disabled={true} > - setFieldValue('erc20Token.tokenSupply', valuePair)} data-testid="tokenVoting-tokenSupplyInput" onKeyDown={restrictChars} diff --git a/src/components/DaoCreator/hooks/usePrepareFormData.ts b/src/components/DaoCreator/hooks/usePrepareFormData.ts index 33ae1832c5..851415239c 100644 --- a/src/components/DaoCreator/hooks/usePrepareFormData.ts +++ b/src/components/DaoCreator/hooks/usePrepareFormData.ts @@ -6,7 +6,7 @@ import { useEthersSigner } from '../../../providers/Ethers/hooks/useEthersSigner import { SafeMultisigDAO, DAOFreezeGuardConfig, - BigNumberValuePair, + BigIntValuePair, TokenCreationType, AzoriusERC20DAO, AzoriusERC721DAO, @@ -14,7 +14,7 @@ import { import { getEstimatedNumberOfBlocks } from '../../../utils/contract'; import { couldBeENS } from '../../../utils/url'; -type FreezeGuardConfigParam = { freezeGuard?: DAOFreezeGuardConfig }; +type FreezeGuardConfigParam = { freezeGuard?: DAOFreezeGuardConfig }; export function usePrepareFormData() { const signer = useEthersSigner(); @@ -23,25 +23,25 @@ export function usePrepareFormData() { // Helper function to prepare freezeGuard data const prepareFreezeGuardData = useCallback( async ( - freezeGuard: DAOFreezeGuardConfig, + freezeGuard: DAOFreezeGuardConfig, ): Promise => { if (provider) { return { executionPeriod: await getEstimatedNumberOfBlocks( - freezeGuard.executionPeriod.bigNumberValue!, + freezeGuard.executionPeriod.bigintValue!, provider, ), timelockPeriod: await getEstimatedNumberOfBlocks( - freezeGuard.timelockPeriod.bigNumberValue!, + freezeGuard.timelockPeriod.bigintValue!, provider, ), - freezeVotesThreshold: freezeGuard.freezeVotesThreshold.bigNumberValue!, + freezeVotesThreshold: freezeGuard.freezeVotesThreshold.bigintValue!, freezeProposalPeriod: await getEstimatedNumberOfBlocks( - freezeGuard.freezeProposalPeriod.bigNumberValue!, + freezeGuard.freezeProposalPeriod.bigintValue!, provider, ), freezePeriod: await getEstimatedNumberOfBlocks( - freezeGuard.freezePeriod.bigNumberValue!, + freezeGuard.freezePeriod.bigintValue!, provider, ), }; @@ -107,7 +107,7 @@ export function usePrepareFormData() { tokenImportAddress, tokenCreationType, ...rest - }: AzoriusERC20DAO & FreezeGuardConfigParam): Promise< + }: AzoriusERC20DAO & FreezeGuardConfigParam): Promise< AzoriusERC20DAO | undefined > => { if (provider) { @@ -117,7 +117,7 @@ export function usePrepareFormData() { if (couldBeENS(address)) { address = await signer!.resolveName(allocation.address); } - return { amount: allocation.amount.bigNumberValue!, address: address }; + return { amount: allocation.amount.bigintValue!, address: address }; }), ); let freezeGuardData; @@ -131,15 +131,12 @@ export function usePrepareFormData() { isVotesToken = await checkVotesToken(tokenImportAddress); } return { - tokenSupply: tokenSupply.bigNumberValue!, - parentAllocationAmount: parentAllocationAmount?.bigNumberValue!, - quorumPercentage: quorumPercentage.bigNumberValue!, - timelock: await getEstimatedNumberOfBlocks(timelock.bigNumberValue!, provider), - executionPeriod: await getEstimatedNumberOfBlocks( - executionPeriod.bigNumberValue!, - provider, - ), - votingPeriod: await getEstimatedNumberOfBlocks(votingPeriod.bigNumberValue!, provider), + tokenSupply: tokenSupply.bigintValue!, + parentAllocationAmount: parentAllocationAmount?.bigintValue!, + quorumPercentage: quorumPercentage.bigintValue!, + timelock: await getEstimatedNumberOfBlocks(timelock.bigintValue!, provider), + executionPeriod: await getEstimatedNumberOfBlocks(executionPeriod.bigintValue!, provider), + votingPeriod: await getEstimatedNumberOfBlocks(votingPeriod.bigintValue!, provider), tokenAllocations: resolvedTokenAllocations, tokenImportAddress, tokenCreationType, @@ -163,7 +160,7 @@ export function usePrepareFormData() { nfts, quorumThreshold, ...rest - }: AzoriusERC721DAO & FreezeGuardConfigParam): Promise< + }: AzoriusERC721DAO & FreezeGuardConfigParam): Promise< AzoriusERC721DAO | undefined > => { if (provider) { @@ -180,21 +177,18 @@ export function usePrepareFormData() { } return { tokenAddress: address, - tokenWeight: nft.tokenWeight.bigNumberValue!, + tokenWeight: nft.tokenWeight.bigintValue!, }; }), ); return { - quorumPercentage: quorumPercentage.bigNumberValue!, - timelock: await getEstimatedNumberOfBlocks(timelock.bigNumberValue!, provider), - executionPeriod: await getEstimatedNumberOfBlocks( - executionPeriod.bigNumberValue!, - provider, - ), - votingPeriod: await getEstimatedNumberOfBlocks(votingPeriod.bigNumberValue!, provider), + quorumPercentage: quorumPercentage.bigintValue!, + timelock: await getEstimatedNumberOfBlocks(timelock.bigintValue!, provider), + executionPeriod: await getEstimatedNumberOfBlocks(executionPeriod.bigintValue!, provider), + votingPeriod: await getEstimatedNumberOfBlocks(votingPeriod.bigintValue!, provider), nfts: resolvedNFTs, - quorumThreshold: quorumThreshold.bigNumberValue!, + quorumThreshold: quorumThreshold.bigintValue!, ...freezeGuardData, ...rest, }; diff --git a/src/components/ProposalCreate/Transaction.tsx b/src/components/ProposalCreate/Transaction.tsx index 481328f087..59cbd7a6bf 100644 --- a/src/components/ProposalCreate/Transaction.tsx +++ b/src/components/ProposalCreate/Transaction.tsx @@ -2,7 +2,7 @@ import { VStack, HStack, Text } from '@chakra-ui/react'; import { useTranslation } from 'react-i18next'; import { CreateProposalTransaction } from '../../types/createProposal'; import ExampleLabel from '../ui/forms/ExampleLabel'; -import { BigNumberComponent, InputComponent } from '../ui/forms/InputComponent'; +import { BigIntComponent, InputComponent } from '../ui/forms/InputComponent'; interface TransactionProps { transaction: CreateProposalTransaction; @@ -106,7 +106,7 @@ function Transaction({ errorMessage={transaction.parameters && txFunctionError ? txFunctionError : undefined} /> - } errorMessage={undefined} - value={transaction.ethValue.bigNumberValue} + value={transaction.ethValue.bigintValue} onChange={e => { setFieldValue(`transactions.${transactionIndex}.ethValue`, e); }} diff --git a/src/components/ProposalCreate/Transactions.tsx b/src/components/ProposalCreate/Transactions.tsx index 29207f54e5..5598f5e5c9 100644 --- a/src/components/ProposalCreate/Transactions.tsx +++ b/src/components/ProposalCreate/Transactions.tsx @@ -11,7 +11,7 @@ import { ArrowDown, ArrowRight, Minus } from '@decent-org/fractal-ui'; import { FormikErrors, FormikProps } from 'formik'; import { Dispatch, SetStateAction } from 'react'; import { useTranslation } from 'react-i18next'; -import { BigNumberValuePair, CreateProposalForm, CreateProposalTransaction } from '../../types'; +import { BigIntValuePair, CreateProposalForm, CreateProposalTransaction } from '../../types'; import Transaction from './Transaction'; interface TransactionsProps extends FormikProps { @@ -42,7 +42,7 @@ function Transactions({ > {transactions.map((_, index) => { const txErrors = errors?.transactions?.[index] as - | FormikErrors> + | FormikErrors> | undefined; const txAddressError = txErrors?.targetAddress; const txFunctionError = txErrors?.encodedFunctionData; diff --git a/src/components/ProposalCreate/constants.ts b/src/components/ProposalCreate/constants.ts index 6c8c3a7486..025a6a8060 100644 --- a/src/components/ProposalCreate/constants.ts +++ b/src/components/ProposalCreate/constants.ts @@ -1,7 +1,6 @@ -import { BigNumber } from 'ethers'; export const DEFAULT_TRANSACTION = { targetAddress: '', - ethValue: { value: '0', bigNumberValue: BigNumber.from('0') }, + ethValue: { value: '0', bigintValue: 0n }, functionName: '', functionSignature: '', parameters: '', diff --git a/src/components/Proposals/MultisigProposalDetails/TxActions.tsx b/src/components/Proposals/MultisigProposalDetails/TxActions.tsx index 30cd4ec77a..d238af610f 100644 --- a/src/components/Proposals/MultisigProposalDetails/TxActions.tsx +++ b/src/components/Proposals/MultisigProposalDetails/TxActions.tsx @@ -36,7 +36,7 @@ export function TxActions({ proposal }: { proposal: MultisigProposal }) { const [contractCall, contractCallPending] = useTransaction(); const loadSafeMultisigProposals = useSafeMultisigProposals(); const baseContracts = useSafeContracts(); - if (user.votingWeight.eq(0)) return <>; + if (user.votingWeight === 0n) return <>; const multisigTx = proposal.transaction as SafeMultisigTransactionWithTransfersResponse; diff --git a/src/components/Proposals/ProposalActions/CastVote.tsx b/src/components/Proposals/ProposalActions/CastVote.tsx index 635ce912b2..fb0b5443f4 100644 --- a/src/components/Proposals/ProposalActions/CastVote.tsx +++ b/src/components/Proposals/ProposalActions/CastVote.tsx @@ -59,7 +59,7 @@ function Vote({ !isSnapshotProposal && isCurrentBlockLoaded && currentBlockNumber && - azoriusProposal.startBlock.gte(currentBlockNumber), + azoriusProposal.startBlock >= currentBlockNumber, ); const disabled = diff --git a/src/components/Proposals/ProposalActions/ProposalAction.tsx b/src/components/Proposals/ProposalActions/ProposalAction.tsx index 1779600201..553dd97c8e 100644 --- a/src/components/Proposals/ProposalActions/ProposalAction.tsx +++ b/src/components/Proposals/ProposalActions/ProposalAction.tsx @@ -63,7 +63,7 @@ export function ProposalAction({ const showActionButton = (isSnapshotProposal && canVote && isActiveProposal) || - (user.votingWeight.gt(0) && + (user.votingWeight > 0n && (isActiveProposal || proposal.state === FractalProposalState.EXECUTABLE || proposal.state === FractalProposalState.TIMELOCKABLE || @@ -106,7 +106,7 @@ export function ProposalAction({ } if (expandedView) { - if (!isSnapshotProposal && (user.votingWeight.eq(0) || (isActiveProposal && !canVote))) + if (!isSnapshotProposal && (user.votingWeight === 0n || (isActiveProposal && !canVote))) return null; return ( diff --git a/src/components/Proposals/ProposalSummary.tsx b/src/components/Proposals/ProposalSummary.tsx index 9f893aed7a..d308b5910e 100644 --- a/src/components/Proposals/ProposalSummary.tsx +++ b/src/components/Proposals/ProposalSummary.tsx @@ -2,7 +2,6 @@ import { Text, Box, Button, Divider, Flex, Tooltip } from '@chakra-ui/react'; import { ArrowAngleUp } from '@decent-org/fractal-ui'; import { format } from 'date-fns'; import { formatInTimeZone } from 'date-fns-tz'; -import { BigNumber } from 'ethers'; import { useMemo, useState, useEffect } from 'react'; import { useTranslation } from 'react-i18next'; import { BACKGROUND_SEMI_TRANSPARENT } from '../../constants/common'; @@ -41,19 +40,19 @@ export default function ProposalSummary({ const azoriusGovernance = governance as AzoriusGovernance; const { votesToken, type, erc721Tokens, votingStrategy } = azoriusGovernance; const { t } = useTranslation(['proposal', 'common', 'navigation']); - const startBlockTimeStamp = useBlockTimestamp(startBlock.toNumber()); + const startBlockTimeStamp = useBlockTimestamp(Number(startBlock.toString())); const [proposalsERC20VotingWeight, setProposalsERC20VotingWeight] = useState('0'); - const totalVotesCasted = useMemo(() => yes.add(no).add(abstain), [yes, no, abstain]); + const totalVotesCasted = useMemo(() => yes + no + abstain, [yes, no, abstain]); const totalVotingWeight = useMemo( () => erc721Tokens?.reduce( - (prev, curr) => prev.add(curr.totalSupply?.mul(curr.votingWeight) || BigNumber.from(0)), - BigNumber.from(0), + (prev, curr) => prev + (curr.totalSupply ? curr.totalSupply * curr.votingWeight : 0n), + 0n, ), [erc721Tokens], ); const votesTokenDecimalsDenominator = useMemo( - () => BigNumber.from(10).pow(votesToken?.decimals || 0), + () => 10n ** BigInt(votesToken?.decimals || 0), [votesToken?.decimals], ); const [showVotingPower, setShowVotingPower] = useState(false); @@ -66,9 +65,9 @@ export default function ProposalSummary({ const tokenContract = baseContracts.votesTokenMasterCopyContract.asProvider.attach( votesToken.address, ); - const pastVotingWeight = await tokenContract.getPastVotes(address, startBlock); + const pastVotingWeight = (await tokenContract.getPastVotes(address, startBlock)).toBigInt(); setProposalsERC20VotingWeight( - pastVotingWeight.div(votesTokenDecimalsDenominator).toString(), + (pastVotingWeight / votesTokenDecimalsDenominator).toString(), ); } } @@ -91,22 +90,23 @@ export default function ProposalSummary({ const strategyQuorum = votesToken && isERC20 - ? votingStrategy.quorumPercentage!.value.toNumber() + ? Number(votingStrategy.quorumPercentage!.value.toString()) : isERC721 - ? votingStrategy.quorumThreshold!.value.toNumber() + ? Number(votingStrategy.quorumThreshold!.value.toString()) : 1; const reachedQuorum = isERC721 - ? totalVotesCasted.sub(no).toString() + ? (totalVotesCasted - no).toString() : votesToken - ? totalVotesCasted.sub(no).div(votesTokenDecimalsDenominator).toString() + ? ((totalVotesCasted - no) / votesTokenDecimalsDenominator).toString() : '0'; const totalQuorum = isERC721 ? strategyQuorum.toString() - : votesToken?.totalSupply - .div(votesTokenDecimalsDenominator) - .div(100) - .mul(strategyQuorum) - .toString(); + : votesToken + ? ( + (votesToken.totalSupply / votesTokenDecimalsDenominator / 100n) * + BigInt(strategyQuorum) + ).toString() + : undefined; const ShowVotingPowerButton = ( - {decentGovernance.lockedVotesToken?.balance && ( - - )} + {decentGovernance.lockedVotesToken?.balance !== null && + decentGovernance.lockedVotesToken?.balance !== undefined && ( + + )} )} diff --git a/src/components/ui/modals/ProposalTemplateModal.tsx b/src/components/ui/modals/ProposalTemplateModal.tsx index 210849e214..e3565a7d70 100644 --- a/src/components/ui/modals/ProposalTemplateModal.tsx +++ b/src/components/ui/modals/ProposalTemplateModal.tsx @@ -8,7 +8,7 @@ import { Switch, VStack, } from '@chakra-ui/react'; -import { utils, BigNumber } from 'ethers'; +import { utils } from 'ethers'; import { useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useNavigate } from 'react-router-dom'; @@ -19,11 +19,11 @@ import useSubmitProposal from '../../../hooks/DAO/proposal/useSubmitProposal'; import { useCanUserCreateProposal } from '../../../hooks/utils/useCanUserSubmitProposal'; import { useFractal } from '../../../providers/App/AppProvider'; import { useNetworkConfig } from '../../../providers/NetworkConfig/NetworkConfigProvider'; -import { BigNumberValuePair } from '../../../types'; +import { BigIntValuePair } from '../../../types'; import { ProposalTemplate } from '../../../types/createProposalTemplate'; import { isValidUrl } from '../../../utils/url'; import { CustomNonceInput } from '../forms/CustomNonceInput'; -import { BigNumberComponent, InputComponent } from '../forms/InputComponent'; +import { BigIntComponent, InputComponent } from '../forms/InputComponent'; import Markdown from '../proposal/Markdown'; interface IProposalTemplateModalProps { @@ -54,7 +54,7 @@ export default function ProposalTemplateModal({ value, }: { transactionIndex: number; - value: BigNumberValuePair; + value: BigIntValuePair; }) => { setFilledProposalTransactions(prevState => prevState.map((transaction, txIndex) => { @@ -202,19 +202,19 @@ export default function ProposalTemplateModal({ ), )} {(showAll || - !transactions[transactionIndex].ethValue.bigNumberValue || - BigNumber.from(transactions[transactionIndex].ethValue.bigNumberValue).eq(0)) && ( + !transactions[transactionIndex].ethValue.bigintValue || + transactions[transactionIndex].ethValue.bigintValue === 0n) && ( - { handleEthValueChange({ transactionIndex, value }); }} diff --git a/src/components/ui/modals/SendAssetsModal.tsx b/src/components/ui/modals/SendAssetsModal.tsx index 212791f78c..e9c96e86e5 100644 --- a/src/components/ui/modals/SendAssetsModal.tsx +++ b/src/components/ui/modals/SendAssetsModal.tsx @@ -1,18 +1,17 @@ import { Box, Divider, Flex, Select, HStack, Text, Button } from '@chakra-ui/react'; import { LabelWrapper } from '@decent-org/fractal-ui'; import { SafeBalanceUsdResponse } from '@safe-global/safe-service-client'; -import { BigNumber } from 'ethers'; import { useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useFractal } from '../../../providers/App/AppProvider'; -import { BigNumberValuePair } from '../../../types'; +import { BigIntValuePair } from '../../../types'; import { formatCoinFromAsset, formatCoinUnitsFromAsset, formatUSD, } from '../../../utils/numberFormats'; import useSendAssets from '../../pages/DAOTreasury/hooks/useSendAssets'; -import { BigNumberInput } from '../forms/BigNumberInput'; +import { BigIntInput } from '../forms/BigIntInput'; import { CustomNonceInput } from '../forms/CustomNonceInput'; import { EthAddressInput } from '../forms/EthAddressInput'; @@ -29,7 +28,7 @@ export function SendAssetsModal({ close }: { close: () => void }) { const [selectedAsset, setSelectedAsset] = useState( fungibleAssetsWithBalance[0], ); - const [inputAmount, setInputAmount] = useState(); + const [inputAmount, setInputAmount] = useState(); const [nonceInput, setNonceInput] = useState(safe!.nonce); const [destination, setDestination] = useState(''); @@ -41,18 +40,18 @@ export function SendAssetsModal({ close }: { close: () => void }) { ); const sendAssets = useSendAssets({ - transferAmount: inputAmount?.bigNumberValue || BigNumber.from(0), + transferAmount: inputAmount?.bigintValue || 0n, asset: selectedAsset, destinationAddress: destination, nonce: nonceInput, }); const handleCoinChange = (index: string) => { - setInputAmount({ value: '0', bigNumberValue: BigNumber.from(0) }); + setInputAmount({ value: '0', bigintValue: 0n }); setSelectedAsset(fungibleAssetsWithBalance[Number(index)]); }; - const onChangeAmount = (value: BigNumberValuePair) => { + const onChangeAmount = (value: BigIntValuePair) => { setInputAmount(value); }; @@ -62,8 +61,10 @@ export function SendAssetsModal({ close }: { close: () => void }) { const overDraft = Number(inputAmount?.value || '0') > formatCoinUnitsFromAsset(selectedAsset); - const isSubmitDisabled = - !isValidAddress || !inputAmount || inputAmount?.bigNumberValue?.isZero() || overDraft; + // @dev next couple of lines are written like this, to keep typing equivalent during the conversion from BN to bigint + const inputBigint = inputAmount?.bigintValue; + const inputBigintIsZero = inputBigint ? inputBigint === 0n : undefined; + const isSubmitDisabled = !isValidAddress || !inputAmount || inputBigintIsZero || overDraft; const onSubmit = async () => { await sendAssets(); @@ -105,12 +106,12 @@ export function SendAssetsModal({ close }: { close: () => void }) { > {t('amountLabel')} - diff --git a/src/components/ui/modals/Stake.tsx b/src/components/ui/modals/Stake.tsx index dc5bc783c9..cd2feb27a4 100644 --- a/src/components/ui/modals/Stake.tsx +++ b/src/components/ui/modals/Stake.tsx @@ -1,6 +1,5 @@ import { Box, Button, Flex, Text } from '@chakra-ui/react'; import { SafeBalanceUsdResponse } from '@safe-global/safe-service-client'; -import { BigNumber } from 'ethers'; import { useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useNavigate } from 'react-router-dom'; @@ -8,8 +7,8 @@ import { DAO_ROUTES } from '../../../constants/routes'; import useLidoStaking from '../../../hooks/stake/lido/useLidoStaking'; import { useFractal } from '../../../providers/App/AppProvider'; import { useNetworkConfig } from '../../../providers/NetworkConfig/NetworkConfigProvider'; -import { BigNumberValuePair } from '../../../types'; -import { BigNumberInput } from '../forms/BigNumberInput'; +import { BigIntValuePair } from '../../../types'; +import { BigIntInput } from '../forms/BigIntInput'; export default function StakeModal({ close }: { close: () => void }) { const { @@ -23,15 +22,15 @@ export default function StakeModal({ close }: { close: () => void }) { const fungibleAssetsWithBalance = assetsFungible.filter(asset => parseFloat(asset.balance) > 0); const [selectedAsset] = useState(fungibleAssetsWithBalance[0]); - const [inputAmount, setInputAmount] = useState(); - const onChangeAmount = (value: BigNumberValuePair) => { + const [inputAmount, setInputAmount] = useState(); + const onChangeAmount = (value: BigIntValuePair) => { setInputAmount(value); }; const { handleStake } = useLidoStaking(); const handleSubmit = async () => { - if (inputAmount?.bigNumberValue) { - await handleStake(inputAmount?.bigNumberValue); + if (inputAmount?.bigintValue) { + await handleStake(inputAmount?.bigintValue); close(); if (daoAddress) { navigate(DAO_ROUTES.proposals.relative(addressPrefix, daoAddress)); @@ -48,12 +47,12 @@ export default function StakeModal({ close }: { close: () => void }) { > {t('stakeAmount')} -