Fix testnet (#1632)
* fix: failed connection and misc changes * default isTestnet to false --------- Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
Rafael committed
Aug 21, 2024 at 19:31 UTC
c0e0cf02aa582e477d0602156a3b01fb4c9db771
6 files changed
+15
-11
cw_bitcoin/lib/electrum.dart
+4
-2
@@ -119,9 +119,11 @@ class ElectrumClient {
119
_setConnectionStatus(ConnectionStatus.failed);
120
},
121
onDone: () {
122
- socket = null;
122
unterminatedString = '';
124
- if (host == socket?.address.host) _setConnectionStatus(ConnectionStatus.disconnected);
123
+ if (host == socket?.address.host) {
124
+ socket = null;
125
+ _setConnectionStatus(ConnectionStatus.disconnected);
126
+ }
127
},
128
cancelOnError: true,
129
);
cw_bitcoin/lib/electrum_wallet.dart
+7
-5
@@ -42,7 +42,6 @@ import 'package:flutter/foundation.dart';
42
import 'package:hive/hive.dart';
43
import 'package:mobx/mobx.dart';
44
import 'package:rxdart/subjects.dart';
45
-import 'package:http/http.dart' as http;
45
import 'package:sp_scanner/sp_scanner.dart';
46
47
part 'electrum_wallet.g.dart';
@@ -89,7 +88,7 @@ abstract class ElectrumWalletBase
88
}
89
: {}),
90
this.unspentCoinsInfo = unspentCoinsInfo,
92
- this.isTestnet = network == BitcoinNetwork.testnet,
91
+ this.isTestnet = !network.isMainnet,
92
this._mnemonic = mnemonic,
93
super(walletInfo) {
94
this.electrumClient = electrumClient ?? ElectrumClient();
@@ -182,7 +181,7 @@ abstract class ElectrumWalletBase
181
BasedUtxoNetwork network;
182
183
@override
185
- bool? isTestnet;
184
+ bool isTestnet;
185
186
bool get hasSilentPaymentsScanning => type == WalletType.bitcoin;
187
@@ -426,7 +425,7 @@ abstract class ElectrumWalletBase
425
await updateTransactions();
426
await updateAllUnspents();
427
await updateBalance();
429
- updateFeeRates();
428
+ await updateFeeRates();
429
430
_updateFeeRateTimer ??=
431
Timer.periodic(const Duration(minutes: 1), (timer) async => await updateFeeRates());
@@ -448,6 +447,8 @@ abstract class ElectrumWalletBase
447
final feeRates = await electrumClient.feeRates(network: network);
448
if (feeRates != [0, 0, 0]) {
449
_feeRates = feeRates;
450
+ } else if (isTestnet) {
451
+ _feeRates = [1, 1, 1];
452
}
453
}
454
@@ -1944,8 +1945,9 @@ abstract class ElectrumWalletBase
1945
Future<void> _setInitialHeight() async {
1946
if (_chainTipUpdateSubject != null) return;
1947
1948
+ _currentChainTip = await getUpdatedChainTip();
1949
+
1950
if ((_currentChainTip == null || _currentChainTip! == 0) && walletInfo.restoreHeight == 0) {
1948
- await getUpdatedChainTip();
1951
await walletInfo.updateRestoreHeight(_currentChainTip!);
1952
}
1953
cw_core/lib/wallet_base.dart
+1
-1
@@ -95,5 +95,5 @@ abstract class WalletBase<BalanceType extends Balance, HistoryType extends Trans
95
96
Future<bool> verifyMessage(String message, String signature, {String? address = null});
97
98
- bool? isTestnet;
98
+ bool isTestnet = false;
99
}
lib/bitcoin/cw_bitcoin.dart
+1
-1
@@ -516,7 +516,7 @@ class CWBitcoin extends Bitcoin {
516
@override
517
bool isTestnet(Object wallet) {
518
final bitcoinWallet = wallet as ElectrumWallet;
519
- return bitcoinWallet.isTestnet ?? false;
519
+ return bitcoinWallet.isTestnet;
520
}
521
522
@override
lib/view_model/node_list/node_list_view_model.dart
+1
-1
@@ -52,7 +52,7 @@ abstract class NodeListViewModelBase with Store {
52
53
switch (_appStore.wallet!.type) {
54
case WalletType.bitcoin:
55
- if (_appStore.wallet!.isTestnet == true) {
55
+ if (_appStore.wallet!.isTestnet) {
56
node = getBitcoinTestnetDefaultElectrumServer(nodes: _nodeSource)!;
57
} else {
58
node = getBitcoinDefaultElectrumServer(nodes: _nodeSource)!;
lib/view_model/transaction_details_view_model.dart
+1
-1
@@ -152,7 +152,7 @@ abstract class TransactionDetailsViewModelBase with Store {
152
case WalletType.monero:
153
return 'https://monero.com/tx/${txId}';
154
case WalletType.bitcoin:
155
- return 'https://mempool.space/${wallet.isTestnet == true ? "testnet/" : ""}tx/${txId}';
155
+ return 'https://mempool.space/${wallet.isTestnet ? "testnet/" : ""}tx/${txId}';
156
case WalletType.litecoin:
157
return 'https://blockchair.com/litecoin/transaction/${txId}';
158
case WalletType.bitcoinCash: