Skip to content

Commit

Permalink
Fixes scanned qr link (#518)
Browse files Browse the repository at this point in the history
  • Loading branch information
elias-garcia authored Nov 8, 2023
1 parent 09f28bc commit 60a83b5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
13 changes: 10 additions & 3 deletions ui/src/adapters/api/credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { z } from "zod";
import { Response, buildErrorResponse, buildSuccessResponse } from "src/adapters";
import { ID, IDParser, Message, buildAuthorizationHeader, messageParser } from "src/adapters/api";
import { datetimeParser, getListParser, getStrictParser } from "src/adapters/parsers";
import { Credential, Env, Json, Link, LinkStatus, ProofType } from "src/domain";
import { Credential, Env, IssuedQRCode, Json, Link, LinkStatus, ProofType } from "src/domain";
import { API_VERSION, QUERY_SEARCH_PARAM, STATUS_SEARCH_PARAM } from "src/utils/constants";
import { List } from "src/utils/types";

Expand Down Expand Up @@ -418,6 +418,13 @@ export async function createAuthQRCode({
}
}

const issuedQRCodeParser = getStrictParser<IssuedQRCode>()(
z.object({
qrCodeLink: z.string(),
schemaType: z.string(),
})
);

export async function getIssuedQRCode({
credentialID,
env,
Expand All @@ -426,15 +433,15 @@ export async function getIssuedQRCode({
credentialID: string;
env: Env;
signal: AbortSignal;
}): Promise<Response<string>> {
}): Promise<Response<IssuedQRCode>> {
try {
const response = await axios({
baseURL: env.api.url,
method: "GET",
signal,
url: `${API_VERSION}/credentials/${credentialID}/qrcode`,
});
return buildSuccessResponse(z.string().parse(response.data));
return buildSuccessResponse(issuedQRCodeParser.parse(response.data));
} catch (error) {
return buildErrorResponse(error);
}
Expand Down
7 changes: 4 additions & 3 deletions ui/src/components/credentials/CredentialIssuedQR.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import { CredentialQR } from "src/components/credentials/CredentialQR";
import { ErrorResult } from "src/components/shared/ErrorResult";
import { LoadingResult } from "src/components/shared/LoadingResult";
import { useEnvContext } from "src/contexts/Env";
import { AppError } from "src/domain";
import { AppError, IssuedQRCode } from "src/domain";
import { AsyncTask, hasAsyncTaskFailed, isAsyncTaskDataAvailable } from "src/utils/async";
import { isAbortedError, makeRequestAbortable } from "src/utils/browser";

export function CredentialIssuedQR() {
const env = useEnvContext();

const [issuedQRCode, setIssuedQRCode] = useState<AsyncTask<string, AppError>>({
const [issuedQRCode, setIssuedQRCode] = useState<AsyncTask<IssuedQRCode, AppError>>({
status: "pending",
});

Expand Down Expand Up @@ -65,7 +65,8 @@ export function CredentialIssuedQR() {

return (
<CredentialQR
qrCode={issuedQRCode.data}
qrCode={issuedQRCode.data.qrCodeLink}
schemaType={issuedQRCode.data.schemaType}
subTitle="Scan the QR code with your Polygon ID wallet to add the credential."
/>
);
Expand Down
2 changes: 1 addition & 1 deletion ui/src/components/credentials/CredentialQR.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function CredentialQR({
subTitle,
}: {
qrCode: string;
schemaType?: string;
schemaType: string;
subTitle: ReactNode;
}) {
const { issuer } = useEnvContext();
Expand Down
2 changes: 1 addition & 1 deletion ui/src/domain/credential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export type Credential = {
};

export type IssuedQRCode = {
qrCode: unknown;
qrCodeLink: string;
schemaType: string;
};

Expand Down

0 comments on commit 60a83b5

Please sign in to comment.