Skip to content

Commit

Permalink
fix(bim): lowercase address
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscotobar committed Oct 24, 2024
1 parent 75dbf88 commit 2fc2680
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 28 deletions.
4 changes: 2 additions & 2 deletions src/app/proposals/create/CreateBuilderProposalForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/app/proposals/create/RemoveBuilderProposalForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 4 additions & 23 deletions src/app/proposals/create/TreasuryWithdrawProposalForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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

Expand All @@ -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' })
Expand Down Expand Up @@ -221,23 +218,7 @@ export const TreasuryWithdrawProposalForm = () => {
<FormInput placeholder="0x123...456" {...field} />
</FormControl>
<FormDescription>Write or paste the wallet address of the recipient</FormDescription>
<FormMessage>
{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.{' '}
<span
className="text-white underline cursor-pointer"
onClick={() => {
setValue('toAddress', checksumAddress(field.value))
trigger('toAddress')
}}
>
Fix address.
</span>
</>
) : undefined}
</FormMessage>
<FormMessage />
</FormItem>
)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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],
})
}
2 changes: 1 addition & 1 deletion src/app/proposals/hooks/useRemoveBuilderProposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ const encodeRemoveBuilderCalldata = (builderAddress: Address) => {
return encodeFunctionData({
abi: SimplifiedRewardDistributorAbi,
functionName: 'removeWhitelistedBuilder',
args: [builderAddress],
args: [builderAddress.toLocaleLowerCase() as Address],
})
}
2 changes: 2 additions & 0 deletions src/app/proposals/shared/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 2fc2680

Please sign in to comment.