From 337de9fd11c7ec215359e3728684bf0c6b74e6cb Mon Sep 17 00:00:00 2001 From: ryleedavis Date: Tue, 26 Sep 2023 09:30:31 -0600 Subject: [PATCH] WIP: fusion progress provider --- lib/models/fusion_progress_ui_state.dart | 76 ++++++++++++++----- .../cashfusion/desktop_cashfusion_view.dart | 4 + 2 files changed, 59 insertions(+), 21 deletions(-) diff --git a/lib/models/fusion_progress_ui_state.dart b/lib/models/fusion_progress_ui_state.dart index 1fbf1f7fd..79faeef36 100644 --- a/lib/models/fusion_progress_ui_state.dart +++ b/lib/models/fusion_progress_ui_state.dart @@ -1,5 +1,7 @@ import 'package:flutter/cupertino.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:stackwallet/pages_desktop_specific/cashfusion/sub_widgets/fusion_dialog.dart'; +import 'package:stackwallet/services/coins/manager.dart'; import 'fusion_progress_state.dart'; @@ -22,10 +24,10 @@ class FusionProgressUIState extends ChangeNotifier { _done &= (_complete == CashFusionStatus.success) || (_complete == CashFusionStatus.failed); - // for (final wallet in _walletStates.values) { - // _done &= (wallet.restoringState == CashFusionStatus.success) || - // (wallet.restoringState == CashFusionStatus.failed); - // } + for (final wallet in _fusionState.values) { + _done &= (wallet.fusionState == CashFusionStatus.success) || + (wallet.fusionState == CashFusionStatus.failed); + } return _done; } @@ -41,9 +43,9 @@ class FusionProgressUIState extends ChangeNotifier { _succeeded &= _fusing == CashFusionStatus.success; _succeeded &= _complete == CashFusionStatus.success; - // for (final wallet in _walletStates.values) { - // _succeeded &= wallet.restoringState == StackRestoringStatus.success; - // } + for (final wallet in _fusionState.values) { + _succeeded &= wallet.fusionState == CashFusionStatus.success; + } return _succeeded; } @@ -83,23 +85,55 @@ class FusionProgressUIState extends ChangeNotifier { notifyListeners(); } - // List get managers { - // List _managers = []; - // for (final item in _walletStates.values) { - // if (item.manager != null) { - // _managers.add(item.manager!); - // } - // } - // return _managers; - // } + List get managers { + List _managers = []; + for (final item in _fusionState.values) { + if (item.manager != null) { + _managers.add(item.manager!); + } + } + return _managers; + } Map _fusionState = {}; + Map> + _fusionStateProviders = {}; + Map> + get fusionStateProviders => _fusionStateProviders; + set fusionState(Map state) { _fusionState = state; - // _fusionStateProviders = {}; - // for (final wallet in _fusionState.values) { - // _fusionStateProviders[wallet.walletId] = - // ChangeNotifierProvider((_) => wallet); - // } + _fusionStateProviders = {}; + for (final wallet in _fusionState.values) { + _fusionStateProviders[wallet.walletId] = + ChangeNotifierProvider((_) => wallet); + } + + /// todo: is this true + _ableToConnect = true; + notifyListeners(); + } + + FusionProgressState getFusionProgressState(String walletId) { + return _fusionState[walletId]!; + } + + ChangeNotifierProvider getFusionProgressStateProvider( + String walletId) { + return _fusionStateProviders[walletId]!; + } + + void update({ + required String walletId, + required CashFusionStatus fusionStatus, + Manager? manager, + String? address, + }) { + _fusionState[walletId]!.fusionState = fusionStatus; + _fusionState[walletId]!.manager = + manager ?? _fusionState[walletId]!.manager; + _fusionState[walletId]!.address = + address ?? _fusionState[walletId]!.address; + notifyListeners(); } } diff --git a/lib/pages_desktop_specific/cashfusion/desktop_cashfusion_view.dart b/lib/pages_desktop_specific/cashfusion/desktop_cashfusion_view.dart index 7b63b6f3f..8f93a2a70 100644 --- a/lib/pages_desktop_specific/cashfusion/desktop_cashfusion_view.dart +++ b/lib/pages_desktop_specific/cashfusion/desktop_cashfusion_view.dart @@ -634,6 +634,10 @@ class _DesktopCashFusion extends ConsumerState { // .wallet as FusionWalletInterface) // .fuse(); + // have nullable of variable type that can be set or unset; of notifier + // when pressed, grab wallet as wallet id + // add to fusion wallet interface and connect to provider + await showDialog( context: context, builder: (context) {