Repository navigation
Show Try again when replacing a receipt fails #102893
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
Merged
mountiny
merged 5 commits into
Expensify:main
from
callstack-internal:receipt-upload-retry-replace-receipt
Oct 7, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b23cbde
fix: show Try again when replacing a receipt fails
rinej fc0eb8b
test: cover the ReplaceReceipt retry
rinej ead2798
fix: drop the unused canBuildRetryPayload re-export
rinej 9ae58dd
Merge branch 'main' into receipt-upload-retry-replace-receipt
rinej 71dc7b7
fix: add comments in file header and justify the File cast
rinej 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 hidden or 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
101 changes: 101 additions & 0 deletions
101
src/libs/ReceiptUploadRetryHandler/buildReplaceReceiptRetryPayload.ts
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| /** Decides whether a failed `ReplaceReceipt` can be retried and rebuilds the call from Onyx. */ | ||
| import {isLocalFile} from '@libs/fileDownload/FileUtils'; | ||
|
|
||
| import type {ReplaceReceipt, ReplaceReceiptRetryParams} from '@userActions/IOU/Receipt'; | ||
|
|
||
| import CONST from '@src/CONST'; | ||
| import type {ReceiptError} from '@src/types/onyx/Transaction'; | ||
| import type {FileObject} from '@src/types/utils/Attachment'; | ||
|
|
||
| import type {ValueOf} from 'type-fest'; | ||
|
|
||
| import type {ReceiptRetryContext} from './types'; | ||
|
|
||
| import isRetrySupported from './isRetrySupported'; | ||
|
|
||
| type StoredReplaceReceiptRetryParams = Pick<ReplaceReceiptRetryParams, 'transactionID' | 'state' | 'isSameReceipt' | 'receiptAddedReportActionID'>; | ||
|
|
||
| const RECEIPT_STATES = new Set<unknown>(Object.values(CONST.IOU.RECEIPT_STATE)); | ||
|
|
||
| function isReceiptState(value: unknown): value is ValueOf<typeof CONST.IOU.RECEIPT_STATE> { | ||
| return RECEIPT_STATES.has(value); | ||
| } | ||
|
|
||
| function parseRetryParams(retryParams: ReceiptError['retryParams']): unknown { | ||
| if (typeof retryParams !== 'string') { | ||
| return retryParams; | ||
| } | ||
| try { | ||
| return JSON.parse(retryParams); | ||
| } catch { | ||
| return undefined; | ||
| } | ||
| } | ||
|
|
||
| function getReplaceReceiptRetryParams(receiptError: ReceiptError): StoredReplaceReceiptRetryParams | undefined { | ||
| if (receiptError.action !== CONST.IOU.ACTION_PARAMS.REPLACE_RECEIPT) { | ||
| return undefined; | ||
| } | ||
|
|
||
| const parsed = parseRetryParams(receiptError.retryParams); | ||
| if (!parsed || typeof parsed !== 'object' || !('transactionID' in parsed) || typeof parsed.transactionID !== 'string') { | ||
| return undefined; | ||
| } | ||
|
|
||
| return { | ||
| transactionID: parsed.transactionID, | ||
| state: 'state' in parsed && isReceiptState(parsed.state) ? parsed.state : undefined, | ||
| isSameReceipt: 'isSameReceipt' in parsed && parsed.isSameReceipt === true ? true : undefined, | ||
| receiptAddedReportActionID: 'receiptAddedReportActionID' in parsed && typeof parsed.receiptAddedReportActionID === 'string' ? parsed.receiptAddedReportActionID : undefined, | ||
| }; | ||
| } | ||
|
|
||
| function canBuildReplaceReceiptRetryPayload(context: ReceiptRetryContext): boolean { | ||
| const {transaction, receiptError} = context; | ||
| if (!isRetrySupported || !transaction?.transactionID || !isLocalFile(receiptError.source)) { | ||
| return false; | ||
| } | ||
|
|
||
| return getReplaceReceiptRetryParams(receiptError)?.transactionID === transaction.transactionID; | ||
| } | ||
|
|
||
| function buildReplaceReceiptRetryPayload(context: ReceiptRetryContext, receiptFile: FileObject): ReplaceReceipt | undefined { | ||
| const { | ||
| transaction, | ||
| receiptError, | ||
| policyParams, | ||
| transactionReport, | ||
| transactionThreadReport, | ||
| transactionViolations, | ||
| isVendorMatchingBetaEnabled, | ||
| delegateAccountID, | ||
| currentUserPersonalDetails, | ||
| } = context; | ||
| const retryParams = getReplaceReceiptRetryParams(receiptError); | ||
| if (!canBuildReplaceReceiptRetryPayload(context) || !retryParams) { | ||
| return undefined; | ||
| } | ||
|
|
||
| return { | ||
| transaction, | ||
| // `replaceReceipt` only reads `FileObject` fields; native callers pass this same shape, cast to `File` the same way. | ||
| // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion | ||
|
mountiny marked this conversation as resolved.
|
||
| file: receiptFile as File, | ||
| source: receiptError.source, | ||
| state: retryParams.state, | ||
| isSameReceipt: retryParams.isSameReceipt, | ||
| receiptAddedReportActionID: retryParams.receiptAddedReportActionID, | ||
| transactionPolicy: policyParams.policy, | ||
| transactionPolicyCategories: policyParams.policyCategories, | ||
| transactionPolicyTagList: policyParams.policyTagList, | ||
| transactionViolations, | ||
| transactionReport, | ||
| transactionThreadReport, | ||
| isVendorMatchingBetaEnabled, | ||
| delegateAccountID, | ||
| currentUserPersonalDetails, | ||
| }; | ||
| } | ||
|
|
||
| export default buildReplaceReceiptRetryPayload; | ||
| export {canBuildReplaceReceiptRetryPayload}; | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.