From 922f81ffc568afd9e241efabecc663ca22b52852 Mon Sep 17 00:00:00 2001 From: Bibash Shrestha Date: Fri, 4 Oct 2024 11:00:28 +0100 Subject: [PATCH] feat: Manage notification data #2927 --- lib/activity_log/activity_log_manager.dart | 2 +- lib/activity_log/log_class.dart | 40 ++++++++++++++---- lib/activity_log/log_enum.dart | 2 +- lib/credentials/cubit/credentials_cubit.dart | 12 ++---- .../activity_log/view/activity_log_page.dart | 24 +++++++---- .../cubit/backup_credential_cubit.dart | 7 +--- .../cubit/backup_polygon_identity_cubit.dart | 7 +--- .../cubit/restore_credential_cubit.dart | 7 +--- .../cubit/import_wallet_cubit.dart | 11 +---- lib/l10n/arb/app_en.arb | 41 +++++++++++++++++-- lib/l10n/untranslated.json | 27 ++++++++++-- .../helper_function/helper_function.dart | 4 +- lib/scan/cubit/scan_cubit.dart | 9 ++-- 13 files changed, 128 insertions(+), 65 deletions(-) diff --git a/lib/activity_log/activity_log_manager.dart b/lib/activity_log/activity_log_manager.dart index d88687d12..2b54f64f3 100644 --- a/lib/activity_log/activity_log_manager.dart +++ b/lib/activity_log/activity_log_manager.dart @@ -29,7 +29,7 @@ class ActivityLogManager { } /// Set log entry - Future writeLog(LogData log) async { + Future saveLog(LogData log) async { final currentBatchIndex = await _getCurrentBatchIndex(); List logs = await _getLogsForCurrentBatch(currentBatchIndex); diff --git a/lib/activity_log/log_class.dart b/lib/activity_log/log_class.dart index fdff6b33a..8f7e73f61 100644 --- a/lib/activity_log/log_class.dart +++ b/lib/activity_log/log_class.dart @@ -1,4 +1,5 @@ import 'package:altme/activity_log/activity_log.dart'; +import 'package:altme/app/app.dart'; import 'package:equatable/equatable.dart'; import 'package:json_annotation/json_annotation.dart'; @@ -6,20 +7,18 @@ part 'log_class.g.dart'; @JsonSerializable() class LogData extends Equatable { - const LogData({ + LogData({ required this.type, - required this.timestamp, - this.credentialId, - this.data, - }); + DateTime? timestamp, + this.vcInfo, + }) : timestamp = timestamp ?? DateTime.now(); factory LogData.fromJson(Map json) => _$LogDataFromJson(json); final LogType type; final DateTime timestamp; - final String? credentialId; - final String? data; + final VCInfo? vcInfo; Map toJson() => _$LogDataToJson(this); @@ -27,7 +26,30 @@ class LogData extends Equatable { List get props => [ type, timestamp, - credentialId, - data, + vcInfo, + ]; +} + +@JsonSerializable() +class VCInfo extends Equatable { + const VCInfo({ + required this.id, + required this.name, + this.issuer, + }); + + factory VCInfo.fromJson(Map json) => _$VCInfoFromJson(json); + + final String id; + final String name; + final Issuer? issuer; + + Map toJson() => _$VCInfoToJson(this); + + @override + List get props => [ + id, + name, + issuer, ]; } diff --git a/lib/activity_log/log_enum.dart b/lib/activity_log/log_enum.dart index 7572797f2..1e34b71b8 100644 --- a/lib/activity_log/log_enum.dart +++ b/lib/activity_log/log_enum.dart @@ -1,6 +1,6 @@ enum LogType { walletInit, - backupData, + backupData, restoreWallet, addVC, deleteVC, diff --git a/lib/credentials/cubit/credentials_cubit.dart b/lib/credentials/cubit/credentials_cubit.dart index e87c4fac3..99491fce4 100644 --- a/lib/credentials/cubit/credentials_cubit.dart +++ b/lib/credentials/cubit/credentials_cubit.dart @@ -211,12 +211,10 @@ class CredentialsCubit extends Cubit { blockchainType: blockchainType, ); - await activityLogManager.writeLog( + await activityLogManager.saveLog( LogData( type: LogType.deleteVC, - timestamp: DateTime.now(), - credentialId: id, - data: credential.getName, + vcInfo: VCInfo(id: credential.id, name: credential.getName), ), ); emit( @@ -341,12 +339,10 @@ class CredentialsCubit extends Cubit { blockchainType: blockchainType, ); - await activityLogManager.writeLog( + await activityLogManager.saveLog( LogData( type: LogType.addVC, - timestamp: DateTime.now(), - credentialId: credential.id, - data: credential.getName, + vcInfo: VCInfo(id: credential.id, name: credential.getName), ), ); diff --git a/lib/dashboard/drawer/activity_log/view/activity_log_page.dart b/lib/dashboard/drawer/activity_log/view/activity_log_page.dart index 2a1792574..15d027d3d 100644 --- a/lib/dashboard/drawer/activity_log/view/activity_log_page.dart +++ b/lib/dashboard/drawer/activity_log/view/activity_log_page.dart @@ -74,21 +74,31 @@ class _ActivityLogViewState extends State { var message = ''; + var credentialName = ''; + var domainName = ''; + + if (logData.vcInfo != null) { + credentialName = logData.vcInfo!.name; + domainName = + logData.vcInfo!.issuer?.organizationInfo.website ?? ''; + } + switch (logData.type) { case LogType.walletInit: - message = 'Wallet Initialized'; + message = l10n.walletInitialized; case LogType.backupData: - message = 'Backup Credentials'; + message = l10n.backupCredentials; case LogType.restoreWallet: - message = 'Restored Credentials'; + message = l10n.restoredCredentials; case LogType.addVC: - message = 'Added credential ${logData.data}'; + message = l10n.addedCredential(credentialName); case LogType.deleteVC: - message = 'Deleted credential ${logData.data}'; + message = l10n.deletedCredential(credentialName); case LogType.presentVC: - message = 'Presented credential ${logData.data}'; + message = + l10n.presentedCredential(credentialName, domainName); case LogType.importKey: - message = 'Keys imported'; + message = l10n.keysImported; } return Column( diff --git a/lib/dashboard/drawer/wallet_security/backup/backup_credential/cubit/backup_credential_cubit.dart b/lib/dashboard/drawer/wallet_security/backup/backup_credential/cubit/backup_credential_cubit.dart index 3fa31129b..e5256d06c 100644 --- a/lib/dashboard/drawer/wallet_security/backup/backup_credential/cubit/backup_credential_cubit.dart +++ b/lib/dashboard/drawer/wallet_security/backup/backup_credential/cubit/backup_credential_cubit.dart @@ -74,12 +74,7 @@ class BackupCredentialCubit extends Cubit { if (filePath != null && filePath.isEmpty) { emit(state.copyWith(status: AppStatus.idle)); } else { - await activityLogManager.writeLog( - LogData( - type: LogType.backupData, - timestamp: DateTime.now(), - ), - ); + await activityLogManager.saveLog(LogData(type: LogType.backupData)); emit( state.copyWith( status: AppStatus.success, diff --git a/lib/dashboard/drawer/wallet_security/backup/backup_polygon_identity/cubit/backup_polygon_identity_cubit.dart b/lib/dashboard/drawer/wallet_security/backup/backup_polygon_identity/cubit/backup_polygon_identity_cubit.dart index 6f7e4ba79..15d4f256a 100644 --- a/lib/dashboard/drawer/wallet_security/backup/backup_polygon_identity/cubit/backup_polygon_identity_cubit.dart +++ b/lib/dashboard/drawer/wallet_security/backup/backup_polygon_identity/cubit/backup_polygon_identity_cubit.dart @@ -87,12 +87,7 @@ class BackupPolygonIdIdentityCubit extends Cubit { if (filePath != null && filePath.isEmpty) { emit(state.copyWith(status: AppStatus.idle)); } else { - await activityLogManager.writeLog( - LogData( - type: LogType.backupData, - timestamp: DateTime.now(), - ), - ); + await activityLogManager.saveLog(LogData(type: LogType.backupData)); emit( state.copyWith( status: AppStatus.success, diff --git a/lib/dashboard/drawer/wallet_security/restore/restore_credential/cubit/restore_credential_cubit.dart b/lib/dashboard/drawer/wallet_security/restore/restore_credential/cubit/restore_credential_cubit.dart index 5e2652889..76c8c4c30 100644 --- a/lib/dashboard/drawer/wallet_security/restore/restore_credential/cubit/restore_credential_cubit.dart +++ b/lib/dashboard/drawer/wallet_security/restore/restore_credential/cubit/restore_credential_cubit.dart @@ -146,12 +146,7 @@ class RestoreCredentialCubit extends Cubit { blockchainType: walletCubit.state.currentAccount!.blockchainType, ); - await activityLogManager.writeLog( - LogData( - type: LogType.restoreWallet, - timestamp: DateTime.now(), - ), - ); + await activityLogManager.saveLog(LogData(type: LogType.restoreWallet)); emit(state.success(recoveredCredentialLength: credentialList.length)); } catch (e) { if (e is MessageHandler) { diff --git a/lib/import_wallet/cubit/import_wallet_cubit.dart b/lib/import_wallet/cubit/import_wallet_cubit.dart index 223880eba..91cbec46e 100644 --- a/lib/import_wallet/cubit/import_wallet_cubit.dart +++ b/lib/import_wallet/cubit/import_wallet_cubit.dart @@ -90,9 +90,7 @@ class ImportWalletCubit extends Cubit { accountType: AccountType.ssi, ); await secureStorageProvider.set(SecureStorageKeys.ssiKey, ssiKey); - await activityLogManager.writeLog( - LogData(type: LogType.walletInit, timestamp: DateTime.now()), - ); + await activityLogManager.saveLog(LogData(type: LogType.walletInit)); } /// crypto wallet with unknown blockchain type @@ -121,12 +119,7 @@ class ImportWalletCubit extends Cubit { ); } - await activityLogManager.writeLog( - LogData( - type: LogType.importKey, - timestamp: DateTime.now(), - ), - ); + await activityLogManager.saveLog(LogData(type: LogType.importKey)); await homeCubit.emitHasWallet(); emit(state.success()); diff --git a/lib/l10n/arb/app_en.arb b/lib/l10n/arb/app_en.arb index 3e5c2e18a..6be34f9ab 100644 --- a/lib/l10n/arb/app_en.arb +++ b/lib/l10n/arb/app_en.arb @@ -1076,8 +1076,8 @@ "keyBindingPayload": "Key Binding Payload", "ebsiV4DecentralizedId": "did:key EBSI V4 P-256", "noNotificationsYet": "No notifications yet", - "approveProfileTitle": "Install configuration", - "approveProfileDescription": "Do you consent to install the configuration of {company}?", + "approveProfileTitle": "Install configuration", + "approveProfileDescription": "Do you consent to install the configuration of {company}?", "@approveProfileDescription": { "description": "name of the company owning the configuration", "type": "text", @@ -1086,5 +1086,40 @@ } }, "activityLog": "Activity Log", - "activityLogDescription": "See your activities" + "activityLogDescription": "See your activities", + "walletInitialized": "Wallet Initialized", + "backupCredentials": "Backup Credentials", + "restoredCredentials": "Restored Credentials", + "addedCredential": "Added credential {credential}", + "@addedCredentialDescription": { + "description": "name of the credential", + "type": "text", + "placeholders": { + "credential": {} + } + }, + "deletedCredential": "Deleted credential {credential}", + "@deletedCredentialDescription": { + "description": "name of the credential", + "type": "text", + "placeholders": { + "credential": {} + } + }, + "presentedCredential": "Presented credential {credential} to {domain}", + "@presentedCredentialDescription": { + "description": "name of the credential", + "type": "text", + "placeholders": { + "credential": {} + } + }, + "@presentedCredentialDomain": { + "description": "name of the credential", + "type": "text", + "placeholders": { + "domain": {} + } + }, + "keysImported": "Keys imported" } diff --git a/lib/l10n/untranslated.json b/lib/l10n/untranslated.json index ef3a3641d..6fc0fbf6e 100644 --- a/lib/l10n/untranslated.json +++ b/lib/l10n/untranslated.json @@ -49,7 +49,14 @@ "approveProfileTitle", "approveProfileDescription", "activityLog", - "activityLogDescription" + "activityLogDescription", + "walletInitialized", + "backupCredentials", + "restoredCredentials", + "addedCredential", + "deletedCredential", + "presentedCredential", + "keysImported" ], "es": [ @@ -102,7 +109,14 @@ "approveProfileTitle", "approveProfileDescription", "activityLog", - "activityLogDescription" + "activityLogDescription", + "walletInitialized", + "backupCredentials", + "restoredCredentials", + "addedCredential", + "deletedCredential", + "presentedCredential", + "keysImported" ], "fr": [ @@ -160,6 +174,13 @@ "approveProfileTitle", "approveProfileDescription", "activityLog", - "activityLogDescription" + "activityLogDescription", + "walletInitialized", + "backupCredentials", + "restoredCredentials", + "addedCredential", + "deletedCredential", + "presentedCredential", + "keysImported" ] } diff --git a/lib/onboarding/helper_function/helper_function.dart b/lib/onboarding/helper_function/helper_function.dart index 03f050c95..d5568bb49 100644 --- a/lib/onboarding/helper_function/helper_function.dart +++ b/lib/onboarding/helper_function/helper_function.dart @@ -36,9 +36,7 @@ Future generateAccount({ await profileCubit.secureStorageProvider .set(SecureStorageKeys.ssiKey, ssiKey); - await activityLogManager.writeLog( - LogData(type: LogType.walletInit, timestamp: DateTime.now()), - ); + await activityLogManager.saveLog(LogData(type: LogType.walletInit)); /// create profile await profileCubit.load(); diff --git a/lib/scan/cubit/scan_cubit.dart b/lib/scan/cubit/scan_cubit.dart index 78996c12d..abc440e5f 100644 --- a/lib/scan/cubit/scan_cubit.dart +++ b/lib/scan/cubit/scan_cubit.dart @@ -995,12 +995,15 @@ class ScanCubit extends Cubit { ); credentialModel.activities.add(activity); - await activityLogManager.writeLog( + await activityLogManager.saveLog( LogData( type: LogType.presentVC, timestamp: now, - credentialId: credentialModel.id, - data: credentialModel.getName, + vcInfo: VCInfo( + id: credentialModel.id, + name: credentialModel.getName, + issuer: issuer, + ), ), );