-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Return promise in payIOUReport / Fix AdditionalDetailsStep #6992
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ce1f80f
Return promise in payIOUReport
marcaaron 3e6fd9d
fix AdditionalDetailsStep address input
marcaaron 5fabcd8
Fix promise returned so second finally does not happen before first
marcaaron 747bc3a
Merge remote-tracking branch 'origin' into marcaaron-improveSendMoney…
marcaaron 8b38d0a
Merge remote-tracking branch 'origin' into marcaaron-improveSendMoney…
marcaaron File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this could cause a bug. You are returning the original promise, not the one that gets created after chaining
then-catch-finally
, which you later use tofinally(() => Navigation.navigate(ROUTES.REPORT))
.In the original code, the
Navigation.navigate(ROUTES.REPORT);
happens inside thefinally
of the new promise object that gets created after chainingthen
andcatch
. The current code may make your newfinally
run before thefinally
that was chained after thethen
andcatch
. To see this, run these in the console:Case 1 (similar to PR code):
Output (reversed "Finally X"):
Case 2
Output:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to be sure I'm following the logic here... the claim is that there are two different promises: one being returned from the method and another one that handles the
.then()
and.catch()
? The observation of the difference in order seems correct, but not sure about the explanation. How is the returned promise different from the one passed toasyncOpenURL()
?For sure open to thoughts on how this change might cause a bug if you have ideas or alternatives. I couldn't think of anything. The only thing we do in the first
finally()
is set loading to false and navigating back to the report has no dependency on each other.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only scenario I think this would cause a bug is if you wanted to make some other type of API call inside the inner
catch
and make sure that call completes before the outerfinally
, but agreed with this specific use case the difference in order doesn't seem to affect the desired behavior. That being said, my expectation here would be that the inner promise handling happens before the outer handling, so I'd prefer to have it updated so there isn't any confusion down the line.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just answering my own question here, but after looking at this for a while I learned something new - which is that a promise will only be handled if you chain off of the result of handling it and not the first promise set up. So code like this is fine:
But if you do this...
you'll get an unhandled promise rejection notice 🤯
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤯
Playing with your example, this other thing was unexpected to me, I thought that reversing the order of chained
catch
andthen
didn't matter:but reversing the callbacks:
prints
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧙