Skip to content

Commit

Permalink
update new contact state
Browse files Browse the repository at this point in the history
  • Loading branch information
KKA11010 committed Jun 21, 2023
1 parent 9234fff commit fa6e39a
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/components/screens/Addressbook/Book.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -180,15 +186,15 @@ 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 })}
/>
}
<TextInput
style={[globals(color).input, { marginBottom: 20 }]}
placeholder="[email protected]"
placeholderTextColor={color.INPUT_PH}
selectionColor={hi[highlight]}
onChangeText={setNewContactLN}
onChangeText={lnUrl => setNewContact({ ...newContact, lnUrl })}
/>
<Button txt='Save' onPress={() => void handleNewContact()} />
<TouchableOpacity
Expand Down

0 comments on commit fa6e39a

Please sign in to comment.