Skip to content

A local-first personal finance app

Attempt to fix entered amount being lost sometimes when tapping the Nearby payee chip before field loses focus (#8196)

Dustin Brewerb6ac7d514d93
diff --git a/packages/desktop-client/src/components/mobile/transactions/TransactionEdit.tsx b/packages/desktop-client/src/components/mobile/transactions/TransactionEdit.tsx
index 17573b911b..568c035869 100644
--- a/packages/desktop-client/src/components/mobile/transactions/TransactionEdit.tsx
+++ b/packages/desktop-client/src/components/mobile/transactions/TransactionEdit.tsx
@@ -1768,6 +1768,7 @@ function TransactionEditUnconnected({
// Run the rules to auto-fill in any data. Right now we only do
// this on new transactions because that's how desktop works.
const newTransaction = { ...transaction };
+ const changedFields = new Set<keyof TransactionEntity>([updatedField]);
if (isTemporary(newTransaction)) {
const afterRules = await send('rules-run', {
transaction: newTransaction,
@@ -1788,6 +1789,7 @@ function TransactionEditUnconnected({
updatedField === 'payee'
) {
(newTransaction as Record<string, unknown>)[field] = diff[field];
+ changedFields.add(field);
}
});
@@ -1805,15 +1807,28 @@ function TransactionEditUnconnected({
}),
}),
);
+ changedFields.add('subtransactions');
}
}
}
- const { data: newTransactions } = updateTransaction(
- transactions,
- newTransaction,
- );
- setTransactions(newTransactions);
+ // Updates can be in flight at the same time (e.g. an amount blur
+ // racing a nearby payee press), so merge only the changed fields onto
+ // the latest state rather than replacing the whole transaction.
+ setTransactions(prevTransactions => {
+ const latestTransaction = prevTransactions.find(
+ t => t.id === newTransaction.id,
+ );
+ if (!latestTransaction) {
+ // The transaction was deleted while this update was in flight.
+ return prevTransactions;
+ }
+ const merged = { ...latestTransaction };
+ for (const field of changedFields) {
+ (merged as Record<string, unknown>)[field] = newTransaction[field];
+ }
+ return updateTransaction(prevTransactions, merged).data;
+ });
if (updatedField === 'payee') {
setShouldShowSaveLocation(false);
@@ -1840,7 +1855,7 @@ function TransactionEditUnconnected({
}
}
},
- [dateFormat, transactions, isLocationGranted],
+ [dateFormat, isLocationGranted],
);
const onSave = useCallback(
diff --git a/upcoming-release-notes/8196.md b/upcoming-release-notes/8196.md
new file mode 100644
index 0000000000..c12a04e2aa
--- /dev/null
+++ b/upcoming-release-notes/8196.md
@@ -0,0 +1,6 @@
+---
+category: Bugfixes
+authors: [mannkind]
+---
+
+Fix entered amount being lost sometimes when tapping the Nearby payee chip before field loses focus