Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cat-voices): roles chooser #923

Merged
merged 13 commits into from
Oct 2, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import 'package:catalyst_voices_shared/catalyst_voices_shared.dart';
import 'package:flutter/material.dart';

class RbacTransactionPanel extends StatelessWidget {
final List<AccountRole> roles;
final Set<AccountRole> roles;
final CardanoWalletDetails walletDetails;
final Coin transactionFee;

const RbacTransactionPanel({
super.key,
required this.roles,
required this.walletDetails,
required this.transactionFee,
});

Expand All @@ -32,6 +34,7 @@ class RbacTransactionPanel extends StatelessWidget {
const SizedBox(height: 12),
_Summary(
roles: roles,
walletDetails: walletDetails,
transactionFee: transactionFee,
),
const SizedBox(height: 18),
Expand All @@ -44,11 +47,13 @@ class RbacTransactionPanel extends StatelessWidget {
}

class _Summary extends StatelessWidget {
final List<AccountRole> roles;
final Set<AccountRole> roles;
final CardanoWalletDetails walletDetails;
final Coin transactionFee;

const _Summary({
required this.roles,
required this.walletDetails,
required this.transactionFee,
});

Expand All @@ -70,6 +75,12 @@ class _Summary extends StatelessWidget {
context.l10n.walletLinkTransactionAccountCompletion,
style: Theme.of(context).textTheme.titleSmall,
),
const SizedBox(height: 12),
Text(
context.l10n
.walletLinkTransactionLinkItem(walletDetails.wallet.name),
style: Theme.of(context).textTheme.bodySmall,
),
for (final role in roles) ...[
const SizedBox(height: 12),
Text(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,51 @@
import 'package:catalyst_voices/pages/registration/placeholder_panel.dart';
import 'package:catalyst_voices/pages/registration/registration_stage_message.dart';
import 'package:catalyst_voices/pages/registration/registration_stage_navigation.dart';
import 'package:catalyst_voices/widgets/buttons/voices_text_button.dart';
import 'package:catalyst_voices/widgets/containers/roles_chooser_container.dart';
import 'package:catalyst_voices_assets/catalyst_voices_assets.dart';
import 'package:catalyst_voices_blocs/catalyst_voices_blocs.dart';
import 'package:catalyst_voices_localization/catalyst_voices_localization.dart';
import 'package:catalyst_voices_models/catalyst_voices_models.dart';
import 'package:flutter/material.dart';

// TODO(dtscalac): define content
class RolesChooserPanel extends StatelessWidget {
const RolesChooserPanel({super.key});
final Set<AccountRole> defaultRoles;
final Set<AccountRole> selectedRoles;

const RolesChooserPanel({
super.key,
required this.defaultRoles,
required this.selectedRoles,
});

@override
Widget build(BuildContext context) {
return const PlaceholderPanel();
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
const SizedBox(height: 24),
RegistrationStageMessage(
title: context.l10n.walletLinkRoleChooserTitle,
subtitle: context.l10n.walletLinkRoleChooserContent,
spacing: 12,
),
const SizedBox(height: 12),
RolesChooserContainer(
selected: selectedRoles,
lockedValuesAsDefault: defaultRoles,
onChanged: RegistrationCubit.of(context).selectRoles,
),
const Spacer(),
const RegistrationBackNextNavigation(),
const SizedBox(height: 10),
VoicesTextButton(
leading: VoicesAssets.icons.wallet.buildIcon(),
onTap: () {
RegistrationCubit.of(context).chooseOtherWallet();
},
child: Text(context.l10n.chooseOtherWallet),
),
],
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ import 'package:flutter/services.dart';

class WalletDetailsPanel extends StatelessWidget {
final Coin minAdaForRegistration;
final CardanoWalletDetails details;
final CardanoWalletDetails walletDetails;

const WalletDetailsPanel({
super.key,
required this.minAdaForRegistration,
required this.details,
required this.walletDetails,
});

@override
Widget build(BuildContext context) {
final hasEnoughBalance = details.balance >= minAdaForRegistration;
final hasEnoughBalance = walletDetails.balance >= minAdaForRegistration;

return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
Expand All @@ -34,14 +34,18 @@ class WalletDetailsPanel extends StatelessWidget {
style: Theme.of(context).textTheme.titleMedium,
),
const SizedBox(height: 32),
_WalletExtension(wallet: details.wallet),
_WalletExtension(wallet: walletDetails.wallet),
const SizedBox(height: 16),
Text(
context.l10n.walletLinkWalletDetailsContent(details.wallet.name),
context.l10n
.walletLinkWalletDetailsContent(walletDetails.wallet.name),
style: Theme.of(context).textTheme.titleMedium,
),
const SizedBox(height: 24),
_WalletSummary(details: details, hasEnoughBalance: hasEnoughBalance),
_WalletSummary(
details: walletDetails,
hasEnoughBalance: hasEnoughBalance,
),
const Spacer(),
if (hasEnoughBalance)
const RegistrationBackNextNavigation()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,17 @@ class WalletLinkPanel extends StatelessWidget {
),
WalletLinkStage.walletDetails => WalletDetailsPanel(
minAdaForRegistration: stateData.minAdaForRegistration,
details: stateData.selectedWallet!,
walletDetails: stateData.selectedWallet!,
),
WalletLinkStage.rolesChooser => RolesChooserPanel(
defaultRoles: stateData.defaultRoles,
selectedRoles: stateData.selectedRoles ?? stateData.defaultRoles,
),
WalletLinkStage.rolesChooser => const RolesChooserPanel(),
WalletLinkStage.rolesSummary => const RolesSummaryPanel(),
// TODO(dtscalac): pass valid parameters
WalletLinkStage.rbacTransaction => RbacTransactionPanel(
roles: AccountRole.values,
roles: stateData.selectedRoles ?? stateData.defaultRoles,
walletDetails: stateData.selectedWallet!,
// TODO(dtscalac): pass valid fee
transactionFee: Coin.fromAda(0.9438),
),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ final class WalletLinkCubit extends Cubit<WalletLink> {
}
}

void selectRoles(Set<AccountRole> roles) {
_stateData = _stateData.copyWith(selectedRoles: Optional(roles));
}

WalletLinkStep? nextStep() {
final currentStageIndex = WalletLinkStage.values.indexOf(state.stage);
final isLast = currentStageIndex == WalletLinkStage.values.length - 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ final class RegistrationCubit extends Cubit<RegistrationState> {
}
}

void chooseOtherWallet() {
_goToStep(const WalletLinkStep(stage: WalletLinkStage.selectWallet));
}

void changeRoleSetup() {
_goToStep(const WalletLinkStep(stage: WalletLinkStage.rolesChooser));
}
Expand Down Expand Up @@ -112,6 +116,10 @@ final class RegistrationCubit extends Cubit<RegistrationState> {
return _walletLinkCubit.selectWallet(wallet);
}

void selectRoles(Set<AccountRole> roles) {
_walletLinkCubit.selectRoles(roles);
}

void submitRegistration() {
// TODO(dtscalac): submit RBAC transaction
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,34 @@ import 'package:result_type/result_type.dart';
final class WalletLinkStateData extends Equatable {
final Result<List<CardanoWallet>, Exception>? wallets;
final CardanoWalletDetails? selectedWallet;
final Set<AccountRole>? selectedRoles;

const WalletLinkStateData({
this.wallets,
this.selectedWallet,
this.selectedRoles,
});

/// Returns the minimum required ADA in user balance to register.
Coin get minAdaForRegistration => CardanoWalletDetails.minAdaForRegistration;

/// Returns the default roles every account will have.
Set<AccountRole> get defaultRoles => {AccountRole.voter};

WalletLinkStateData copyWith({
Optional<Result<List<CardanoWallet>, Exception>>? wallets,
Optional<CardanoWalletDetails>? selectedWallet,
Optional<Set<AccountRole>>? selectedRoles,
}) {
return WalletLinkStateData(
wallets: wallets != null ? wallets.data : this.wallets,
selectedWallet:
selectedWallet != null ? selectedWallet.data : this.selectedWallet,
selectedRoles:
selectedRoles != null ? selectedRoles.data : this.selectedRoles,
);
}

@override
List<Object?> get props => [wallets, selectedWallet];
List<Object?> get props => [wallets, selectedWallet, selectedRoles];
}
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,18 @@ abstract class VoicesLocalizations {
/// **'1 {role} registration to Catalyst Keychain'**
String walletLinkTransactionRoleItem(String role);

/// A title on the role chooser screen in registration.
///
/// In en, this message translates to:
/// **'How do you want to participate in Catalyst?'**
String get walletLinkRoleChooserTitle;

/// A message on the role chooser screen in registration.
///
/// In en, this message translates to:
/// **'In Catalyst you can take on different roles, learn more below and choose your additional roles now.'**
String get walletLinkRoleChooserContent;

/// Message shown when redirecting to external content that describes which wallets are supported.
///
/// In en, this message translates to:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,12 @@ class VoicesLocalizationsEn extends VoicesLocalizations {
return '1 $role registration to Catalyst Keychain';
}

@override
String get walletLinkRoleChooserTitle => 'How do you want to participate in Catalyst?';

@override
String get walletLinkRoleChooserContent => 'In Catalyst you can take on different roles, learn more below and choose your additional roles now.';

@override
String get seeAllSupportedWallets => 'See all supported wallets';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,12 @@ class VoicesLocalizationsEs extends VoicesLocalizations {
return '1 $role registration to Catalyst Keychain';
}

@override
String get walletLinkRoleChooserTitle => 'How do you want to participate in Catalyst?';

@override
String get walletLinkRoleChooserContent => 'In Catalyst you can take on different roles, learn more below and choose your additional roles now.';

@override
String get seeAllSupportedWallets => 'See all supported wallets';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,14 @@
}
}
},
"walletLinkRoleChooserTitle": "How do you want to participate in Catalyst?",
"@walletLinkRoleChooserTitle": {
"description": "A title on the role chooser screen in registration."
},
"walletLinkRoleChooserContent": "In Catalyst you can take on different roles, learn more below and choose your additional roles now.",
"@walletLinkRoleChooserContent": {
"description": "A message on the role chooser screen in registration."
},
"seeAllSupportedWallets": "See all supported wallets",
"@seeAllSupportedWallets": {
"description": "Message shown when redirecting to external content that describes which wallets are supported."
Expand Down
Loading