Skip to content

refactor: read src/pages/iou (3/3) Onyx data in event handlers with Onyx.get - #106706

Merged
luacmartins merged 11 commits into
Expensify:mainfrom
callstack-internal:feat/onyx-get-p1-4-iou-3
Nov 19, 2026
Merged

luacmartins merged 11 commits into
Expensify:mainfrom
callstack-internal:feat/onyx-get-p1-4-iou-3

Conversation

@LukasMod

@LukasMod LukasMod commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Explanation of Change

Part of the useOnyx to Onyx.get / Onyx.multiGet migration (Phase 1, src/pages/iou 3 of 3).

These IOU handlers read some values only when the user acts, but each value was a useOnyx subscription, so every change to its key re-rendered the screen or hook. Each handler now reads those values once with a single await Onyx.multiGet([...]), and the code below the read keeps its order. The Concierge chat key is in the same list.

  • Reads sit where the value is used: after the guards, inside the hasChanges branch of the odometer edit, and inside if (policy) in Hours.
  • In the report picker, handleRegularReportSelection and removeFromReport read first, then go back or dismiss. The transition callbacks stay synchronous.
  • In the pay flow, PayConfirmation.handleSendMoney reads quickAction and whether the report already has transactions, then passes both to sendMoney. submitWithDismissFirst still gets a synchronous write, so it runs before the report is revealed. useSendMoneySubmission no longer subscribes through useReportTransactions.
  • Handlers that now return a Promise widen their slot types to void | Promise<void>: onSendMoney in MoneyRequestConfirmationList, the GPS navigateToNextStep prop, removeFromReport in IOURequestEditReportCommon, and the report picker action types.
  • Subscriptions that render reads, or that use Search snapshot keys, stay on useOnyx.

Fixed Issues

$ #101910
PROPOSAL: N/A

Tests

Test 1: Odometer distance, create

  1. Open FAB > Track distance > Odometer.
  2. Enter a start and end reading and tap Next.
  3. Verify the confirmation page shows the computed distance and amount.
  4. Submit and verify the expense appears in the chat.

Test 2: Odometer distance, edit

  1. Open an existing odometer expense and tap Distance.
  2. Change the end reading and tap Save.
  3. Verify the screen closes and the expense shows the new distance and amount.
  4. Reopen it, tap Save without changes, and verify the screen just closes.

Test 3: GPS distance (iOS and Android native only)

  1. Open FAB > Track distance > GPS.
  2. Start a trip, stop it, then tap Save.
  3. Verify the confirmation page shows the GPS distance, then submit and verify the expense is created.
  4. Repeat with a 0 distance trip and verify the zero-distance modal shows.

Test 4: Time expense

  1. On a workspace with time tracking enabled, open Create expense > Time.
  2. Enter hours and tap Next.
  3. Verify the confirmation page opens with the right amount.

Test 5: Change report while editing

  1. Open a single existing expense from its details, tap the Report field, and pick a different report.
  2. Verify the picker closes and the expense moves to the picked report.
  3. Verify it no longer shows in the old report.

Test 6: Remove from report

  1. Open an existing expense on a report and tap Report.
  2. Tap "Remove from report".
  3. Verify the panel closes and the expense moves to your personal space.

Test 7: Report pick while creating

  1. In the create flow, tap Report on the confirmation page.
  2. Pick a report.
  3. Verify the confirmation page shows the picked report.

Test 8: Pay someone from a chat

  1. Open a DM with another user, tap + in the composer, and choose Pay .
  2. Enter an amount, open the pay button, and choose Mark as paid.
  3. Verify the chat shows the payment.

Test 9: Scan from the FAB quick action

  1. If the quick action will point at a workspace chat, turn off the Categories feature in that workspace's More features. Otherwise the confirmation page is not skipped
  2. Create one scan expense in that chat (composer + > Submit expense > Scan).
  3. Open the FAB and tap the "Scan receipt for " quick action.
  4. Take or pick a receipt.
  5. Verify the expense is created without the confirmation page.
  • Verify that no errors appear in the JS console

Offline tests

  1. Go offline, then repeat tests 1, 2, 5, 6, 8 and 9. Verify each action is applied optimistically (expense created, moved or paid, with the pending style) and syncs after you go back online.

QA Steps

Same as tests.

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I verified any copy / text that was added to the app is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If the PR adds or modifies the UI:
    • I asked an AI agent to review the changes for accessibility issues and addressed its findings.
    • I tested with a screen reader (VoiceOver on macOS) and verified all new/changed elements are reachable with a logical focus order.
    • I verified all new/changed elements have meaningful accessible names and roles.
    • I verified state changes are announced (e.g. checked/unchecked, expanded/collapsed, selected).
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
android.1.2.4.5.6.7.mov
android.3.mov
android.8.9.mov
Android: mWeb Chrome
android.web.mov
iOS: Native
ios.1.2.4.5.6.mov
ios.3.mov
ios.7.8.mov
ios.9.mov
iOS: mWeb Safari
ios.web.mov
MacOS: Chrome / Safari
web.test.1-2.mov
web.test.4-7.mov
web.test.8.mov
web.test.9.mov

@LukasMod LukasMod changed the title [NoQA] refactor: read src/pages/iou (3/3) Onyx data in event handlers with Onyx.get refactor: read src/pages/iou (3/3) Onyx data in event handlers with Onyx.get Nov 12, 2026
@codecov

codecov Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

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.

Files with missing lines Coverage Δ
...ents/MoneyRequestConfirmationList/confirmAction.ts 100.00% <ø> (ø)
...es/iou/request/step/IOURequestEditReportCommon.tsx 86.66% <ø> (-0.46%) ⬇️
...RequestStepDistance/hooks/useOdometerNavigation.ts 100.00% <100.00%> (ø)
...tep/IOURequestStepDistanceGPS/GPSButtons/index.tsx 0.00% <ø> (ø)
...equestStepScan/components/ScanSkipConfirmation.tsx 94.88% <100.00%> (-0.33%) ⬇️
.../confirmation/submission/useSendMoneySubmission.ts 100.00% <100.00%> (ø)
...questStepConfirmation/variants/PayConfirmation.tsx 86.66% <83.33%> (+0.95%) ⬆️
...ou/request/step/IOURequestStepDistanceOdometer.tsx 84.78% <66.66%> (-0.76%) ⬇️
...questStepReport/hooks/useReportSelectionActions.ts 84.04% <75.00%> (-3.46%) ⬇️
src/pages/iou/request/step/IOURequestStepHours.tsx 84.53% <77.77%> (ø)
... and 1 more
... and 883 files with indirect coverage changes

@LukasMod

Copy link
Copy Markdown
Contributor Author

@MelvinBot deep review

@LukasMod

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-13T15:56:10.927874Z 7d915a0 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@MelvinBot

Copy link
Copy Markdown
Contributor

Deep review: 1 finding

P2 — Update the report-picker test for asynchronous selection

The new await Onyx.multiGet defers the transaction update. However, the unchanged ReportFieldDropdown test invokes selection inside synchronous act and immediately checks the write.

The test fails reproducibly: expected 1 call, received 0. Update it to await asynchronous act before asserting the write and picker closure.

Validation: 88 targeted tests passed; 1 failed. Reviewed all changed files, including selector equivalence, Search snapshot compatibility, billing restrictions, and navigation/write ordering. No additional concrete functional regressions found.

Limitations: No browser/native verification or full-suite run. Running the failing test against the base revision was blocked by environment permissions.


view run

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

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: 6d285a81e6

ℹ️ About Codex in GitHub

Your team has set up Codex to 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 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

return;
}

const [quickAction, reportTransactionsAndViolations] = await Onyx.multiGet([ONYXKEYS.NVP_QUICK_ACTION_GLOBAL_CREATE, ONYXKEYS.DERIVED.REPORT_TRANSACTIONS_AND_VIOLATIONS]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Lock Pay submission before awaiting Onyx

If a valid pay is activated twice while this multiGet is pending, both invocations pass the isConfirmed guard above while it is still false. The direct paths only set that state inside sendMoney, and the dismiss-first path sets it later, so both continuations can issue separate send-money writes; take a synchronous submit lock before yielding.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Could't repro. The read can’t be interleaved. Onyx.multiGet resolves from the cache in microtasks, so a second tap runs after the first handler has already finished. The pay option is also a popover item that fires after the modal hides, so a second activation needs a second selection

const isFromGlobalCreate = getIsFromGlobalCreate(transaction);

const firstReceiptFile = files.at(0);
const [quickAction, policyRecentlyUsedCurrencies, activePolicyID, recentWaypoints, userLocation, onboarding, transactionDrafts, conciergeChat] = await Onyx.multiGet([

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Lock scan submission before awaiting Onyx

In MultiScan, the receipt Submit button remains enabled after capture while this read is pending. A second tap re-enters submitDirectly; each invocation has already generated fresh optimistic transaction IDs, so both can submit the same receipt batch as separate expenses. Add a synchronous in-flight guard before awaiting.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Same reasoning as previous one. The read resolves in microtasks before any later tap can run. The old handler was synchronous with no in-flight guard either, and the button stayed tappable until the screen left, so this adds no new exposure

const navigateToNextStep = () => {
const navigateToNextStep = async () => {
const [lastSelectedDistanceRates, quickAction, policyRecentlyUsedCurrencies, recentWaypoints, rules, introSelected, allTransactionDrafts, onboarding, conciergeChat] =
await Onyx.multiGet([

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Lock GPS save while the Onyx snapshot is pending

For a new GPS request, Save remains enabled while this read is pending. Two taps before it resolves can each reach handleMoneyRequestStepDistanceNavigation; on a quick-action path that skips confirmation, both continuations submit a distance request, creating two expenses for one trip. Guard the submission before yielding.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Same reasoning as previous one. The multiGet finishes before a second tap runs, and the old handler had no guard, so behavior is unchanged

allTransactionDrafts,
onboarding,
conciergeChat,
] = await Onyx.multiGet([

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Lock odometer submission while the Onyx read is pending

In create mode, Next remains enabled while this read is pending. A second tap can start another navigation, and on a quick-action path that skips confirmation each call can submit a separate mileage expense. Take a synchronous submit lock before awaiting.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Same as above. The old handler was synchronous with no guard, and the new read resolves before a second tap can run

@LukasMod

Copy link
Copy Markdown
Contributor Author

@MelvinBot review

@MelvinBot

Copy link
Copy Markdown
Contributor

No new findings on 7d915a0.

  • The report-picker test fix resolves the previous failure without weakening its assertions.
  • Rechecked the double-submit concerns: no introduced regression established; initialized Onyx.multiGet resolves from cache before another ordinary tap can run.
  • Validation: 50 targeted tests passed across five suites.

No browser verification or full-suite run performed.


view run

@LukasMod
LukasMod marked this pull request as ready for review November 13, 2026 15:37
@LukasMod
LukasMod requested review from a team as code owners November 13, 2026 15:37
@melvin-bot
melvin-bot Bot requested review from TaduJR and aimane-chnaif and removed request for a team November 13, 2026 15:37
@melvin-bot

melvin-bot Bot commented Nov 13, 2026

Copy link
Copy Markdown

@TaduJR @aimane-chnaif One of you needs to 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]

@melvin-bot
melvin-bot Bot requested review from joekaufmanexpensify and removed request for a team November 13, 2026 15:37
@joekaufmanexpensify

Copy link
Copy Markdown
Contributor

No product review needed.

@joekaufmanexpensify
joekaufmanexpensify removed their request for review November 13, 2026 20:42
luacmartins
luacmartins previously approved these changes Nov 13, 2026
@mountiny
mountiny removed their request for review November 13, 2026 23:39
tgolen
tgolen previously approved these changes Nov 16, 2026

/** Caller-provided send-money handler for pay flows */
onSendMoney?: (paymentMethod: PaymentMethodType | undefined) => void;
onSendMoney?: (paymentMethod: PaymentMethodType | undefined) => void | Promise<void>;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is a strange type signature to me. Is there any downside to making it always return a promise?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I did the same for the other slots that only get an async handler. The shared removeFromReport prop in IOURequestEditReportCommon stays void | Promise<void>, because two callers pass a sync function and it would cause error TS2322: Type '() => void' is not assignable to type '() => Promise<void>'.

@LukasMod
LukasMod dismissed stale reviews from tgolen and luacmartins via 1817d4c November 17, 2026 10:24
@github-actions
github-actions Bot requested a review from mountiny November 17, 2026 10:24
@github-actions

Copy link
Copy Markdown
Contributor

This PR adds a new Onyx.get or Onyx.multiGet call, so I've requested a review from the Onyx performance reviewers (@tgolen, @mountiny, @chuckdries, @luacmartins). A review from any one of them is enough. Please check the call against the Onyx.get() rules in ONYX-DATA-MANAGEMENT and ONYX-1.

@luacmartins

Copy link
Copy Markdown
Contributor

@aimane-chnaif are you still reviewing this one?

@aimane-chnaif

Copy link
Copy Markdown
Contributor

yes but since new commits pushed, doing final test shortly...

@melvin-bot
melvin-bot Bot requested a review from chuckdries November 17, 2026 19:41
@mountiny
mountiny removed their request for review November 19, 2026 00:26
@luacmartins

Copy link
Copy Markdown
Contributor

Merging since @chuckdries had already approved

@luacmartins
luacmartins merged commit 3f24ef0 into Expensify:main Nov 19, 2026
41 of 43 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

🚧 luacmartins has triggered a test Expensify/App build. You can view the workflow run here.

@github-actions

Copy link
Copy Markdown
Contributor

@OSBotify

Copy link
Copy Markdown
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/luacmartins in version: 9.5.43-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

@MelvinBot

Copy link
Copy Markdown
Contributor

No help site update needed — this PR refactors internal data reads without adding features, changing user-facing workflows or labels, removing beta gates, or making existing article instructions incorrect.


view run

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/luacmartins in version: 9.5.47-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/luacmartins in version: 9.5.51-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 failure ❌

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/marcaaron in version: 9.5.51-1 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

Bundle Size Analysis (Sentry):

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.

8 participants