-
Notifications
You must be signed in to change notification settings - Fork 5
♻️ app: use new kyc flow #653
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@exactly/mobile": patch | ||
| --- | ||
|
|
||
| ♻️ use new kyc flow |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,52 +5,43 @@ import { IdCard } from "@tamagui/lucide-icons"; | |
| import { useToastController } from "@tamagui/toast"; | ||
| import { Spinner, YStack } from "tamagui"; | ||
|
|
||
| import { useMutation, useQuery } from "@tanstack/react-query"; | ||
| import { useMutation } from "@tanstack/react-query"; | ||
|
|
||
| import Progression from "./Progression"; | ||
| import { createInquiry, KYC_TEMPLATE_ID, resumeInquiry } from "../../../utils/persona"; | ||
| import { startKYC } from "../../../utils/persona"; | ||
| import queryClient from "../../../utils/queryClient"; | ||
| import reportError from "../../../utils/reportError"; | ||
| import { APIError, getKYCStatus } from "../../../utils/server"; | ||
| import Button from "../../shared/Button"; | ||
| import Text from "../../shared/Text"; | ||
| import View from "../../shared/View"; | ||
|
|
||
| import type { Credential } from "@exactly/common/validation"; | ||
|
|
||
| export default function VerifyIdentity() { | ||
| const toast = useToastController(); | ||
| const { t } = useTranslation(); | ||
| const { data: credential } = useQuery<Credential>({ queryKey: ["credential"] }); | ||
| const { mutateAsync: startKYC, isPending } = useMutation({ | ||
| const { mutate: beginKYC, isPending } = useMutation({ | ||
| mutationKey: ["kyc"], | ||
| mutationFn: async () => { | ||
| if (!credential) throw new Error("missing credential"); | ||
| async mutationFn() { | ||
| try { | ||
| const result = await getKYCStatus(KYC_TEMPLATE_ID); | ||
| if (result === "ok") { | ||
| const status = await getKYCStatus(); | ||
| if ("code" in status && (status.code === "ok" || status.code === "legacy kyc")) { | ||
| queryClient.setQueryData(["card-upgrade"], 1); | ||
| return; | ||
| } | ||
| if (typeof result !== "string") { | ||
| await resumeInquiry(result.inquiryId, result.sessionToken); | ||
| } | ||
| } catch (error) { | ||
| if (!(error instanceof APIError)) { | ||
| reportError(error); | ||
| return; | ||
| throw error; | ||
| } | ||
| if (error.text === "kyc required" || error.text === "kyc not found" || error.text === "kyc not started") { | ||
| await createInquiry(credential); | ||
| return; | ||
| if (error.text !== "not started" && error.text !== "no kyc") { | ||
| throw error; | ||
| } | ||
| reportError(error); | ||
| } | ||
|
Comment on lines
31
to
38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The To fix this, you should remove the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @coderabbitai review this finding, especially considering the latest force-pushed code There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Looking at the current implementation (lines 31-38), the } catch (error) {
if (!(error instanceof APIError)) {
throw error;
}
if (error.text !== "not started" && error.text !== "no kyc") {
throw error;
}
}All errors are now properly thrown and handled exclusively by the 🧠 Learnings used |
||
| await startKYC(); | ||
| }, | ||
| onSettled: async () => { | ||
| async onSettled() { | ||
| await queryClient.invalidateQueries({ queryKey: ["kyc", "status"] }); | ||
| }, | ||
| onError: (error) => { | ||
| onError(error) { | ||
| toast.show(t("Error verifying identity"), { | ||
| native: true, | ||
| duration: 1000, | ||
|
|
@@ -79,7 +70,7 @@ export default function VerifyIdentity() { | |
| <Button | ||
| disabled={isPending} | ||
| onPress={() => { | ||
| startKYC().catch(reportError); | ||
| beginKYC(); | ||
| }} | ||
| flexBasis={60} | ||
| contained | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.