From 8597ab765264dd1818c6ad71fa63a51f8c2464d1 Mon Sep 17 00:00:00 2001 From: Czarek Nakamoto Date: Sun, 20 Oct 2024 18:58:49 +0200 Subject: [PATCH] experiment with view model code --- lib/view_model/send/send_view_model.dart | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/view_model/send/send_view_model.dart b/lib/view_model/send/send_view_model.dart index 0ad8ba376..3629dc898 100644 --- a/lib/view_model/send/send_view_model.dart +++ b/lib/view_model/send/send_view_model.dart @@ -1,3 +1,4 @@ +import 'package:cake_wallet/di.dart'; import 'package:cake_wallet/entities/contact.dart'; import 'package:cake_wallet/entities/priority_for_wallet_type.dart'; import 'package:cake_wallet/entities/transaction_description.dart'; @@ -16,6 +17,7 @@ import 'package:cake_wallet/tron/tron.dart'; import 'package:cake_wallet/view_model/contact_list/contact_list_view_model.dart'; import 'package:cake_wallet/view_model/dashboard/balance_view_model.dart'; import 'package:cake_wallet/view_model/hardware_wallet/ledger_view_model.dart'; +import 'package:cake_wallet/view_model/unspent_coins/unspent_coins_list_view_model.dart'; import 'package:cake_wallet/wownero/wownero.dart'; import 'package:cw_core/exceptions.dart'; import 'package:cw_core/transaction_info.dart'; @@ -501,6 +503,17 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor throw Exception('Priority is null for wallet type: ${wallet.type}'); } + if (hasCoinControl) { + final vm = getIt.get(param1: coinTypeToSpendFrom); + bool isCoinSelected = false; + for (var coin in vm.items) { + isCoinSelected = isCoinSelected || (coin.isSending && !coin.isFrozen); + } + if (!isCoinSelected) { + throw Exception("No coin selected in coin control, you need to select a coin in order to spend"); + } + } + switch (wallet.type) { case WalletType.bitcoin: case WalletType.litecoin: