mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-12-31 15:59:26 +00:00
Simplify fusion_progress_ui_state.dart to work with .family provider, and WIP hook it up to the fusion wallet interface
This commit is contained in:
parent
693255a2c0
commit
bc0f182b0b
6 changed files with 69 additions and 128 deletions
|
@ -1,44 +0,0 @@
|
|||
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,
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,12 +1,8 @@
|
|||
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';
|
||||
|
||||
class FusionProgressUIState extends ChangeNotifier {
|
||||
bool _ableToConnect = false;
|
||||
bool _ableToConnect = true; // set to true for now
|
||||
|
||||
bool get done {
|
||||
if (!_ableToConnect) {
|
||||
|
@ -24,10 +20,8 @@ class FusionProgressUIState extends ChangeNotifier {
|
|||
_done &= (_complete == CashFusionStatus.success) ||
|
||||
(_complete == CashFusionStatus.failed);
|
||||
|
||||
for (final wallet in _fusionState.values) {
|
||||
_done &= (wallet.fusionState == CashFusionStatus.success) ||
|
||||
(wallet.fusionState == CashFusionStatus.failed);
|
||||
}
|
||||
_done &= (fusionState == CashFusionStatus.success) ||
|
||||
(fusionState == CashFusionStatus.failed);
|
||||
|
||||
return _done;
|
||||
}
|
||||
|
@ -43,9 +37,7 @@ class FusionProgressUIState extends ChangeNotifier {
|
|||
_succeeded &= _fusing == CashFusionStatus.success;
|
||||
_succeeded &= _complete == CashFusionStatus.success;
|
||||
|
||||
for (final wallet in _fusionState.values) {
|
||||
_succeeded &= wallet.fusionState == CashFusionStatus.success;
|
||||
}
|
||||
_succeeded &= fusionState == CashFusionStatus.success;
|
||||
|
||||
return _succeeded;
|
||||
}
|
||||
|
@ -85,55 +77,10 @@ class FusionProgressUIState extends ChangeNotifier {
|
|||
notifyListeners();
|
||||
}
|
||||
|
||||
List<Manager> get managers {
|
||||
List<Manager> _managers = [];
|
||||
for (final item in _fusionState.values) {
|
||||
if (item.manager != null) {
|
||||
_managers.add(item.manager!);
|
||||
}
|
||||
}
|
||||
return _managers;
|
||||
}
|
||||
|
||||
Map<String, FusionProgressState> _fusionState = {};
|
||||
Map<String, ChangeNotifierProvider<FusionProgressState>>
|
||||
_fusionStateProviders = {};
|
||||
Map<String, ChangeNotifierProvider<FusionProgressState>>
|
||||
get fusionStateProviders => _fusionStateProviders;
|
||||
|
||||
set fusionState(Map<String, FusionProgressState> state) {
|
||||
_fusionState = state;
|
||||
_fusionStateProviders = {};
|
||||
for (final wallet in _fusionState.values) {
|
||||
_fusionStateProviders[wallet.walletId] =
|
||||
ChangeNotifierProvider<FusionProgressState>((_) => wallet);
|
||||
}
|
||||
|
||||
/// todo: is this true
|
||||
_ableToConnect = true;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
FusionProgressState getFusionProgressState(String walletId) {
|
||||
return _fusionState[walletId]!;
|
||||
}
|
||||
|
||||
ChangeNotifierProvider<FusionProgressState> 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;
|
||||
CashFusionStatus _fusionStatus = CashFusionStatus.waiting;
|
||||
CashFusionStatus get fusionState => _fusionStatus;
|
||||
set fusionState(CashFusionStatus fusionStatus) {
|
||||
_fusionStatus = fusionStatus;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import 'package:flutter_svg/svg.dart';
|
|||
import 'package:stackwallet/pages_desktop_specific/cashfusion/sub_widgets/fusion_dialog.dart';
|
||||
import 'package:stackwallet/pages_desktop_specific/desktop_menu.dart';
|
||||
import 'package:stackwallet/pages_desktop_specific/settings/settings_menu.dart';
|
||||
import 'package:stackwallet/providers/cash_fusion/fusion_progress_ui_state_provider.dart';
|
||||
import 'package:stackwallet/providers/desktop/current_desktop_menu_item.dart';
|
||||
import 'package:stackwallet/providers/global/wallets_provider.dart';
|
||||
import 'package:stackwallet/providers/ui/check_box_state_provider.dart';
|
||||
|
@ -630,20 +631,23 @@ class _DesktopCashFusion extends ConsumerState<DesktopCashFusionView> {
|
|||
PrimaryButton(
|
||||
label: "Start",
|
||||
onPressed: () async {
|
||||
await (ref
|
||||
.read(walletsChangeNotifierProvider)
|
||||
.getManager(widget.walletId)
|
||||
.wallet as FusionWalletInterface)
|
||||
.fuse();
|
||||
final fusionWallet = ref
|
||||
.read(walletsChangeNotifierProvider)
|
||||
.getManager(widget.walletId)
|
||||
.wallet as FusionWalletInterface;
|
||||
|
||||
// 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
|
||||
fusionWallet.uiState = ref.read(
|
||||
fusionProgressUIStateProvider(widget.walletId),
|
||||
);
|
||||
|
||||
await showDialog(
|
||||
unawaited(fusionWallet.fuse());
|
||||
|
||||
await showDialog<void>(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return FusionDialog();
|
||||
return FusionDialog(
|
||||
walletId: widget.walletId,
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
|
|
|
@ -16,8 +16,11 @@ enum CashFusionStatus { waiting, fusing, success, failed }
|
|||
class FusionDialog extends StatelessWidget {
|
||||
const FusionDialog({
|
||||
Key? key,
|
||||
required this.walletId,
|
||||
}) : super(key: key);
|
||||
|
||||
final String walletId;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Widget _getIconForState(CashFusionStatus state) {
|
||||
|
@ -103,8 +106,9 @@ class FusionDialog extends StatelessWidget {
|
|||
height: 20,
|
||||
),
|
||||
Consumer(builder: (_, ref, __) {
|
||||
final state = ref.watch(fusionProgressUIStateProvider
|
||||
.select((value) => value.connecting));
|
||||
final state = ref.watch(
|
||||
fusionProgressUIStateProvider(walletId)
|
||||
.select((value) => value.connecting));
|
||||
return RoundedContainer(
|
||||
padding: EdgeInsets.zero,
|
||||
color:
|
||||
|
@ -143,8 +147,9 @@ class FusionDialog extends StatelessWidget {
|
|||
height: 12,
|
||||
),
|
||||
Consumer(builder: (_, ref, __) {
|
||||
final state = ref.watch(fusionProgressUIStateProvider
|
||||
.select((value) => value.outputs));
|
||||
final state = ref.watch(
|
||||
fusionProgressUIStateProvider(walletId)
|
||||
.select((value) => value.outputs));
|
||||
return RoundedContainer(
|
||||
padding: EdgeInsets.zero,
|
||||
color:
|
||||
|
@ -183,8 +188,9 @@ class FusionDialog extends StatelessWidget {
|
|||
height: 12,
|
||||
),
|
||||
Consumer(builder: (_, ref, __) {
|
||||
final state = ref.watch(fusionProgressUIStateProvider
|
||||
.select((value) => value.peers));
|
||||
final state = ref.watch(
|
||||
fusionProgressUIStateProvider(walletId)
|
||||
.select((value) => value.peers));
|
||||
return RoundedContainer(
|
||||
padding: EdgeInsets.zero,
|
||||
color:
|
||||
|
@ -223,8 +229,9 @@ class FusionDialog extends StatelessWidget {
|
|||
height: 12,
|
||||
),
|
||||
Consumer(builder: (_, ref, __) {
|
||||
final state = ref.watch(fusionProgressUIStateProvider
|
||||
.select((value) => value.fusing));
|
||||
final state = ref.watch(
|
||||
fusionProgressUIStateProvider(walletId)
|
||||
.select((value) => value.fusing));
|
||||
return RoundedContainer(
|
||||
padding: EdgeInsets.zero,
|
||||
color:
|
||||
|
@ -263,8 +270,9 @@ class FusionDialog extends StatelessWidget {
|
|||
height: 12,
|
||||
),
|
||||
Consumer(builder: (_, ref, __) {
|
||||
final state = ref.watch(fusionProgressUIStateProvider
|
||||
.select((value) => value.complete));
|
||||
final state = ref.watch(
|
||||
fusionProgressUIStateProvider(walletId)
|
||||
.select((value) => value.complete));
|
||||
return RoundedContainer(
|
||||
padding: EdgeInsets.zero,
|
||||
color:
|
||||
|
|
|
@ -12,5 +12,8 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|||
import 'package:stackwallet/models/fusion_progress_ui_state.dart';
|
||||
|
||||
final fusionProgressUIStateProvider =
|
||||
ChangeNotifierProvider<FusionProgressUIState>(
|
||||
(ref) => FusionProgressUIState());
|
||||
ChangeNotifierProvider.family<FusionProgressUIState, String>(
|
||||
(ref, walletId) {
|
||||
return FusionProgressUIState();
|
||||
},
|
||||
);
|
||||
|
|
|
@ -7,6 +7,7 @@ import 'package:fusiondart/fusiondart.dart' as fusion;
|
|||
import 'package:isar/isar.dart';
|
||||
import 'package:stackwallet/db/isar/main_db.dart';
|
||||
import 'package:stackwallet/electrumx_rpc/cached_electrumx.dart';
|
||||
import 'package:stackwallet/models/fusion_progress_ui_state.dart';
|
||||
import 'package:stackwallet/models/isar/models/isar_models.dart';
|
||||
import 'package:stackwallet/services/fusion_tor_service.dart';
|
||||
import 'package:stackwallet/utilities/amount/amount.dart';
|
||||
|
@ -24,6 +25,22 @@ mixin FusionWalletInterface {
|
|||
late final MainDB _db;
|
||||
late final FusionTorService _torService;
|
||||
|
||||
// setting values on this should notify any listeners (the GUI)
|
||||
FusionProgressUIState? _uiState;
|
||||
FusionProgressUIState get uiState {
|
||||
if (_uiState == null) {
|
||||
throw Exception("FusionProgressUIState has not been set for $_walletId");
|
||||
}
|
||||
return _uiState!;
|
||||
}
|
||||
|
||||
set uiState(FusionProgressUIState state) {
|
||||
if (_uiState != null) {
|
||||
throw Exception("FusionProgressUIState was already set for $_walletId");
|
||||
}
|
||||
_uiState = state;
|
||||
}
|
||||
|
||||
// Passed in wallet functions.
|
||||
late final Future<Address> Function() _getNextUnusedChangeAddress;
|
||||
late final CachedElectrumX Function() _getWalletCachedElectrumX;
|
||||
|
@ -59,6 +76,12 @@ mixin FusionWalletInterface {
|
|||
_getChainHeight = getChainHeight;
|
||||
}
|
||||
|
||||
// callback to update the ui state object
|
||||
void updateStatus(fusion.FusionStatus fusionStatus) {
|
||||
// TODO: this
|
||||
// set _uiState states
|
||||
}
|
||||
|
||||
/// Returns a list of all addresses in the wallet.
|
||||
Future<List<fusion.Address>> getFusionAddresses() async {
|
||||
List<Address> _addresses = await _db.getAddresses(_walletId).findAll();
|
||||
|
@ -213,10 +236,10 @@ mixin FusionWalletInterface {
|
|||
getAddresses: getFusionAddresses,
|
||||
getTransactionsByAddress: getTransactionsByAddress,
|
||||
getInputsByAddress: getInputsByAddress,
|
||||
/*createNewReservedChangeAddress: createNewReservedChangeAddress,*/
|
||||
getUnusedReservedChangeAddresses: getUnusedReservedChangeAddresses,
|
||||
getSocksProxyAddress: getSocksProxyAddress,
|
||||
getChainHeight: _getChainHeight,
|
||||
updateStatusCallback: updateStatus,
|
||||
);
|
||||
|
||||
// Add stack UTXOs.
|
||||
|
|
Loading…
Reference in a new issue