CW-766 fix coin freezing (#1751)

* fix coin freezing

* fix frozen balance

* update monero_c hash

* update monero_c hash (after merge)

* fix test E
make it ready

* revert local change

* throw error on wow as well

* experiment with view model code

* move view model into di.dart
This commit is contained in:
cyan
2024-11-27 17:34:36 +02:00
committed by GitHub
parent 9706243c81
commit 87178b2a54
8 changed files with 92 additions and 28 deletions
+1
View File
@@ -746,6 +746,7 @@ Future<void> setup({
_transactionDescriptionBox,
getIt.get<AppStore>().wallet!.isHardwareWallet ? getIt.get<LedgerViewModel>() : null,
coinTypeToSpendFrom: coinTypeToSpendFrom ?? UnspentCoinType.any,
getIt.get<UnspentCoinsListViewModel>(param1: coinTypeToSpendFrom),
),
);
+15 -1
View File
@@ -19,6 +19,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';
@@ -64,6 +65,8 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor
wallet.type == WalletType.tron;
}
UnspentCoinsListViewModel unspentCoinsListViewModel;
SendViewModelBase(
AppStore appStore,
this.sendTemplateViewModel,
@@ -71,7 +74,8 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor
this.balanceViewModel,
this.contactListViewModel,
this.transactionDescriptionBox,
this.ledgerViewModel, {
this.ledgerViewModel,
this.unspentCoinsListViewModel, {
this.coinTypeToSpendFrom = UnspentCoinType.any,
}) : state = InitialExecutionState(),
currencies = appStore.wallet!.balance.keys.toList(),
@@ -530,6 +534,16 @@ abstract class SendViewModelBase extends WalletChangeListenerViewModel with Stor
throw Exception('Priority is null for wallet type: ${wallet.type}');
}
if (hasCoinControl) {
bool isCoinSelected = false;
for (var coin in unspentCoinsListViewModel.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: