@@ -4,6 +4,7 @@ import ONYXKEYS from '@src/ONYXKEYS';
44import type { TransactionViolation } from '@src/types/onyx' ;
55
66let previousViolations : OnyxCollection < TransactionViolation [ ] > = { } ;
7+ const transactionReportIDMapping : Record < string , string > = { } ;
78
89const transactionToReportIDMap : Record < string , string > = { } ;
910
@@ -34,11 +35,18 @@ export default createOnyxDerivedValueConfig({
3435 const reportID = transaction ?. reportID ;
3536
3637 // If the reportID of the transaction has changed (e.g. the transaction was split into multiple reports), we need to delete the transaction from the previous reportID and the violations from the previous reportID
37- const previousReportID = transactionToReportIDMap [ transactionKey ] ;
38+ const previousReportID = transactionReportIDMapping [ transactionKey ] ;
39+
3840 if ( previousReportID && previousReportID !== reportID && reportTransactionsAndViolations [ previousReportID ] ) {
3941 delete reportTransactionsAndViolations [ previousReportID ] . transactions [ transactionKey ] ;
4042 const transactionID = transactionKey . replace ( ONYXKEYS . COLLECTION . TRANSACTION , '' ) ;
41- delete reportTransactionsAndViolations [ previousReportID ] . violations [ `${ ONYXKEYS . COLLECTION . TRANSACTION_VIOLATIONS } ${ transactionID } ` ] ;
43+ if ( transactionID ) {
44+ delete reportTransactionsAndViolations [ previousReportID ] . violations [ `${ ONYXKEYS . COLLECTION . TRANSACTION_VIOLATIONS } ${ transactionID } ` ] ;
45+ }
46+ }
47+
48+ if ( ! transaction && transactionReportIDMapping [ transactionKey ] ) {
49+ delete transactionReportIDMapping [ transactionKey ] ;
4250 }
4351
4452 if ( ! reportID ) {
@@ -69,7 +77,7 @@ export default createOnyxDerivedValueConfig({
6977 }
7078
7179 reportTransactionsAndViolations [ reportID ] . transactions [ transactionKey ] = transaction ;
72- transactionToReportIDMap [ transactionKey ] = reportID ;
80+ transactionReportIDMapping [ transactionKey ] = reportID ;
7381 }
7482
7583 previousViolations = violations ;
0 commit comments