From b0d0fec5e4ee4d3a276b9e359646d85e8dd4e978 Mon Sep 17 00:00:00 2001 From: ryleedavis Date: Fri, 22 Sep 2023 16:20:48 -0600 Subject: [PATCH] WIP: fusion progress provider --- lib/models/fusion_progress_state.dart | 44 +++++++++++++++++++++++ lib/models/fusion_progress_ui_state.dart | 46 ++++++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 lib/models/fusion_progress_state.dart diff --git a/lib/models/fusion_progress_state.dart b/lib/models/fusion_progress_state.dart new file mode 100644 index 000000000..a382d71c4 --- /dev/null +++ b/lib/models/fusion_progress_state.dart @@ -0,0 +1,44 @@ +import 'package:flutter/cupertino.dart'; +import 'package:stackwallet/pages_desktop_specific/cashfusion/sub_widgets/fusion_dialog.dart'; +import 'package:stackwallet/services/coins/manager.dart'; +import 'package:stackwallet/utilities/enums/coin_enum.dart'; + +class FusionProgressState extends ChangeNotifier { + final String walletId; + final String walletName; + final Coin coin; + late CashFusionStatus _fusionStatus; + Manager? manager; + String? address; + + CashFusionStatus get fusionState => _fusionStatus; + set fusionState(CashFusionStatus fusionStatus) { + _fusionStatus = fusionStatus; + notifyListeners(); + } + + FusionProgressState({ + required this.walletId, + required this.walletName, + required this.coin, + required CashFusionStatus fusionStatus, + this.manager, + this.address, + }) { + _fusionStatus = fusionStatus; + } + + FusionProgressState copyWith({ + CashFusionStatus? fusionStatus, + String? address, + }) { + return FusionProgressState( + walletId: walletId, + walletName: walletName, + coin: coin, + fusionStatus: fusionStatus ?? _fusionStatus, + manager: manager, + address: this.address, + ); + } +} diff --git a/lib/models/fusion_progress_ui_state.dart b/lib/models/fusion_progress_ui_state.dart index 86bb558e1..1fbf1f7fd 100644 --- a/lib/models/fusion_progress_ui_state.dart +++ b/lib/models/fusion_progress_ui_state.dart @@ -1,6 +1,8 @@ import 'package:flutter/cupertino.dart'; import 'package:stackwallet/pages_desktop_specific/cashfusion/sub_widgets/fusion_dialog.dart'; +import 'fusion_progress_state.dart'; + class FusionProgressUIState extends ChangeNotifier { bool _ableToConnect = false; @@ -19,9 +21,33 @@ class FusionProgressUIState extends ChangeNotifier { (_fusing == CashFusionStatus.failed); _done &= (_complete == CashFusionStatus.success) || (_complete == CashFusionStatus.failed); + + // for (final wallet in _walletStates.values) { + // _done &= (wallet.restoringState == CashFusionStatus.success) || + // (wallet.restoringState == CashFusionStatus.failed); + // } + return _done; } + bool get succeeded { + if (!_ableToConnect) { + return false; + } + + bool _succeeded = _connecting == CashFusionStatus.success; + _succeeded &= _outputs == CashFusionStatus.success; + _succeeded &= _peers == CashFusionStatus.success; + _succeeded &= _fusing == CashFusionStatus.success; + _succeeded &= _complete == CashFusionStatus.success; + + // for (final wallet in _walletStates.values) { + // _succeeded &= wallet.restoringState == StackRestoringStatus.success; + // } + + return _succeeded; + } + CashFusionStatus _connecting = CashFusionStatus.waiting; CashFusionStatus get connecting => _connecting; set connecting(CashFusionStatus state) { @@ -56,4 +82,24 @@ class FusionProgressUIState extends ChangeNotifier { _complete = state; notifyListeners(); } + + // List get managers { + // List _managers = []; + // for (final item in _walletStates.values) { + // if (item.manager != null) { + // _managers.add(item.manager!); + // } + // } + // return _managers; + // } + + Map _fusionState = {}; + set fusionState(Map state) { + _fusionState = state; + // _fusionStateProviders = {}; + // for (final wallet in _fusionState.values) { + // _fusionStateProviders[wallet.walletId] = + // ChangeNotifierProvider((_) => wallet); + // } + } }