Skip to content

Commit 3179626

Browse files
MelvinBotEskalifer1
andcommitted
Fix stale TRANSACTION_DRAFT entry after editing split expense amount
setSplitShares and resetSplitShares unconditionally wrote to TRANSACTION_DRAFT even when editing an existing (non-draft) split transaction. This left an orphaned entry that was never cleaned up, causing the next new expense to show "Create 2 expenses" on the confirmation page. Add an isDraft parameter (default true) to both functions, matching the pattern used by setMoneyRequestCreated and other peer functions. Pass isDraft=false from IOURequestStepAmount when editing. Co-authored-by: Eskalifer1 <Eskalifer1@users.noreply.github.com>
1 parent b4db455 commit 3179626

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

src/libs/actions/IOU/Split.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,15 +1077,17 @@ function completeSplitBill(
10771077
/**
10781078
* Sets the `splitShares` map that holds individual shares of a split bill
10791079
*/
1080-
function setSplitShares(transaction: OnyxEntry<OnyxTypes.Transaction>, amount: number, currency: string, newAccountIDs: number[]) {
1080+
function setSplitShares(transaction: OnyxEntry<OnyxTypes.Transaction>, amount: number, currency: string, newAccountIDs: number[], isDraft = true) {
10811081
if (!transaction) {
10821082
return;
10831083
}
10841084

1085+
const collectionKey = isDraft ? ONYXKEYS.COLLECTION.TRANSACTION_DRAFT : ONYXKEYS.COLLECTION.TRANSACTION;
1086+
10851087
// For pending split distance requests, we don't want to set split shares to zero amount
10861088
// instead we will reset it which would mean splitting the amount equally when the pending distance is resolved.
10871089
if (isDistanceRequestTransactionUtils(transaction) && !amount) {
1088-
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transaction.transactionID}`, {splitShares: null});
1090+
Onyx.merge(`${collectionKey}${transaction.transactionID}`, {splitShares: null});
10891091
return;
10901092
}
10911093

@@ -1116,18 +1118,18 @@ function setSplitShares(transaction: OnyxEntry<OnyxTypes.Transaction>, amount: n
11161118
return acc;
11171119
}, {});
11181120

1119-
Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION_DRAFT}${transaction.transactionID}`, {splitShares});
1121+
Onyx.merge(`${collectionKey}${transaction.transactionID}`, {splitShares});
11201122
}
11211123

1122-
function resetSplitShares(transaction: OnyxEntry<OnyxTypes.Transaction>, newAmount?: number, currency?: string) {
1124+
function resetSplitShares(transaction: OnyxEntry<OnyxTypes.Transaction>, newAmount?: number, currency?: string, isDraft = true) {
11231125
if (!transaction) {
11241126
return;
11251127
}
11261128
const accountIDs = Object.keys(transaction.splitShares ?? {}).map((key) => Number(key));
11271129
if (!accountIDs) {
11281130
return;
11291131
}
1130-
setSplitShares(transaction, newAmount ?? transaction.amount, currency ?? transaction.currency, accountIDs);
1132+
setSplitShares(transaction, newAmount ?? transaction.amount, currency ?? transaction.currency, accountIDs, isDraft);
11311133
}
11321134

11331135
function setDraftSplitTransaction(

src/pages/iou/request/step/IOURequestStepAmount.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ function IOURequestStepAmount({
399399

400400
// Edits to the amount from the splits page should reset the split shares.
401401
if (transaction?.splitShares) {
402-
resetSplitShares(transaction, newAmount, selectedCurrency);
402+
resetSplitShares(transaction, newAmount, selectedCurrency, !isEditing);
403403
}
404404

405405
if (!isEditing) {

0 commit comments

Comments
 (0)