refactor requestMoney to use transaction drafts data from useOnyx #79948
refactor requestMoney to use transaction drafts data from useOnyx #79948tgolen merged 24 commits intoExpensify:mainfrom
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.
💡 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.
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✅ Changes either increased or maintained existing code coverage, great job!
|
|
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.
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.
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.
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.
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.
@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.
@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.
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.
@DylanDylann Why do we need to pass all draft transactions?
There was a problem hiding this comment.
@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.
@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
There was a problem hiding this comment.
@dukenv0307 This is the original removeDraftTransactions. In case we don't pass any params, it loops through all draft transactions
There was a problem hiding this comment.
if (shouldExcludeInitialTransaction && item.transactionID === CONST.IOU.OPTIMISTIC_TRANSACTION_ID) {
return acc;
}
In this case, we just use item.transactionID to compare with OPTIMISTIC_TRANSACTION_ID, then return acc, so we don't modify this transaction.
acc[
${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${item.transactionID}] = null;
Otherwise, we'll clear the transaction by assigning it to null, we also just use item.transactionID.
So passing the transactionIDs is enough
There was a problem hiding this comment.
Nope, I agree that we only need to pass the ID. But we should pass all draft transaction IDs
There was a problem hiding this comment.
looks like all IDs are already being passed. I recall we had some filtering before, but it seems that's no longer the case
|
@dukenv0307 the code looks good now |
|
|
@DylanDylann Done |
Reviewer Checklist
Screenshots/VideosScreen.Recording.2026-02-23.at.13.37.44.mov |
|
cc @tgolen since Daniel is OOO |
| const {isExpenseSplit} = getOriginalTransactionWithSplitInfo(transaction, originalTransaction); | ||
| const [allTransactions] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION, {canBeMissing: false}); | ||
| const [allReports] = useOnyx(ONYXKEYS.COLLECTION.REPORT, {canBeMissing: false}); | ||
| const [transactionDrafts] = useOptimisticDraftTransactions(undefined); |
There was a problem hiding this comment.
I don't really understand the case for passing undefined. Can you explain that?
I think it might be better to create a new hook just to get the draftTransactionIDs that are needed. Maybe it would be more simple than passing undefined to the existing hook and then doing an extra map() to get the IDs. For example, maybe it's more simple to use useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_DRAFT); with a selector.
There was a problem hiding this comment.
@tgolen Thanks for your feedback, I used useOptimisticDraftTransactions(undefined) to get the all transactionDrafts. I think the better idea now is to use useOnyx(ONYXKEYS.COLLECTION.TRANSACTION_DRAFT, selector). @DylanDylann Can you please take a look again?
There was a problem hiding this comment.
@tgolen We not only need draftTransactionIDs, but also need transactionDrafts
There was a problem hiding this comment.
@dukenv0307 The change looks fine, please resolve conflict
There was a problem hiding this comment.
We not only need draftTransactionIDs, but also need transactionDrafts
I was basically thinking that the new hook could return both things (since the IDs come from the same set of data). Let me see what was implemented in the changes.
There was a problem hiding this comment.
OK, yes, you could easily return the draftTransactionIDs from the hook, which would reduce a couple lines of duplicated code. It's fine how it is now though, so this is NAB.
DylanDylann
left a comment
There was a problem hiding this comment.
Lots of tests have been covered
|
@tgolen I resolved the conflicts |
src/libs/actions/IOU/MoneyRequest.ts
Outdated
| const draftTransactionIDs = Object.values(allTransactionDrafts ?? {}) | ||
| .filter((transaction): transaction is NonNullable<typeof transaction> => !!transaction) | ||
| .map((transaction) => transaction.transactionID); |
There was a problem hiding this comment.
Is there a reason you can't use Object.keys(transactionDrafts ?? {}); here? Is it because you want to filter out null values? If so, why are there null values?
There was a problem hiding this comment.
Thanks for your feedback @tgolen. I was overthinking. Actually, we can use Object.keys(transactionDrafts ?? {});
|
🚧 @tgolen has triggered a test Expensify/App build. You can view the workflow run here. |
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, and Web. Happy testing! 🧪🧪
|
|
🚀 Deployed to staging by https://github.com/tgolen in version: 9.3.27-0 🚀
|
|
🚀 Deployed to production by https://github.com/blimpich in version: 9.3.27-8 🚀
|
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