Fix electrum unspent coins error (#1912)

* Refresh unspent coins before creating a transaction * disable seed verification in debug mode [skip ci]

Omar Hatem committed Dec 29, 2024 at 23:48 UTC 214fc7113c4a865029a38942cb0dadca9947dbe7
4 files changed +13 -5
cw_bitcoin/lib/electrum_wallet.dart
+3 -1
@@ -4,7 +4,6 @@ import 'dart:io';
4 import 'dart:isolate';
5
6 import 'package:bitcoin_base/bitcoin_base.dart';
7 -import 'package:cw_bitcoin/litecoin_wallet_addresses.dart';
7 import 'package:cw_core/utils/print_verbose.dart';
8 import 'package:cw_bitcoin/bitcoin_wallet.dart';
9 import 'package:cw_bitcoin/litecoin_wallet.dart';
@@ -991,6 +990,9 @@ abstract class ElectrumWalletBase
990 @override
991 Future<PendingTransaction> createTransaction(Object credentials) async {
992 try {
993 + // start by updating unspent coins
994 + await updateAllUnspents();
995 +
996 final outputs = <BitcoinOutput>[];
997 final transactionCredentials = credentials as BitcoinTransactionCredentials;
998 final hasMultiDestination = transactionCredentials.outputs.length > 1;
lib/src/screens/seed/seed_verification/seed_verification_page.dart
+2 -1
@@ -20,7 +20,8 @@ class SeedVerificationPage extends BasePage {
20 builder: (context) {
21 return Padding(
22 padding: const EdgeInsets.all(16.0),
23 - child: walletSeedViewModel.isVerificationComplete
23 + child: walletSeedViewModel.isVerificationComplete ||
24 + walletSeedViewModel.verificationIndices.isEmpty
25 ? SeedVerificationSuccessView(
26 imageColor: titleColor(context),
27 )
lib/utils/feature_flag.dart
+3 -1
@@ -1,7 +1,9 @@
1 +import 'package:flutter/foundation.dart';
2 +
3 class FeatureFlag {
4 static const bool isCakePayEnabled = false;
5 static const bool isExolixEnabled = true;
6 static const bool isInAppTorEnabled = false;
7 static const bool isBackgroundSyncEnabled = false;
6 - static const int verificationWordsCount = 2;
8 + static const int verificationWordsCount = kDebugMode ? 0 : 2;
9 }
\ No newline at end of file
lib/view_model/wallet_seed_view_model.dart
+5 -2
@@ -29,6 +29,7 @@ abstract class WalletSeedViewModelBase with Store {
29 List<String> get seedSplit => seed.split(RegExp(r'\s+'));
30
31 int get columnCount => seedSplit.length <= 16 ? 2 : 3;
32 +
33 double get columnAspectRatio => seedSplit.length <= 16 ? 1.8 : 2.8;
34
35 /// The indices of the seed to be verified.
@@ -60,8 +61,10 @@ abstract class WalletSeedViewModelBase with Store {
61 bool isVerificationComplete = false;
62
63 void setupSeedVerification() {
63 - generateRandomIndices();
64 - generateOptions();
64 + if (verificationWordCount != 0) {
65 + generateRandomIndices();
66 + generateOptions();
67 + }
68 }
69
70 /// Generate the indices of the seeds to be verified.