Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contacts CRUD #162

Merged
merged 11 commits into from
Aug 7, 2023
Merged

Contacts CRUD #162

merged 11 commits into from
Aug 7, 2023

Conversation

nop33
Copy link
Member

@nop33 nop33 commented Jun 23, 2023

Sorry for the long PR, the feature of contacts is a big one. I will work on the remaining sub-features (like contact sharing, selecting contact in send screens #160, etc) in a follow-up PR.

@nop33 nop33 requested a review from mvaivre June 23, 2023 15:28
@nop33 nop33 changed the title Contacts Contacts CRUD Jun 26, 2023
@@ -260,6 +262,70 @@ export const persistAddressesMetadata = async (walletId: string, addressesMetada
await persistWalletsMetadata(walletsMetadata)
}

export const persistContact = async (contactData: ContactFormData) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: why not adding those function to a dedicated contacts.ts file?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. I chose to leave them in this file because I made contacts be part of the wallet metadata object. Since all wallet metadata functions are in this file, I decided to keep these here as well. Not a strong opinion on this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok! If you don't have a strong opinion on this, I find that having a dedicated contact.ts file makes it easier to find the functions we're looking for, and to understand the structure of the project :)

@mvaivre
Copy link
Member

mvaivre commented Jul 31, 2023

Functional testing: I get an error when trying to create a contact.

Screenshot 2023-07-31 at 11 17 45

@nop33
Copy link
Member Author

nop33 commented Aug 2, 2023

Functional testing: I get an error when trying to create a contact.

I fixed this, it was probably cause the wallet you used had old metadata stored. I updated the code to take this into consideration.

@nop33 nop33 requested a review from mvaivre August 2, 2023 09:25
@nop33 nop33 changed the base branch from fix-wallet-delete to master August 2, 2023 11:19
innerStyle?: StyleProp<ViewStyle>
hideSeparator?: boolean
rightSideContent?: ReactNode
children?: ReactNode
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The children prop is already defined in PressableProps I believe.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does, but if I remove it I get this error:

    Type 'ReactNode | ((state: PressableStateCallbackType) => ReactNode)' is not assignable to type 'ReactNode'.ts(2769)

@@ -260,6 +262,70 @@ export const persistAddressesMetadata = async (walletId: string, addressesMetada
await persistWalletsMetadata(walletsMetadata)
}

export const persistContact = async (contactData: ContactFormData) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok! If you don't have a strong opinion on this, I find that having a dedicated contact.ts file makes it easier to find the functions we're looking for, and to understand the structure of the project :)

const indexOfContactWithSameId = contacts.findIndex((c: Contact) => c.id === contactData.id)

if (indexOfContactWithSameId < 0) throw new Error('Could not find a contact with this ID')
if (indexOfContactWithSameAddress >= 0 && indexOfContactWithSameAddress !== indexOfContactWithSameId)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I'd add some new lines between those conditions. It's a bit dense 'round here (also above).

setIsDeleting(true)

try {
await deleteContact(params.contactId)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function call should always be followed by the dispatch of contactDeletedFromPersistentStorage right? In this case, why not dispatch directly from within the deleteContact function?

setLoading(true)

try {
await persistContact(formData)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same remark as above.

try {
const id = await persistContact(formData)

dispatch(contactStoredInPersistentStorage({ ...formData, id }))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here too (I won't signal the others if any)

@nop33
Copy link
Member Author

nop33 commented Aug 4, 2023

I've addressed all your comments in a follow-up PR, is that a problem for you?https://github.com/alephium/mobile-wallet/pull/167/commits

Copy link
Member

@mvaivre mvaivre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏄‍♂️ 👏

@nop33 nop33 merged commit ad05998 into master Aug 7, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants