[INJIMOB-3167] add null checks in card view and cache to fix vc render after download (#2048)

Signed-off-by: Abhishek Paul <paul.apaul.abhishek.ap@gmail.com>
This commit is contained in:
abhip2565
2025-08-08 16:06:14 +05:30
committed by GitHub
parent 6e8386f3ae
commit 7b4889d705
4 changed files with 31 additions and 21 deletions

View File

@@ -76,7 +76,9 @@ export const VCCardView: React.FC<VCItemProps> = ({
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<VCItemProps> = ({
}
}, [verifiableCredentialData]);
if (!isVCLoaded(controller.credential, fields) || !wellknown || !vc) {
if (!isVCLoaded(controller.credential) || !wellknown || !vc) {
return <VCCardSkeleton />;
}

View File

@@ -456,8 +456,7 @@ export const fieldItemIterator = (
};
export const isVCLoaded = (
verifiableCredential: Credential | null,
fields: string[],
verifiableCredential: Credential | null
) => {
return verifiableCredential != null;
};

View File

@@ -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) => {

View File

@@ -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),