From 157e57ad7f696522f07fecbf7aacd133811d49c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96zg=C3=BCn=20=C3=96zerk?= Date: Fri, 22 Dec 2023 11:51:39 +0300 Subject: [PATCH] fix transaction reset (#35) --- lib/controllers/user_assets_controller.dart | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/controllers/user_assets_controller.dart b/lib/controllers/user_assets_controller.dart index 451dce5..fbeede8 100644 --- a/lib/controllers/user_assets_controller.dart +++ b/lib/controllers/user_assets_controller.dart @@ -202,9 +202,14 @@ class UserAssetsController extends GetxController { } if (isThereAnyChange()) { + // applying category updates even when there are only transaction changes + // is not harmful, and `isThereAnyChange` check eliminates code duplication + // and extra checks for differentiating between category and transaction changes + _userAssets.value.pruneEmptyCategoriesOnSave(); _oldCategories = cloneCategoryMap(_userAssets.value.categoryMap); _isThereAnyCategoryChange.value = false; + _transactions.value = Transactions.empty(); await _saveUserAssetsToDevice(_userAssets.value); } } @@ -212,6 +217,7 @@ class UserAssetsController extends GetxController { discardChanges() { _userAssets.value.categoryMap = cloneCategoryMap(_oldCategories); _isThereAnyCategoryChange.value = false; + _transactions.value = Transactions.empty(); _userAssets.value.assets = _snapshotsController.getLastSnapshot()!.clone(); }