cake_wallet/cw_core/lib/sync_status.dart
Matthew Fosse 37b822b7f5
Mweb enhancements (#1715)
* node peer enhancement, delay mweb address generation, increase logging

* prevent unnecessary sync status changes if we can't connect to the ltc node

* handle potential errors

* set nodeUri to null for testing

* [skip ci] redo good changes

* [skip ci] draft

* [skip ci] minor

* [skip ci] cleanup

* [skip ci] minor

* [skip ci] minor

* [skip ci] localization

* [skip ci] save

* [skip ci] wip

* use proxy layer

* ui

* minor changes
Add ToDos for later

* fixes

* [skip ci] minor

* [skip ci] minor

* [skip ci] ui

* handle case where there are no addresses with txcount > 0

* comment out pegin button

---------

Co-authored-by: OmarHatem <omarh.ismail1@gmail.com>
2024-10-05 03:30:52 +03:00

98 lines
2.1 KiB
Dart

abstract class SyncStatus {
const SyncStatus();
double progress();
}
class StartingScanSyncStatus extends SyncStatus {
StartingScanSyncStatus(this.beginHeight);
final int beginHeight;
@override
double progress() => 0.0;
}
class SyncingSyncStatus extends SyncStatus {
SyncingSyncStatus(this.blocksLeft, this.ptc);
final double ptc;
final int blocksLeft;
@override
double progress() => ptc;
@override
String toString() => '$blocksLeft';
factory SyncingSyncStatus.fromHeightValues(int chainTip, int initialSyncHeight, int syncHeight) {
final track = chainTip - initialSyncHeight;
final diff = track - (chainTip - syncHeight);
final ptc = diff <= 0 ? 0.0 : diff / track;
final left = chainTip - syncHeight;
// sum 1 because if at the chain tip, will say "0 blocks left"
return SyncingSyncStatus(left + 1, ptc);
}
}
class SyncedSyncStatus extends SyncStatus {
@override
double progress() => 1.0;
}
class SyncedTipSyncStatus extends SyncedSyncStatus {
SyncedTipSyncStatus(this.tip);
final int tip;
}
class SyncronizingSyncStatus extends SyncStatus {
@override
double progress() => 0.0;
}
class NotConnectedSyncStatus extends SyncStatus {
const NotConnectedSyncStatus();
@override
double progress() => 0.0;
}
class AttemptingSyncStatus extends SyncStatus {
@override
double progress() => 0.0;
}
class AttemptingScanSyncStatus extends SyncStatus {
@override
double progress() => 0.0;
}
class FailedSyncStatus extends NotConnectedSyncStatus {
String? error;
FailedSyncStatus({this.error});
@override
String toString() => error ?? super.toString();
}
class ConnectingSyncStatus extends SyncStatus {
@override
double progress() => 0.0;
}
class ConnectedSyncStatus extends SyncStatus {
@override
double progress() => 0.0;
}
class UnsupportedSyncStatus extends NotConnectedSyncStatus {}
class TimedOutSyncStatus extends NotConnectedSyncStatus {
@override
String toString() => 'Timed out';
}
class LostConnectionSyncStatus extends NotConnectedSyncStatus {
@override
String toString() => 'Reconnecting';
}