Skip to content

Commit

Permalink
[INJIMOB-2571]: refactor all the state machine related to backup and …
Browse files Browse the repository at this point in the history
…restore (#1748)

Signed-off-by: Alka Prasad <[email protected]>
  • Loading branch information
Alka1703 authored Dec 18, 2024
1 parent f6055a4 commit 944967d
Show file tree
Hide file tree
Showing 37 changed files with 1,675 additions and 1,165 deletions.
9 changes: 7 additions & 2 deletions machines/Issuers/IssuersActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from '../../shared/constants';
import {assign, send} from 'xstate';
import {StoreEvents} from '../store';
import {BackupEvents} from '../backupAndRestore/backup';
import {BackupEvents} from '../backupAndRestore/backup/backupMachine';
import {getVCMetadata, VCMetadata} from '../../shared/VCMetadata';
import {isHardwareKeystoreExists} from '../../shared/cryptoutil/cryptoUtil';
import {ActivityLogEvents} from '../activityLog';
Expand Down Expand Up @@ -113,7 +113,12 @@ export const IssuersActions = (model: any) => {
if (error.includes(REQUEST_TIMEOUT)) {
return ErrorMessage.REQUEST_TIMEDOUT;
}
if (error.includes(OIDCErrors.AUTHORIZATION_ENDPOINT_DISCOVERY.GRANT_TYPE_NOT_SUPPORTED)) {
if (
error.includes(
OIDCErrors.AUTHORIZATION_ENDPOINT_DISCOVERY
.GRANT_TYPE_NOT_SUPPORTED,
)
) {
return ErrorMessage.AUTHORIZATION_GRANT_TYPE_NOT_SUPPORTED;
}
return ErrorMessage.GENERIC;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
} from '../../../shared/telemetry/TelemetryUtils';

import {ActivityLogEvents} from '../../activityLog';
import {BackupEvents} from '../../backupAndRestore/backup';
import {BackupEvents} from '../../backupAndRestore/backup/backupMachine';
import {VcMetaEvents} from '../VCMetaMachine/VCMetaMachine';
import {WalletBindingResponse} from '../VCMetaMachine/vc';
import {BannerStatusType} from '../../../components/BannerNotification';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
RECEIVED_VCS_STORE_KEY,
} from '../../../shared/constants';
import {ActivityLogEvents} from '../../activityLog';
import {BackupEvents} from '../../backupAndRestore/backup';
import {BackupEvents} from '../../backupAndRestore/backup/backupMachine';
import {StoreEvents} from '../../store';
import {vcVerificationBannerDetails} from '../../../components/BannerNotificationContainer';

Expand Down
118 changes: 118 additions & 0 deletions machines/VerifiableCredential/VCMetaMachine/VCMetaMachine.typegen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
// This file was automatically generated. Edits will be overwritten

export interface Typegen0 {
'@@xstate/typegen': true;
internalEvents: {
'done.invoke.vcMeta.ready.tamperedVCs.triggerAutoBackupForTamperedVcDeletion:invocation[0]': {
type: 'done.invoke.vcMeta.ready.tamperedVCs.triggerAutoBackupForTamperedVcDeletion:invocation[0]';
data: unknown;
__tip: 'See the XState TS docs to learn how to strongly type this.';
};
'xstate.init': {type: 'xstate.init'};
};
invokeSrcNameMap: {
isUserSignedAlready: 'done.invoke.vcMeta.ready.tamperedVCs.triggerAutoBackupForTamperedVcDeletion:invocation[0]';
};
missingImplementations: {
actions:
| 'addVcToInProgressDownloads'
| 'getVcItemResponse'
| 'loadMyVcs'
| 'loadReceivedVcs'
| 'logTamperedVCsremoved'
| 'prependToMyVcsMetadata'
| 'removeDownloadFailedVcsFromStorage'
| 'removeDownloadingFailedVcsFromMyVcs'
| 'removeVcFromInProgressDownlods'
| 'removeVcFromMyVcsMetadata'
| 'resetDownloadCreadentialsFailed'
| 'resetDownloadCredentialsSuccess'
| 'resetDownloadFailedVcs'
| 'resetInProgressVcsDownloaded'
| 'resetTamperedVcs'
| 'resetVerificationErrorMessage'
| 'resetVerificationStatus'
| 'resetWalletBindingSuccess'
| 'sendBackupEvent'
| 'setDownloadCreadentialsFailed'
| 'setDownloadCredentialsSuccess'
| 'setDownloadedVc'
| 'setDownloadingFailedVcs'
| 'setMyVcs'
| 'setReceivedVcs'
| 'setUpdatedVcMetadatas'
| 'setVerificationErrorMessage'
| 'setVerificationStatus'
| 'setWalletBindingSuccess'
| 'updateMyVcsMetadata';
delays: never;
guards: 'isAnyVcTampered' | 'isSignedIn';
services: 'isUserSignedAlready';
};
eventsCausingActions: {
addVcToInProgressDownloads: 'ADD_VC_TO_IN_PROGRESS_DOWNLOADS';
getVcItemResponse: 'GET_VC_ITEM';
loadMyVcs:
| 'REFRESH_MY_VCS'
| 'REFRESH_RECEIVED_VCS'
| 'STORE_RESPONSE'
| 'VERIFY_VC_FAILED'
| 'xstate.init';
loadReceivedVcs: 'REFRESH_RECEIVED_VCS' | 'STORE_RESPONSE';
logTamperedVCsremoved: 'done.invoke.vcMeta.ready.tamperedVCs.triggerAutoBackupForTamperedVcDeletion:invocation[0]';
prependToMyVcsMetadata: 'VC_ADDED';
removeDownloadFailedVcsFromStorage: 'DELETE_VC';
removeDownloadingFailedVcsFromMyVcs: 'STORE_RESPONSE';
removeVcFromInProgressDownlods:
| 'DOWNLOAD_LIMIT_EXPIRED'
| 'REMOVE_VC_FROM_IN_PROGRESS_DOWNLOADS'
| 'VERIFY_VC_FAILED';
removeVcFromMyVcsMetadata: 'REMOVE_VC_FROM_CONTEXT';
resetDownloadCreadentialsFailed: 'RESET_DOWNLOADING_FAILED';
resetDownloadCredentialsSuccess: 'RESET_DOWNLOADING_SUCCESS';
resetDownloadFailedVcs: 'STORE_RESPONSE';
resetInProgressVcsDownloaded: 'RESET_IN_PROGRESS_VCS_DOWNLOADED';
resetTamperedVcs: 'REMOVE_TAMPERED_VCS';
resetVerificationErrorMessage: 'RESET_VERIFY_ERROR';
resetVerificationStatus: 'RESET_VERIFICATION_STATUS';
resetWalletBindingSuccess: 'RESET_WALLET_BINDING_SUCCESS';
sendBackupEvent: 'done.invoke.vcMeta.ready.tamperedVCs.triggerAutoBackupForTamperedVcDeletion:invocation[0]';
setDownloadCreadentialsFailed: 'VC_DOWNLOADING_FAILED';
setDownloadCredentialsSuccess: 'VC_DOWNLOADED';
setDownloadedVc: 'VC_DOWNLOADED';
setDownloadingFailedVcs: 'DOWNLOAD_LIMIT_EXPIRED';
setMyVcs: 'STORE_RESPONSE';
setReceivedVcs: 'STORE_RESPONSE';
setUpdatedVcMetadatas: 'VC_METADATA_UPDATED';
setVerificationErrorMessage: 'VERIFY_VC_FAILED';
setVerificationStatus: 'SET_VERIFICATION_STATUS';
setWalletBindingSuccess: 'WALLET_BINDING_SUCCESS';
updateMyVcsMetadata: 'VC_METADATA_UPDATED';
};
eventsCausingDelays: {};
eventsCausingGuards: {
isAnyVcTampered: 'SHOW_TAMPERED_POPUP';
isSignedIn: 'done.invoke.vcMeta.ready.tamperedVCs.triggerAutoBackupForTamperedVcDeletion:invocation[0]';
};
eventsCausingServices: {
isUserSignedAlready: 'REMOVE_TAMPERED_VCS';
};
matchesStates:
| 'deletingFailedVcs'
| 'ready'
| 'ready.myVcs'
| 'ready.receivedVcs'
| 'ready.showTamperedPopup'
| 'ready.tamperedVCs'
| 'ready.tamperedVCs.idle'
| 'ready.tamperedVCs.triggerAutoBackupForTamperedVcDeletion'
| {
ready?:
| 'myVcs'
| 'receivedVcs'
| 'showTamperedPopup'
| 'tamperedVCs'
| {tamperedVCs?: 'idle' | 'triggerAutoBackupForTamperedVcDeletion'};
};
tags: never;
}
24 changes: 13 additions & 11 deletions machines/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ import {
SETTINGS_STORE_KEY,
} from '../shared/constants';
import {logState} from '../shared/commonUtil';
import {backupMachine, createBackupMachine} from './backupAndRestore/backup';
import {
backupRestoreMachine,
createBackupRestoreMachine,
} from './backupAndRestore/backupRestore';
backupMachine,
createBackupMachine,
} from './backupAndRestore/backup/backupMachine';
import {
restoreMachine,
createRestoreMachine,
} from './backupAndRestore/restore/restoreMachine';
import {
createVcMetaMachine,
vcMetaMachine,
Expand Down Expand Up @@ -103,8 +106,8 @@ export const appMachine = model.createMachine(
target: 'init',
},
BIOMETRIC_CANCELLED: {
target: 'init'
}
target: 'init',
},
},
states: {
init: {
Expand Down Expand Up @@ -171,9 +174,8 @@ export const appMachine = model.createMachine(
target: 'info',
},
BIOMETRIC_CANCELLED: {
target: 'store'
}

target: 'store',
},
},
},
info: {
Expand Down Expand Up @@ -340,8 +342,8 @@ export const appMachine = model.createMachine(
);

serviceRefs.backupRestore = spawn(
createBackupRestoreMachine(serviceRefs),
backupRestoreMachine.id,
createRestoreMachine(serviceRefs),
restoreMachine.id,
);

serviceRefs.activityLog = spawn(
Expand Down
2 changes: 2 additions & 0 deletions machines/app.typegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export interface Typegen0 {
loadEsignetHostFromStorage: 'READY';
logServiceEvents: 'done.invoke.app.init.checkKeyPairs:invocation[0]';
logStoreEvents:
| 'BIOMETRIC_CANCELLED'
| 'KEY_INVALIDATE_ERROR'
| 'RESET_KEY_INVALIDATE_ERROR_DISMISS'
| 'xstate.init';
Expand All @@ -59,6 +60,7 @@ export interface Typegen0 {
setLinkCode: 'done.invoke.app.ready.focus.active:invocation[0]';
spawnServiceActors: 'done.invoke.app.init.checkKeyPairs:invocation[0]';
spawnStoreActor:
| 'BIOMETRIC_CANCELLED'
| 'KEY_INVALIDATE_ERROR'
| 'RESET_KEY_INVALIDATE_ERROR_DISMISS'
| 'xstate.init';
Expand Down
82 changes: 0 additions & 82 deletions machines/backupAndRestore/backup.typegen.ts

This file was deleted.

Loading

0 comments on commit 944967d

Please sign in to comment.