-
Notifications
You must be signed in to change notification settings - Fork 3.6k
refactor requestMoney to use transaction drafts data from useOnyx #79948
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
base: main
Are you sure you want to change the base?
Conversation
|
@DylanDylann Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bb74529969
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
src/libs/actions/IOU/index.ts
Outdated
| const existingTransaction = | ||
| action === CONST.IOU.ACTION.SUBMIT | ||
| ? allTransactionDrafts[`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${existingTransactionID}`] | ||
| ? allTransactionDraftsParam[`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${existingTransactionID}`] | ||
| : allTransactions[`${ONYXKEYS.COLLECTION.TRANSACTION}${existingTransactionID}`]; |
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.
Guard null allTransactionDrafts before indexing
Because handleRetryPress now forwards allTransactionDrafts from useOnyx(..., {canBeMissing: true}), callers can pass null while Onyx is still loading; the destructuring default only applies to undefined, so allTransactionDraftsParam can remain null and this indexed access will throw when the retry path uses action === SUBMIT (e.g., retrying a failed submit/track‑expense conversion). Consider normalizing with requestMoneyInformation.allTransactionDrafts ?? allTransactionDrafts or guarding before indexing so null can’t crash.
Useful? React with 👍 / 👎.
Codecov Report❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.
|
|
No product considerations, removing my review |
| requestMoneyParams.transactionParams.receipt = file; | ||
| requestMoneyParams.isRetry = true; | ||
| requestMoneyParams.shouldPlaySound = false; | ||
| requestMoneyParams.allTransactionDrafts = allTransactionDrafts; |
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.
I think allTransactionDrafts should be included in retryParams
src/libs/actions/IOU/Duplicate.ts
Outdated
| transactionViolations: {}, | ||
| policyRecentlyUsedCurrencies, | ||
| quickAction, | ||
| allTransactionDrafts, |
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.
We should only pass allTransactionDrafts if it's actually used. For example, the trackExpense function doesn't use it, so we shouldn't pass it there.
src/libs/actions/IOU/index.ts
Outdated
| const existingTransaction = | ||
| action === CONST.IOU.ACTION.SUBMIT | ||
| ? allTransactionDrafts[`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${existingTransactionID}`] | ||
| ? allTransactionDraftsParam[`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${existingTransactionID}`] |
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.
We're passing all allTransactionDrafts, but we only use one item from it. I think we should move existingTransactionID to the component level, so we can pass just one transactionDraft to the function. This approach will also help when refactoring allTransactions later, we'll only need to pass a single transaction instead of the entire collection.
src/libs/actions/IOU/index.ts
Outdated
| if (shouldHandleNavigation) { | ||
| // eslint-disable-next-line @typescript-eslint/no-deprecated | ||
| InteractionManager.runAfterInteractions(() => removeDraftTransactions()); | ||
| InteractionManager.runAfterInteractions(() => removeDraftTransactions(undefined, allTransactionDraftsParam)); |
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.
For this, I suggest creating a hook to perform a list of transactionDraftIDs, then passing this list across functions.
|
@DylanDylann Done |
| InteractionManager.runAfterInteractions(() => removeDraftTransactions()); | ||
| InteractionManager.runAfterInteractions(() => removeDraftTransactionsByIDs(draftTransactionIDs)); |
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.
@dukenv0307 Could you explain this change?
removeDraftTransactions() will remove all draft transactions
removeDraftTransactionsByIDs(draftTransactionIDs)); only reset some draft transactions
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.
@DylanDylann but the draftTransactionIDs are taken from allTransactionDraft. I don't want to pass the whole allTransactionDrafts to removeDraftTransactions
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.
Looks like we need to pass all draft transactions, but we only need the IDs, not the full objects.
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.
@DylanDylann Why do we need to pass all draft transactions?
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.
@dukenv0307 Isn't this the original implementation (that removeDraftTransactions function did)? I think in this refactor we should keep the existing behavior and only focus on removing the Onyx.connect method
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.
If you'd like to change the original behavior, could you explain the reasoning behind it?
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.
@DylanDylann Hmm, I don't change the original behavior, in removeDraftTransactions we just use the transactionID, so we don't need to pass all transactionDrafts
Explanation of Change
Fixed Issues
$ #67778
PROPOSAL:
Tests
Offline tests
QA Steps
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectioncanBeMissingparam foruseOnyxtoggleReportand notonIconClick)src/languages/*files and using the translation methodSTYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.ScrollViewcomponent to make it scrollable when more elements are added to the page.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
Screen.Recording.2026-01-20.at.15.48.22.mov