diff --git a/frontend/src/api/credential.ts b/frontend/src/api/credential.ts index de48629..ae9ed46 100644 --- a/frontend/src/api/credential.ts +++ b/frontend/src/api/credential.ts @@ -1,4 +1,4 @@ -import { getBackendUrl } from '../utils/utils'; +import { getBackendUrl } from '../utils/utils' import { getAxiosClient } from './dataProvider' import { InjectedWindowProvider } from '@kiltprotocol/kilt-extension-api' @@ -7,10 +7,9 @@ export async function fetchCredential(extension: InjectedWindowProvider, session const client = await getAxiosClient() - const credentialUrl = `${apiUrl}/credential`; - - const getTermsResponse = await client.post(`${credentialUrl}/terms/${sessionId}/${attestationId}`, sessionId); + const credentialUrl = `${apiUrl}/credential` + const getTermsResponse = await client.post(`${credentialUrl}/terms/${sessionId}/${attestationId}`, sessionId) const getCredentialRequestFromExtension = await new Promise((resolve, reject) => { try { diff --git a/frontend/src/api/dataProvider.ts b/frontend/src/api/dataProvider.ts index f598000..46b2391 100644 --- a/frontend/src/api/dataProvider.ts +++ b/frontend/src/api/dataProvider.ts @@ -26,5 +26,5 @@ async function httpClient(url: string, options: { [key: string]: any } = {}) { return fetchUtils.fetchJson(url, options) } -const apiUrl = getBackendUrl(); +const apiUrl = getBackendUrl() export const dataProvider = simpleRestProvider(apiUrl, httpClient) diff --git a/frontend/src/api/endpoints.ts b/frontend/src/api/endpoints.ts index 166cbc5..23f8a10 100644 --- a/frontend/src/api/endpoints.ts +++ b/frontend/src/api/endpoints.ts @@ -1,19 +1,17 @@ -import axios from "axios"; - +import axios from 'axios' export async function getEndpoints(): Promise> { + const origin = window.location.origin + const backendUrl = `${origin}/api/v1` + const endpointUrl = `${backendUrl}/endpoints` + const response = await axios.get>(endpointUrl) - const origin = window.location.origin; - const backendUrl = `${origin}/api/v1` - const endpointUrl = `${backendUrl}/endpoints`; - const response = await axios.get>(endpointUrl) - - if (response.status !== 200) { - throw new Error("Could not fetch endpoints") - } + if (response.status !== 200) { + throw new Error('Could not fetch endpoints') + } - const endpoints = response.data; - endpoints.push(backendUrl) + const endpoints = response.data + endpoints.push(backendUrl) - return endpoints + return endpoints } diff --git a/frontend/src/api/session.ts b/frontend/src/api/session.ts index bcd7c71..d183e54 100644 --- a/frontend/src/api/session.ts +++ b/frontend/src/api/session.ts @@ -1,4 +1,4 @@ -import { getBackendUrl } from '../utils/utils'; +import { getBackendUrl } from '../utils/utils' import { getAxiosClient } from './dataProvider' import { InjectedWindowProvider, PubSubSessionV1, PubSubSessionV2 } from '@kiltprotocol/kilt-extension-api' @@ -9,7 +9,7 @@ export async function getSession(provider: InjectedWindowProvider): Promise = {} Object.entries(ctypeDetails.cType.properties).map( - ([key, type]) => (claimContent[key] = getDefaultEntryForType(type as { type: string })), + ([key, type]) => (claimContent[key] = getDefaultEntryForType(type as { type: string; format?: string })), ) setCtypeDetails(ctypeDetails.cType) setClaimContent(claimContent) @@ -72,7 +84,9 @@ export default function AttestationCreate() { return KiltCredential.fromClaim(claim) } catch (e) { console.error(e) - notify('Ctype Verification failed') + notify('Ctype Verification failed', { type: 'error' }) + + throw e } } @@ -80,7 +94,7 @@ export default function AttestationCreate() { const CustomToolBar = () => { return ( - + ) } diff --git a/frontend/src/utils/utils.ts b/frontend/src/utils/utils.ts index e79e391..2e5b427 100644 --- a/frontend/src/utils/utils.ts +++ b/frontend/src/utils/utils.ts @@ -12,23 +12,23 @@ export function isUserAdmin() { } export function storeEndpoints(endpoints: Array) { - const authorizeUrl = endpoints[0]; - const kiltEndpoint = endpoints[1]; - const backendUrl = endpoints[2]; + const authorizeUrl = endpoints[0] + const kiltEndpoint = endpoints[1] + const backendUrl = endpoints[2] - localStorage.setItem("authorizeUrl", authorizeUrl); - localStorage.setItem("kiltEndpoint", kiltEndpoint); - localStorage.setItem("backendUrl", backendUrl); + localStorage.setItem('authorizeUrl', authorizeUrl) + localStorage.setItem('kiltEndpoint', kiltEndpoint) + localStorage.setItem('backendUrl', backendUrl) } export function getBackendUrl(): string { - return localStorage.getItem("backendUrl") || "" + return localStorage.getItem('backendUrl') || '' } export function getKiltEndpoint(): string { - return localStorage.getItem("kiltEndpoint") || "" + return localStorage.getItem('kiltEndpoint') || '' } export function getAuthorizeUrl(): string { - return localStorage.getItem("authorizeUrl") || "" + return localStorage.getItem('authorizeUrl') || '' }