update all uiStates whenever we update any of them

except on failure
This commit is contained in:
sneurlax 2023-10-27 11:43:42 -05:00
parent a3ad7b5926
commit c0389d2da7
2 changed files with 147 additions and 71 deletions

View file

@ -52,56 +52,68 @@ class FusionProgressUIState extends ChangeNotifier {
CashFusionState _connecting = CashFusionState _connecting =
CashFusionState(status: CashFusionStatus.waiting, info: null); CashFusionState(status: CashFusionStatus.waiting, info: null);
CashFusionState get connecting => _connecting; CashFusionState get connecting => _connecting;
set connecting(CashFusionState state) { void setConnecting(CashFusionState state, {bool shouldNotify = true}) {
_connecting = state; _connecting = state;
_running = true; _running = true;
if (shouldNotify) {
notifyListeners(); notifyListeners();
} }
}
CashFusionState _outputs = CashFusionState _outputs =
CashFusionState(status: CashFusionStatus.waiting, info: null); CashFusionState(status: CashFusionStatus.waiting, info: null);
CashFusionState get outputs => _outputs; CashFusionState get outputs => _outputs;
set outputs(CashFusionState state) { void setOutputs(CashFusionState state, {bool shouldNotify = true}) {
_outputs = state; _outputs = state;
_running = true; _running = true;
if (shouldNotify) {
notifyListeners(); notifyListeners();
} }
}
CashFusionState _peers = CashFusionState _peers =
CashFusionState(status: CashFusionStatus.waiting, info: null); CashFusionState(status: CashFusionStatus.waiting, info: null);
CashFusionState get peers => _peers; CashFusionState get peers => _peers;
set peers(CashFusionState state) { void setPeers(CashFusionState state, {bool shouldNotify = true}) {
_peers = state; _peers = state;
_running = true; _running = true;
if (shouldNotify) {
notifyListeners(); notifyListeners();
} }
}
CashFusionState _fusing = CashFusionState _fusing =
CashFusionState(status: CashFusionStatus.waiting, info: null); CashFusionState(status: CashFusionStatus.waiting, info: null);
CashFusionState get fusing => _fusing; CashFusionState get fusing => _fusing;
set fusing(CashFusionState state) { void setFusing(CashFusionState state, {bool shouldNotify = true}) {
_fusing = state; _fusing = state;
_updateRunningState(state.status); _running = true;
if (shouldNotify) {
notifyListeners(); notifyListeners();
} }
}
CashFusionState _complete = CashFusionState _complete =
CashFusionState(status: CashFusionStatus.waiting, info: null); CashFusionState(status: CashFusionStatus.waiting, info: null);
CashFusionState get complete => _complete; CashFusionState get complete => _complete;
set complete(CashFusionState state) { void setComplete(CashFusionState state, {bool shouldNotify = true}) {
_complete = state; _complete = state;
_updateRunningState(state.status); _running = true;
if (shouldNotify) {
notifyListeners(); notifyListeners();
} }
}
CashFusionState _fusionStatus = CashFusionState _fusionStatus =
CashFusionState(status: CashFusionStatus.waiting, info: null); CashFusionState(status: CashFusionStatus.waiting, info: null);
CashFusionState get fusionState => _fusionStatus; CashFusionState get fusionState => _fusionStatus;
set fusionState(CashFusionState state) { void setFusionState(CashFusionState state, {bool shouldNotify = true}) {
_fusionStatus = state; _fusionStatus = state;
_updateRunningState(state.status); _updateRunningState(state.status);
if (shouldNotify) {
notifyListeners(); notifyListeners();
} }
}
/// An int storing the number of successfully completed fusion rounds. /// An int storing the number of successfully completed fusion rounds.
int _fusionRoundsCompleted = 0; int _fusionRoundsCompleted = 0;
@ -141,18 +153,22 @@ class FusionProgressUIState extends ChangeNotifier {
/// Used to be named maxConsecutiveFusionRoundsFailed. /// Used to be named maxConsecutiveFusionRoundsFailed.
bool _failed = false; bool _failed = false;
bool get failed => _failed; bool get failed => _failed;
set failed(bool failed) { void setFailed(bool failed, {bool shouldNotify = true}) {
_failed = failed; _failed = failed;
if (shouldNotify) {
notifyListeners(); notifyListeners();
} }
}
/// A flag indicating that fusion is running. /// A flag indicating that fusion is running.
bool _running = false; bool _running = false;
bool get running => _running; bool get running => _running;
set running(bool running) { void setRunning(bool running, {bool shouldNotify = true}) {
_running = running; _running = running;
if (shouldNotify) {
notifyListeners(); notifyListeners();
} }
}
/// A helper method for setting the running flag. /// A helper method for setting the running flag.
/// ///

View file

@ -184,63 +184,118 @@ mixin FusionWalletInterface {
void _updateStatus({required fusion.FusionStatus status, String? info}) { void _updateStatus({required fusion.FusionStatus status, String? info}) {
switch (status) { switch (status) {
case fusion.FusionStatus.connecting: case fusion.FusionStatus.connecting:
_uiState?.connecting = CashFusionState( _uiState?.setConnecting(
status: CashFusionStatus.running, CashFusionState(status: CashFusionStatus.running, info: null),
info: shouldNotify: false);
null); // We only want to show error messages for failed states. _uiState?.setOutputs(
CashFusionState(status: CashFusionStatus.waiting, info: null),
shouldNotify: false);
_uiState?.setPeers(
CashFusionState(status: CashFusionStatus.waiting, info: null),
shouldNotify: false);
_uiState?.setFusing(
CashFusionState(status: CashFusionStatus.waiting, info: null),
shouldNotify: false);
_uiState?.setComplete(
CashFusionState(status: CashFusionStatus.waiting, info: null),
shouldNotify: true);
break; break;
case fusion.FusionStatus.setup: case fusion.FusionStatus.setup:
_uiState?.connecting = _uiState?.setConnecting(
CashFusionState(status: CashFusionStatus.success, info: null); CashFusionState(status: CashFusionStatus.success, info: null),
_uiState?.outputs = shouldNotify: false);
CashFusionState(status: CashFusionStatus.running, info: null); _uiState?.setOutputs(
CashFusionState(status: CashFusionStatus.running, info: null),
shouldNotify: false);
_uiState?.setPeers(
CashFusionState(status: CashFusionStatus.waiting, info: null),
shouldNotify: false);
_uiState?.setFusing(
CashFusionState(status: CashFusionStatus.waiting, info: null),
shouldNotify: false);
_uiState?.setComplete(
CashFusionState(status: CashFusionStatus.waiting, info: null),
shouldNotify: true);
break; break;
case fusion.FusionStatus.waiting: case fusion.FusionStatus.waiting:
_uiState?.outputs = _uiState?.setConnecting(
CashFusionState(status: CashFusionStatus.success, info: null); CashFusionState(status: CashFusionStatus.success, info: null),
_uiState?.peers = shouldNotify: false);
CashFusionState(status: CashFusionStatus.running, info: null); _uiState?.setOutputs(
CashFusionState(status: CashFusionStatus.success, info: null),
shouldNotify: false);
_uiState?.setPeers(
CashFusionState(status: CashFusionStatus.running, info: null),
shouldNotify: false);
_uiState?.setFusing(
CashFusionState(status: CashFusionStatus.waiting, info: null),
shouldNotify: false);
_uiState?.setComplete(
CashFusionState(status: CashFusionStatus.waiting, info: null),
shouldNotify: true);
break; break;
case fusion.FusionStatus.running: case fusion.FusionStatus.running:
_uiState?.peers = _uiState?.setConnecting(
CashFusionState(status: CashFusionStatus.success, info: null); CashFusionState(status: CashFusionStatus.success, info: null),
_uiState?.fusing = shouldNotify: false);
CashFusionState(status: CashFusionStatus.running, info: null); _uiState?.setOutputs(
CashFusionState(status: CashFusionStatus.success, info: null),
shouldNotify: false);
_uiState?.setPeers(
CashFusionState(status: CashFusionStatus.success, info: null),
shouldNotify: false);
_uiState?.setFusing(
CashFusionState(status: CashFusionStatus.running, info: null),
shouldNotify: false);
_uiState?.setComplete(
CashFusionState(status: CashFusionStatus.waiting, info: null),
shouldNotify: true);
break; break;
case fusion.FusionStatus.complete: case fusion.FusionStatus.complete:
_uiState?.fusing = _uiState?.setConnecting(
CashFusionState(status: CashFusionStatus.success, info: null); CashFusionState(status: CashFusionStatus.success, info: null),
_uiState?.complete = shouldNotify: false);
CashFusionState(status: CashFusionStatus.success, info: null); _uiState?.setOutputs(
CashFusionState(status: CashFusionStatus.success, info: null),
shouldNotify: false);
_uiState?.setPeers(
CashFusionState(status: CashFusionStatus.success, info: null),
shouldNotify: false);
_uiState?.setFusing(
CashFusionState(status: CashFusionStatus.success, info: null),
shouldNotify: false);
_uiState?.setComplete(
CashFusionState(status: CashFusionStatus.success, info: null),
shouldNotify: true);
break; break;
case fusion.FusionStatus.failed: case fusion.FusionStatus.failed:
// _uiState?.fusing = CashFusionStatus.failed;
// _uiState?.complete =
// CashFusionState(status: CashFusionStatus.failed, info: info);
failCurrentUiState(info); failCurrentUiState(info);
break; break;
case fusion.FusionStatus.exception: case fusion.FusionStatus.exception:
// _uiState?.complete =
// CashFusionState(status: CashFusionStatus.failed, info: info);
failCurrentUiState(info); failCurrentUiState(info);
break; break;
case fusion.FusionStatus.reset: case fusion.FusionStatus.reset:
_uiState?.outputs = _uiState?.setConnecting(
CashFusionState(status: CashFusionStatus.waiting, info: info); CashFusionState(status: CashFusionStatus.waiting, info: info),
_uiState?.peers = shouldNotify: false);
CashFusionState(status: CashFusionStatus.waiting, info: info); _uiState?.setOutputs(
_uiState?.connecting = CashFusionState(status: CashFusionStatus.waiting, info: info),
CashFusionState(status: CashFusionStatus.waiting, info: info); shouldNotify: false);
_uiState?.fusing = _uiState?.setPeers(
CashFusionState(status: CashFusionStatus.waiting, info: info); CashFusionState(status: CashFusionStatus.waiting, info: info),
_uiState?.complete = shouldNotify: false);
CashFusionState(status: CashFusionStatus.waiting, info: info); _uiState?.setFusing(
_uiState?.fusionState = CashFusionState(status: CashFusionStatus.waiting, info: info),
CashFusionState(status: CashFusionStatus.waiting, info: info); shouldNotify: false);
_uiState?.failed = false; _uiState?.setComplete(
CashFusionState(status: CashFusionStatus.waiting, info: info),
shouldNotify: false);
_uiState?.setFusionState(
CashFusionState(status: CashFusionStatus.waiting, info: info),
shouldNotify: false);
_uiState?.setFailed(false, shouldNotify: true);
break; break;
} }
} }
@ -248,28 +303,33 @@ mixin FusionWalletInterface {
void failCurrentUiState(String? info) { void failCurrentUiState(String? info) {
// Check each _uiState value to see if it is running. If so, set it to failed. // Check each _uiState value to see if it is running. If so, set it to failed.
if (_uiState?.connecting.status == CashFusionStatus.running) { if (_uiState?.connecting.status == CashFusionStatus.running) {
_uiState?.connecting = _uiState?.setConnecting(
CashFusionState(status: CashFusionStatus.failed, info: info); CashFusionState(status: CashFusionStatus.failed, info: info),
shouldNotify: true);
return; return;
} }
if (_uiState?.outputs.status == CashFusionStatus.running) { if (_uiState?.outputs.status == CashFusionStatus.running) {
_uiState?.outputs = _uiState?.setOutputs(
CashFusionState(status: CashFusionStatus.failed, info: info); CashFusionState(status: CashFusionStatus.failed, info: info),
shouldNotify: true);
return; return;
} }
if (_uiState?.peers.status == CashFusionStatus.running) { if (_uiState?.peers.status == CashFusionStatus.running) {
_uiState?.peers = _uiState?.setPeers(
CashFusionState(status: CashFusionStatus.failed, info: info); CashFusionState(status: CashFusionStatus.failed, info: info),
shouldNotify: true);
return; return;
} }
if (_uiState?.fusing.status == CashFusionStatus.running) { if (_uiState?.fusing.status == CashFusionStatus.running) {
_uiState?.fusing = _uiState?.setFusing(
CashFusionState(status: CashFusionStatus.failed, info: info); CashFusionState(status: CashFusionStatus.failed, info: info),
shouldNotify: true);
return; return;
} }
if (_uiState?.complete.status == CashFusionStatus.running) { if (_uiState?.complete.status == CashFusionStatus.running) {
_uiState?.complete = _uiState?.setComplete(
CashFusionState(status: CashFusionStatus.failed, info: info); CashFusionState(status: CashFusionStatus.failed, info: info),
shouldNotify: true);
return; return;
} }
} }
@ -656,7 +716,7 @@ mixin FusionWalletInterface {
status: fusion.FusionStatus.failed, status: fusion.FusionStatus.failed,
info: "Failed $maxFailedFuseCount times in a row, stopping."); info: "Failed $maxFailedFuseCount times in a row, stopping.");
_stopRequested = true; _stopRequested = true;
_uiState?.failed = true; _uiState?.setFailed(true, shouldNotify: true);
} }
} }
} }
@ -669,7 +729,7 @@ mixin FusionWalletInterface {
// Stop the fusion process and update the UI state. // Stop the fusion process and update the UI state.
await _mainFusionObject?.stop(); await _mainFusionObject?.stop();
_mainFusionObject = null; _mainFusionObject = null;
_uiState?.running = false; _uiState?.setRunning(false, shouldNotify: true);
} }
} }