diff --git a/src/components/ValidatorCredentialRow/ValidatorCredentialRow.tsx b/src/components/ValidatorCredentialRow/ValidatorCredentialRow.tsx index 84fc73b9..bf3929e3 100644 --- a/src/components/ValidatorCredentialRow/ValidatorCredentialRow.tsx +++ b/src/components/ValidatorCredentialRow/ValidatorCredentialRow.tsx @@ -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 @@ -16,7 +16,7 @@ export interface ValidatorCredentialRowProps { const ValidatorCredentialRow: FC = ({ validatorCandidate, - onUpdateCandidate + onUpdateCandidate, }) => { const { t } = useTranslation() const { id, index, isVerifiedCredentials } = validatorCandidate @@ -28,10 +28,10 @@ const ValidatorCredentialRow: FC = ({ 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' } @@ -39,7 +39,11 @@ const ValidatorCredentialRow: FC = ({ } const setCredential = (e: ChangeEvent) => { - onUpdateCandidate(id, {...validatorCandidate, withdrawalCredentials: '', isVerifiedCredentials: false}) + onUpdateCandidate(id, { + ...validatorCandidate, + withdrawalCredentials: undefined, + isVerifiedCredentials: false, + }) setError('') setIsValidAddress(false) reset() @@ -48,7 +52,7 @@ const ValidatorCredentialRow: FC = ({ 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) @@ -69,12 +73,11 @@ const ValidatorCredentialRow: FC = ({ 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 { diff --git a/src/components/ValidatorManagement/CreateValidatorView/CreateValidatorView.tsx b/src/components/ValidatorManagement/CreateValidatorView/CreateValidatorView.tsx index 30f25f8c..f0f0d668 100644 --- a/src/components/ValidatorManagement/CreateValidatorView/CreateValidatorView.tsx +++ b/src/components/ValidatorManagement/CreateValidatorView/CreateValidatorView.tsx @@ -48,7 +48,7 @@ const CreateValidatorView: FC = ({ ] const [candidates, setValidatorCandidates] = useState([]) const [keyPhrase, setKeyPhrase] = useState('') - const [sharedWithdrawalCredentials, setSharedCredentials] = useState('') + const [sharedWithdrawalCredentials, setSharedCredentials] = useState() const [sharedKeystorePassword, setSharedKeystorePassword] = useState('') const [isRisk, setIsRisk] = useState(false) @@ -73,7 +73,7 @@ const CreateValidatorView: FC = ({ const decrementStep = () => setStep((prevStep) => Math.max(prevStep - 1, 0)) const setNewValidators = (vals: ValidatorCandidate[]) => setValidatorCandidates(vals) const setPhrase = (e: ChangeEvent) => 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) @@ -163,7 +163,7 @@ const CreateValidatorView: FC = ({ onValidatorChange={setNewValidators} onBackStep={decrementStep} onNextStep={incrementStep} - onUpdateSharedCredentials={setCredentials} + onUpdateSharedCredentials={updateSharedCredentials} sharedCredentials={sharedWithdrawalCredentials} /> diff --git a/src/components/ValidatorManagement/CreateValidatorView/Steps/WithdrawalCredentials.tsx b/src/components/ValidatorManagement/CreateValidatorView/Steps/WithdrawalCredentials.tsx index 7a26d298..358c82f0 100644 --- a/src/components/ValidatorManagement/CreateValidatorView/Steps/WithdrawalCredentials.tsx +++ b/src/components/ValidatorManagement/CreateValidatorView/Steps/WithdrawalCredentials.tsx @@ -15,7 +15,7 @@ export interface WithdrawalCredentialsProps { onValidatorChange: (vals: ValidatorCandidate[]) => void isActive: boolean onShowRisk: () => void - sharedCredentials: string + sharedCredentials?: string | undefined onUpdateSharedCredentials: (credentials?: string) => void } @@ -62,7 +62,7 @@ const WithdrawalCredentials: FC = ({ } const toggleAssignAllCredentials = (): void => { - onUpdateSharedCredentials('') + onUpdateSharedCredentials(undefined) const updatedCandidates = candidates.map((validator) => ({ ...validator, withdrawalCredentials: '',