diff --git a/components/VC/Views/VCCardView.tsx b/components/VC/Views/VCCardView.tsx index 1c38033a..89851095 100644 --- a/components/VC/Views/VCCardView.tsx +++ b/components/VC/Views/VCCardView.tsx @@ -76,7 +76,9 @@ export const VCCardView: React.FC = ({ vcMetadata.issuerHost, ) .then(response => { + if(response && response.matchingCredentialIssuerMetadata) { setWellknown(response.matchingCredentialIssuerMetadata); + } setFields(response.fields); }) .catch(error => { @@ -88,7 +90,7 @@ export const VCCardView: React.FC = ({ } }, [verifiableCredentialData]); - if (!isVCLoaded(controller.credential, fields) || !wellknown || !vc) { + if (!isVCLoaded(controller.credential) || !wellknown || !vc) { return ; } diff --git a/components/VC/common/VCUtils.tsx b/components/VC/common/VCUtils.tsx index 0eeb9acd..9f04fab8 100644 --- a/components/VC/common/VCUtils.tsx +++ b/components/VC/common/VCUtils.tsx @@ -456,8 +456,7 @@ export const fieldItemIterator = ( }; export const isVCLoaded = ( - verifiableCredential: Credential | null, - fields: string[], + verifiableCredential: Credential | null ) => { return verifiableCredential != null; }; diff --git a/machines/Issuers/IssuersService.ts b/machines/Issuers/IssuersService.ts index c66e3bc9..da77d75e 100644 --- a/machines/Issuers/IssuersService.ts +++ b/machines/Issuers/IssuersService.ts @@ -1,7 +1,7 @@ import NetInfo from '@react-native-community/netinfo'; -import { NativeModules } from 'react-native'; +import {NativeModules} from 'react-native'; import Cloud from '../../shared/CloudBackupAndRestoreUtils'; -import getAllConfigurations, { CACHED_API } from '../../shared/api'; +import getAllConfigurations, {CACHED_API} from '../../shared/api'; import { fetchKeyPair, generateKeyPair, @@ -30,17 +30,21 @@ export const IssuersService = () => { }, checkInternet: async () => await NetInfo.fetch(), downloadIssuerWellknown: async (context: any) => { - const wellknownResponse = (await VciClient.getInstance().getIssuerMetadata( - context.selectedIssuer.credential_issuer_host, - )) as issuerType; - const wellknownCacheObject = createCacheObject(wellknownResponse); - await setItem( - API_CACHED_STORAGE_KEYS.fetchIssuerWellknownConfig( + const wellknownResponse = + (await VciClient.getInstance().getIssuerMetadata( context.selectedIssuer.credential_issuer_host, - ), - wellknownCacheObject, - '', - ); + )) as issuerType; + if (wellknownResponse) { + const wellknownCacheObject = createCacheObject(wellknownResponse); + await setItem( + API_CACHED_STORAGE_KEYS.fetchIssuerWellknownConfig( + context.selectedIssuer.credential_issuer_host, + ), + wellknownCacheObject, + '', + ); + } + return wellknownResponse; }, getCredentialTypes: async (context: any) => { @@ -238,12 +242,14 @@ export const IssuersService = () => { const issuerMetadata = (await VciClient.getInstance().getIssuerMetadata( credentialIssuer, )) as issuerType; - const wellknownCacheObject = createCacheObject(issuerMetadata); - await setItem( - API_CACHED_STORAGE_KEYS.fetchIssuerWellknownConfig(credentialIssuer), - wellknownCacheObject, - '', - ); + if (issuerMetadata) { + const wellknownCacheObject = createCacheObject(issuerMetadata); + await setItem( + API_CACHED_STORAGE_KEYS.fetchIssuerWellknownConfig(credentialIssuer), + wellknownCacheObject, + '', + ); + } return issuerMetadata; }, constructProof: async (context: any) => { diff --git a/shared/api.ts b/shared/api.ts index c419497b..7e6e8444 100644 --- a/shared/api.ts +++ b/shared/api.ts @@ -251,6 +251,9 @@ async function generateCacheAPIFunctionWithCachePreference( return cachedData.response; } else { const response = await fetchCall(); + if(!response) { + throw new Error('Received Empty response in fetch call'); + } const cacheObject = createCacheObject(response); setItem(cacheKey, cacheObject, '').then(() => console.info('Cached response for ' + cacheKey),