Skip to content

Commit

Permalink
Fix:build fix deposits (#287)
Browse files Browse the repository at this point in the history
  • Loading branch information
rickimoore committed Dec 17, 2024
1 parent 03be39a commit 769f142
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 23 deletions.
39 changes: 21 additions & 18 deletions src/components/ValidatorCredentialRow/ValidatorCredentialRow.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { getAddress, verifyMessage } from 'ethers';
import { ChangeEvent, FC, useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useSignMessage } from 'wagmi';
import addClassString from '../../../utilities/addClassString';
import { ValidatorCandidate } from '../../types';
import Button, { ButtonFace } from '../Button/Button';
import Typography from '../Typography/Typography';
import ValidatorCandidateRow from '../ValidatorCandidateRow/ValidatorCandidateRow';
import WalletActionBtn from '../WalletActionBtn/WalletActionBtn';
import { getAddress, verifyMessage } from 'ethers'
import { ChangeEvent, FC, useEffect, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { useSignMessage } from 'wagmi'
import addClassString from '../../../utilities/addClassString'
import { ValidatorCandidate } from '../../types'
import Button, { ButtonFace } from '../Button/Button'
import Typography from '../Typography/Typography'
import ValidatorCandidateRow from '../ValidatorCandidateRow/ValidatorCandidateRow'
import WalletActionBtn from '../WalletActionBtn/WalletActionBtn'

export interface ValidatorCredentialRowProps {
validatorCandidate: ValidatorCandidate
Expand All @@ -16,7 +16,7 @@ export interface ValidatorCredentialRowProps {

const ValidatorCredentialRow: FC<ValidatorCredentialRowProps> = ({
validatorCandidate,
onUpdateCandidate
onUpdateCandidate,
}) => {
const { t } = useTranslation()
const { id, index, isVerifiedCredentials } = validatorCandidate
Expand All @@ -28,18 +28,22 @@ const ValidatorCredentialRow: FC<ValidatorCredentialRowProps> = ({

const { data, signMessage, error, reset } = useSignMessage()

const handleError = (e) => {
const handleError = (e: any) => {
let message = 'error.unexpectedAddressError'

if (e?.code === "INVALID_ARGUMENT") {
if (e?.code === 'INVALID_ARGUMENT') {
message = 'error.invalidAddressFormat'
}

setError(t(message))
}

const setCredential = (e: ChangeEvent<HTMLInputElement>) => {
onUpdateCandidate(id, {...validatorCandidate, withdrawalCredentials: '', isVerifiedCredentials: false})
onUpdateCandidate(id, {
...validatorCandidate,
withdrawalCredentials: undefined,
isVerifiedCredentials: false,
})
setError('')
setIsValidAddress(false)
reset()
Expand All @@ -48,7 +52,7 @@ const ValidatorCredentialRow: FC<ValidatorCredentialRowProps> = ({
const value = e.target.value
setCredentialInput(value)
const checkSumAddress = getAddress(value)
onUpdateCandidate(id, {...validatorCandidate, withdrawalCredentials: checkSumAddress})
onUpdateCandidate(id, { ...validatorCandidate, withdrawalCredentials: checkSumAddress })
setIsValidAddress(true)
} catch (e) {
handleError(e)
Expand All @@ -69,12 +73,11 @@ const ValidatorCredentialRow: FC<ValidatorCredentialRowProps> = ({
const checkSumAddress = getAddress(credentialInput)
const isVerifiedCredentials = signedAddress === checkSumAddress

onUpdateCandidate(id, {...validatorCandidate, isVerifiedCredentials })
onUpdateCandidate(id, { ...validatorCandidate, isVerifiedCredentials })

if(!isVerifiedCredentials) {
if (!isVerifiedCredentials) {
setError(t('validatorManagement.withdrawalCredentials.incorrectSignature'))
}

} catch (e) {
handleError(e)
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const CreateValidatorView: FC<CreateValidatorViewProps> = ({
]
const [candidates, setValidatorCandidates] = useState<ValidatorCandidate[]>([])
const [keyPhrase, setKeyPhrase] = useState('')
const [sharedWithdrawalCredentials, setSharedCredentials] = useState('')
const [sharedWithdrawalCredentials, setSharedCredentials] = useState<string | undefined>()
const [sharedKeystorePassword, setSharedKeystorePassword] = useState('')
const [isRisk, setIsRisk] = useState(false)

Expand All @@ -73,7 +73,7 @@ const CreateValidatorView: FC<CreateValidatorViewProps> = ({
const decrementStep = () => setStep((prevStep) => Math.max(prevStep - 1, 0))
const setNewValidators = (vals: ValidatorCandidate[]) => setValidatorCandidates(vals)
const setPhrase = (e: ChangeEvent<HTMLTextAreaElement>) => setKeyPhrase(e.target.value)
const setCredentials = (credentials: string) => setSharedCredentials(credentials)
const updateSharedCredentials = (credentials?: string) => setSharedCredentials(credentials)
const setKeystorePassword = (password: string) => setSharedKeystorePassword(password)

const showRiskMessage = () => setIsRisk(true)
Expand Down Expand Up @@ -163,7 +163,7 @@ const CreateValidatorView: FC<CreateValidatorViewProps> = ({
onValidatorChange={setNewValidators}
onBackStep={decrementStep}
onNextStep={incrementStep}
onUpdateSharedCredentials={setCredentials}
onUpdateSharedCredentials={updateSharedCredentials}
sharedCredentials={sharedWithdrawalCredentials}
/>
</CreateValidatorStep>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface WithdrawalCredentialsProps {
onValidatorChange: (vals: ValidatorCandidate[]) => void
isActive: boolean
onShowRisk: () => void
sharedCredentials: string
sharedCredentials?: string | undefined
onUpdateSharedCredentials: (credentials?: string) => void
}

Expand Down Expand Up @@ -62,7 +62,7 @@ const WithdrawalCredentials: FC<WithdrawalCredentialsProps> = ({
}

const toggleAssignAllCredentials = (): void => {
onUpdateSharedCredentials('')
onUpdateSharedCredentials(undefined)
const updatedCandidates = candidates.map((validator) => ({
...validator,
withdrawalCredentials: '',
Expand Down

0 comments on commit 769f142

Please sign in to comment.