Fix testnet (#1632)

* fix: failed connection and misc changes

* default isTestnet to false

---------

Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
This commit is contained in:
Rafael 2024-08-21 19:31:20 -03:00 committed by GitHub
parent 49d2560eb9
commit c0e0cf02aa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 15 additions and 11 deletions

View file

@ -119,9 +119,11 @@ class ElectrumClient {
_setConnectionStatus(ConnectionStatus.failed);
},
onDone: () {
socket = null;
unterminatedString = '';
if (host == socket?.address.host) _setConnectionStatus(ConnectionStatus.disconnected);
if (host == socket?.address.host) {
socket = null;
_setConnectionStatus(ConnectionStatus.disconnected);
}
},
cancelOnError: true,
);

View file

@ -42,7 +42,6 @@ import 'package:flutter/foundation.dart';
import 'package:hive/hive.dart';
import 'package:mobx/mobx.dart';
import 'package:rxdart/subjects.dart';
import 'package:http/http.dart' as http;
import 'package:sp_scanner/sp_scanner.dart';
part 'electrum_wallet.g.dart';
@ -89,7 +88,7 @@ abstract class ElectrumWalletBase
}
: {}),
this.unspentCoinsInfo = unspentCoinsInfo,
this.isTestnet = network == BitcoinNetwork.testnet,
this.isTestnet = !network.isMainnet,
this._mnemonic = mnemonic,
super(walletInfo) {
this.electrumClient = electrumClient ?? ElectrumClient();
@ -182,7 +181,7 @@ abstract class ElectrumWalletBase
BasedUtxoNetwork network;
@override
bool? isTestnet;
bool isTestnet;
bool get hasSilentPaymentsScanning => type == WalletType.bitcoin;
@ -426,7 +425,7 @@ abstract class ElectrumWalletBase
await updateTransactions();
await updateAllUnspents();
await updateBalance();
updateFeeRates();
await updateFeeRates();
_updateFeeRateTimer ??=
Timer.periodic(const Duration(minutes: 1), (timer) async => await updateFeeRates());
@ -448,6 +447,8 @@ abstract class ElectrumWalletBase
final feeRates = await electrumClient.feeRates(network: network);
if (feeRates != [0, 0, 0]) {
_feeRates = feeRates;
} else if (isTestnet) {
_feeRates = [1, 1, 1];
}
}
@ -1944,8 +1945,9 @@ abstract class ElectrumWalletBase
Future<void> _setInitialHeight() async {
if (_chainTipUpdateSubject != null) return;
_currentChainTip = await getUpdatedChainTip();
if ((_currentChainTip == null || _currentChainTip! == 0) && walletInfo.restoreHeight == 0) {
await getUpdatedChainTip();
await walletInfo.updateRestoreHeight(_currentChainTip!);
}

View file

@ -95,5 +95,5 @@ abstract class WalletBase<BalanceType extends Balance, HistoryType extends Trans
Future<bool> verifyMessage(String message, String signature, {String? address = null});
bool? isTestnet;
bool isTestnet = false;
}

View file

@ -516,7 +516,7 @@ class CWBitcoin extends Bitcoin {
@override
bool isTestnet(Object wallet) {
final bitcoinWallet = wallet as ElectrumWallet;
return bitcoinWallet.isTestnet ?? false;
return bitcoinWallet.isTestnet;
}
@override

View file

@ -52,7 +52,7 @@ abstract class NodeListViewModelBase with Store {
switch (_appStore.wallet!.type) {
case WalletType.bitcoin:
if (_appStore.wallet!.isTestnet == true) {
if (_appStore.wallet!.isTestnet) {
node = getBitcoinTestnetDefaultElectrumServer(nodes: _nodeSource)!;
} else {
node = getBitcoinDefaultElectrumServer(nodes: _nodeSource)!;

View file

@ -152,7 +152,7 @@ abstract class TransactionDetailsViewModelBase with Store {
case WalletType.monero:
return 'https://monero.com/tx/${txId}';
case WalletType.bitcoin:
return 'https://mempool.space/${wallet.isTestnet == true ? "testnet/" : ""}tx/${txId}';
return 'https://mempool.space/${wallet.isTestnet ? "testnet/" : ""}tx/${txId}';
case WalletType.litecoin:
return 'https://blockchair.com/litecoin/transaction/${txId}';
case WalletType.bitcoinCash: