WIP mobile fusion progress view

This commit is contained in:
julian 2023-10-16 15:28:09 -06:00
parent c54b4d39d3
commit 1b868426f9
4 changed files with 391 additions and 2 deletions

View file

@ -15,6 +15,7 @@ import 'package:flutter/services.dart';
import 'package:flutter_native_splash/cli_commands.dart'; import 'package:flutter_native_splash/cli_commands.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_svg/svg.dart'; import 'package:flutter_svg/svg.dart';
import 'package:stackwallet/pages/cashfusion/fusion_progress_view.dart';
import 'package:stackwallet/pages/cashfusion/fusion_rounds_selection_sheet.dart'; import 'package:stackwallet/pages/cashfusion/fusion_rounds_selection_sheet.dart';
import 'package:stackwallet/providers/cash_fusion/fusion_progress_ui_state_provider.dart'; import 'package:stackwallet/providers/cash_fusion/fusion_progress_ui_state_provider.dart';
import 'package:stackwallet/providers/global/prefs_provider.dart'; import 'package:stackwallet/providers/global/prefs_provider.dart';
@ -407,7 +408,10 @@ class _CashFusionViewState extends ConsumerState<CashFusionView> {
), ),
); );
// TODO: navigate to progress screen await Navigator.of(context).pushNamed(
FusionProgressView.routeName,
arguments: widget.walletId,
);
}, },
), ),
], ],

View file

@ -0,0 +1,370 @@
/*
* This file is part of Stack Wallet.
*
* Copyright (c) 2023 Cypher Stack
* All Rights Reserved.
* The code is distributed under GPLv3 license, see LICENSE file for details.
* Generated by julian on 2023-10-16
*
*/
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:stackwallet/pages/settings_views/global_settings_view/stack_backup_views/sub_widgets/restoring_item_card.dart';
import 'package:stackwallet/pages_desktop_specific/cashfusion/sub_widgets/fusion_dialog.dart';
import 'package:stackwallet/providers/cash_fusion/fusion_progress_ui_state_provider.dart';
import 'package:stackwallet/themes/stack_colors.dart';
import 'package:stackwallet/utilities/assets.dart';
import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/widgets/background.dart';
import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
import 'package:stackwallet/widgets/desktop/secondary_button.dart';
import 'package:stackwallet/widgets/rounded_container.dart';
class FusionProgressView extends StatefulWidget {
const FusionProgressView({
super.key,
required this.walletId,
});
static const routeName = "/cashFusionProgressView";
final String walletId;
@override
State<FusionProgressView> createState() => _FusionProgressViewState();
}
class _FusionProgressViewState extends State<FusionProgressView> {
Widget _getIconForState(CashFusionStatus state) {
switch (state) {
case CashFusionStatus.waiting:
return SvgPicture.asset(
Assets.svg.loader,
color:
Theme.of(context).extension<StackColors>()!.buttonBackSecondary,
);
case CashFusionStatus.running:
return SvgPicture.asset(
Assets.svg.loader,
color: Theme.of(context).extension<StackColors>()!.accentColorGreen,
);
case CashFusionStatus.success:
return SvgPicture.asset(
Assets.svg.checkCircle,
color: Theme.of(context).extension<StackColors>()!.accentColorGreen,
);
case CashFusionStatus.failed:
return SvgPicture.asset(
Assets.svg.circleAlert,
color: Theme.of(context).extension<StackColors>()!.textError,
);
}
}
/// return true on will cancel, false if cancel cancelled
Future<bool> _requestCancel() async {
//
return false;
}
@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () async {
return await _requestCancel();
},
child: Background(
child: SafeArea(
child: Scaffold(
backgroundColor:
Theme.of(context).extension<StackColors>()!.background,
appBar: AppBar(
automaticallyImplyLeading: false,
leading: AppBarBackButton(
onPressed: () async {
if (await _requestCancel()) {
if (mounted) {
Navigator.of(context).pop();
}
}
},
),
title: Text(
"Fusion progress",
style: STextStyles.navBarTitle(context),
),
titleSpacing: 0,
),
body: LayoutBuilder(
builder: (builderContext, constraints) {
return SingleChildScrollView(
child: ConstrainedBox(
constraints: BoxConstraints(
minHeight: constraints.maxHeight,
),
child: IntrinsicHeight(
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
children: [
RoundedContainer(
color: Theme.of(context)
.extension<StackColors>()!
.snackBarBackError,
child: Text(
"Do not close this window. If you exit, "
"the process will be canceled.",
style: STextStyles.smallMed14(context).copyWith(
color: Theme.of(context)
.extension<StackColors>()!
.snackBarTextError,
),
textAlign: TextAlign.center,
),
),
const SizedBox(
height: 20,
),
Consumer(
builder: (_, ref, __) {
final state = ref.watch(
fusionProgressUIStateProvider(
widget.walletId)
.select((value) => value.connecting));
return RoundedContainer(
padding: EdgeInsets.zero,
color: Theme.of(context)
.extension<StackColors>()!
.popupBG,
borderColor: Theme.of(context)
.extension<StackColors>()!
.background,
child: RestoringItemCard(
left: SizedBox(
width: 32,
height: 32,
child: RoundedContainer(
padding: const EdgeInsets.all(0),
color: Theme.of(context)
.extension<StackColors>()!
.buttonBackSecondary,
child: Center(
child: SvgPicture.asset(
Assets.svg.node,
width: 16,
height: 16,
),
),
),
),
right: SizedBox(
width: 20,
height: 20,
child: _getIconForState(state),
),
title: "Connecting to server",
),
);
},
),
const SizedBox(
height: 12,
),
Consumer(builder: (_, ref, __) {
final state = ref.watch(
fusionProgressUIStateProvider(widget.walletId)
.select((value) => value.outputs));
return RoundedContainer(
padding: EdgeInsets.zero,
color: Theme.of(context)
.extension<StackColors>()!
.popupBG,
borderColor: Theme.of(context)
.extension<StackColors>()!
.background,
child: RestoringItemCard(
left: SizedBox(
width: 32,
height: 32,
child: RoundedContainer(
padding: const EdgeInsets.all(0),
color: Theme.of(context)
.extension<StackColors>()!
.buttonBackSecondary,
child: Center(
child: SvgPicture.asset(
Assets.svg.upFromLine,
width: 18,
height: 18,
),
),
),
),
right: SizedBox(
width: 20,
height: 20,
child: _getIconForState(state),
),
title: "Allocating outputs",
),
);
}),
const SizedBox(
height: 12,
),
Consumer(builder: (_, ref, __) {
final state = ref.watch(
fusionProgressUIStateProvider(widget.walletId)
.select((value) => value.peers));
return RoundedContainer(
padding: EdgeInsets.zero,
color: Theme.of(context)
.extension<StackColors>()!
.popupBG,
borderColor: Theme.of(context)
.extension<StackColors>()!
.background,
child: RestoringItemCard(
left: SizedBox(
width: 32,
height: 32,
child: RoundedContainer(
padding: const EdgeInsets.all(0),
color: Theme.of(context)
.extension<StackColors>()!
.buttonBackSecondary,
child: Center(
child: SvgPicture.asset(
Assets.svg.peers,
width: 20,
height: 20,
),
),
),
),
right: SizedBox(
width: 20,
height: 20,
child: _getIconForState(state),
),
title: "Waiting for peers",
),
);
}),
const SizedBox(
height: 12,
),
Consumer(builder: (_, ref, __) {
final state = ref.watch(
fusionProgressUIStateProvider(widget.walletId)
.select((value) => value.fusing));
return RoundedContainer(
padding: EdgeInsets.zero,
color: Theme.of(context)
.extension<StackColors>()!
.popupBG,
borderColor: Theme.of(context)
.extension<StackColors>()!
.background,
child: RestoringItemCard(
left: SizedBox(
width: 32,
height: 32,
child: RoundedContainer(
padding: const EdgeInsets.all(0),
color: Theme.of(context)
.extension<StackColors>()!
.buttonBackSecondary,
child: Center(
child: SvgPicture.asset(
Assets.svg.fusing,
width: 20,
height: 20,
),
),
),
),
right: SizedBox(
width: 20,
height: 20,
child: _getIconForState(state),
),
title: "Fusing",
),
);
}),
const SizedBox(
height: 12,
),
Consumer(builder: (_, ref, __) {
final state = ref.watch(
fusionProgressUIStateProvider(widget.walletId)
.select((value) => value.complete));
return RoundedContainer(
padding: EdgeInsets.zero,
color: Theme.of(context)
.extension<StackColors>()!
.popupBG,
borderColor: Theme.of(context)
.extension<StackColors>()!
.shadow,
child: RestoringItemCard(
left: SizedBox(
width: 32,
height: 32,
child: RoundedContainer(
padding: const EdgeInsets.all(0),
color: Theme.of(context)
.extension<StackColors>()!
.buttonBackSecondary,
child: Center(
child: SvgPicture.asset(
Assets.svg.checkCircle,
width: 18,
height: 18,
),
),
),
),
right: SizedBox(
width: 20,
height: 20,
child: _getIconForState(state),
),
title: "Complete",
),
);
}),
const Spacer(),
const SizedBox(
height: 16,
),
// TODO: various button states
// tempt only show cancel button
SecondaryButton(
label: "Cancel",
onPressed: () async {
if (await _requestCancel()) {
if (mounted) {
Navigator.of(context).pop();
}
}
},
),
],
),
),
),
),
);
},
),
),
),
),
);
}
}

View file

@ -96,7 +96,7 @@ class FusionDialog extends StatelessWidget {
style: STextStyles.smallMed14(context).copyWith( style: STextStyles.smallMed14(context).copyWith(
color: Theme.of(context) color: Theme.of(context)
.extension<StackColors>()! .extension<StackColors>()!
.textDark, .snackBarTextError,
), ),
), ),
], ],

View file

@ -45,6 +45,7 @@ import 'package:stackwallet/pages/buy_view/buy_in_wallet_view.dart';
import 'package:stackwallet/pages/buy_view/buy_quote_preview.dart'; import 'package:stackwallet/pages/buy_view/buy_quote_preview.dart';
import 'package:stackwallet/pages/buy_view/buy_view.dart'; import 'package:stackwallet/pages/buy_view/buy_view.dart';
import 'package:stackwallet/pages/cashfusion/cashfusion_view.dart'; import 'package:stackwallet/pages/cashfusion/cashfusion_view.dart';
import 'package:stackwallet/pages/cashfusion/fusion_progress_view.dart';
import 'package:stackwallet/pages/coin_control/coin_control_view.dart'; import 'package:stackwallet/pages/coin_control/coin_control_view.dart';
import 'package:stackwallet/pages/coin_control/utxo_details_view.dart'; import 'package:stackwallet/pages/coin_control/utxo_details_view.dart';
import 'package:stackwallet/pages/exchange_view/choose_from_stack_view.dart'; import 'package:stackwallet/pages/exchange_view/choose_from_stack_view.dart';
@ -595,6 +596,20 @@ class RouteGenerator {
} }
return _routeError("${settings.name} invalid args: ${args.toString()}"); return _routeError("${settings.name} invalid args: ${args.toString()}");
case FusionProgressView.routeName:
if (args is String) {
return getRoute(
shouldUseMaterialRoute: useMaterialPageRoute,
builder: (_) => FusionProgressView(
walletId: args,
),
settings: RouteSettings(
name: settings.name,
),
);
}
return _routeError("${settings.name} invalid args: ${args.toString()}");
case DesktopCashFusionView.routeName: case DesktopCashFusionView.routeName:
if (args is String) { if (args is String) {
return getRoute( return getRoute(