Skip to content

Commit

Permalink
feat: Manage notification data #2927
Browse files Browse the repository at this point in the history
  • Loading branch information
bibash28 committed Oct 4, 2024
1 parent 31fce45 commit 922f81f
Show file tree
Hide file tree
Showing 13 changed files with 128 additions and 65 deletions.
2 changes: 1 addition & 1 deletion lib/activity_log/activity_log_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ActivityLogManager {
}

/// Set log entry
Future<void> writeLog(LogData log) async {
Future<void> saveLog(LogData log) async {
final currentBatchIndex = await _getCurrentBatchIndex();

List<LogData> logs = await _getLogsForCurrentBatch(currentBatchIndex);
Expand Down
40 changes: 31 additions & 9 deletions lib/activity_log/log_class.dart
Original file line number Diff line number Diff line change
@@ -1,33 +1,55 @@
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';

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<String, dynamic> json) =>
_$LogDataFromJson(json);

final LogType type;
final DateTime timestamp;
final String? credentialId;
final String? data;
final VCInfo? vcInfo;

Map<String, dynamic> toJson() => _$LogDataToJson(this);

@override
List<Object?> 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<String, dynamic> json) => _$VCInfoFromJson(json);

final String id;
final String name;
final Issuer? issuer;

Map<String, dynamic> toJson() => _$VCInfoToJson(this);

@override
List<Object?> get props => [
id,
name,
issuer,
];
}
2 changes: 1 addition & 1 deletion lib/activity_log/log_enum.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
enum LogType {
walletInit,
backupData,
backupData,
restoreWallet,
addVC,
deleteVC,
Expand Down
12 changes: 4 additions & 8 deletions lib/credentials/cubit/credentials_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,10 @@ class CredentialsCubit extends Cubit<CredentialsState> {
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(
Expand Down Expand Up @@ -341,12 +339,10 @@ class CredentialsCubit extends Cubit<CredentialsState> {
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),
),
);

Expand Down
24 changes: 17 additions & 7 deletions lib/dashboard/drawer/activity_log/view/activity_log_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,31 @@ class _ActivityLogViewState extends State<ActivityLogView> {

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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,7 @@ class BackupCredentialCubit extends Cubit<BackupCredentialState> {
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,7 @@ class BackupPolygonIdIdentityCubit extends Cubit<BackupPolygonIdIdentityState> {
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,7 @@ class RestoreCredentialCubit extends Cubit<RestoreCredentialState> {
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) {
Expand Down
11 changes: 2 additions & 9 deletions lib/import_wallet/cubit/import_wallet_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ class ImportWalletCubit extends Cubit<ImportWalletState> {
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
Expand Down Expand Up @@ -121,12 +119,7 @@ class ImportWalletCubit extends Cubit<ImportWalletState> {
);
}

await activityLogManager.writeLog(
LogData(
type: LogType.importKey,
timestamp: DateTime.now(),
),
);
await activityLogManager.saveLog(LogData(type: LogType.importKey));

await homeCubit.emitHasWallet();
emit(state.success());
Expand Down
41 changes: 38 additions & 3 deletions lib/l10n/arb/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
}
27 changes: 24 additions & 3 deletions lib/l10n/untranslated.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,14 @@
"approveProfileTitle",
"approveProfileDescription",
"activityLog",
"activityLogDescription"
"activityLogDescription",
"walletInitialized",
"backupCredentials",
"restoredCredentials",
"addedCredential",
"deletedCredential",
"presentedCredential",
"keysImported"
],

"es": [
Expand Down Expand Up @@ -102,7 +109,14 @@
"approveProfileTitle",
"approveProfileDescription",
"activityLog",
"activityLogDescription"
"activityLogDescription",
"walletInitialized",
"backupCredentials",
"restoredCredentials",
"addedCredential",
"deletedCredential",
"presentedCredential",
"keysImported"
],

"fr": [
Expand Down Expand Up @@ -160,6 +174,13 @@
"approveProfileTitle",
"approveProfileDescription",
"activityLog",
"activityLogDescription"
"activityLogDescription",
"walletInitialized",
"backupCredentials",
"restoredCredentials",
"addedCredential",
"deletedCredential",
"presentedCredential",
"keysImported"
]
}
4 changes: 1 addition & 3 deletions lib/onboarding/helper_function/helper_function.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ Future<void> 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();
Expand Down
9 changes: 6 additions & 3 deletions lib/scan/cubit/scan_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -995,12 +995,15 @@ class ScanCubit extends Cubit<ScanState> {
);
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,
),
),
);

Expand Down

0 comments on commit 922f81f

Please sign in to comment.