From fa6e39a0d5d05b42fcaf4494bb725908542f665b Mon Sep 17 00:00:00 2001 From: KKA11010 Date: Wed, 21 Jun 2023 20:42:43 +0200 Subject: [PATCH] update new contact state --- src/components/screens/Addressbook/Book.tsx | 22 +++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/components/screens/Addressbook/Book.tsx b/src/components/screens/Addressbook/Book.tsx index 791bccc7..0cc1d397 100644 --- a/src/components/screens/Addressbook/Book.tsx +++ b/src/components/screens/Addressbook/Book.tsx @@ -31,21 +31,27 @@ export default function AddressBook({ nav, isModal, closeModal, setInput }: IAdd isOwner: false, }) // new contact input - const [newContactName, setNewContactName] = useState('') - const [newContactLN, setNewContactLN] = useState('') + const [newContact, setNewContact] = useState({ + name: '', + lnUrl: '' + }) const { prompt, openPromptAutoClose } = usePrompt() const handleNewContact = async () => { - if (!isLnurl(newContactLN)) { + const contact = { + name: newContact.name.trim(), + lnUrl: newContact.lnUrl.trim(), + } + if (!isLnurl(contact.lnUrl)) { openPromptAutoClose({ msg: 'Invalid LNURL!', ms: 1500 }) return } - if (!newContactName && !openNew.isOwner) { + if (!contact.name && !openNew.isOwner) { openPromptAutoClose({ msg: 'Invalid name!', ms: 1500 }) return } const success = await addContact({ - name: openNew.isOwner ? 'Personal LNURL' : newContactName, - ln: newContactLN, + name: openNew.isOwner ? 'Personal LNURL' : contact.name, + ln: contact.lnUrl, isOwner: openNew.isOwner }) if (!success) { @@ -180,7 +186,7 @@ export default function AddressBook({ nav, isModal, closeModal, setInput }: IAdd placeholder="Name" placeholderTextColor={color.INPUT_PH} selectionColor={hi[highlight]} - onChangeText={setNewContactName} + onChangeText={name => setNewContact({ ...newContact, name })} /> } setNewContact({ ...newContact, lnUrl })} />