Skip to content

Commit

Permalink
fix(INJI-397)error message for deleted vcfile (mosip#875)
Browse files Browse the repository at this point in the history
* fix(INJI-397)error message for deleted vcfile

* fix(INJI-397)refactor:log activity event

* fix(INJI-397)refactor:log activity event

* fix(INJI-397)refactor:comparing VCMetadata

Signed-off-by: Tilak Puli <[email protected]>
  • Loading branch information
srikanth716 authored and tilak-puli committed Oct 11, 2023
1 parent 1f7f832 commit 26f1391
Show file tree
Hide file tree
Showing 18 changed files with 197 additions and 97 deletions.
41 changes: 41 additions & 0 deletions components/ActivityLogEvent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
enum ActivityLogType {
TAMPERED_VC_REMOVED = 'TAMPERED_VC_REMOVED',
}

export class ActivityLog {
_vcKey: string;
timestamp: number;
deviceName: string;
vcLabel: string;
type: ActivityLogType | string;

constructor({
_vcKey = '',
type = '',
timestamp = Date.now(),
deviceName = '',
vcLabel = '',
} = {}) {
this._vcKey = _vcKey;
this.type = type;
this.timestamp = timestamp;
this.deviceName = deviceName;
this.vcLabel = vcLabel;
}

static logTamperedVCs() {
return {
_vcKey: '',
type: ActivityLogType.TAMPERED_VC_REMOVED,
timestamp: Date.now(),
deviceName: '',
vcLabel: '',
};
}
}

export function getActionText(activity: ActivityLog, t) {
return activity.vcLabel
? `${activity.vcLabel} ${t(activity.type)}`
: `${t(activity.type)}`;
}
3 changes: 2 additions & 1 deletion components/ActivityLogText.strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
"QRLOGIN_SUCCESFULL": "QRLogin successful",
"WALLET_BINDING_SUCCESSFULL": "Activation successful",
"WALLET_BINDING_FAILURE": "Activation failed",
"VC_REMOVED":"Removed from wallet"
"VC_REMOVED": "Removed from wallet",
"TAMPERED_VC_REMOVED": "Some cards removed due to malicious activity"
}
18 changes: 9 additions & 9 deletions components/ActivityLogText.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import React from 'react';
import { formatDistanceToNow } from 'date-fns';
import { useTranslation } from 'react-i18next';
import {formatDistanceToNow} from 'date-fns';
import {useTranslation} from 'react-i18next';

import * as DateFnsLocale from 'date-fns/locale';
import { ActivityLog } from '../machines/activityLog';
import { TextItem } from './ui/TextItem';
import {TextItem} from './ui/TextItem';
import {ActivityLog, getActionText} from './ActivityLogEvent';

export const ActivityLogText: React.FC<{ activity: ActivityLog }> = (props) => {
const { t, i18n } = useTranslation('ActivityLogText');
const { activity } = props;
export const ActivityLogText: React.FC<{activity: ActivityLog}> = props => {
const {t, i18n} = useTranslation('ActivityLogText');
const {activity} = props;

return (
<TextItem
label={getActionLabel(activity, i18n.language)}
text={`${activity.vcLabel} ${t(activity.type)}`}
text={getActionText(activity, t)}
topDivider
/>
);
Expand All @@ -27,6 +27,6 @@ function getActionLabel(activity: ActivityLog, language: string) {
locale: DateFnsLocale[language],
}),
]
.filter((label) => label?.trim() !== '')
.filter(label => label?.trim() !== '')
.join(' · ');
}
3 changes: 2 additions & 1 deletion locales/ara.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"QRLOGIN_SUCCESFULL": "QRL تم تسجيل الدخول بنجاح",
"WALLET_BINDING_SUCCESSFULL": "تفعيل ناجحة",
"WALLET_BINDING_FAILURE": "فشل التفعيل",
"VC_REMOVED": "تمت إزالته من المحفظة"
"VC_REMOVED": "تمت إزالته من المحفظة",
"TAMPERED_VC_REMOVED": "تمت إزالة بعض البطاقات بسبب نشاط ضار"
},
"DeviceInfoList": {
"requestedBy": "مطلوب بواسطة",
Expand Down
5 changes: 3 additions & 2 deletions locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"QRLOGIN_SUCCESFULL": "QRLogin successful",
"WALLET_BINDING_SUCCESSFULL": "Activation successful",
"WALLET_BINDING_FAILURE": "Activation failed",
"VC_REMOVED": "Removed from wallet"
"VC_REMOVED": "Removed from wallet",
"TAMPERED_VC_REMOVED": "Some cards removed due to malicious activity"
},
"DeviceInfoList": {
"requestedBy": "Requested by",
Expand Down Expand Up @@ -160,7 +161,7 @@
"IssuersScreen": {
"title": "Add new card",
"header": "Please select a preferred method from below to add a new card",
"itemHeading":"Download via {{issuer}}",
"itemHeading": "Download via {{issuer}}",
"itemSubHeading": "Enter the mentioned ID and get your card",
"modal": {
"title": "In Progress",
Expand Down
3 changes: 2 additions & 1 deletion locales/hin.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"QRLOGIN_SUCCESFULL": "क्यूआरलॉगिन सफल",
"WALLET_BINDING_SUCCESSFULL": "सक्रियण सफल",
"WALLET_BINDING_FAILURE": "सक्रियकरण असफल",
"VC_REMOVED": "वॉलेट से हटाया गया"
"VC_REMOVED": "वॉलेट से हटाया गया",
"TAMPERED_VC_REMOVED": "दुर्भावनापूर्ण गतिविधि के कारण कुछ कार्ड हटा दिए गए"
},
"DeviceInfoList": {
"requestedBy": "द्वारा अनुरोध किया गया",
Expand Down
3 changes: 2 additions & 1 deletion locales/kan.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"QRLOGIN_SUCCESFULL": "QRಲಾಗಿನ್ ಯಶಸ್ವಿಯಾಗಿದೆ",
"WALLET_BINDING_SUCCESSFULL": "ಸಕ್ರಿಯಗೊಳಿಸುವಿಕೆ ಯಶಸ್ವಿಯಾಗಿದೆ",
"WALLET_BINDING_FAILURE": "ಸಕ್ರಿಯಗೊಳಿಸುವಿಕೆ ವಿಫಲವಾಗಿದೆ",
"VC_REMOVED": "ಕೈಚೀಲದಿಂದ ತೆಗೆದುಹಾಕಲಾಗಿದೆ"
"VC_REMOVED": "ಕೈಚೀಲದಿಂದ ತೆಗೆದುಹಾಕಲಾಗಿದೆ",
"TAMPERED_VC_REMOVED": "ದುರುದ್ದೇಶಪೂರಿತ ಚಟುವಟಿಕೆಯಿಂದಾಗಿ ಕೆಲವು ಕಾರ್ಡ್‌ಗಳನ್ನು ತೆಗೆದುಹಾಕಲಾಗಿದೆ"
},
"DeviceInfoList": {
"requestedBy": "ವಿನಂತಿಸಿದವರು",
Expand Down
4 changes: 3 additions & 1 deletion locales/spa.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"QRLOGIN_SUCCESFULL": "Inicio de sesión QR exitoso",
"WALLET_BINDING_SUCCESSFULL": "Activación exitosa",
"WALLET_BINDING_FAILURE": "Activación fallida",
"VC_REMOVED": "Eliminado de la billetera"
"VC_REMOVED": "Eliminado de la billetera",
"TAMPERED_VC_REMOVED": "Algunas tarjetas eliminadas debido a actividad maliciosa"
},
"DeviceInfoList": {
"requestedBy": "Solicitado por",
Expand Down Expand Up @@ -963,3 +964,4 @@
}
}
}

3 changes: 2 additions & 1 deletion locales/tam.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"QRLOGIN_SUCCESFULL": "QRஉள்நுழைவு வெற்றிகரமாக உள்ளது",
"WALLET_BINDING_SUCCESSFULL": "செயல்படுத்தல் வெற்றி",
"WALLET_BINDING_FAILURE": "செயல்படுத்துவதில் தோல்வி",
"VC_REMOVED": "பணப்பையிலிருந்து அகற்றப்பட்டது"
"VC_REMOVED": "பணப்பையிலிருந்து அகற்றப்பட்டது",
"TAMPERED_VC_REMOVED": "தீங்கிழைக்கும் செயல்பாட்டின் காரணமாக சில கார்டுகள் அகற்றப்பட்டன"
},
"DeviceInfoList": {
"requestedBy": "கோரியவர்",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ const model = createModel(
SHOW_ACTIVITY: () => ({}),
REMOVE: (vcMetadata: VCMetadata) => ({vcMetadata}),
UPDATE_VC_METADATA: (vcMetadata: VCMetadata) => ({vcMetadata}),
TAMPERED_VC: (key: string) => ({key}),
},
},
);
Expand Down Expand Up @@ -154,6 +155,9 @@ export const ExistingMosipVCItemMachine =
target: 'checkingServerData',
},
],
TAMPERED_VC: {
actions: ['sendTamperedVc', 'removeTamperedVcItem'],
},
},
},
checkingServerData: {
Expand Down Expand Up @@ -441,7 +445,7 @@ export const ExistingMosipVCItemMachine =
entry: 'removeVcItem',
on: {
STORE_RESPONSE: {
actions: ['removedVc', 'logVCremoved'],
actions: ['refreshMyVcs', 'logVCremoved'],
target: '#vc-item',
},
},
Expand Down Expand Up @@ -870,6 +874,13 @@ export const ExistingMosipVCItemMachine =
},
),

sendTamperedVc: send(
context => VcEvents.TAMPERED_VC(context.vcMetadata),
{
to: context => context.serviceRefs.vc,
},
),

updateVc: send(
context => {
const {serviceRefs, ...vc} = context;
Expand Down Expand Up @@ -904,16 +915,6 @@ export const ExistingMosipVCItemMachine =
},
),

VcUpdated: send(
context => {
const {serviceRefs, ...vc} = context;
return {type: 'VC_UPDATE', vc};
},
{
to: context => context.serviceRefs.vc,
},
),

setThumbprintForWalletBindingId: send(
context => {
const {walletBindingResponse} = context;
Expand All @@ -930,7 +931,7 @@ export const ExistingMosipVCItemMachine =
},
),

removedVc: send(
refreshMyVcs: send(
() => ({
type: 'REFRESH_MY_VCS',
}),
Expand Down Expand Up @@ -1128,6 +1129,16 @@ export const ExistingMosipVCItemMachine =
{to: context => context.serviceRefs.store},
),

removeTamperedVcItem: send(
_context => {
return StoreEvents.REMOVE(
MY_VCS_STORE_KEY,
_context.vcMetadata.getVcKey(),
);
},
{to: context => context.serviceRefs.store},
),

logVCremoved: send(
(context, _) =>
ActivityLogEvents.LOG_ACTIVITY({
Expand Down
34 changes: 14 additions & 20 deletions machines/activityLog.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { EventFrom, send, sendParent, StateFrom } from 'xstate';
import { createModel } from 'xstate/lib/model';
import { AppServices } from '../shared/GlobalContext';
import { ACTIVITY_LOG_STORE_KEY } from '../shared/constants';
import { StoreEvents } from './store';
import {EventFrom, send, sendParent, StateFrom} from 'xstate';
import {createModel} from 'xstate/lib/model';
import {AppServices} from '../shared/GlobalContext';
import {ACTIVITY_LOG_STORE_KEY} from '../shared/constants';
import {StoreEvents} from './store';
import {ActivityLog} from '../components/ActivityLogEvent';

const model = createModel(
{
Expand All @@ -11,11 +12,11 @@ const model = createModel(
},
{
events: {
STORE_RESPONSE: (response: unknown) => ({ response }),
LOG_ACTIVITY: (log: ActivityLog | ActivityLog[]) => ({ log }),
STORE_RESPONSE: (response: unknown) => ({response}),
LOG_ACTIVITY: (log: ActivityLog | ActivityLog[]) => ({log}),
REFRESH: () => ({}),
},
}
},
);

export const ActivityLogEvents = model.events;
Expand Down Expand Up @@ -81,7 +82,7 @@ export const activityLogMachine =
{
actions: {
loadActivities: send(StoreEvents.GET(ACTIVITY_LOG_STORE_KEY), {
to: (context) => context.serviceRefs.store,
to: context => context.serviceRefs.store,
}),

setActivities: model.assign({
Expand All @@ -90,7 +91,7 @@ export const activityLogMachine =

storeActivity: send(
(_, event) => StoreEvents.PREPEND(ACTIVITY_LOG_STORE_KEY, event.log),
{ to: (context) => context.serviceRefs.store }
{to: context => context.serviceRefs.store},
),

prependActivity: model.assign({
Expand All @@ -100,7 +101,7 @@ export const activityLogMachine =
: [event.response, ...context.activities]) as ActivityLog[],
}),
},
}
},
);

export function createActivityLogMachine(serviceRefs: AppServices) {
Expand All @@ -110,14 +111,6 @@ export function createActivityLogMachine(serviceRefs: AppServices) {
});
}

export interface ActivityLog {
_vcKey: string;
timestamp: number;
deviceName: string;
vcLabel: string;
type: ActivityLogType;
}

export type ActivityLogType =
| 'VC_SHARED'
| 'VC_RECEIVED'
Expand All @@ -134,7 +127,8 @@ export type ActivityLogType =
| 'QRLOGIN_SUCCESFULL'
| 'WALLET_BINDING_SUCCESSFULL'
| 'WALLET_BINDING_FAILURE'
| 'VC_REMOVED';
| 'VC_REMOVED'
| 'TAMPERED_VC_REMOVED';

type State = StateFrom<typeof activityLogMachine>;

Expand Down
Loading

0 comments on commit 26f1391

Please sign in to comment.