Skip to content

Commit

Permalink
feat: Add 3 switches and bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
bibash28 committed Aug 19, 2023
1 parent 3ebe527 commit afa5fa3
Show file tree
Hide file tree
Showing 13 changed files with 387 additions and 184 deletions.
6 changes: 6 additions & 0 deletions lib/app/shared/constants/secure_storage_keys.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ class SecureStorageKeys {
static const String isHumanityProofEnabled = 'isHumanityProofEnabled';
static const String isWalletIntegrityEnabled = 'isWalletIntegrityEnabled';
static const String isBiometricEnabled = 'fingerprintEnabled';

static const String alertEnabled = 'alertEnabled';
static const String userConsentForIssuerAccess = 'userConsentForIssuerAccess';
static const String userConsentForVerifierAccess =
'userConsentForVerifierAccess';
static const String userPINCodeForAuthentication =
'userPINCodeForAuthentication';

static const String pinCode = 'pinCode';
static const String data = 'data';
Expand Down
18 changes: 18 additions & 0 deletions lib/app/shared/helper_functions/helper_functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -439,3 +439,21 @@ bool isUriAsValueValid(List<String> keys) =>
keys.contains('client_id') &&
keys.contains('redirect_uri') &&
keys.contains('nonce');

bool isPolygonIdUrl(String url) =>
url.startsWith('{"id":') ||
url.startsWith('{"body":{"') ||
url.startsWith('{"from": "did:polygonid:') ||
url.startsWith('{"to": "did:polygonid:') ||
url.startsWith('{"thid":') ||
url.startsWith('{"typ":') ||
url.startsWith('{"type":');

OIDC4VCType? getOIDC4VCTypeForIssuance(String url) {
for (final oidc4vcType in OIDC4VCType.values) {
if (oidc4vcType.isEnabled && url.startsWith(oidc4vcType.offerPrefix)) {
return oidc4vcType;
}
}
return null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,53 @@ class WalletSecurityView extends StatelessWidget {
),
),
),
DrawerItem(
title: l10n.userConsentForIssuerAccess,
trailing: SizedBox(
height: 25,
child: Switch(
onChanged: (value) async {
await context
.read<ProfileCubit>()
.setUserConsentForIssuerAccess(enabled: value);
},
value: state.model.userConsentForIssuerAccess,
activeColor: Theme.of(context).colorScheme.primary,
),
),
),
DrawerItem(
title: l10n.userConsentForVerifierAccess,
trailing: SizedBox(
height: 25,
child: Switch(
onChanged: (value) async {
await context
.read<ProfileCubit>()
.setUserConsentForVerifierAccess(
enabled: value);
},
value: state.model.userConsentForVerifierAccess,
activeColor: Theme.of(context).colorScheme.primary,
),
),
),
DrawerItem(
title: l10n.userPINCodeForAuthentication,
trailing: SizedBox(
height: 25,
child: Switch(
onChanged: (value) async {
await context
.read<ProfileCubit>()
.setUserPINCodeForAuthentication(
enabled: value);
},
value: state.model.userPINCodeForAuthentication,
activeColor: Theme.of(context).colorScheme.primary,
),
),
),
DrawerItem(
title: l10n.showWalletRecoveryPhrase,
onTap: () async {
Expand Down
60 changes: 57 additions & 3 deletions lib/dashboard/profile/cubit/profile_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,27 @@ class ProfileCubit extends Cubit<ProfileState> {
.get(SecureStorageKeys.isBiometricEnabled)) ==
'true';

final isAlertEnabled =
(await secureStorageProvider.get(SecureStorageKeys.alertEnabled)) ==
'true';
final alertValue =
await secureStorageProvider.get(SecureStorageKeys.alertEnabled);
final isAlertEnabled = alertValue == null || alertValue == 'true';

final userConsentForIssuerAccessValue = await secureStorageProvider
.get(SecureStorageKeys.userConsentForIssuerAccess);
final userConsentForIssuerAccess =
userConsentForIssuerAccessValue == null ||
userConsentForIssuerAccessValue == 'true';

final userConsentForVerifierAccessValue = await secureStorageProvider
.get(SecureStorageKeys.userConsentForVerifierAccess);
final userConsentForVerifierAccess =
userConsentForVerifierAccessValue == null ||
userConsentForVerifierAccessValue == 'true';

final userPINCodeForAuthenticationValue = await secureStorageProvider
.get(SecureStorageKeys.userPINCodeForAuthentication);
final userPINCodeForAuthentication =
userPINCodeForAuthenticationValue == null ||
userPINCodeForAuthenticationValue == 'true';

var oidc4vcType = OIDC4VCType.EBSIV2;

Expand Down Expand Up @@ -121,6 +139,9 @@ class ProfileCubit extends Cubit<ProfileState> {
isEnterprise: isEnterprise,
isBiometricEnabled: isBiometricEnabled,
isAlertEnabled: isAlertEnabled,
userConsentForIssuerAccess: userConsentForIssuerAccess,
userConsentForVerifierAccess: userConsentForVerifierAccess,
userPINCodeForAuthentication: userPINCodeForAuthentication,
oidc4vcType: oidc4vcType,
);

Expand Down Expand Up @@ -203,6 +224,21 @@ class ProfileCubit extends Cubit<ProfileState> {
profileModel.isAlertEnabled.toString(),
);

await secureStorageProvider.set(
SecureStorageKeys.userConsentForIssuerAccess,
profileModel.userConsentForIssuerAccess.toString(),
);

await secureStorageProvider.set(
SecureStorageKeys.userConsentForVerifierAccess,
profileModel.userConsentForVerifierAccess.toString(),
);

await secureStorageProvider.set(
SecureStorageKeys.userPINCodeForAuthentication,
profileModel.userPINCodeForAuthentication.toString(),
);

await secureStorageProvider.set(
SecureStorageKeys.oidc4vcType,
profileModel.oidc4vcType.name,
Expand Down Expand Up @@ -241,6 +277,24 @@ class ProfileCubit extends Cubit<ProfileState> {
await update(profileModel);
}

Future<void> setUserConsentForIssuerAccess({bool enabled = false}) async {
final profileModel =
state.model.copyWith(userConsentForIssuerAccess: enabled);
await update(profileModel);
}

Future<void> setUserConsentForVerifierAccess({bool enabled = false}) async {
final profileModel =
state.model.copyWith(userConsentForVerifierAccess: enabled);
await update(profileModel);
}

Future<void> setUserPINCodeForAuthentication({bool enabled = false}) async {
final profileModel =
state.model.copyWith(userPINCodeForAuthentication: enabled);
await update(profileModel);
}

Future<void> updatePolygonIdNetwork({
required PolygonIdNetwork polygonIdNetwork,
required PolygonIdCubit polygonIdCubit,
Expand Down
21 changes: 21 additions & 0 deletions lib/dashboard/profile/models/profile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ class ProfileModel extends Equatable {
required this.isEnterprise,
required this.isBiometricEnabled,
required this.isAlertEnabled,
required this.userConsentForIssuerAccess,
required this.userConsentForVerifierAccess,
required this.userPINCodeForAuthentication,
this.companyName = '',
this.companyWebsite = '',
this.jobTitle = '',
Expand All @@ -39,6 +42,9 @@ class ProfileModel extends Equatable {
isEnterprise: false,
isBiometricEnabled: false,
isAlertEnabled: false,
userConsentForIssuerAccess: true,
userConsentForVerifierAccess: true,
userPINCodeForAuthentication: true,
tezosNetwork: TezosNetwork.mainNet(),
oidc4vcType: OIDC4VCType.EBSIV2,
);
Expand All @@ -56,6 +62,9 @@ class ProfileModel extends Equatable {
final bool isEnterprise;
final bool isBiometricEnabled;
final bool isAlertEnabled;
final bool userConsentForIssuerAccess;
final bool userConsentForVerifierAccess;
final bool userPINCodeForAuthentication;
final OIDC4VCType oidc4vcType;

@override
Expand All @@ -73,6 +82,9 @@ class ProfileModel extends Equatable {
isEnterprise,
isBiometricEnabled,
isAlertEnabled,
userConsentForIssuerAccess,
userConsentForVerifierAccess,
userPINCodeForAuthentication,
oidc4vcType,
];

Expand All @@ -92,6 +104,9 @@ class ProfileModel extends Equatable {
bool? isEnterprise,
bool? isBiometricEnabled,
bool? isAlertEnabled,
bool? userConsentForIssuerAccess,
bool? userConsentForVerifierAccess,
bool? userPINCodeForAuthentication,
OIDC4VCType? oidc4vcType,
}) {
return ProfileModel(
Expand All @@ -108,6 +123,12 @@ class ProfileModel extends Equatable {
isEnterprise: isEnterprise ?? this.isEnterprise,
isBiometricEnabled: isBiometricEnabled ?? this.isBiometricEnabled,
isAlertEnabled: isAlertEnabled ?? this.isAlertEnabled,
userConsentForIssuerAccess:
userConsentForIssuerAccess ?? this.userConsentForIssuerAccess,
userConsentForVerifierAccess:
userConsentForVerifierAccess ?? this.userConsentForVerifierAccess,
userPINCodeForAuthentication:
userPINCodeForAuthentication ?? this.userPINCodeForAuthentication,
oidc4vcType: oidc4vcType ?? this.oidc4vcType,
);
}
Expand Down
Loading

0 comments on commit afa5fa3

Please sign in to comment.