From 86a3b6d65d96b74be1667d7a93dbba0d998b983a Mon Sep 17 00:00:00 2001 From: Konstantin Ullrich Date: Thu, 7 Nov 2024 12:21:02 +0100 Subject: [PATCH] Minor cleanup --- cw_bitcoin/lib/electrum_wallet.dart | 17 +++++++------- cw_core/lib/sync_status.dart | 35 +++++++++++++---------------- 2 files changed, 24 insertions(+), 28 deletions(-) diff --git a/cw_bitcoin/lib/electrum_wallet.dart b/cw_bitcoin/lib/electrum_wallet.dart index c05095cf1..5597ddc99 100644 --- a/cw_bitcoin/lib/electrum_wallet.dart +++ b/cw_bitcoin/lib/electrum_wallet.dart @@ -582,6 +582,8 @@ abstract class ElectrumWalletBase extends WalletBase< Future connectToNode({required Node node}) async { this.node = node; + // if (syncStatus is ConnectingSyncStatus || syn) return; + try { syncStatus = ConnectingSyncStatus(); @@ -2090,7 +2092,7 @@ abstract class ElectrumWalletBase extends WalletBase< }); } - final balances = await Future.wait(balanceFutures); + final balances = await Future.wait(balanceFutures); // ToDo: add onError ignore failed balances for (var i = 0; i < balances.length; i++) { final addressRecord = addresses[i]; @@ -2229,13 +2231,14 @@ abstract class ElectrumWalletBase extends WalletBase< if (syncStatus is NotConnectedSyncStatus || syncStatus is LostConnectionSyncStatus || syncStatus is ConnectingSyncStatus) { - syncStatus = AttemptingSyncStatus(); - startSync(); + syncStatus = ConnectedSyncStatus(); } break; case ConnectionStatus.disconnected: - if (syncStatus is! NotConnectedSyncStatus) { + if (syncStatus is! NotConnectedSyncStatus && + syncStatus is! ConnectingSyncStatus && + syncStatus is! SyncronizingSyncStatus) { syncStatus = NotConnectedSyncStatus(); } break; @@ -2292,10 +2295,8 @@ abstract class ElectrumWalletBase extends WalletBase< void _updateInputsAndOutputs(ElectrumTransactionInfo tx, ElectrumTransactionBundle bundle) { tx.inputAddresses = tx.inputAddresses?.where((address) => address.isNotEmpty).toList(); - if (tx.inputAddresses == null || - tx.inputAddresses!.isEmpty || - tx.outputAddresses == null || - tx.outputAddresses!.isEmpty) { + if (tx.inputAddresses?.isNotEmpty != true || + tx.outputAddresses?.isNotEmpty != true) { List inputAddresses = []; List outputAddresses = []; diff --git a/cw_core/lib/sync_status.dart b/cw_core/lib/sync_status.dart index 7d6b0a285..aa3edf5c8 100644 --- a/cw_core/lib/sync_status.dart +++ b/cw_core/lib/sync_status.dart @@ -1,13 +1,5 @@ abstract class SyncStatus { const SyncStatus(); - double progress(); -} - -class StartingScanSyncStatus extends SyncStatus { - StartingScanSyncStatus(this.beginHeight); - - final int beginHeight; - @override double progress() => 0.0; } @@ -39,16 +31,25 @@ class SyncedSyncStatus extends SyncStatus { double progress() => 1.0; } +/// =========================================================================== + +abstract class ScanSyncStatus extends SyncStatus {} + +class StartingScanSyncStatus extends SyncStatus { + StartingScanSyncStatus(this.beginHeight); + + final int beginHeight; +} + class SyncedTipSyncStatus extends SyncedSyncStatus { SyncedTipSyncStatus(this.tip); final int tip; } -class SyncronizingSyncStatus extends SyncStatus { - @override - double progress() => 0.0; -} +/// =========================================================================== + +class SyncronizingSyncStatus extends SyncStatus {} class NotConnectedSyncStatus extends SyncStatus { const NotConnectedSyncStatus(); @@ -75,15 +76,9 @@ class FailedSyncStatus extends NotConnectedSyncStatus { String toString() => error ?? super.toString(); } -class ConnectingSyncStatus extends SyncStatus { - @override - double progress() => 0.0; -} +class ConnectingSyncStatus extends SyncStatus {} -class ConnectedSyncStatus extends SyncStatus { - @override - double progress() => 0.0; -} +class ConnectedSyncStatus extends SyncStatus {} class UnsupportedSyncStatus extends NotConnectedSyncStatus {}