From 567e02be7179788d7f732ad882b67ff1afa9b7a8 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Thu, 11 Jun 2020 17:18:29 +0200 Subject: [PATCH] Fix contracts address addition (#2936) --- packages/page-accounts/src/Contacts/modals/Create.tsx | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/page-accounts/src/Contacts/modals/Create.tsx b/packages/page-accounts/src/Contacts/modals/Create.tsx index ddd978ea76..f01ed12fe4 100644 --- a/packages/page-accounts/src/Contacts/modals/Create.tsx +++ b/packages/page-accounts/src/Contacts/modals/Create.tsx @@ -14,6 +14,7 @@ import { useTranslation } from '../../translate'; interface AddrState { address: string; + addressInput: string; isAddressExisting: boolean; isAddressValid: boolean; } @@ -26,18 +27,18 @@ interface NameState { function Create ({ onClose, onStatusChange }: Props): React.ReactElement { const { t } = useTranslation(); const [{ isNameValid, name }, setName] = useState({ isNameValid: false, name: '' }); - const [{ address, isAddressExisting, isAddressValid }, setAddress] = useState({ address: '', isAddressExisting: false, isAddressValid: false }); + const [{ address, addressInput, isAddressExisting, isAddressValid }, setAddress] = useState({ address: '', addressInput: '', isAddressExisting: false, isAddressValid: false }); const isValid = isAddressValid && isNameValid; const _onChangeAddress = useCallback( - (input: string): void => { + (addressInput: string): void => { let address = ''; let isAddressValid = true; let isAddressExisting = false; try { address = keyring.encodeAddress( - keyring.decodeAddress(input) + keyring.decodeAddress(addressInput) ); isAddressValid = keyring.isAvailable(address); @@ -57,7 +58,7 @@ function Create ({ onClose, onStatusChange }: Props): React.ReactElement isAddressValid = false; } - setAddress({ address: address || input, isAddressExisting, isAddressValid }); + setAddress({ address: isAddressValid ? address : '', addressInput, isAddressExisting, isAddressValid }); }, [name] ); @@ -113,7 +114,7 @@ function Create ({ onClose, onStatusChange }: Props): React.ReactElement onChange={_onChangeAddress} onEnter={_onCommit} placeholder={t('new address')} - value={address} + value={addressInput} />