Skip to content

Commit

Permalink
fix(INJI-536):check status failed while downloading vc (#985)
Browse files Browse the repository at this point in the history
* fix(INJI-536):check status failed while downloading vc

Signed-off-by: Sri Kanth Kola <[email protected]>

* fix(INJI-536):refactor the default switch case

Signed-off-by: Sri Kanth Kola <[email protected]>

* fix(INJI-536):fix error handling and avoid usage of VCmetadata

Signed-off-by: Sri Kanth Kola <[email protected]>

* fix(INJI-536):fix error handling and avoid usage of VCmetadata

Signed-off-by: Sri Kanth Kola <[email protected]>

---------

Signed-off-by: Sri Kanth Kola <[email protected]>
  • Loading branch information
srikanth716 authored Nov 8, 2023
1 parent 5a3ad48 commit 1ce89cb
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ const model = createModel(
bindingTransactionId: '',
revoked: false,
downloadCounter: 0,
maxDownloadCount: 10,
downloadInterval: 5000,
maxDownloadCount: null as number,
downloadInterval: null as number,
walletBindingResponse: null as WalletBindingResponse,
walletBindingError: '',
walletBindingSuccess: false,
Expand All @@ -84,6 +84,7 @@ const model = createModel(
STORE_RESPONSE: (response: VC) => ({response}),
POLL: () => ({}),
DOWNLOAD_READY: () => ({}),
FAILED: () => ({}),
GET_VC_RESPONSE: (vc: VC) => ({vc}),
VERIFY: () => ({}),
LOCK_VC: () => ({}),
Expand Down Expand Up @@ -184,7 +185,6 @@ export const ExistingMosipVCItemMachine =
log((_, event) => (event.data as Error).message),
'sendDownloadLimitExpire',
],
target: 'checkingStatus',
},
},
},
Expand All @@ -201,6 +201,12 @@ export const ExistingMosipVCItemMachine =
DOWNLOAD_READY: {
target: 'downloadingCredential',
},
FAILED: [
{
actions: ['incrementDownloadCounter'],
target: 'verifyingDownloadLimitExpiry',
},
],
},
},
downloadingCredential: {
Expand All @@ -217,6 +223,9 @@ export const ExistingMosipVCItemMachine =
'incrementDownloadCounter',
],
},
{
target: 'verifyingDownloadLimitExpiry',
},
],
CREDENTIAL_DOWNLOADED: {
actions: ['setStoreVerifiableCredential', 'storeContext'],
Expand Down Expand Up @@ -1369,19 +1378,27 @@ export const ExistingMosipVCItemMachine =

onReceive(async event => {
if (event.type === 'POLL_STATUS') {
const response = await request(
API_URLS.credentialStatus.method,
API_URLS.credentialStatus.buildURL(
context.vcMetadata.requestId,
),
);
switch (response.response?.statusCode) {
case 'NEW':
break;
case 'ISSUED':
case 'printing':
callback(model.events.DOWNLOAD_READY());
break;
try {
const response = await request(
API_URLS.credentialStatus.method,
API_URLS.credentialStatus.buildURL(
context.vcMetadata.requestId,
),
);
switch (response.response?.statusCode) {
case 'NEW':
break;
case 'ISSUED':
case 'printing':
callback(model.events.DOWNLOAD_READY());
break;
case 'FAILED':
default:
callback(model.events.FAILED());
break;
}
} catch (error) {
callback(model.events.FAILED());
}
}
});
Expand Down
18 changes: 5 additions & 13 deletions machines/vc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,10 @@ export const vcMachine =
'removeVcFromInProgressDownlods',
'setDownloadingFailedVcs',
],
target: 'downloadLimitExpired',
target: '#vc.ready.myVcs.refreshing',
},
DELETE_VC: {
target: 'deletingFailedVcs',
},
},
},
Expand All @@ -221,13 +224,6 @@ export const vcMachine =
},
},
},
downloadLimitExpired: {
on: {
DELETE_VC: {
target: 'deletingFailedVcs',
},
},
},
deletingFailedVcs: {
entry: 'removeDownloadFailedVcsFromStorage',
on: {
Expand Down Expand Up @@ -283,8 +279,8 @@ export const vcMachine =

setDownloadingFailedVcs: model.assign({
downloadingFailedVcs: (context, event) => [
event.vcMetadata,
...context.downloadingFailedVcs,
event.vcMetadata,
],
}),

Expand Down Expand Up @@ -526,10 +522,6 @@ export function selectIsTampered(state: State) {
return state.matches('tamperedVCs');
}

export function selectIsDownloadLimitExpired(state: State) {
return state.matches('downloadLimitExpired');
}

export function selectDownloadingFailedVcs(state: State) {
return state.context.downloadingFailedVcs;
}
13 changes: 10 additions & 3 deletions screens/Home/MyVcsTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
import {TelemetryConstants} from '../../shared/telemetry/TelemetryConstants';

import {Error} from '../../components/ui/Error';
import {useIsFocused} from '@react-navigation/native';

const pinIconProps = {iconName: 'pushpin', iconType: 'antdesign'};

Expand Down Expand Up @@ -80,11 +81,17 @@ export const MyVcsTab: React.FC<HomeScreenTabProps> = props => {

let failedVCsList = [];
controller.downloadFailedVcs.forEach(vc => {
failedVCsList.push(`${vc.idType}:${vc.id}\n`);
failedVCsList.push(`\n${vc.idType}:${vc.id}`);
});
const downloadFailedVcsErrorMessage = `${t(
'errors.downloadLimitExpires.message',
)}\n${failedVCsList}`;
)}${failedVCsList}`;

const isDownloadFailedVcs =
useIsFocused() &&
controller.downloadFailedVcs.length >= 1 &&
!controller.AddVcModalService &&
!controller.GetVcModalService;

return (
<React.Fragment>
Expand Down Expand Up @@ -213,7 +220,7 @@ export const MyVcsTab: React.FC<HomeScreenTabProps> = props => {
/>

<MessageOverlay
isVisible={controller.isDownloadLimitExpires}
isVisible={isDownloadFailedVcs}
title={t('errors.downloadLimitExpires.title')}
message={downloadFailedVcsErrorMessage}
onButtonPress={controller.DELETE_VC}
Expand Down
6 changes: 0 additions & 6 deletions screens/Home/MyVcsTabController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
selectAreAllVcsDownloaded,
selectInProgressVcDownloads,
selectIsTampered,
selectIsDownloadLimitExpired,
selectDownloadingFailedVcs,
} from '../../machines/vc';
import {
Expand Down Expand Up @@ -63,11 +62,6 @@ export function useMyVcsTab(props: HomeScreenTabProps) {

isTampered: useSelector(vcService, selectIsTampered),

isDownloadLimitExpires: useSelector(
vcService,
selectIsDownloadLimitExpired,
),

downloadFailedVcs: useSelector(vcService, selectDownloadingFailedVcs),

SET_STORE_VC_ITEM_STATUS: () =>
Expand Down

0 comments on commit 1ce89cb

Please sign in to comment.