Skip to content

Commit

Permalink
fix: API versioning changes for send proof request API
Browse files Browse the repository at this point in the history
Signed-off-by: pranalidhanavade <[email protected]>
  • Loading branch information
pranalidhanavade committed Dec 23, 2024
1 parent ef81a0e commit 3d6ea2b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
19 changes: 18 additions & 1 deletion src/api/verification.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { IssueCredential, RequestType } from '../common/enums';
import { APIVersion, type IssueCredential, type RequestType } from '../common/enums';
import { apiRoutes } from '../config/apiRoutes';
import { storageKeys } from '../config/CommonConstant';
import { getHeaderConfigs } from '../config/GetHeaderConfigs';
Expand All @@ -23,6 +23,23 @@ export const verifyCredential = async (payload: object, requestType:RequestType)
}
};

export const verifyCredentialV2 = async (payload: object, requestType:RequestType) => {
const orgId = await getFromLocalStorage(storageKeys.ORG_ID);
const url = `${APIVersion.version_v2}${apiRoutes.organizations.root}/${orgId}${apiRoutes.Verification.verifyCredential}?requestType=${requestType}`;
const axiosPayload = {
url,
payload,
config: await getHeaderConfigs(),
};

try {
return await axiosPost(axiosPayload);
} catch (error) {
const err = error as Error;
return err?.message;
}
};

export const createOobProofRequest = async (payload: object, requestType: RequestType) => {
const orgId = await getFromLocalStorage(storageKeys.ORG_ID);
const url = `${apiRoutes.organizations.root}/${orgId}${apiRoutes.Verification.oobProofRequest}?requestType=${requestType}`;
Expand Down
4 changes: 4 additions & 0 deletions src/common/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,8 @@ export enum Environment {
PROD = 'PROD',
DEV = 'DEV',
QA = 'QA'
}

export enum APIVersion {
version_v2 = '/v2'
}
16 changes: 11 additions & 5 deletions src/components/Verification/Connections.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import React from "react";
import type { IConnectionList } from "./interface";
import DateTooltip from "../Tooltip";
import { dateConversion } from "../../utils/DateConversion";
import { verifyCredential } from '../../api/verification';
import { verifyCredential, verifyCredentialV2 } from '../../api/verification';
import type { AxiosResponse } from "axios";
import { v4 as uuidv4 } from 'uuid';
import { getOrganizationById } from "../../api/organization";
Expand Down Expand Up @@ -165,7 +165,7 @@ const Connections = () => {

verifyCredentialPayload = {

connectionId: connectionIds,
connectionId: connectionIds.length === 1 ? connectionIds[0] : connectionIds,
orgId,
proofFormats: {
indy: {
Expand Down Expand Up @@ -198,7 +198,7 @@ const Connections = () => {

verifyCredentialPayload = {

connectionId: connectionIds,
connectionId: connectionIds.length === 1 ? connectionIds[0] : connectionIds,
comment: 'proof request',
presentationDefinition: {
id: uuidv4(),
Expand Down Expand Up @@ -232,9 +232,15 @@ const Connections = () => {
}
}

if (attributes && verifyCredentialPayload) {
if (attributes && verifyCredentialPayload ) {
const requestType = isW3cDid ? RequestType.PRESENTATION_EXCHANGE : RequestType.INDY;
const response = await verifyCredential(verifyCredentialPayload, requestType);
let response;
if (typeof verifyCredentialPayload.connectionId === 'string') {
response = await verifyCredential(verifyCredentialPayload, requestType);
} else if (Array.isArray(verifyCredentialPayload.connectionId)) {
response = await verifyCredentialV2(verifyCredentialPayload, requestType);
}

const { data } = response as AxiosResponse;
if (data?.statusCode === apiStatusCodes.API_STATUS_CREATED) {
await removeFromLocalStorage(storageKeys.ATTRIBUTE_DATA);
Expand Down

0 comments on commit 3d6ea2b

Please sign in to comment.