From 3d51297b43d50be4a258d97a33cf2cf4396cab7c Mon Sep 17 00:00:00 2001 From: Matthew Fosse Date: Wed, 26 Feb 2025 12:50:21 -0800 Subject: [PATCH 1/2] fix coin control --- lib/view_model/send/send_view_model.dart | 15 ++++++++------- .../unspent_coins_list_view_model.dart | 15 +++++++++++++-- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/lib/view_model/send/send_view_model.dart b/lib/view_model/send/send_view_model.dart index 53c52aa1e7..998521edee 100644 --- a/lib/view_model/send/send_view_model.dart +++ b/lib/view_model/send/send_view_model.dart @@ -102,7 +102,9 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor outputs .add(Output(wallet, _settingsStore, _fiatConversationStore, () => selectedCryptoCurrency)); - unspentCoinsListViewModel.initialSetup(); + unspentCoinsListViewModel.initialSetup().then((_) { + unspentCoinsListViewModel.resetUnspentCoinsInfoSelections(); + }); } @observable @@ -728,11 +730,10 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor return S.current.insufficient_funds_for_tx; } - return - '''${S.current.insufficient_funds_for_tx} \n\n''' - '''${S.current.balance}: ${parsedErrorMessageResult.balanceEth} ${walletType == WalletType.polygon ? "POL" : "ETH"} (${parsedErrorMessageResult.balanceUsd} ${fiatFromSettings.name})\n\n''' - '''${S.current.transaction_cost}: ${parsedErrorMessageResult.txCostEth} ${walletType == WalletType.polygon ? "POL" : "ETH"} (${parsedErrorMessageResult.txCostUsd} ${fiatFromSettings.name})\n\n''' - '''${S.current.overshot}: ${parsedErrorMessageResult.overshotEth} ${walletType == WalletType.polygon ? "POL" : "ETH"} (${parsedErrorMessageResult.overshotUsd} ${fiatFromSettings.name})'''; + return '''${S.current.insufficient_funds_for_tx} \n\n''' + '''${S.current.balance}: ${parsedErrorMessageResult.balanceEth} ${walletType == WalletType.polygon ? "POL" : "ETH"} (${parsedErrorMessageResult.balanceUsd} ${fiatFromSettings.name})\n\n''' + '''${S.current.transaction_cost}: ${parsedErrorMessageResult.txCostEth} ${walletType == WalletType.polygon ? "POL" : "ETH"} (${parsedErrorMessageResult.txCostUsd} ${fiatFromSettings.name})\n\n''' + '''${S.current.overshot}: ${parsedErrorMessageResult.overshotEth} ${walletType == WalletType.polygon ? "POL" : "ETH"} (${parsedErrorMessageResult.overshotUsd} ${fiatFromSettings.name})'''; } return errorMessage; @@ -809,4 +810,4 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor return false; } -} \ No newline at end of file +} diff --git a/lib/view_model/unspent_coins/unspent_coins_list_view_model.dart b/lib/view_model/unspent_coins/unspent_coins_list_view_model.dart index 52820adcb1..b4e8eeccad 100644 --- a/lib/view_model/unspent_coins/unspent_coins_list_view_model.dart +++ b/lib/view_model/unspent_coins/unspent_coins_list_view_model.dart @@ -68,7 +68,6 @@ abstract class UnspentCoinsListViewModelBase with Store { bool get hasAdjustableFieldChanged => items.any(_hasAdjustableFieldChanged); - Future saveUnspentCoinInfo(UnspentCoinsItem item) async { try { final existingInfo = _unspentCoinsInfo.values @@ -79,7 +78,6 @@ abstract class UnspentCoinsListViewModelBase with Store { existingInfo.isSending = item.isSending; existingInfo.note = item.note; - await existingInfo.save(); _updateUnspentCoinsInfo(); } catch (e) { @@ -167,6 +165,19 @@ abstract class UnspentCoinsListViewModelBase with Store { items.addAll(unspents); } + @action + void resetUnspentCoinsInfoSelections() { + // reset all unspent coins selections to true + for (final item in items) { + // if (!item.isSending) { + // item.isSending = true; + // saveUnspentCoinInfo(item); + // } + item.isSending = true; + saveUnspentCoinInfo(item); + } + } + @action void toggleSelectAll(bool value) { for (final item in items) { From 0b97b21bf65f241898540c806f12947a80615bd1 Mon Sep 17 00:00:00 2001 From: Matthew Fosse Date: Fri, 28 Feb 2025 08:35:08 -0800 Subject: [PATCH 2/2] don't reselect frozen coins --- .../unspent_coins/unspent_coins_list_view_model.dart | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/view_model/unspent_coins/unspent_coins_list_view_model.dart b/lib/view_model/unspent_coins/unspent_coins_list_view_model.dart index b4e8eeccad..9a8a4a8f29 100644 --- a/lib/view_model/unspent_coins/unspent_coins_list_view_model.dart +++ b/lib/view_model/unspent_coins/unspent_coins_list_view_model.dart @@ -167,14 +167,12 @@ abstract class UnspentCoinsListViewModelBase with Store { @action void resetUnspentCoinsInfoSelections() { - // reset all unspent coins selections to true + // reset all unspent coins selections to true except frozen ones for (final item in items) { - // if (!item.isSending) { - // item.isSending = true; - // saveUnspentCoinInfo(item); - // } - item.isSending = true; - saveUnspentCoinInfo(item); + if (!item.isFrozen) { + item.isSending = true; + saveUnspentCoinInfo(item); + } } }