@@ -411,4 +411,43 @@ function getYourSpendSnapshotTotalUpdates({transaction, updatedTransaction, iouR
411411 return result ;
412412}
413413
414- export { getYourSpendSnapshotReportMoveUpdates , getYourSpendSnapshotTotalUpdates , getYourSpendSnapshotTransactionRemovalUpdates , transactionMatchesAwaitingApprovalQuery } ;
414+ type GetYourSpendSnapshotSplitUpdatesParams = {
415+ iouReport : OnyxEntry < Report > ;
416+ originalTransaction : OnyxEntry < Transaction > ;
417+ // Signed change to the report's reimbursable total, in the transaction/report currency
418+ // (new split total minus the pre-split total). Negative when the expense is split to a lower amount.
419+ reimbursableDiff : number ;
420+ currentUserAccountID : number ;
421+ } ;
422+
423+ /**
424+ * Optimistically patches the "Awaiting approval" snapshot total when a SUBMITTED expense is split and the resulting
425+ * reimbursable total changes (e.g. split to a lower amount). The report stays in the awaiting-approval section, so this
426+ * is a same-section amount delta rather than a state move. Home reads totals from `snapshot.search.total`, which is only
427+ * refreshed online. Mirrors the amount-edit path: same-currency only (the currency guard in
428+ * `buildSnapshotTotalUpdatesForHash` skips a mismatch, since FX conversion isn't available offline).
429+ */
430+ function getYourSpendSnapshotSplitUpdates ( { iouReport, originalTransaction, reimbursableDiff, currentUserAccountID} : GetYourSpendSnapshotSplitUpdatesParams ) : YourSpendSnapshotOnyxData {
431+ const result : YourSpendSnapshotOnyxData = { optimisticData : [ ] , successData : [ ] , failureData : [ ] } ;
432+ if ( ! iouReport || ! originalTransaction || reimbursableDiff === 0 ) {
433+ return result ;
434+ }
435+
436+ const paidGroupPolicyIDs = getPaidGroupPolicyIDs ( ) ;
437+ if ( ! transactionMatchesAwaitingApprovalQuery ( iouReport , originalTransaction , currentUserAccountID , paidGroupPolicyIDs ) ) {
438+ return result ;
439+ }
440+
441+ const currency = getCurrency ( originalTransaction ) ;
442+ const approvalQueryJSON = buildSearchQueryJSON ( buildAwaitingApprovalQuery ( currentUserAccountID , paidGroupPolicyIDs ) ) ;
443+ mergeYourSpendSnapshotOnyxData ( result , buildSnapshotTotalUpdatesForHash ( approvalQueryJSON ?. hash , reimbursableDiff , currency ) ) ;
444+ return result ;
445+ }
446+
447+ export {
448+ getYourSpendSnapshotReportMoveUpdates ,
449+ getYourSpendSnapshotSplitUpdates ,
450+ getYourSpendSnapshotTotalUpdates ,
451+ getYourSpendSnapshotTransactionRemovalUpdates ,
452+ transactionMatchesAwaitingApprovalQuery ,
453+ } ;
0 commit comments