@@ -159,6 +159,7 @@ import {
159
159
isPerDiemRequest as isPerDiemRequestTransactionUtils ,
160
160
isReceiptBeingScanned as isReceiptBeingScannedTransactionUtils ,
161
161
isScanRequest as isScanRequestTransactionUtils ,
162
+ removeSettledAndApprovedTransactions ,
162
163
shouldShowBrokenConnectionViolation ,
163
164
} from '@libs/TransactionUtils' ;
164
165
import ViolationsUtils from '@libs/Violations/ViolationsUtils' ;
@@ -6764,6 +6765,56 @@ function deleteMoneyRequest(transactionID: string | undefined, reportAction: Ony
6764
6765
value : null ,
6765
6766
} ) ;
6766
6767
6768
+ const failureData : OnyxUpdate [ ] = [
6769
+ {
6770
+ onyxMethod : Onyx . METHOD . SET ,
6771
+ key : `${ ONYXKEYS . COLLECTION . TRANSACTION } ${ transactionID } ` ,
6772
+ value : transaction ?? null ,
6773
+ } ,
6774
+ ] ;
6775
+
6776
+ if ( transactionViolations ) {
6777
+ removeSettledAndApprovedTransactions (
6778
+ transactionViolations . filter ( ( violation ) => violation ?. name === CONST . VIOLATIONS . DUPLICATED_TRANSACTION ) . flatMap ( ( violation ) => violation ?. data ?. duplicates ?? [ ] ) ,
6779
+ ) . forEach ( ( duplicateID ) => {
6780
+ const duplicateTransactionsViolations = allTransactionViolations [ `${ ONYXKEYS . COLLECTION . TRANSACTION_VIOLATIONS } ${ duplicateID } ` ] ;
6781
+ if ( ! duplicateTransactionsViolations ) {
6782
+ return ;
6783
+ }
6784
+
6785
+ const duplicateViolation = duplicateTransactionsViolations . find ( ( violation ) => violation . name === CONST . VIOLATIONS . DUPLICATED_TRANSACTION ) ;
6786
+ if ( ! duplicateViolation ?. data ?. duplicates ) {
6787
+ return ;
6788
+ }
6789
+
6790
+ const duplicateTransactionIDs = duplicateViolation . data . duplicates . filter ( ( duplicateTransactionID ) => duplicateTransactionID !== transactionID ) ;
6791
+
6792
+ const optimisticViolations : OnyxTypes . TransactionViolations = duplicateTransactionsViolations . filter ( ( violation ) => violation . name !== CONST . VIOLATIONS . DUPLICATED_TRANSACTION ) ;
6793
+
6794
+ if ( duplicateTransactionIDs . length > 0 ) {
6795
+ optimisticViolations . push ( {
6796
+ ...duplicateViolation ,
6797
+ data : {
6798
+ ...duplicateViolation . data ,
6799
+ duplicates : duplicateTransactionIDs ,
6800
+ } ,
6801
+ } ) ;
6802
+ }
6803
+
6804
+ optimisticData . push ( {
6805
+ onyxMethod : Onyx . METHOD . SET ,
6806
+ key : `${ ONYXKEYS . COLLECTION . TRANSACTION_VIOLATIONS } ${ duplicateID } ` ,
6807
+ value : optimisticViolations . length > 0 ? optimisticViolations : null ,
6808
+ } ) ;
6809
+
6810
+ failureData . push ( {
6811
+ onyxMethod : Onyx . METHOD . SET ,
6812
+ key : `${ ONYXKEYS . COLLECTION . TRANSACTION_VIOLATIONS } ${ duplicateID } ` ,
6813
+ value : duplicateTransactionsViolations ,
6814
+ } ) ;
6815
+ } ) ;
6816
+ }
6817
+
6767
6818
if ( shouldDeleteTransactionThread ) {
6768
6819
optimisticData . push (
6769
6820
// Use merge instead of set to avoid deleting the report too quickly, which could cause a brief "not found" page to appear.
@@ -6909,14 +6960,6 @@ function deleteMoneyRequest(transactionID: string | undefined, reportAction: Ony
6909
6960
} ) ;
6910
6961
}
6911
6962
6912
- const failureData : OnyxUpdate [ ] = [
6913
- {
6914
- onyxMethod : Onyx . METHOD . SET ,
6915
- key : `${ ONYXKEYS . COLLECTION . TRANSACTION } ${ transactionID } ` ,
6916
- value : transaction ?? null ,
6917
- } ,
6918
- ] ;
6919
-
6920
6963
failureData . push ( {
6921
6964
onyxMethod : Onyx . METHOD . SET ,
6922
6965
key : `${ ONYXKEYS . COLLECTION . TRANSACTION_VIOLATIONS } ${ transactionID } ` ,
0 commit comments