From 7b7dc05fcf80e8b3d1d88fcc9c9c4c615b0f2340 Mon Sep 17 00:00:00 2001 From: Bibash Shrestha Date: Fri, 28 Jul 2023 12:09:32 +0545 Subject: [PATCH] feat: Added profile page for oidc4vc profiles #1744 --- .../shared/constants/secure_storage_keys.dart | 2 + .../shared/widget}/grouped_section.dart | 0 lib/app/shared/widget/widget.dart | 3 +- .../widgets/widgets.dart | 1 - .../ssi/oidc4vc_profile/oidc4vc_profile.dart | 1 + .../view/oidc4vc_profile_page.dart | 97 +++++++++++++++++++ .../drawer/ssi/src/view/ssi_menu.dart | 8 ++ .../profile/cubit/profile_cubit.dart | 18 ++++ lib/dashboard/profile/models/profile.dart | 8 +- lib/l10n/arb/app_en.arb | 3 +- lib/l10n/untranslated.json | 12 ++- 11 files changed, 145 insertions(+), 8 deletions(-) rename lib/{dashboard/drawer/ssi/manage_issuers_registry/widgets => app/shared/widget}/grouped_section.dart (100%) create mode 100644 lib/dashboard/drawer/ssi/oidc4vc_profile/oidc4vc_profile.dart create mode 100644 lib/dashboard/drawer/ssi/oidc4vc_profile/view/oidc4vc_profile_page.dart diff --git a/lib/app/shared/constants/secure_storage_keys.dart b/lib/app/shared/constants/secure_storage_keys.dart index 6597e51d9..c84d799b3 100644 --- a/lib/app/shared/constants/secure_storage_keys.dart +++ b/lib/app/shared/constants/secure_storage_keys.dart @@ -75,4 +75,6 @@ class SecureStorageKeys { static const String buildNumber = 'buildNumber'; static const String hasVerifiedMnemonics = 'hasVerifiedMnemonics'; + + static const String oidc4vcType = 'oidc4vcType'; } diff --git a/lib/dashboard/drawer/ssi/manage_issuers_registry/widgets/grouped_section.dart b/lib/app/shared/widget/grouped_section.dart similarity index 100% rename from lib/dashboard/drawer/ssi/manage_issuers_registry/widgets/grouped_section.dart rename to lib/app/shared/widget/grouped_section.dart diff --git a/lib/app/shared/widget/widget.dart b/lib/app/shared/widget/widget.dart index 815ffdbde..f341bdd68 100644 --- a/lib/app/shared/widget/widget.dart +++ b/lib/app/shared/widget/widget.dart @@ -15,9 +15,10 @@ export 'dialog/dialog.dart'; export 'dialog_close_button.dart'; export 'display_terms.dart'; export 'error_view.dart'; +export 'grouped_section.dart'; export 'hero_workaround.dart'; export 'image_card_text.dart'; -export 'imported_tag.dart'; +export 'imported_tag.dart'; export 'm_webview/m_webview.dart'; export 'mnemonic.dart'; export 'my_rich_text.dart'; diff --git a/lib/dashboard/drawer/ssi/manage_issuers_registry/widgets/widgets.dart b/lib/dashboard/drawer/ssi/manage_issuers_registry/widgets/widgets.dart index e4e3db9dc..9decb6152 100644 --- a/lib/dashboard/drawer/ssi/manage_issuers_registry/widgets/widgets.dart +++ b/lib/dashboard/drawer/ssi/manage_issuers_registry/widgets/widgets.dart @@ -1,2 +1 @@ -export 'grouped_section.dart'; export 'issuer_verifier_selector.dart'; diff --git a/lib/dashboard/drawer/ssi/oidc4vc_profile/oidc4vc_profile.dart b/lib/dashboard/drawer/ssi/oidc4vc_profile/oidc4vc_profile.dart new file mode 100644 index 000000000..4b6f291e7 --- /dev/null +++ b/lib/dashboard/drawer/ssi/oidc4vc_profile/oidc4vc_profile.dart @@ -0,0 +1 @@ +export 'view/oidc4vc_profile_page.dart'; diff --git a/lib/dashboard/drawer/ssi/oidc4vc_profile/view/oidc4vc_profile_page.dart b/lib/dashboard/drawer/ssi/oidc4vc_profile/view/oidc4vc_profile_page.dart new file mode 100644 index 000000000..124e4649a --- /dev/null +++ b/lib/dashboard/drawer/ssi/oidc4vc_profile/view/oidc4vc_profile_page.dart @@ -0,0 +1,97 @@ +import 'package:altme/app/app.dart'; +import 'package:altme/dashboard/profile/profile.dart'; +import 'package:altme/l10n/l10n.dart'; +import 'package:altme/theme/theme.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; + +class OIDC4VCProfilePage extends StatelessWidget { + const OIDC4VCProfilePage({super.key}); + + static Route route() { + return MaterialPageRoute( + builder: (_) => const OIDC4VCProfilePage(), + settings: const RouteSettings(name: '/OIDC4VCProfilePage'), + ); + } + + @override + Widget build(BuildContext context) { + final l10n = context.l10n; + return BasePage( + title: l10n.oidc4vcProfile, + useSafeArea: true, + scrollView: false, + titleAlignment: Alignment.topCenter, + padding: const EdgeInsets.symmetric(horizontal: Sizes.spaceSmall), + titleLeading: const BackLeadingButton(), + body: BlocBuilder( + builder: (context, state) { + return Column( + crossAxisAlignment: CrossAxisAlignment.stretch, + mainAxisSize: MainAxisSize.max, + children: [ + Container( + padding: const EdgeInsets.all(Sizes.spaceSmall), + margin: const EdgeInsets.all(Sizes.spaceXSmall), + decoration: BoxDecoration( + color: Theme.of(context).colorScheme.cardHighlighted, + borderRadius: const BorderRadius.all( + Radius.circular(Sizes.largeRadius), + ), + ), + child: ListView.builder( + itemCount: OIDC4VCTye.values.length, + shrinkWrap: true, + physics: const ScrollPhysics(), + itemBuilder: (context, index) { + return Column( + children: [ + ListTile( + onTap: () { + context + .read() + .updateOIDC4VCType(OIDC4VCTye.values[index]); + }, + shape: const RoundedRectangleBorder( + side: BorderSide( + color: Color(0xFFDDDDEE), width: 0.5), + ), + title: Text( + OIDC4VCTye.values[index].name, + style: Theme.of(context) + .listTileTheme + .titleTextStyle + ?.copyWith(color: const Color(0xFF080F33)), + ), + trailing: Icon( + state.model.oidc4vcType == + OIDC4VCTye.values[index].toString() + ? Icons.radio_button_checked + : Icons.radio_button_unchecked, + size: Sizes.icon2x, + ), + ), + if (index < OIDC4VCTye.values.length - 1) + Padding( + padding: const EdgeInsets.symmetric( + horizontal: Sizes.spaceSmall, + vertical: Sizes.spaceXSmall, + ), + child: Divider( + height: 0, + color: Theme.of(context).colorScheme.borderColor, + ), + ), + ], + ); + }, + ), + ), + ], + ); + }, + ), + ); + } +} diff --git a/lib/dashboard/drawer/ssi/src/view/ssi_menu.dart b/lib/dashboard/drawer/ssi/src/view/ssi_menu.dart index 9221b2821..497434391 100644 --- a/lib/dashboard/drawer/ssi/src/view/ssi_menu.dart +++ b/lib/dashboard/drawer/ssi/src/view/ssi_menu.dart @@ -1,6 +1,7 @@ import 'package:altme/app/app.dart'; import 'package:altme/dashboard/dashboard.dart'; import 'package:altme/dashboard/drawer/ssi/manage_did/view/did_menu.dart'; +import 'package:altme/dashboard/drawer/ssi/oidc4vc_profile/oidc4vc_profile.dart'; import 'package:altme/l10n/l10n.dart'; import 'package:altme/theme/theme.dart'; import 'package:flutter/material.dart'; @@ -64,6 +65,13 @@ class SSIView extends StatelessWidget { await Navigator.of(context).push(RestoreMenu.route()); }, ), + DrawerItem( + title: l10n.oidc4vcProfile, + onTap: () async { + await Navigator.of(context) + .push(OIDC4VCProfilePage.route()); + }, + ), DrawerItem( title: l10n.verifiableDataRegistry, onTap: () async { diff --git a/lib/dashboard/profile/cubit/profile_cubit.dart b/lib/dashboard/profile/cubit/profile_cubit.dart index f1bff9bad..23be4582f 100644 --- a/lib/dashboard/profile/cubit/profile_cubit.dart +++ b/lib/dashboard/profile/cubit/profile_cubit.dart @@ -94,6 +94,10 @@ class ProfileCubit extends Cubit { (await secureStorageProvider.get(SecureStorageKeys.alertEnabled)) == 'true'; + final oidc4vcType = + (await secureStorageProvider.get(SecureStorageKeys.oidc4vcType)) ?? + OIDC4VCTye.EBSIV2.toString(); + final profileModel = ProfileModel( firstName: firstName, lastName: lastName, @@ -108,6 +112,7 @@ class ProfileCubit extends Cubit { isEnterprise: isEnterprise, isBiometricEnabled: isBiometricEnabled, isAlertEnabled: isAlertEnabled, + oidc4vcType: oidc4vcType, ); emit( @@ -185,6 +190,11 @@ class ProfileCubit extends Cubit { profileModel.isAlertEnabled.toString(), ); + await secureStorageProvider.set( + SecureStorageKeys.oidc4vcType, + profileModel.oidc4vcType, + ); + emit( state.copyWith( model: profileModel, @@ -227,6 +237,14 @@ class ProfileCubit extends Cubit { await update(profileModel); } + Future updateOIDC4VCType(OIDC4VCTye oidc4vcTye) async { + emit(state.copyWith(status: AppStatus.loading)); + final profileModel = + state.model.copyWith(oidc4vcType: oidc4vcTye.toString()); + + await update(profileModel); + } + @override Future close() async { _timer?.cancel(); diff --git a/lib/dashboard/profile/models/profile.dart b/lib/dashboard/profile/models/profile.dart index c41b07051..b814815c7 100644 --- a/lib/dashboard/profile/models/profile.dart +++ b/lib/dashboard/profile/models/profile.dart @@ -20,6 +20,7 @@ class ProfileModel extends Equatable { this.companyName = '', this.companyWebsite = '', this.jobTitle = '', + required this.oidc4vcType, }); factory ProfileModel.fromJson(Map json) => @@ -39,6 +40,7 @@ class ProfileModel extends Equatable { isBiometricEnabled: false, isAlertEnabled: false, tezosNetwork: TezosNetwork.mainNet(), + oidc4vcType: OIDC4VCTye.EBSIV2.toString(), ); final String firstName; @@ -54,6 +56,7 @@ class ProfileModel extends Equatable { final bool isEnterprise; final bool isBiometricEnabled; final bool isAlertEnabled; + final String oidc4vcType; @override List get props => [ @@ -69,7 +72,8 @@ class ProfileModel extends Equatable { jobTitle, isEnterprise, isBiometricEnabled, - isAlertEnabled + isAlertEnabled, + oidc4vcType, ]; Map toJson() => _$ProfileModelToJson(this); @@ -88,6 +92,7 @@ class ProfileModel extends Equatable { bool? isEnterprise, bool? isBiometricEnabled, bool? isAlertEnabled, + String? oidc4vcType, }) { return ProfileModel( firstName: firstName ?? this.firstName, @@ -103,6 +108,7 @@ class ProfileModel extends Equatable { isEnterprise: isEnterprise ?? this.isEnterprise, isBiometricEnabled: isBiometricEnabled ?? this.isBiometricEnabled, isAlertEnabled: isAlertEnabled ?? this.isAlertEnabled, + oidc4vcType: oidc4vcType ?? this.oidc4vcType, ); } } diff --git a/lib/l10n/arb/app_en.arb b/lib/l10n/arb/app_en.arb index 4af8afebe..5674c3c8e 100644 --- a/lib/l10n/arb/app_en.arb +++ b/lib/l10n/arb/app_en.arb @@ -924,5 +924,6 @@ "placeholders": { "networkType": {} } - } + }, + "oidc4vcProfile": "OIDC4VC Profile" } \ No newline at end of file diff --git a/lib/l10n/untranslated.json b/lib/l10n/untranslated.json index a61cfaa62..202715e4a 100644 --- a/lib/l10n/untranslated.json +++ b/lib/l10n/untranslated.json @@ -836,7 +836,8 @@ "burn", "wouldYouLikeToConfirmThatYouIntendToBurnThisNFT", "pleaseAddXtoConnectToTheDapp", - "pleaseSwitchPolygonNetwork" + "pleaseSwitchPolygonNetwork", + "oidc4vcProfile" ], "es": [ @@ -1676,7 +1677,8 @@ "burn", "wouldYouLikeToConfirmThatYouIntendToBurnThisNFT", "pleaseAddXtoConnectToTheDapp", - "pleaseSwitchPolygonNetwork" + "pleaseSwitchPolygonNetwork", + "oidc4vcProfile" ], "fr": [ @@ -1819,7 +1821,8 @@ "burn", "wouldYouLikeToConfirmThatYouIntendToBurnThisNFT", "pleaseAddXtoConnectToTheDapp", - "pleaseSwitchPolygonNetwork" + "pleaseSwitchPolygonNetwork", + "oidc4vcProfile" ], "it": [ @@ -2659,6 +2662,7 @@ "burn", "wouldYouLikeToConfirmThatYouIntendToBurnThisNFT", "pleaseAddXtoConnectToTheDapp", - "pleaseSwitchPolygonNetwork" + "pleaseSwitchPolygonNetwork", + "oidc4vcProfile" ] }