Skip to content

Save unsent receipts to the device gallery on sign-out#94973

Merged
mountiny merged 11 commits into
Expensify:mainfrom
callstack-internal:durable-receipts-save-signout-v2
Jul 9, 2026
Merged

Save unsent receipts to the device gallery on sign-out#94973
mountiny merged 11 commits into
Expensify:mainfrom
callstack-internal:durable-receipts-save-signout-v2

Conversation

@rinej

@rinej rinej commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Explanation of Change

It is the PR based on the original -> #94327

On iOS and Android, if you sign out while a receipt is still uploading, the app now saves that receipt image to your device gallery before it clears storage. That way you can add it again later instead of losing it.

Manual sign-out from Settings shows a short confirmation prompt. Forced sign-outs (expired or invalid session) save silently without a prompt. If saving fails for any reason, sign-out still completes normally.

Fixed Issues

$ #92139
PROPOSAL:

Tests

Tests
Unit tests (all passing):

  • Pending-receipt enumeration (savePendingReceiptsToGalleryTest.ts): verifies correct receipts are picked from the Onyx queue
  • Gallery-save batch behavior: one write per file, survives a single failure, swallows errors so sign-out always completes
  • SignInRedirectSaveReceiptsTest.ts: verifies save-before-clear ordering and the fail-safe (sign-out completes even if saving throws)

Offline tests

QA Steps

iOS Native and Android Native only

  • Capture a receipt while the device is offline so it stays in the upload queue.
  • Go to Settings and tap Sign Out.
  • Verify a confirmation prompt appears mentioning unsaved receipts.
  • Confirm sign-out. Verify the receipt image appears in the device gallery and sign-out completes.
  • Repeat step 1. Trigger a forced sign-out (e.g. invalidate the session from another device). Verify the receipt is saved to the gallery with no prompt shown and sign-out completes.
    -Repeat step 1. Deny photo-library permission when prompted (or pre-deny it in Settings). Tap Sign Out and confirm. - Verify sign-out still completes even though the gallery save fails.
  • iOS-specific: Verify the image lands in the Camera Roll via the Photos framework.
  • Android-specific: Verify the image lands in the media store (visible in the Gallery app).

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 followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and 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 followed the guidelines as stated in the Review Guidelines
  • 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 any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • 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.
  • 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: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari

adhorodyski and others added 3 commits June 30, 2026 15:08
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…ut save

getPendingReceiptRequests() missed pending receipts in two ways, both of which
let Onyx.clear() delete a local receipt on sign-out without saving it:

- REPLACE_RECEIPT queues the raw File object, whose local path lives under `uri`
  (and name under `name`), not `source`/`localSource`. It was allow-listed but
  could never match, so every offline receipt-replace was silently dropped.
  Fall back to `uri` for the path and `name` for the filename.
- Other receipt-bearing commands (SEND_MONEY_ELSEWHERE, SEND_MONEY_WITH_WALLET,
  SHARE_TRACKED_EXPENSE, CATEGORIZE_TRACKED_EXPENSE, ADD_TRACKED_EXPENSE_TO_POLICY)
  were absent from the allow-list. Add them.

Also collapse the repeated string-property guards into a single isRecord-based
getString helper.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@melvin-bot

melvin-bot Bot commented Jun 30, 2026

Copy link
Copy Markdown

Hey, I noticed you changed src/languages/en.ts in a PR from a fork. For security reasons, translations are not generated automatically for PRs from forks.

If you want to automatically generate translations for other locales, an Expensify employee will have to:

  1. Look at the code and make sure there are no malicious changes.
  2. Run the Generate static translations GitHub workflow. If you have write access and the K2 extension, you can simply click: [this button]

Alternatively, if you are an external contributor, you can run the translation script locally with your own OpenAI API key. To learn more, try running:

npx ts-node ./scripts/generateTranslations.ts --help

Typically, you'd want to translate only what you changed by running npx ts-node ./scripts/generateTranslations.ts --compare-ref main

@codecov

codecov Bot commented Jun 30, 2026

Copy link
Copy Markdown

@rinej rinej changed the title Durable receipts save signout v2 Save unsent receipts to the device gallery on sign-out Jul 1, 2026
@rinej

rinej commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

I applied the coding-standards review fixes on top of the cherry-picked commits.
Also manually verified on iOS and Android - the paths both work as expected.

One thing I wanted confirm - when the user is offline with a pending receipt and taps Sign Out, we show two back-to-back modals - first the pre-existing "you'll lose your offline data" warning, then the new "you have 1 receipt in the queue, save it to the gallery?" prompt. Cancelling either aborts sign-out.

Since the save-receipts feature specifically exists for the offline case, both modals will almost always fire together -not sure this is intended. Maybe we could merge the modals into one. Adding videos below:

Android:

ReceiptsModal-Android.mp4

iOS:

ReceiptsModal-iOS.mp4

@rinej rinej marked this pull request as ready for review July 1, 2026 16:33
@rinej rinej requested review from a team as code owners July 1, 2026 16:33
@melvin-bot melvin-bot Bot requested review from eVoloshchak and flaviadefaria and removed request for a team July 1, 2026 16:33
@melvin-bot

melvin-bot Bot commented Jul 1, 2026

Copy link
Copy Markdown

@eVoloshchak 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]

@melvin-bot melvin-bot Bot removed the request for review from a team July 1, 2026 16:33

@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: 37c834e476

ℹ️ 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".

Comment thread src/libs/actions/SignInRedirect.ts Outdated
// `Onyx.clear` reinitializes the Onyx instance with initial values so use `Onyx.merge` instead of `Onyx.set`
Onyx.merge(ONYXKEYS.SESSION, {errors: getMicroSecondOnyxErrorWithMessage(errorMessage)});
});
return saveUnsentReceiptsBeforeClear().then(() =>

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 Avoid permission-gated saves during forced sign-out

redirectToSignIn is used for invalid/expired-session redirects as well as the Settings button, but this unconditional save runs before Onyx.clear() for all of them. On a forced sign-out with a queued receipt and no Photos/storage permission, the native save path can show OS permission UI (Android requests it in hasGalleryWritePermission.android.ts, iOS prompts from CameraRoll.saveAsset) and the clear/redirect waits on that promise, so the supposedly silent forced sign-out can be delayed or appear blocked until the user responds. Gate permission-prompting saves to the manual flow or use a non-prompting check for forced redirects.

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.

added the changes 👍

Comment thread src/libs/fileDownload/saveLocalFileToGallery.ios.ts
@rinej

rinej commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

@eVoloshchak please have a look on the PR. I addressed the codex review comments

@adhorodyski

Copy link
Copy Markdown
Contributor

Oh I think we should only show the 1st modal really? and the logic should run for it, I didn't know we have this already.

@rinej

rinej commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

So one modal to rule them all? 😄

We can combine it into something like that:

Title: Sign out and save receipts?
Text: You have 1 unsent receipt. We'll save it to your Photos so you can add it to a new expense later. Any other offline changes will be lost

wdyt?

@eVoloshchak

eVoloshchak commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible 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 checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and 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 verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
  • 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.
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this 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.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: HybridApp
screen-20260706-215600-1783367710526.mp4
Android: mWeb Chrome
Screen.Recording.2026-07-06.at.23.18.09.mov
iOS: HybridApp
Screen.Recording.2026-07-09.at.13.26.29.mov
iOS: mWeb Safari
Screen.Recording.2026-07-06.at.22.06.44.mov
MacOS: Chrome / Safari
Screen.Recording.2026-07-06.at.22.05.25.mov

@rinej

rinej commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

I added the change with combining two modals, here is the video:

ReceiptModalCombined-Android.mp4

And screenshot:

Screenshot 2026-07-06 at 17 13 40

}

return PermissionsAndroid.requestMultiple([PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE, PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE]).then(
(status) => status['android.permission.READ_EXTERNAL_STORAGE'] === 'granted' && status['android.permission.WRITE_EXTERNAL_STORAGE'] === 'granted',

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.

Suggested change
(status) => status['android.permission.READ_EXTERNAL_STORAGE'] === 'granted' && status['android.permission.WRITE_EXTERNAL_STORAGE'] === 'granted',
(status) => status[PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE] === PermissionsAndroid.RESULTS.GRANTED && status[PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE] === PermissionsAndroid.RESULTS.GRANTED,

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 added the change👍

@eVoloshchak

Copy link
Copy Markdown
Contributor

Looks and works well on web/Android!
Could you trigger an ad hoc build, please? The camera flow isn't possible to test on iOS simulator

@rinej

rinej commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

thanks! I added the requested changes

I cannot run the adhoc - someone internal from Expensify should be able to do it.

@mountiny could you help and run the adhoc build for it, please?

@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

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

@github-actions

This comment has been minimized.

@eVoloshchak eVoloshchak left a comment

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.

LGTM!

@melvin-bot melvin-bot Bot requested a review from cead22 July 9, 2026 11:27

@mountiny mountiny left a comment

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.

Just one comment, but not sure how to go about that, looks good to me

Comment on lines +9 to +21
const RECEIPT_BEARING_COMMANDS = new Set<string>([
WRITE_COMMANDS.REQUEST_MONEY,
WRITE_COMMANDS.TRACK_EXPENSE,
WRITE_COMMANDS.SPLIT_BILL,
WRITE_COMMANDS.SPLIT_BILL_AND_OPEN_REPORT,
WRITE_COMMANDS.START_SPLIT_BILL,
WRITE_COMMANDS.REPLACE_RECEIPT,
WRITE_COMMANDS.SEND_MONEY_ELSEWHERE,
WRITE_COMMANDS.SEND_MONEY_WITH_WALLET,
WRITE_COMMANDS.SHARE_TRACKED_EXPENSE,
WRITE_COMMANDS.CATEGORIZE_TRACKED_EXPENSE,
WRITE_COMMANDS.ADD_TRACKED_EXPENSE_TO_POLICY,
]);

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.

I am not sure what is a better solution but my worry with this is that we could add a new command that will carry a request and people will forget to add it here. Either way, just raising that as I do not have better idea how to avoid it

@mountiny mountiny merged commit 5cdd139 into Expensify:main Jul 9, 2026
39 checks passed
@OSBotify

OSBotify commented Jul 9, 2026

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.

@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

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

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/mountiny in version: 9.4.33-0 🚀

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

@MelvinBot

Copy link
Copy Markdown
Contributor

📝 Help site review — docs update needed

Yes, this PR introduces new user-facing behavior worth documenting: on iOS and Android, signing out while receipts are still uploading now saves those receipts to the device's photos, and manual sign-out shows a Save your receipts? confirmation prompt with a Save and sign out button.

Nothing under docs/articles currently covers what happens to in-progress receipt uploads on sign-out, and a user could reasonably search for this (e.g. "why did Expensify save receipts to my photos" / "I signed out and my receipt was uploading").

What I did: Rather than create a whole new article for this edge case (one-workflow-per-article rule), I added a targeted FAQ entry to the existing New Expensify Create an Expense article, which already documents mobile SmartScan. All button/feature labels (Settings, Save your receipts?, Save and sign out, Sign out) were verified against the copy added in this PR and the current UI, per HELPSITE_NAMING_CONVENTIONS.md and HELP_AUTHORING_GUIDELINES.md.

Draft help site PR: #95844 (labeled HelpDot, assigned to you)

FAQ entry added

What happens to receipts that are still uploading when I sign out on mobile?

On the Expensify mobile app (iOS and Android), if you sign out while one or more receipts are still uploading, Expensify saves those receipt images to your device's photos first so you don't lose them.

  • When you sign out from Settings, a Save your receipts? prompt appears. Tap Save and sign out to save the pending receipts to your photos and finish signing out.
  • If you're signed out automatically (for example, when your session expires), the receipts are saved to your photos without a prompt.

The next time you sign in, you can add the saved images to a new expense. If Expensify can't save the receipts (for example, if photo access is denied), sign-out still completes.


@rinej, please review the linked help site PR and confirm it reflects the current behavior. Then mark the linked help site PR Ready for review

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.

6 participants