mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-05 18:29:22 +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/cupertino.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:stackwallet/pages_desktop_specific/cashfusion/sub_widgets/fusion_dialog.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 {
|
class FusionProgressUIState extends ChangeNotifier {
|
||||||
bool _ableToConnect = false;
|
bool _ableToConnect = true; // set to true for now
|
||||||
|
|
||||||
bool get done {
|
bool get done {
|
||||||
if (!_ableToConnect) {
|
if (!_ableToConnect) {
|
||||||
|
@ -24,10 +20,8 @@ class FusionProgressUIState extends ChangeNotifier {
|
||||||
_done &= (_complete == CashFusionStatus.success) ||
|
_done &= (_complete == CashFusionStatus.success) ||
|
||||||
(_complete == CashFusionStatus.failed);
|
(_complete == CashFusionStatus.failed);
|
||||||
|
|
||||||
for (final wallet in _fusionState.values) {
|
_done &= (fusionState == CashFusionStatus.success) ||
|
||||||
_done &= (wallet.fusionState == CashFusionStatus.success) ||
|
(fusionState == CashFusionStatus.failed);
|
||||||
(wallet.fusionState == CashFusionStatus.failed);
|
|
||||||
}
|
|
||||||
|
|
||||||
return _done;
|
return _done;
|
||||||
}
|
}
|
||||||
|
@ -43,9 +37,7 @@ class FusionProgressUIState extends ChangeNotifier {
|
||||||
_succeeded &= _fusing == CashFusionStatus.success;
|
_succeeded &= _fusing == CashFusionStatus.success;
|
||||||
_succeeded &= _complete == CashFusionStatus.success;
|
_succeeded &= _complete == CashFusionStatus.success;
|
||||||
|
|
||||||
for (final wallet in _fusionState.values) {
|
_succeeded &= fusionState == CashFusionStatus.success;
|
||||||
_succeeded &= wallet.fusionState == CashFusionStatus.success;
|
|
||||||
}
|
|
||||||
|
|
||||||
return _succeeded;
|
return _succeeded;
|
||||||
}
|
}
|
||||||
|
@ -85,55 +77,10 @@ class FusionProgressUIState extends ChangeNotifier {
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Manager> get managers {
|
CashFusionStatus _fusionStatus = CashFusionStatus.waiting;
|
||||||
List<Manager> _managers = [];
|
CashFusionStatus get fusionState => _fusionStatus;
|
||||||
for (final item in _fusionState.values) {
|
set fusionState(CashFusionStatus fusionStatus) {
|
||||||
if (item.manager != null) {
|
_fusionStatus = fusionStatus;
|
||||||
_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;
|
|
||||||
notifyListeners();
|
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/cashfusion/sub_widgets/fusion_dialog.dart';
|
||||||
import 'package:stackwallet/pages_desktop_specific/desktop_menu.dart';
|
import 'package:stackwallet/pages_desktop_specific/desktop_menu.dart';
|
||||||
import 'package:stackwallet/pages_desktop_specific/settings/settings_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/desktop/current_desktop_menu_item.dart';
|
||||||
import 'package:stackwallet/providers/global/wallets_provider.dart';
|
import 'package:stackwallet/providers/global/wallets_provider.dart';
|
||||||
import 'package:stackwallet/providers/ui/check_box_state_provider.dart';
|
import 'package:stackwallet/providers/ui/check_box_state_provider.dart';
|
||||||
|
@ -630,20 +631,23 @@ class _DesktopCashFusion extends ConsumerState<DesktopCashFusionView> {
|
||||||
PrimaryButton(
|
PrimaryButton(
|
||||||
label: "Start",
|
label: "Start",
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
await (ref
|
final fusionWallet = ref
|
||||||
.read(walletsChangeNotifierProvider)
|
.read(walletsChangeNotifierProvider)
|
||||||
.getManager(widget.walletId)
|
.getManager(widget.walletId)
|
||||||
.wallet as FusionWalletInterface)
|
.wallet as FusionWalletInterface;
|
||||||
.fuse();
|
|
||||||
|
|
||||||
// have nullable of variable type that can be set or unset; of notifier
|
fusionWallet.uiState = ref.read(
|
||||||
// when pressed, grab wallet as wallet id
|
fusionProgressUIStateProvider(widget.walletId),
|
||||||
// add to fusion wallet interface and connect to provider
|
);
|
||||||
|
|
||||||
await showDialog(
|
unawaited(fusionWallet.fuse());
|
||||||
|
|
||||||
|
await showDialog<void>(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) {
|
builder: (context) {
|
||||||
return FusionDialog();
|
return FusionDialog(
|
||||||
|
walletId: widget.walletId,
|
||||||
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
|
@ -16,8 +16,11 @@ enum CashFusionStatus { waiting, fusing, success, failed }
|
||||||
class FusionDialog extends StatelessWidget {
|
class FusionDialog extends StatelessWidget {
|
||||||
const FusionDialog({
|
const FusionDialog({
|
||||||
Key? key,
|
Key? key,
|
||||||
|
required this.walletId,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
|
final String walletId;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
Widget _getIconForState(CashFusionStatus state) {
|
Widget _getIconForState(CashFusionStatus state) {
|
||||||
|
@ -103,7 +106,8 @@ class FusionDialog extends StatelessWidget {
|
||||||
height: 20,
|
height: 20,
|
||||||
),
|
),
|
||||||
Consumer(builder: (_, ref, __) {
|
Consumer(builder: (_, ref, __) {
|
||||||
final state = ref.watch(fusionProgressUIStateProvider
|
final state = ref.watch(
|
||||||
|
fusionProgressUIStateProvider(walletId)
|
||||||
.select((value) => value.connecting));
|
.select((value) => value.connecting));
|
||||||
return RoundedContainer(
|
return RoundedContainer(
|
||||||
padding: EdgeInsets.zero,
|
padding: EdgeInsets.zero,
|
||||||
|
@ -143,7 +147,8 @@ class FusionDialog extends StatelessWidget {
|
||||||
height: 12,
|
height: 12,
|
||||||
),
|
),
|
||||||
Consumer(builder: (_, ref, __) {
|
Consumer(builder: (_, ref, __) {
|
||||||
final state = ref.watch(fusionProgressUIStateProvider
|
final state = ref.watch(
|
||||||
|
fusionProgressUIStateProvider(walletId)
|
||||||
.select((value) => value.outputs));
|
.select((value) => value.outputs));
|
||||||
return RoundedContainer(
|
return RoundedContainer(
|
||||||
padding: EdgeInsets.zero,
|
padding: EdgeInsets.zero,
|
||||||
|
@ -183,7 +188,8 @@ class FusionDialog extends StatelessWidget {
|
||||||
height: 12,
|
height: 12,
|
||||||
),
|
),
|
||||||
Consumer(builder: (_, ref, __) {
|
Consumer(builder: (_, ref, __) {
|
||||||
final state = ref.watch(fusionProgressUIStateProvider
|
final state = ref.watch(
|
||||||
|
fusionProgressUIStateProvider(walletId)
|
||||||
.select((value) => value.peers));
|
.select((value) => value.peers));
|
||||||
return RoundedContainer(
|
return RoundedContainer(
|
||||||
padding: EdgeInsets.zero,
|
padding: EdgeInsets.zero,
|
||||||
|
@ -223,7 +229,8 @@ class FusionDialog extends StatelessWidget {
|
||||||
height: 12,
|
height: 12,
|
||||||
),
|
),
|
||||||
Consumer(builder: (_, ref, __) {
|
Consumer(builder: (_, ref, __) {
|
||||||
final state = ref.watch(fusionProgressUIStateProvider
|
final state = ref.watch(
|
||||||
|
fusionProgressUIStateProvider(walletId)
|
||||||
.select((value) => value.fusing));
|
.select((value) => value.fusing));
|
||||||
return RoundedContainer(
|
return RoundedContainer(
|
||||||
padding: EdgeInsets.zero,
|
padding: EdgeInsets.zero,
|
||||||
|
@ -263,7 +270,8 @@ class FusionDialog extends StatelessWidget {
|
||||||
height: 12,
|
height: 12,
|
||||||
),
|
),
|
||||||
Consumer(builder: (_, ref, __) {
|
Consumer(builder: (_, ref, __) {
|
||||||
final state = ref.watch(fusionProgressUIStateProvider
|
final state = ref.watch(
|
||||||
|
fusionProgressUIStateProvider(walletId)
|
||||||
.select((value) => value.complete));
|
.select((value) => value.complete));
|
||||||
return RoundedContainer(
|
return RoundedContainer(
|
||||||
padding: EdgeInsets.zero,
|
padding: EdgeInsets.zero,
|
||||||
|
|
|
@ -12,5 +12,8 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:stackwallet/models/fusion_progress_ui_state.dart';
|
import 'package:stackwallet/models/fusion_progress_ui_state.dart';
|
||||||
|
|
||||||
final fusionProgressUIStateProvider =
|
final fusionProgressUIStateProvider =
|
||||||
ChangeNotifierProvider<FusionProgressUIState>(
|
ChangeNotifierProvider.family<FusionProgressUIState, String>(
|
||||||
(ref) => FusionProgressUIState());
|
(ref, walletId) {
|
||||||
|
return FusionProgressUIState();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
|
@ -7,6 +7,7 @@ import 'package:fusiondart/fusiondart.dart' as fusion;
|
||||||
import 'package:isar/isar.dart';
|
import 'package:isar/isar.dart';
|
||||||
import 'package:stackwallet/db/isar/main_db.dart';
|
import 'package:stackwallet/db/isar/main_db.dart';
|
||||||
import 'package:stackwallet/electrumx_rpc/cached_electrumx.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/models/isar/models/isar_models.dart';
|
||||||
import 'package:stackwallet/services/fusion_tor_service.dart';
|
import 'package:stackwallet/services/fusion_tor_service.dart';
|
||||||
import 'package:stackwallet/utilities/amount/amount.dart';
|
import 'package:stackwallet/utilities/amount/amount.dart';
|
||||||
|
@ -24,6 +25,22 @@ mixin FusionWalletInterface {
|
||||||
late final MainDB _db;
|
late final MainDB _db;
|
||||||
late final FusionTorService _torService;
|
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.
|
// Passed in wallet functions.
|
||||||
late final Future<Address> Function() _getNextUnusedChangeAddress;
|
late final Future<Address> Function() _getNextUnusedChangeAddress;
|
||||||
late final CachedElectrumX Function() _getWalletCachedElectrumX;
|
late final CachedElectrumX Function() _getWalletCachedElectrumX;
|
||||||
|
@ -59,6 +76,12 @@ mixin FusionWalletInterface {
|
||||||
_getChainHeight = getChainHeight;
|
_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.
|
/// Returns a list of all addresses in the wallet.
|
||||||
Future<List<fusion.Address>> getFusionAddresses() async {
|
Future<List<fusion.Address>> getFusionAddresses() async {
|
||||||
List<Address> _addresses = await _db.getAddresses(_walletId).findAll();
|
List<Address> _addresses = await _db.getAddresses(_walletId).findAll();
|
||||||
|
@ -213,10 +236,10 @@ mixin FusionWalletInterface {
|
||||||
getAddresses: getFusionAddresses,
|
getAddresses: getFusionAddresses,
|
||||||
getTransactionsByAddress: getTransactionsByAddress,
|
getTransactionsByAddress: getTransactionsByAddress,
|
||||||
getInputsByAddress: getInputsByAddress,
|
getInputsByAddress: getInputsByAddress,
|
||||||
/*createNewReservedChangeAddress: createNewReservedChangeAddress,*/
|
|
||||||
getUnusedReservedChangeAddresses: getUnusedReservedChangeAddresses,
|
getUnusedReservedChangeAddresses: getUnusedReservedChangeAddresses,
|
||||||
getSocksProxyAddress: getSocksProxyAddress,
|
getSocksProxyAddress: getSocksProxyAddress,
|
||||||
getChainHeight: _getChainHeight,
|
getChainHeight: _getChainHeight,
|
||||||
|
updateStatusCallback: updateStatus,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Add stack UTXOs.
|
// Add stack UTXOs.
|
||||||
|
|
Loading…
Reference in a new issue