From 2fc268091d9ebc3ac9a0514a5c121f9ab543bacb Mon Sep 17 00:00:00 2001 From: Francisco Tobar Date: Thu, 24 Oct 2024 09:57:12 -0600 Subject: [PATCH] fix(bim): lowercase address --- .../create/CreateBuilderProposalForm.tsx | 4 +-- .../create/RemoveBuilderProposalForm.tsx | 3 ++- .../create/TreasuryWithdrawProposalForm.tsx | 27 +++---------------- .../useCreateBuilderWhitelistProposal.ts | 2 +- .../hooks/useRemoveBuilderProposal.ts | 2 +- src/app/proposals/shared/utils.ts | 2 ++ 6 files changed, 12 insertions(+), 28 deletions(-) diff --git a/src/app/proposals/create/CreateBuilderProposalForm.tsx b/src/app/proposals/create/CreateBuilderProposalForm.tsx index 724f6965..33453add 100644 --- a/src/app/proposals/create/CreateBuilderProposalForm.tsx +++ b/src/app/proposals/create/CreateBuilderProposalForm.tsx @@ -16,13 +16,13 @@ import { zodResolver } from '@hookform/resolvers/zod' import { useRouter } from 'next/navigation' import { FC, useState } from 'react' import { useForm } from 'react-hook-form' -import { Address, isAddress } from 'viem' +import { Address } from 'viem' import { z } from 'zod' import { useVotingPowerRedirect } from '@/app/proposals/hooks/useVotingPowerRedirect' import { Accordion, AccordionItem, AccordionTrigger, AccordionContent } from '@/components/Accordion' import { Header, Paragraph } from '@/components/Typography' import { Button } from '@/components/Button' -import { DISPLAY_NAME_SEPARATOR } from '../shared/utils' +import { isAddress, DISPLAY_NAME_SEPARATOR } from '@/app/proposals/shared/utils' const FormSchema = z.object({ builderName: z diff --git a/src/app/proposals/create/RemoveBuilderProposalForm.tsx b/src/app/proposals/create/RemoveBuilderProposalForm.tsx index e8a74b23..7f9887c5 100644 --- a/src/app/proposals/create/RemoveBuilderProposalForm.tsx +++ b/src/app/proposals/create/RemoveBuilderProposalForm.tsx @@ -16,12 +16,13 @@ import { zodResolver } from '@hookform/resolvers/zod' import { useRouter, useSearchParams } from 'next/navigation' import { FC, useEffect, useState } from 'react' import { useForm } from 'react-hook-form' -import { Address, isAddress } from 'viem' +import { Address } from 'viem' import { z } from 'zod' import { CreateProposalHeaderSection } from '@/app/proposals/create/CreateProposalHeaderSection' import { Accordion, AccordionItem, AccordionTrigger, AccordionContent } from '@/components/Accordion' import { Header, Paragraph } from '@/components/Typography' import { Button } from '@/components/Button' +import { isAddress } from '@/app/proposals/shared/utils' const FormSchema = z.object({ proposalName: z diff --git a/src/app/proposals/create/TreasuryWithdrawProposalForm.tsx b/src/app/proposals/create/TreasuryWithdrawProposalForm.tsx index 395afd8d..817d6192 100644 --- a/src/app/proposals/create/TreasuryWithdrawProposalForm.tsx +++ b/src/app/proposals/create/TreasuryWithdrawProposalForm.tsx @@ -8,7 +8,7 @@ import { zodResolver } from '@hookform/resolvers/zod' import Image from 'next/image' import { useRouter } from 'next/navigation' import { useEffect, useMemo, useState } from 'react' -import { Address, isAddress, zeroAddress, checksumAddress } from 'viem' +import { Address, zeroAddress } from 'viem' import { z } from 'zod' import { rbtcIconSrc } from '@/shared/rbtcIconSrc' import { MAX_INPUT_NUMBER_AMOUNT } from '@/components/Input/InputNumber' @@ -33,8 +33,8 @@ import { useCreateTreasuryTransferProposal } from '@/app/proposals/hooks/useCrea import React from 'react' import { useForm } from 'react-hook-form' import { CreateProposalHeaderSection } from '@/app/proposals/create/CreateProposalHeaderSection' +import { isAddress } from '@/app/proposals/shared/utils' -const ADDRESS_REGEX = /^0x[a-fA-F0-9]{40}$/ const rifMinimumAmount = ENV === 'mainnet' ? 10 : 1 const rbtcMinimumAmount = ENV === 'mainnet' ? 0.0001 : 0.000001 @@ -48,10 +48,7 @@ const FormSchema = z .string() .max(3000) .refine(s => s.trim().replace(/\s+/g, ' ').length >= 10, 'Field must contain at least 10 characters'), - toAddress: z - .string() - .refine(value => ADDRESS_REGEX.test(value), 'Please enter a valid address') - .refine(value => isAddress(value), 'Invalid checksum'), + toAddress: z.string().refine(value => isAddress(value), 'Please enter a valid address'), tokenAddress: z.string().length(42), amount: z.coerce .number({ invalid_type_error: 'Required field' }) @@ -221,23 +218,7 @@ export const TreasuryWithdrawProposalForm = () => { Write or paste the wallet address of the recipient - - {errors.toAddress?.message === 'Invalid checksum' ? ( - <> - Please check that the address is correct before continuing. If the address is - correct, use the button below to convert your address to a valid checksum address.{' '} - { - setValue('toAddress', checksumAddress(field.value)) - trigger('toAddress') - }} - > - Fix address. - - - ) : undefined} - + )} /> diff --git a/src/app/proposals/hooks/useCreateBuilderWhitelistProposal.ts b/src/app/proposals/hooks/useCreateBuilderWhitelistProposal.ts index cdf6f189..3439d4b5 100644 --- a/src/app/proposals/hooks/useCreateBuilderWhitelistProposal.ts +++ b/src/app/proposals/hooks/useCreateBuilderWhitelistProposal.ts @@ -37,6 +37,6 @@ export const encodeWhitelistBuilderCalldata = (builderAddress: Address, receiver return encodeFunctionData({ abi: SimplifiedRewardDistributorAbi, functionName: 'whitelistBuilder', - args: [getAddress(builderAddress), getAddress(receiverAddress)], + args: [builderAddress.toLocaleLowerCase() as Address, receiverAddress.toLocaleLowerCase() as Address], }) } diff --git a/src/app/proposals/hooks/useRemoveBuilderProposal.ts b/src/app/proposals/hooks/useRemoveBuilderProposal.ts index 5e0755e7..6cd6daf1 100644 --- a/src/app/proposals/hooks/useRemoveBuilderProposal.ts +++ b/src/app/proposals/hooks/useRemoveBuilderProposal.ts @@ -33,6 +33,6 @@ const encodeRemoveBuilderCalldata = (builderAddress: Address) => { return encodeFunctionData({ abi: SimplifiedRewardDistributorAbi, functionName: 'removeWhitelistedBuilder', - args: [builderAddress], + args: [builderAddress.toLocaleLowerCase() as Address], }) } diff --git a/src/app/proposals/shared/utils.ts b/src/app/proposals/shared/utils.ts index 3a1a5c7f..6f5a56dd 100644 --- a/src/app/proposals/shared/utils.ts +++ b/src/app/proposals/shared/utils.ts @@ -122,3 +122,5 @@ export const splitCombinedName = (name: string) => { export const ADDRESS_PADDING_LENGTH = 24 export const RELAY_PARAMETER_PADDING_LENGTH = 256 + +export const isAddress = (value: string) => /^0x[a-fA-F0-9]{40}$/.test(value)