mobile initiate resharing view updates

This commit is contained in:
julian 2024-04-29 10:55:46 -06:00
parent 10b9e5433e
commit 7250215edc
3 changed files with 101 additions and 40 deletions

View file

@ -12,7 +12,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:stackwallet/pages/settings_views/sub_widgets/settings_list_button.dart'; import 'package:stackwallet/pages/settings_views/sub_widgets/settings_list_button.dart';
import 'package:stackwallet/pages/settings_views/wallet_settings_view/frost_ms/frost_participants_view.dart'; import 'package:stackwallet/pages/settings_views/wallet_settings_view/frost_ms/frost_participants_view.dart';
import 'package:stackwallet/pages/settings_views/wallet_settings_view/frost_ms/resharing/involved/step_1a/begin_reshare_config_view.dart'; import 'package:stackwallet/pages/settings_views/wallet_settings_view/frost_ms/resharing/involved/step_1a/initiate_resharing_view.dart';
import 'package:stackwallet/pages/settings_views/wallet_settings_view/frost_ms/resharing/involved/step_1b/import_reshare_config_view.dart'; import 'package:stackwallet/pages/settings_views/wallet_settings_view/frost_ms/resharing/involved/step_1b/import_reshare_config_view.dart';
import 'package:stackwallet/pages_desktop_specific/my_stack_view/exit_to_my_stack_button.dart'; import 'package:stackwallet/pages_desktop_specific/my_stack_view/exit_to_my_stack_button.dart';
import 'package:stackwallet/providers/db/main_db_provider.dart'; import 'package:stackwallet/providers/db/main_db_provider.dart';
@ -120,7 +120,7 @@ class FrostMSWalletOptionsView extends ConsumerWidget {
ref.read(pFrostMyName.state).state = frostInfo.myName; ref.read(pFrostMyName.state).state = frostInfo.myName;
Navigator.of(context).pushNamed( Navigator.of(context).pushNamed(
BeginReshareConfigView.routeName, InitiateResharingView.routeName,
arguments: walletId, arguments: walletId,
); );
}, },

View file

@ -5,7 +5,6 @@ import 'package:stackwallet/pages_desktop_specific/my_stack_view/exit_to_my_stac
import 'package:stackwallet/providers/db/main_db_provider.dart'; import 'package:stackwallet/providers/db/main_db_provider.dart';
import 'package:stackwallet/providers/frost_wallet/frost_wallet_providers.dart'; import 'package:stackwallet/providers/frost_wallet/frost_wallet_providers.dart';
import 'package:stackwallet/themes/stack_colors.dart'; import 'package:stackwallet/themes/stack_colors.dart';
import 'package:stackwallet/utilities/constants.dart';
import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/utilities/text_styles.dart';
import 'package:stackwallet/utilities/util.dart'; import 'package:stackwallet/utilities/util.dart';
import 'package:stackwallet/wallets/isar/models/frost_wallet_info.dart'; import 'package:stackwallet/wallets/isar/models/frost_wallet_info.dart';
@ -15,9 +14,10 @@ import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
import 'package:stackwallet/widgets/desktop/desktop_app_bar.dart'; import 'package:stackwallet/widgets/desktop/desktop_app_bar.dart';
import 'package:stackwallet/widgets/desktop/desktop_scaffold.dart'; import 'package:stackwallet/widgets/desktop/desktop_scaffold.dart';
import 'package:stackwallet/widgets/desktop/primary_button.dart'; import 'package:stackwallet/widgets/desktop/primary_button.dart';
import 'package:stackwallet/widgets/rounded_white_container.dart';
final class BeginReshareConfigView extends ConsumerStatefulWidget { final class InitiateResharingView extends ConsumerStatefulWidget {
const BeginReshareConfigView({ const InitiateResharingView({
super.key, super.key,
required this.walletId, required this.walletId,
}); });
@ -27,16 +27,18 @@ final class BeginReshareConfigView extends ConsumerStatefulWidget {
final String walletId; final String walletId;
@override @override
ConsumerState<BeginReshareConfigView> createState() => ConsumerState<InitiateResharingView> createState() =>
_BeginReshareConfigViewState(); _BeginReshareConfigViewState();
} }
class _BeginReshareConfigViewState class _BeginReshareConfigViewState
extends ConsumerState<BeginReshareConfigView> { extends ConsumerState<InitiateResharingView> {
late final String myName;
late final int currentThreshold; late final int currentThreshold;
late final List<String> currentParticipants; late final List<String> originalParticipants;
late final List<String> currentParticipantsWithoutMe;
final Map<String, int> pFrostResharersMap = {}; final Set<String> selectedParticipants = {};
@override @override
void initState() { void initState() {
@ -50,7 +52,14 @@ class _BeginReshareConfigViewState
.getByWalletIdSync(widget.walletId)!; .getByWalletIdSync(widget.walletId)!;
currentThreshold = frostInfo.threshold; currentThreshold = frostInfo.threshold;
currentParticipants = frostInfo.participants; originalParticipants = frostInfo.participants.toList(growable: false);
currentParticipantsWithoutMe = originalParticipants.toList();
// sanity check (should never actually fail, but very bad if it does)
assert(originalParticipants.length == currentParticipantsWithoutMe.length);
myName = frostInfo.myName;
currentParticipantsWithoutMe.remove(myName);
super.initState(); super.initState();
} }
@ -83,10 +92,10 @@ class _BeginReshareConfigViewState
Navigator.of(context).pop(); Navigator.of(context).pop();
}, },
), ),
// title: Text( title: Text(
// "Modify Participants", "Initiate resharing",
// style: STextStyles.navBarTitle(context), style: STextStyles.navBarTitle(context),
// ), ),
), ),
body: SafeArea( body: SafeArea(
child: LayoutBuilder( child: LayoutBuilder(
@ -112,34 +121,49 @@ class _BeginReshareConfigViewState
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [
RoundedWhiteContainer(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [ children: [
Text( Text(
"Select participants for resharing", "Select group members who will participate in resharing.",
style: STextStyles.label(context), style: STextStyles.w600_12(context),
),
const SizedBox(
height: 10,
),
Text(
"You must have the threshold number of members (including you) to initiate resharing.",
style: STextStyles.w600_12(context).copyWith(
color: Theme.of(context)
.extension<StackColors>()!
.customTextButtonEnabledText,
),
),
],
),
), ),
const SizedBox( const SizedBox(
height: 16, height: 16,
), ),
Column( Column(
children: [ children: [
for (int i = 0; i < currentParticipants.length; i++) for (int i = 0; i < currentParticipantsWithoutMe.length; i++)
Padding( Padding(
padding: const EdgeInsets.only( padding: const EdgeInsets.only(
top: 10, top: 10,
), ),
child: RawMaterialButton( child: RoundedWhiteContainer(
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, padding: EdgeInsets.zero,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(
Constants.size.circularBorderRadius,
),
),
onPressed: () { onPressed: () {
if (pFrostResharersMap[currentParticipants[i]] == if (selectedParticipants
null) { .contains(currentParticipantsWithoutMe[i])) {
pFrostResharersMap[currentParticipants[i]] = i; selectedParticipants
.remove(currentParticipantsWithoutMe[i]);
} else { } else {
pFrostResharersMap.remove(currentParticipants[i]); selectedParticipants
.add(currentParticipantsWithoutMe[i]);
} }
setState(() {}); setState(() {});
@ -150,16 +174,15 @@ class _BeginReshareConfigViewState
child: Row( child: Row(
children: [ children: [
Checkbox( Checkbox(
value: pFrostResharersMap[ value: selectedParticipants
currentParticipants[i]] == .contains(currentParticipantsWithoutMe[i]),
i, onChanged: (_) {},
onChanged: (bool? value) {},
), ),
const SizedBox( const SizedBox(
width: 10, width: 10,
), ),
Text( Text(
currentParticipants[i], currentParticipantsWithoutMe[i],
style: STextStyles.itemSubtitle12(context), style: STextStyles.itemSubtitle12(context),
), ),
], ],
@ -174,16 +197,54 @@ class _BeginReshareConfigViewState
const SizedBox( const SizedBox(
height: 16, height: 16,
), ),
RoundedWhiteContainer(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"Required members",
style: STextStyles.w500_14(context).copyWith(
color:
Theme.of(context).extension<StackColors>()!.textDark3,
),
),
Text(
// +1 is included as the initiator who will also take part
"${selectedParticipants.length + 1} / $currentThreshold",
style: STextStyles.w500_14(context).copyWith(
color: selectedParticipants.length + 1 >= currentThreshold
? Theme.of(context)
.extension<StackColors>()!
.accentColorGreen
: Theme.of(context)
.extension<StackColors>()!
.accentColorRed,
),
),
],
),
),
const SizedBox(
height: 16,
),
PrimaryButton( PrimaryButton(
label: "Continue", label: "Continue",
enabled: pFrostResharersMap.length >= currentThreshold, // +1 is included as the initiator who will also take part
enabled: selectedParticipants.length + 1 >= currentThreshold,
onPressed: () async { onPressed: () async {
// include self now
selectedParticipants.add(myName);
final List<int> resharers = [];
for (final name in selectedParticipants) {
resharers.add(originalParticipants.indexOf(name));
}
await Navigator.of(context).pushNamed( await Navigator.of(context).pushNamed(
CompleteReshareConfigView.routeName, CompleteReshareConfigView.routeName,
arguments: ( arguments: (
walletId: widget.walletId, walletId: widget.walletId,
resharers: resharers: resharers,
pFrostResharersMap.values.toList(growable: false),
), ),
); );
}, },

View file

@ -126,9 +126,9 @@ import 'package:stackwallet/pages/settings_views/global_settings_view/tor_settin
import 'package:stackwallet/pages/settings_views/wallet_settings_view/frost_ms/frost_ms_options_view.dart'; import 'package:stackwallet/pages/settings_views/wallet_settings_view/frost_ms/frost_ms_options_view.dart';
import 'package:stackwallet/pages/settings_views/wallet_settings_view/frost_ms/frost_participants_view.dart'; import 'package:stackwallet/pages/settings_views/wallet_settings_view/frost_ms/frost_participants_view.dart';
import 'package:stackwallet/pages/settings_views/wallet_settings_view/frost_ms/resharing/finish_resharing_view.dart'; import 'package:stackwallet/pages/settings_views/wallet_settings_view/frost_ms/resharing/finish_resharing_view.dart';
import 'package:stackwallet/pages/settings_views/wallet_settings_view/frost_ms/resharing/involved/step_1a/begin_reshare_config_view.dart';
import 'package:stackwallet/pages/settings_views/wallet_settings_view/frost_ms/resharing/involved/step_1a/complete_reshare_config_view.dart'; import 'package:stackwallet/pages/settings_views/wallet_settings_view/frost_ms/resharing/involved/step_1a/complete_reshare_config_view.dart';
import 'package:stackwallet/pages/settings_views/wallet_settings_view/frost_ms/resharing/involved/step_1a/display_reshare_config_view.dart'; import 'package:stackwallet/pages/settings_views/wallet_settings_view/frost_ms/resharing/involved/step_1a/display_reshare_config_view.dart';
import 'package:stackwallet/pages/settings_views/wallet_settings_view/frost_ms/resharing/involved/step_1a/initiate_resharing_view.dart';
import 'package:stackwallet/pages/settings_views/wallet_settings_view/frost_ms/resharing/involved/step_1b/import_reshare_config_view.dart'; import 'package:stackwallet/pages/settings_views/wallet_settings_view/frost_ms/resharing/involved/step_1b/import_reshare_config_view.dart';
import 'package:stackwallet/pages/settings_views/wallet_settings_view/frost_ms/resharing/involved/step_2/begin_resharing_view.dart'; import 'package:stackwallet/pages/settings_views/wallet_settings_view/frost_ms/resharing/involved/step_2/begin_resharing_view.dart';
import 'package:stackwallet/pages/settings_views/wallet_settings_view/frost_ms/resharing/involved/step_2/continue_resharing_view.dart'; import 'package:stackwallet/pages/settings_views/wallet_settings_view/frost_ms/resharing/involved/step_2/continue_resharing_view.dart';
@ -634,11 +634,11 @@ class RouteGenerator {
} }
return _routeError("${settings.name} invalid args: ${args.toString()}"); return _routeError("${settings.name} invalid args: ${args.toString()}");
case BeginReshareConfigView.routeName: case InitiateResharingView.routeName:
if (args is String) { if (args is String) {
return getRoute( return getRoute(
shouldUseMaterialRoute: useMaterialPageRoute, shouldUseMaterialRoute: useMaterialPageRoute,
builder: (_) => BeginReshareConfigView( builder: (_) => InitiateResharingView(
walletId: args, walletId: args,
), ),
settings: RouteSettings( settings: RouteSettings(