mirror of
https://github.com/mosip/inji-wallet.git
synced 2026-01-10 05:58:01 -05:00
[INJIMOB-1162] fix bottom tab not showing in history screen (#1383)
Signed-off-by: adityankannan-tw <adityan410pm@gmail.com> Co-authored-by: adityankannan-tw <adityan410pm@gmail.com>
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
import {useContext} from 'react';
|
||||
import {GlobalContext} from '../shared/GlobalContext';
|
||||
import {useSelector} from '@xstate/react';
|
||||
import {
|
||||
VcMetaEvents,
|
||||
selectWalletBindingSuccess,
|
||||
} from '../machines/VerifiableCredential/VCMetaMachine/VCMetaMachine';
|
||||
import {selectWalletBindingSuccess} from '../machines/VerifiableCredential/VCMetaMachine/VCMetaSelectors';
|
||||
import { VcMetaEvents } from '../machines/VerifiableCredential/VCMetaMachine/VCMetaMachine';
|
||||
|
||||
export const UseWalletBindingSuccess = () => {
|
||||
const {appService} = useContext(GlobalContext);
|
||||
|
||||
237
machines/VerifiableCredential/VCMetaMachine/VCMetaActions.ts
Normal file
237
machines/VerifiableCredential/VCMetaMachine/VCMetaActions.ts
Normal file
@@ -0,0 +1,237 @@
|
||||
import {send} from 'xstate';
|
||||
import {respond} from 'xstate/lib/actions';
|
||||
import {ActivityLog} from '../../../components/ActivityLogEvent';
|
||||
import {VCMetadata, parseMetadatas} from '../../../shared/VCMetadata';
|
||||
import {
|
||||
MY_VCS_STORE_KEY,
|
||||
RECEIVED_VCS_STORE_KEY,
|
||||
} from '../../../shared/constants';
|
||||
import {ActivityLogEvents} from '../../activityLog';
|
||||
import {BackupEvents} from '../../backupAndRestore/backup';
|
||||
import {StoreEvents} from '../../store';
|
||||
|
||||
export const VCMetaActions = (model: any) => {
|
||||
return {
|
||||
sendBackupEvent: send(BackupEvents.DATA_BACKUP(true), {
|
||||
to: context => context.serviceRefs.backup,
|
||||
}),
|
||||
|
||||
getVcItemResponse: respond((context, event) => {
|
||||
if (context.tamperedVcs.includes(event.vcMetadata)) {
|
||||
return {
|
||||
type: 'TAMPERED_VC',
|
||||
};
|
||||
}
|
||||
|
||||
const isMyVCs = context.myVcsMetadata?.filter(
|
||||
(vcMetadataObject: Object) => {
|
||||
return (
|
||||
new VCMetadata(vcMetadataObject).getVcKey() ===
|
||||
VCMetadata.fromVC(event.vcMetadata)?.getVcKey()
|
||||
);
|
||||
},
|
||||
).length;
|
||||
|
||||
const vcData = isMyVCs
|
||||
? context.myVcs[VCMetadata.fromVC(event.vcMetadata)?.getVcKey()]
|
||||
: context.receivedVcs[VCMetadata.fromVC(event.vcMetadata)?.getVcKey()];
|
||||
|
||||
return {
|
||||
type: 'GET_VC_RESPONSE',
|
||||
response: vcData,
|
||||
};
|
||||
}),
|
||||
|
||||
loadMyVcsMetadata: send(StoreEvents.GET(MY_VCS_STORE_KEY), {
|
||||
to: context => context.serviceRefs.store,
|
||||
}),
|
||||
|
||||
loadReceivedVcsMetadata: send(StoreEvents.GET(RECEIVED_VCS_STORE_KEY), {
|
||||
to: context => context.serviceRefs.store,
|
||||
}),
|
||||
|
||||
setMyVcsMetadata: model.assign({
|
||||
myVcsMetadata: (_context, event) => {
|
||||
return parseMetadatas((event.response || []) as object[]);
|
||||
},
|
||||
}),
|
||||
|
||||
setReceivedVcsMetadata: model.assign({
|
||||
receivedVcsMetadata: (_context, event) => {
|
||||
return parseMetadatas((event.response || []) as object[]);
|
||||
},
|
||||
}),
|
||||
|
||||
loadMyVcs: send(
|
||||
context => StoreEvents.GET_VCS_DATA(context.myVcsMetadata),
|
||||
{
|
||||
to: context => context.serviceRefs.store,
|
||||
},
|
||||
),
|
||||
|
||||
loadReceivedVcs: send(
|
||||
context => StoreEvents.GET_VCS_DATA(context.receivedVcsMetadata),
|
||||
{
|
||||
to: context => context.serviceRefs.store,
|
||||
},
|
||||
),
|
||||
|
||||
setMyVcs: model.assign({
|
||||
myVcs: (_context, event) => {
|
||||
return event.response.vcsData;
|
||||
},
|
||||
tamperedVcs: (context, event) => {
|
||||
return [...context.tamperedVcs, ...event.response.tamperedVcsList];
|
||||
},
|
||||
}),
|
||||
|
||||
setReceivedVcs: model.assign({
|
||||
receivedVcs: (_context, event) => {
|
||||
return event.response.vcsData;
|
||||
},
|
||||
tamperedVcs: (context, event) => {
|
||||
return [...context.tamperedVcs, ...event.response.tamperedVcsList];
|
||||
},
|
||||
}),
|
||||
|
||||
resetTamperedVcs: model.assign({
|
||||
tamperedVcs: () => [],
|
||||
}),
|
||||
|
||||
setDownloadingFailedVcs: model.assign({
|
||||
downloadingFailedVcs: (context, event) => [
|
||||
...context.downloadingFailedVcs,
|
||||
event.vcMetadata,
|
||||
],
|
||||
}),
|
||||
|
||||
setVerificationErrorMessage: model.assign({
|
||||
verificationErrorMessage: (context, event) => event.errorMessage,
|
||||
}),
|
||||
|
||||
resetVerificationErrorMessage: model.assign({
|
||||
verificationErrorMessage: (_context, event) => '',
|
||||
}),
|
||||
|
||||
resetDownloadFailedVcs: model.assign({
|
||||
downloadingFailedVcs: (context, event) => [],
|
||||
}),
|
||||
|
||||
setDownloadedVc: (context, event) => {
|
||||
const vcMetaData = event.vcMetadata ? event.vcMetadata : event.vc;
|
||||
const vcUniqueId = VCMetadata.fromVC(vcMetaData).getVcKey();
|
||||
context.myVcs[vcUniqueId] = event.vc;
|
||||
},
|
||||
|
||||
addVcToInProgressDownloads: model.assign({
|
||||
inProgressVcDownloads: (context, event) => {
|
||||
let paresedInProgressList: Set<string> = context.inProgressVcDownloads;
|
||||
const newVcRequestID = event.requestId;
|
||||
const newInProgressList = paresedInProgressList.add(newVcRequestID);
|
||||
return newInProgressList;
|
||||
},
|
||||
}),
|
||||
|
||||
removeVcFromInProgressDownlods: model.assign({
|
||||
inProgressVcDownloads: (context, event) => {
|
||||
let updatedInProgressList: Set<string> = context.inProgressVcDownloads;
|
||||
if (!event.vcMetadata) {
|
||||
return updatedInProgressList;
|
||||
}
|
||||
const removeVcRequestID = event.vcMetadata.requestId;
|
||||
updatedInProgressList.delete(removeVcRequestID);
|
||||
|
||||
return updatedInProgressList;
|
||||
},
|
||||
areAllVcsDownloaded: context => {
|
||||
if (context.inProgressVcDownloads.size == 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
}),
|
||||
|
||||
resetInProgressVcsDownloaded: model.assign({
|
||||
areAllVcsDownloaded: () => false,
|
||||
inProgressVcDownloads: new Set<string>(),
|
||||
}),
|
||||
|
||||
setUpdatedVcMetadatas: send(
|
||||
_context => {
|
||||
return StoreEvents.SET(MY_VCS_STORE_KEY, _context.myVcsMetadata);
|
||||
},
|
||||
{to: context => context.serviceRefs.store},
|
||||
),
|
||||
|
||||
prependToMyVcsMetadata: model.assign({
|
||||
myVcsMetadata: (context, event) => [
|
||||
event.vcMetadata,
|
||||
...context.myVcsMetadata,
|
||||
],
|
||||
}),
|
||||
|
||||
removeVcFromMyVcsMetadata: model.assign({
|
||||
myVcsMetadata: (context, event) =>
|
||||
context.myVcsMetadata.filter(
|
||||
(vc: VCMetadata) => !vc.equals(event.vcMetadata),
|
||||
),
|
||||
}),
|
||||
|
||||
removeDownloadingFailedVcsFromMyVcs: model.assign({
|
||||
myVcsMetadata: (context, event) =>
|
||||
context.myVcsMetadata.filter(
|
||||
value =>
|
||||
!context.downloadingFailedVcs.some(item => item?.equals(value)),
|
||||
),
|
||||
}),
|
||||
|
||||
removeDownloadFailedVcsFromStorage: send(
|
||||
context => {
|
||||
return StoreEvents.REMOVE_ITEMS(
|
||||
MY_VCS_STORE_KEY,
|
||||
context.downloadingFailedVcs.map(m => m.getVcKey()),
|
||||
);
|
||||
},
|
||||
{
|
||||
to: context => context.serviceRefs.store,
|
||||
},
|
||||
),
|
||||
|
||||
logTamperedVCsremoved: send(
|
||||
context => ActivityLogEvents.LOG_ACTIVITY(ActivityLog.logTamperedVCs()),
|
||||
{
|
||||
to: context => context.serviceRefs.activityLog,
|
||||
},
|
||||
),
|
||||
|
||||
updateMyVcsMetadata: model.assign({
|
||||
myVcsMetadata: (context, event) => [
|
||||
...getUpdatedVCMetadatas(context.myVcsMetadata, event.vcMetadata),
|
||||
],
|
||||
}),
|
||||
|
||||
setWalletBindingSuccess: model.assign({
|
||||
walletBindingSuccess: true,
|
||||
}),
|
||||
resetWalletBindingSuccess: model.assign({
|
||||
walletBindingSuccess: false,
|
||||
}),
|
||||
};
|
||||
};
|
||||
|
||||
function getUpdatedVCMetadatas(
|
||||
existingVCMetadatas: VCMetadata[],
|
||||
updatedVcMetadata: VCMetadata,
|
||||
) {
|
||||
const isPinStatusUpdated = updatedVcMetadata.isPinned;
|
||||
|
||||
return existingVCMetadatas.map(value => {
|
||||
if (value.equals(updatedVcMetadata)) {
|
||||
return updatedVcMetadata;
|
||||
} else if (isPinStatusUpdated) {
|
||||
return new VCMetadata({...value, isPinned: false});
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
});
|
||||
}
|
||||
36
machines/VerifiableCredential/VCMetaMachine/VCMetaEvents.ts
Normal file
36
machines/VerifiableCredential/VCMetaMachine/VCMetaEvents.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import {VCMetadata} from '../../../shared/VCMetadata';
|
||||
import {VC} from './vc';
|
||||
|
||||
export const VcMetaEvents = {
|
||||
VIEW_VC: (vc: VC) => ({vc}),
|
||||
GET_VC_ITEM: (vcMetadata: VCMetadata) => ({vcMetadata}),
|
||||
STORE_RESPONSE: (response: unknown) => ({response}),
|
||||
STORE_ERROR: (error: Error) => ({error}),
|
||||
VC_ADDED: (vcMetadata: VCMetadata) => ({vcMetadata}),
|
||||
REMOVE_VC_FROM_CONTEXT: (vcMetadata: VCMetadata) => ({vcMetadata}),
|
||||
VC_METADATA_UPDATED: (vcMetadata: VCMetadata) => ({vcMetadata}),
|
||||
VC_DOWNLOADED: (vc: VC, vcMetadata?: VCMetadata) => ({
|
||||
vc,
|
||||
vcMetadata,
|
||||
}),
|
||||
REFRESH_MY_VCS: () => ({}),
|
||||
REFRESH_MY_VCS_TWO: (vc: VC) => ({vc}),
|
||||
REFRESH_RECEIVED_VCS: () => ({}),
|
||||
WALLET_BINDING_SUCCESS: () => ({}),
|
||||
RESET_WALLET_BINDING_SUCCESS: () => ({}),
|
||||
ADD_VC_TO_IN_PROGRESS_DOWNLOADS: (requestId: string) => ({requestId}),
|
||||
REMOVE_VC_FROM_IN_PROGRESS_DOWNLOADS: (vcMetadata: VCMetadata) => ({
|
||||
vcMetadata,
|
||||
}),
|
||||
RESET_IN_PROGRESS_VCS_DOWNLOADED: () => ({}),
|
||||
REMOVE_TAMPERED_VCS: () => ({}),
|
||||
DOWNLOAD_LIMIT_EXPIRED: (vcMetadata: VCMetadata) => ({vcMetadata}),
|
||||
DELETE_VC: () => ({}),
|
||||
VERIFY_VC_FAILED: (errorMessage: string, vcMetadata?: VCMetadata) => ({
|
||||
errorMessage,
|
||||
vcMetadata,
|
||||
}),
|
||||
RESET_VERIFY_ERROR: () => ({}),
|
||||
REFRESH_VCS_METADATA: () => ({}),
|
||||
SHOW_TAMPERED_POPUP: () => ({}),
|
||||
};
|
||||
11
machines/VerifiableCredential/VCMetaMachine/VCMetaGuards.ts
Normal file
11
machines/VerifiableCredential/VCMetaMachine/VCMetaGuards.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { isSignedInResult } from "../../../shared/CloudBackupAndRestoreUtils";
|
||||
|
||||
export const VCMetaGuards = () => {
|
||||
return {
|
||||
isSignedIn: (_context, event) =>
|
||||
(event.data as isSignedInResult).isSignedIn,
|
||||
isAnyVcTampered: context => {
|
||||
return context.tamperedVcs.length > 0;
|
||||
},
|
||||
};
|
||||
};
|
||||
@@ -1,72 +1,11 @@
|
||||
import {EventFrom, send, sendParent, StateFrom} from 'xstate';
|
||||
import {createModel} from 'xstate/lib/model';
|
||||
import {StoreEvents} from '../../store';
|
||||
import {VC} from './vc';
|
||||
import {EventFrom, send, sendParent} from 'xstate';
|
||||
import {AppServices} from '../../../shared/GlobalContext';
|
||||
import {log, respond} from 'xstate/lib/actions';
|
||||
import {
|
||||
MY_VCS_STORE_KEY,
|
||||
RECEIVED_VCS_STORE_KEY,
|
||||
} from '../../../shared/constants';
|
||||
import {parseMetadatas, VCMetadata} from '../../../shared/VCMetadata';
|
||||
import {ActivityLogEvents} from '../../activityLog';
|
||||
import {ActivityLog} from '../../../components/ActivityLogEvent';
|
||||
import Cloud, {
|
||||
isSignedInResult,
|
||||
} from '../../../shared/CloudBackupAndRestoreUtils';
|
||||
import {BackupEvents} from '../../backupAndRestore/backup';
|
||||
|
||||
const model = createModel(
|
||||
{
|
||||
serviceRefs: {} as AppServices,
|
||||
myVcsMetadata: [] as VCMetadata[],
|
||||
receivedVcsMetadata: [] as VCMetadata[],
|
||||
myVcs: {} as Record<string, VC>,
|
||||
receivedVcs: {} as Record<string, VC>,
|
||||
inProgressVcDownloads: new Set<string>(), //VCDownloadInProgress
|
||||
areAllVcsDownloaded: false as boolean,
|
||||
walletBindingSuccess: false,
|
||||
tamperedVcs: [] as VCMetadata[],
|
||||
downloadingFailedVcs: [] as VCMetadata[], //VCDownloadFailed
|
||||
verificationErrorMessage: '' as string,
|
||||
},
|
||||
{
|
||||
events: {
|
||||
VIEW_VC: (vc: VC) => ({vc}),
|
||||
GET_VC_ITEM: (vcMetadata: VCMetadata) => ({vcMetadata}),
|
||||
STORE_RESPONSE: (response: unknown) => ({response}),
|
||||
STORE_ERROR: (error: Error) => ({error}),
|
||||
VC_ADDED: (vcMetadata: VCMetadata) => ({vcMetadata}),
|
||||
REMOVE_VC_FROM_CONTEXT: (vcMetadata: VCMetadata) => ({vcMetadata}),
|
||||
VC_METADATA_UPDATED: (vcMetadata: VCMetadata) => ({vcMetadata}),
|
||||
VC_DOWNLOADED: (vc: VC, vcMetadata?: VCMetadata) => ({
|
||||
vc,
|
||||
vcMetadata,
|
||||
}),
|
||||
REFRESH_MY_VCS: () => ({}),
|
||||
REFRESH_MY_VCS_TWO: (vc: VC) => ({vc}),
|
||||
REFRESH_RECEIVED_VCS: () => ({}),
|
||||
WALLET_BINDING_SUCCESS: () => ({}),
|
||||
RESET_WALLET_BINDING_SUCCESS: () => ({}),
|
||||
ADD_VC_TO_IN_PROGRESS_DOWNLOADS: (requestId: string) => ({requestId}),
|
||||
REMOVE_VC_FROM_IN_PROGRESS_DOWNLOADS: (vcMetadata: VCMetadata) => ({
|
||||
vcMetadata,
|
||||
}),
|
||||
RESET_IN_PROGRESS_VCS_DOWNLOADED: () => ({}),
|
||||
REMOVE_TAMPERED_VCS: () => ({}),
|
||||
DOWNLOAD_LIMIT_EXPIRED: (vcMetadata: VCMetadata) => ({vcMetadata}),
|
||||
DELETE_VC: () => ({}),
|
||||
VERIFY_VC_FAILED: (errorMessage: string, vcMetadata?: VCMetadata) => ({
|
||||
errorMessage,
|
||||
vcMetadata,
|
||||
}),
|
||||
RESET_VERIFY_ERROR: () => ({}),
|
||||
REFRESH_VCS_METADATA: () => ({}),
|
||||
SHOW_TAMPERED_POPUP: () => ({}),
|
||||
},
|
||||
},
|
||||
);
|
||||
import { VCMetamodel } from './VCMetaModel';
|
||||
import { VCMetaActions } from './VCMetaActions';
|
||||
import { VCMetaGuards } from './VCMetaGuards';
|
||||
import { VCMetaServices } from './VCMetaServices';
|
||||
|
||||
const model = VCMetamodel;
|
||||
export const VcMetaEvents = model.events;
|
||||
|
||||
export const vcMetaMachine =
|
||||
@@ -237,231 +176,9 @@ export const vcMetaMachine =
|
||||
},
|
||||
},
|
||||
{
|
||||
actions: {
|
||||
sendBackupEvent: send(BackupEvents.DATA_BACKUP(true), {
|
||||
to: context => context.serviceRefs.backup,
|
||||
}),
|
||||
|
||||
getVcItemResponse: respond((context, event) => {
|
||||
if (context.tamperedVcs.includes(event.vcMetadata)) {
|
||||
return {
|
||||
type: 'TAMPERED_VC',
|
||||
};
|
||||
}
|
||||
|
||||
const isMyVCs = context.myVcsMetadata?.filter(
|
||||
(vcMetadataObject: Object) => {
|
||||
return (
|
||||
new VCMetadata(vcMetadataObject).getVcKey() ===
|
||||
VCMetadata.fromVC(event.vcMetadata)?.getVcKey()
|
||||
);
|
||||
},
|
||||
).length;
|
||||
|
||||
const vcData = isMyVCs
|
||||
? context.myVcs[VCMetadata.fromVC(event.vcMetadata)?.getVcKey()]
|
||||
: context.receivedVcs[
|
||||
VCMetadata.fromVC(event.vcMetadata)?.getVcKey()
|
||||
];
|
||||
|
||||
return {
|
||||
type: 'GET_VC_RESPONSE',
|
||||
response: vcData,
|
||||
};
|
||||
}),
|
||||
|
||||
loadMyVcsMetadata: send(StoreEvents.GET(MY_VCS_STORE_KEY), {
|
||||
to: context => context.serviceRefs.store,
|
||||
}),
|
||||
|
||||
loadReceivedVcsMetadata: send(StoreEvents.GET(RECEIVED_VCS_STORE_KEY), {
|
||||
to: context => context.serviceRefs.store,
|
||||
}),
|
||||
|
||||
setMyVcsMetadata: model.assign({
|
||||
myVcsMetadata: (_context, event) => {
|
||||
return parseMetadatas((event.response || []) as object[]);
|
||||
},
|
||||
}),
|
||||
|
||||
setReceivedVcsMetadata: model.assign({
|
||||
receivedVcsMetadata: (_context, event) => {
|
||||
return parseMetadatas((event.response || []) as object[]);
|
||||
},
|
||||
}),
|
||||
|
||||
loadMyVcs: send(
|
||||
context => StoreEvents.GET_VCS_DATA(context.myVcsMetadata),
|
||||
{
|
||||
to: context => context.serviceRefs.store,
|
||||
},
|
||||
),
|
||||
|
||||
loadReceivedVcs: send(
|
||||
context => StoreEvents.GET_VCS_DATA(context.receivedVcsMetadata),
|
||||
{
|
||||
to: context => context.serviceRefs.store,
|
||||
},
|
||||
),
|
||||
|
||||
setMyVcs: model.assign({
|
||||
myVcs: (_context, event) => {
|
||||
return event.response.vcsData;
|
||||
},
|
||||
tamperedVcs: (context, event) => {
|
||||
return [...context.tamperedVcs, ...event.response.tamperedVcsList];
|
||||
},
|
||||
}),
|
||||
|
||||
setReceivedVcs: model.assign({
|
||||
receivedVcs: (_context, event) => {
|
||||
return event.response.vcsData;
|
||||
},
|
||||
tamperedVcs: (context, event) => {
|
||||
return [...context.tamperedVcs, ...event.response.tamperedVcsList];
|
||||
},
|
||||
}),
|
||||
|
||||
resetTamperedVcs: model.assign({
|
||||
tamperedVcs: () => [],
|
||||
}),
|
||||
|
||||
setDownloadingFailedVcs: model.assign({
|
||||
downloadingFailedVcs: (context, event) => [
|
||||
...context.downloadingFailedVcs,
|
||||
event.vcMetadata,
|
||||
],
|
||||
}),
|
||||
|
||||
setVerificationErrorMessage: model.assign({
|
||||
verificationErrorMessage: (context, event) => event.errorMessage,
|
||||
}),
|
||||
|
||||
resetVerificationErrorMessage: model.assign({
|
||||
verificationErrorMessage: (_context, event) => '',
|
||||
}),
|
||||
|
||||
resetDownloadFailedVcs: model.assign({
|
||||
downloadingFailedVcs: (context, event) => [],
|
||||
}),
|
||||
|
||||
setDownloadedVc: (context, event) => {
|
||||
const vcMetaData = event.vcMetadata ? event.vcMetadata : event.vc;
|
||||
const vcUniqueId = VCMetadata.fromVC(vcMetaData).getVcKey();
|
||||
context.myVcs[vcUniqueId] = event.vc;
|
||||
},
|
||||
|
||||
addVcToInProgressDownloads: model.assign({
|
||||
inProgressVcDownloads: (context, event) => {
|
||||
let paresedInProgressList: Set<string> =
|
||||
context.inProgressVcDownloads;
|
||||
const newVcRequestID = event.requestId;
|
||||
const newInProgressList = paresedInProgressList.add(newVcRequestID);
|
||||
return newInProgressList;
|
||||
},
|
||||
}),
|
||||
|
||||
removeVcFromInProgressDownlods: model.assign({
|
||||
inProgressVcDownloads: (context, event) => {
|
||||
let updatedInProgressList: Set<string> =
|
||||
context.inProgressVcDownloads;
|
||||
if (!event.vcMetadata) {
|
||||
return updatedInProgressList;
|
||||
}
|
||||
const removeVcRequestID = event.vcMetadata.requestId;
|
||||
updatedInProgressList.delete(removeVcRequestID);
|
||||
|
||||
return updatedInProgressList;
|
||||
},
|
||||
areAllVcsDownloaded: context => {
|
||||
if (context.inProgressVcDownloads.size == 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
}),
|
||||
|
||||
resetInProgressVcsDownloaded: model.assign({
|
||||
areAllVcsDownloaded: () => false,
|
||||
inProgressVcDownloads: new Set<string>(),
|
||||
}),
|
||||
|
||||
setUpdatedVcMetadatas: send(
|
||||
_context => {
|
||||
return StoreEvents.SET(MY_VCS_STORE_KEY, _context.myVcsMetadata);
|
||||
},
|
||||
{to: context => context.serviceRefs.store},
|
||||
),
|
||||
|
||||
prependToMyVcsMetadata: model.assign({
|
||||
myVcsMetadata: (context, event) => [
|
||||
event.vcMetadata,
|
||||
...context.myVcsMetadata,
|
||||
],
|
||||
}),
|
||||
|
||||
removeVcFromMyVcsMetadata: model.assign({
|
||||
myVcsMetadata: (context, event) =>
|
||||
context.myVcsMetadata.filter(
|
||||
(vc: VCMetadata) => !vc.equals(event.vcMetadata),
|
||||
),
|
||||
}),
|
||||
|
||||
removeDownloadingFailedVcsFromMyVcs: model.assign({
|
||||
myVcsMetadata: (context, event) =>
|
||||
context.myVcsMetadata.filter(
|
||||
value =>
|
||||
!context.downloadingFailedVcs.some(item => item?.equals(value)),
|
||||
),
|
||||
}),
|
||||
|
||||
removeDownloadFailedVcsFromStorage: send(
|
||||
context => {
|
||||
return StoreEvents.REMOVE_ITEMS(
|
||||
MY_VCS_STORE_KEY,
|
||||
context.downloadingFailedVcs.map(m => m.getVcKey()),
|
||||
);
|
||||
},
|
||||
{
|
||||
to: context => context.serviceRefs.store,
|
||||
},
|
||||
),
|
||||
|
||||
logTamperedVCsremoved: send(
|
||||
context =>
|
||||
ActivityLogEvents.LOG_ACTIVITY(ActivityLog.logTamperedVCs()),
|
||||
{
|
||||
to: context => context.serviceRefs.activityLog,
|
||||
},
|
||||
),
|
||||
|
||||
updateMyVcsMetadata: model.assign({
|
||||
myVcsMetadata: (context, event) => [
|
||||
...getUpdatedVCMetadatas(context.myVcsMetadata, event.vcMetadata),
|
||||
],
|
||||
}),
|
||||
|
||||
setWalletBindingSuccess: model.assign({
|
||||
walletBindingSuccess: true,
|
||||
}),
|
||||
resetWalletBindingSuccess: model.assign({
|
||||
walletBindingSuccess: false,
|
||||
}),
|
||||
},
|
||||
|
||||
guards: {
|
||||
isSignedIn: (_context, event) =>
|
||||
(event.data as isSignedInResult).isSignedIn,
|
||||
isAnyVcTampered: context => {
|
||||
return context.tamperedVcs.length > 0;
|
||||
},
|
||||
},
|
||||
|
||||
services: {
|
||||
isUserSignedAlready: () => async () => {
|
||||
return await Cloud.isSignedInAlready();
|
||||
},
|
||||
},
|
||||
actions: VCMetaActions(model),
|
||||
guards: VCMetaGuards(),
|
||||
services: VCMetaServices(),
|
||||
},
|
||||
);
|
||||
|
||||
@@ -470,98 +187,4 @@ export function createVcMetaMachine(serviceRefs: AppServices) {
|
||||
...vcMetaMachine.context,
|
||||
serviceRefs,
|
||||
});
|
||||
}
|
||||
|
||||
type State = StateFrom<typeof vcMetaMachine>;
|
||||
|
||||
export function selectMyVcsMetadata(state: State): VCMetadata[] {
|
||||
return state.context.myVcsMetadata;
|
||||
}
|
||||
|
||||
export function selectShareableVcsMetadata(state: State): VCMetadata[] {
|
||||
return state.context.myVcsMetadata.filter(
|
||||
vcMetadata =>
|
||||
state.context.myVcs[vcMetadata.getVcKey()]?.credential != null ||
|
||||
state.context.myVcs[vcMetadata.getVcKey()]?.verifiableCredential != null,
|
||||
);
|
||||
}
|
||||
|
||||
export function selectReceivedVcsMetadata(state: State): VCMetadata[] {
|
||||
return state.context.receivedVcsMetadata;
|
||||
}
|
||||
|
||||
export function selectIsRefreshingMyVcs(state: State) {
|
||||
return (
|
||||
state.matches('ready.myVcsMetadata') || state.matches('ready.myVcsData')
|
||||
);
|
||||
}
|
||||
|
||||
export function selectIsRefreshingReceivedVcs(state: State) {
|
||||
return (
|
||||
state.matches('ready.receivedVcsMetadata') ||
|
||||
state.matches('ready.receivedVcs')
|
||||
);
|
||||
}
|
||||
|
||||
export function selectAreAllVcsDownloaded(state: State) {
|
||||
return state.context.areAllVcsDownloaded;
|
||||
}
|
||||
|
||||
/*
|
||||
this methods returns all the binded vc's in the wallet.
|
||||
*/
|
||||
export function selectBindedVcsMetadata(state: State): VCMetadata[] {
|
||||
return state.context.myVcsMetadata.filter(vcMetadata => {
|
||||
const walletBindingResponse =
|
||||
state.context.myVcs[vcMetadata.getVcKey()]?.walletBindingResponse;
|
||||
return (
|
||||
!isEmpty(walletBindingResponse) &&
|
||||
!isEmpty(walletBindingResponse?.walletBindingId)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
export function selectInProgressVcDownloads(state: State) {
|
||||
return state.context.inProgressVcDownloads;
|
||||
}
|
||||
|
||||
function getUpdatedVCMetadatas(
|
||||
existingVCMetadatas: VCMetadata[],
|
||||
updatedVcMetadata: VCMetadata,
|
||||
) {
|
||||
const isPinStatusUpdated = updatedVcMetadata.isPinned;
|
||||
|
||||
return existingVCMetadatas.map(value => {
|
||||
if (value.equals(updatedVcMetadata)) {
|
||||
return updatedVcMetadata;
|
||||
} else if (isPinStatusUpdated) {
|
||||
return new VCMetadata({...value, isPinned: false});
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function isEmpty(object) {
|
||||
return object == null || object == '' || object == undefined;
|
||||
}
|
||||
|
||||
export function selectWalletBindingSuccess(state: State) {
|
||||
return state.context.walletBindingSuccess;
|
||||
}
|
||||
|
||||
export function selectIsTampered(state: State) {
|
||||
return state.matches('ready.tamperedVCs');
|
||||
}
|
||||
|
||||
export function selectDownloadingFailedVcs(state: State) {
|
||||
return state.context.downloadingFailedVcs;
|
||||
}
|
||||
|
||||
export function selectMyVcs(state: State) {
|
||||
return state.context.myVcs;
|
||||
}
|
||||
|
||||
export function selectVerificationErrorMessage(state: State) {
|
||||
return state.context.verificationErrorMessage;
|
||||
}
|
||||
}
|
||||
24
machines/VerifiableCredential/VCMetaMachine/VCMetaModel.ts
Normal file
24
machines/VerifiableCredential/VCMetaMachine/VCMetaModel.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { createModel } from "xstate/lib/model";
|
||||
import { AppServices } from "../../../shared/GlobalContext";
|
||||
import { VCMetadata } from "../../../shared/VCMetadata";
|
||||
import { VC } from "./vc";
|
||||
import { VcMetaEvents } from "./VCMetaEvents";
|
||||
|
||||
export const VCMetamodel = createModel(
|
||||
{
|
||||
serviceRefs: {} as AppServices,
|
||||
myVcsMetadata: [] as VCMetadata[],
|
||||
receivedVcsMetadata: [] as VCMetadata[],
|
||||
myVcs: {} as Record<string, VC>,
|
||||
receivedVcs: {} as Record<string, VC>,
|
||||
inProgressVcDownloads: new Set<string>(), //VCDownloadInProgress
|
||||
areAllVcsDownloaded: false as boolean,
|
||||
walletBindingSuccess: false,
|
||||
tamperedVcs: [] as VCMetadata[],
|
||||
downloadingFailedVcs: [] as VCMetadata[], //VCDownloadFailed
|
||||
verificationErrorMessage: '' as string,
|
||||
},
|
||||
{
|
||||
events: VcMetaEvents,
|
||||
}
|
||||
);
|
||||
@@ -0,0 +1,80 @@
|
||||
import { StateFrom } from "xstate";
|
||||
import { VCMetadata } from "../../../shared/VCMetadata";
|
||||
import { vcMetaMachine } from "./VCMetaMachine";
|
||||
|
||||
type State = StateFrom<typeof vcMetaMachine>;
|
||||
|
||||
export function selectMyVcsMetadata(state: State): VCMetadata[] {
|
||||
return state.context.myVcsMetadata;
|
||||
}
|
||||
|
||||
export function selectShareableVcsMetadata(state: State): VCMetadata[] {
|
||||
return state.context.myVcsMetadata.filter(
|
||||
vcMetadata =>
|
||||
state.context.myVcs[vcMetadata.getVcKey()]?.credential != null ||
|
||||
state.context.myVcs[vcMetadata.getVcKey()]?.verifiableCredential != null,
|
||||
);
|
||||
}
|
||||
|
||||
export function selectReceivedVcsMetadata(state: State): VCMetadata[] {
|
||||
return state.context.receivedVcsMetadata;
|
||||
}
|
||||
|
||||
export function selectIsRefreshingMyVcs(state: State) {
|
||||
return (
|
||||
state.matches('ready.myVcsMetadata') || state.matches('ready.myVcsData')
|
||||
);
|
||||
}
|
||||
|
||||
export function selectIsRefreshingReceivedVcs(state: State) {
|
||||
return (
|
||||
state.matches('ready.receivedVcsMetadata') ||
|
||||
state.matches('ready.receivedVcs')
|
||||
);
|
||||
}
|
||||
|
||||
export function selectAreAllVcsDownloaded(state: State) {
|
||||
return state.context.areAllVcsDownloaded;
|
||||
}
|
||||
|
||||
/*
|
||||
this methods returns all the binded vc's in the wallet.
|
||||
*/
|
||||
export function selectBindedVcsMetadata(state: State): VCMetadata[] {
|
||||
return state.context.myVcsMetadata.filter(vcMetadata => {
|
||||
const walletBindingResponse =
|
||||
state.context.myVcs[vcMetadata.getVcKey()]?.walletBindingResponse;
|
||||
return (
|
||||
!isEmpty(walletBindingResponse) &&
|
||||
!isEmpty(walletBindingResponse?.walletBindingId)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
export function selectInProgressVcDownloads(state: State) {
|
||||
return state.context.inProgressVcDownloads;
|
||||
}
|
||||
|
||||
function isEmpty(object) {
|
||||
return object == null || object == '' || object == undefined;
|
||||
}
|
||||
|
||||
export function selectWalletBindingSuccess(state: State) {
|
||||
return state.context.walletBindingSuccess;
|
||||
}
|
||||
|
||||
export function selectIsTampered(state: State) {
|
||||
return state.matches('ready.tamperedVCs');
|
||||
}
|
||||
|
||||
export function selectDownloadingFailedVcs(state: State) {
|
||||
return state.context.downloadingFailedVcs;
|
||||
}
|
||||
|
||||
export function selectMyVcs(state: State) {
|
||||
return state.context.myVcs;
|
||||
}
|
||||
|
||||
export function selectVerificationErrorMessage(state: State) {
|
||||
return state.context.verificationErrorMessage;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import Cloud from "../../../shared/CloudBackupAndRestoreUtils";
|
||||
|
||||
export const VCMetaServices = () => {
|
||||
return {
|
||||
isUserSignedAlready: () => async () => {
|
||||
return await Cloud.isSignedInAlready();
|
||||
},
|
||||
};
|
||||
};
|
||||
@@ -11,8 +11,7 @@ import {
|
||||
selectMyVcsMetadata,
|
||||
selectVerificationErrorMessage,
|
||||
selectWalletBindingSuccess,
|
||||
VcMetaEvents,
|
||||
} from '../../machines/VerifiableCredential/VCMetaMachine/VCMetaMachine';
|
||||
} from '../../machines/VerifiableCredential/VCMetaMachine/VCMetaSelectors';
|
||||
import {
|
||||
selectWalletBindingError,
|
||||
selectShowWalletBindingError,
|
||||
@@ -33,6 +32,7 @@ import {
|
||||
SettingsEvents,
|
||||
} from '../../machines/settings';
|
||||
import {VCItemMachine} from '../../machines/VerifiableCredential/VCItemMachine/VCItemMachine';
|
||||
import { VcMetaEvents } from '../../machines/VerifiableCredential/VCMetaMachine/VCMetaMachine';
|
||||
|
||||
export function useMyVcsTab(props: HomeScreenTabProps) {
|
||||
const service = props.service as ActorRefFrom<typeof MyVcsTabMachine>;
|
||||
|
||||
@@ -4,7 +4,7 @@ import {ActorRefFrom} from 'xstate';
|
||||
import {
|
||||
selectIsRefreshingReceivedVcs,
|
||||
selectReceivedVcsMetadata,
|
||||
} from '../../machines/VerifiableCredential/VCMetaMachine/VCMetaMachine';
|
||||
} from '../../machines/VerifiableCredential/VCMetaMachine/VCMetaSelectors';
|
||||
import {GlobalContext} from '../../shared/GlobalContext';
|
||||
import {
|
||||
ReceivedVcsTabEvents,
|
||||
|
||||
@@ -26,7 +26,7 @@ import {
|
||||
selectCredential,
|
||||
selectVerifiableCredentialData,
|
||||
} from '../../machines/QrLoginMachine';
|
||||
import {selectBindedVcsMetadata} from '../../machines/VerifiableCredential/VCMetaMachine/VCMetaMachine';
|
||||
import {selectBindedVcsMetadata} from '../../machines/VerifiableCredential/VCMetaMachine/VCMetaSelectors';
|
||||
import {GlobalContext} from '../../shared/GlobalContext';
|
||||
import {QrLoginProps} from './QrLogin';
|
||||
import {NavigationProp, useNavigation} from '@react-navigation/native';
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import {useSelector} from '@xstate/react';
|
||||
import {useContext} from 'react';
|
||||
import {useTranslation} from 'react-i18next';
|
||||
import {selectShareableVcsMetadata} from '../../machines/VerifiableCredential/VCMetaMachine/VCMetaMachine';
|
||||
import {selectShareableVcsMetadata} from '../../machines/VerifiableCredential/VCMetaMachine/VCMetaSelectors';
|
||||
import {GlobalContext} from '../../shared/GlobalContext';
|
||||
import {
|
||||
selectIsLocationDenied,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import {useSelector} from '@xstate/react';
|
||||
import {useContext, useState} from 'react';
|
||||
import {ActorRefFrom} from 'xstate';
|
||||
import {selectShareableVcsMetadata} from '../../machines/VerifiableCredential/VCMetaMachine/VCMetaMachine';
|
||||
import {selectShareableVcsMetadata} from '../../machines/VerifiableCredential/VCMetaMachine/VCMetaSelectors';
|
||||
import {GlobalContext} from '../../shared/GlobalContext';
|
||||
import {
|
||||
selectCredential,
|
||||
@@ -24,9 +24,14 @@ import {NavigationProp, useNavigation} from '@react-navigation/native';
|
||||
import {RootRouteProps} from '../../routes';
|
||||
import {BOTTOM_TAB_ROUTES} from '../../routes/routesConstants';
|
||||
import {VCItemMachine} from '../../machines/VerifiableCredential/VCItemMachine/VCItemMachine';
|
||||
import { Theme } from '../../components/ui/styleUtils';
|
||||
|
||||
type MyVcsTabNavigation = NavigationProp<RootRouteProps>;
|
||||
|
||||
const changeTabBarVisible = (visible: string) => {
|
||||
Theme.BottomTabBarStyle.tabBarStyle.display = visible;
|
||||
};
|
||||
|
||||
export function useSendVcScreen() {
|
||||
const {appService} = useContext(GlobalContext);
|
||||
const scanService = appService.children.get('scan')!!;
|
||||
@@ -70,6 +75,7 @@ export function useSendVcScreen() {
|
||||
RETRY_VERIFICATION: () => scanService.send(ScanEvents.RETRY_VERIFICATION()),
|
||||
GO_TO_HOME: () => {
|
||||
navigation.navigate(BOTTOM_TAB_ROUTES.home, {screen: 'HomeScreen'});
|
||||
changeTabBarVisible('flex');
|
||||
},
|
||||
SELECT_VC_ITEM:
|
||||
(index: number) => (vcRef: ActorRefFrom<typeof VCItemMachine>) => {
|
||||
|
||||
Reference in New Issue
Block a user