CW-687 Coin control fixes (#2058)

* fix coin control * don't reselect frozen coins

Matthew Fosse committed Mar 3, 2025 at 17:38 UTC 0c14c0b1f493536d31eb6d967b6d3e1fc11174e9
2 files changed +19 -9
lib/view_model/send/send_view_model.dart
+8 -7
@@ -102,7 +102,9 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor
102 outputs
103 .add(Output(wallet, _settingsStore, _fiatConversationStore, () => selectedCryptoCurrency));
104
105 - unspentCoinsListViewModel.initialSetup();
105 + unspentCoinsListViewModel.initialSetup().then((_) {
106 + unspentCoinsListViewModel.resetUnspentCoinsInfoSelections();
107 + });
108 }
109
110 @observable
@@ -728,11 +730,10 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor
730 return S.current.insufficient_funds_for_tx;
731 }
732
731 - return
732 - '''${S.current.insufficient_funds_for_tx} \n\n'''
733 - '''${S.current.balance}: ${parsedErrorMessageResult.balanceEth} ${walletType == WalletType.polygon ? "POL" : "ETH"} (${parsedErrorMessageResult.balanceUsd} ${fiatFromSettings.name})\n\n'''
734 - '''${S.current.transaction_cost}: ${parsedErrorMessageResult.txCostEth} ${walletType == WalletType.polygon ? "POL" : "ETH"} (${parsedErrorMessageResult.txCostUsd} ${fiatFromSettings.name})\n\n'''
735 - '''${S.current.overshot}: ${parsedErrorMessageResult.overshotEth} ${walletType == WalletType.polygon ? "POL" : "ETH"} (${parsedErrorMessageResult.overshotUsd} ${fiatFromSettings.name})''';
733 + return '''${S.current.insufficient_funds_for_tx} \n\n'''
734 + '''${S.current.balance}: ${parsedErrorMessageResult.balanceEth} ${walletType == WalletType.polygon ? "POL" : "ETH"} (${parsedErrorMessageResult.balanceUsd} ${fiatFromSettings.name})\n\n'''
735 + '''${S.current.transaction_cost}: ${parsedErrorMessageResult.txCostEth} ${walletType == WalletType.polygon ? "POL" : "ETH"} (${parsedErrorMessageResult.txCostUsd} ${fiatFromSettings.name})\n\n'''
736 + '''${S.current.overshot}: ${parsedErrorMessageResult.overshotEth} ${walletType == WalletType.polygon ? "POL" : "ETH"} (${parsedErrorMessageResult.overshotUsd} ${fiatFromSettings.name})''';
737 }
738
739 return errorMessage;
@@ -809,4 +810,4 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor
810
811 return false;
812 }
812 -}
\ No newline at end of file
813 +}
lib/view_model/unspent_coins/unspent_coins_list_view_model.dart
+11 -2
@@ -68,7 +68,6 @@ abstract class UnspentCoinsListViewModelBase with Store {
68
69 bool get hasAdjustableFieldChanged => items.any(_hasAdjustableFieldChanged);
70
71 -
71 Future<void> saveUnspentCoinInfo(UnspentCoinsItem item) async {
72 try {
73 final existingInfo = _unspentCoinsInfo.values
@@ -79,7 +78,6 @@ abstract class UnspentCoinsListViewModelBase with Store {
78 existingInfo.isSending = item.isSending;
79 existingInfo.note = item.note;
80
82 -
81 await existingInfo.save();
82 _updateUnspentCoinsInfo();
83 } catch (e) {
@@ -167,6 +165,17 @@ abstract class UnspentCoinsListViewModelBase with Store {
165 items.addAll(unspents);
166 }
167
168 + @action
169 + void resetUnspentCoinsInfoSelections() {
170 + // reset all unspent coins selections to true except frozen ones
171 + for (final item in items) {
172 + if (!item.isFrozen) {
173 + item.isSending = true;
174 + saveUnspentCoinInfo(item);
175 + }
176 + }
177 + }
178 +
179 @action
180 void toggleSelectAll(bool value) {
181 for (final item in items) {