Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize Initial Data Fetching and Add Missing Credential Issuer Metadata Retrieval #533

Merged
merged 2 commits into from
Feb 25, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { useEffect } from 'react';
import { UseStorageHandle, useClearStorages, useLocalStorage, useSessionStorage } from '../hooks/useStorage';
import { addItem, getItem } from '../indexedDB';
import { loginWebAuthnBeginOffline } from './LocalAuthentication';
import { useOpenID4VCIHelper } from '@/lib/services/OpenID4VCIHelper';

const walletBackendUrl = config.BACKEND_URL;

Expand Down Expand Up @@ -94,6 +95,8 @@ export function useApi(isOnline: boolean = true): BackendApi {
*/
const [privateDataEtag, setPrivateDataEtag] = useLocalStorage<string | null>("privateDataEtag", null);

const openID4VCIHelper = useOpenID4VCIHelper();

function getAppToken(): string | null {
return appToken;
}
Expand Down Expand Up @@ -166,12 +169,18 @@ export function useApi(isOnline: boolean = true): BackendApi {

async function fetchInitialData(appToken: string, userUuid: string): Promise<void> {
try {
await get('/storage/vc', userUuid, { appToken });
await get('/storage/vp', userUuid, { appToken });
// get('/storage/vc') on home page ('/')
// get('/storage/vp') on home page ('/')
await get('/user/session/account-info', userUuid, { appToken });
await getExternalEntity('/verifier/all', { appToken }, false);
await getExternalEntity('/issuer/all', { appToken }, false);

const response = await getExternalEntity('/issuer/all', { appToken }, false);
response.data.forEach(async (issuer) => {
try {
await openID4VCIHelper.getCredentialIssuerMetadata(issuer.credentialIssuerIdentifier);
} catch (err) {
console.error(err);
}
});
} catch (error) {
console.error('Failed to perform get requests', error);
}
Expand Down