Skip to content

Commit

Permalink
✨ app: implement persona for web
Browse files Browse the repository at this point in the history
  • Loading branch information
dieguezguille committed Jan 10, 2025
1 parent 188158e commit ba286cc
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/components/card/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export default function Card() {
const { data: card } = await refetchCard();
if (card?.url) setCardDetailsOpen(true);
} else {
resumeInquiry(result.inquiryId, result.sessionToken);
resumeInquiry(result.inquiryId, result.sessionToken).catch(handleError);
}
} catch (error) {
if (!(error instanceof APIError)) {
Expand All @@ -120,7 +120,7 @@ export default function Card() {
(code === 404 && text === "kyc not found") ||
(code === 400 && text === "kyc not started")
) {
createInquiry(passkey);
createInquiry(passkey).catch(handleError);
}
handleError(error);
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/getting-started/GettingStarted.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ function CurrentStep() {
try {
const result = await getKYCStatus();
if (result === "ok") return;
resumeInquiry(result.inquiryId, result.sessionToken);
resumeInquiry(result.inquiryId, result.sessionToken).catch(handleError);
} catch (error) {
if (!(error instanceof APIError)) {
handleError(error);
Expand All @@ -140,7 +140,7 @@ function CurrentStep() {
(code === 404 && text === "kyc not found") ||
(code === 400 && text === "kyc not started")
) {
createInquiry(passkey);
createInquiry(passkey).catch(handleError);
}
handleError(error);
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/home/GettingStarted.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default function GettingStarted({ hasFunds, hasKYC }: { hasFunds: boolean
try {
const result = await getKYCStatus();
if (result === "ok") return;
resumeInquiry(result.inquiryId, result.sessionToken);
resumeInquiry(result.inquiryId, result.sessionToken).catch(handleError);
} catch (error) {
if (!(error instanceof APIError)) {
handleError(error);
Expand All @@ -37,7 +37,7 @@ export default function GettingStarted({ hasFunds, hasKYC }: { hasFunds: boolean
(code === 404 && text === "kyc not found") ||
(code === 400 && text === "kyc not started")
) {
createInquiry(passkey);
createInquiry(passkey).catch(handleError);
}
handleError(error);
}
Expand Down
18 changes: 16 additions & 2 deletions src/utils/persona.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
import type { Passkey } from "@exactly/common/validation";
import { router } from "expo-router";
import { Platform } from "react-native";
import { Environment, Inquiry } from "react-native-persona";

import handleError from "./handleError";
import queryClient from "./queryClient";
import { getKYCLink } from "./server";

export const templateId = "itmpl_8uim4FvD5P3kFpKHX37CW817";
export const environment = __DEV__ ? Environment.SANDBOX : Environment.PRODUCTION;

export function createInquiry(passkey: Passkey) {
export async function createInquiry(passkey: Passkey) {
if (Platform.OS === "web") {
const otl = await getKYCLink();
window.open(otl, "_blank");
return;
}

Inquiry.fromTemplate(templateId)
.environment(environment)
.referenceId(passkey.credentialId)
Expand All @@ -25,7 +33,13 @@ export function createInquiry(passkey: Passkey) {
.start();
}

export function resumeInquiry(inquiryId: string, sessionToken: string) {
export async function resumeInquiry(inquiryId: string, sessionToken: string) {
if (Platform.OS === "web") {
const otl = await getKYCLink();
window.open(otl, "_blank");
return;
}

Inquiry.fromInquiry(inquiryId)
.sessionToken(sessionToken)
.onCanceled(() => {
Expand Down

0 comments on commit ba286cc

Please sign in to comment.