From 7a5c65cac9c819cd1b3fd0f6472d2fcc23ed66a8 Mon Sep 17 00:00:00 2001 From: Nicolas Comont Date: Thu, 23 Nov 2023 16:16:21 +0100 Subject: [PATCH] quote validation --- .../TransferInternationalWizardAmount.tsx | 55 ++++++++++++++----- 1 file changed, 42 insertions(+), 13 deletions(-) diff --git a/clients/banking/src/components/TransferInternationalWizardAmount.tsx b/clients/banking/src/components/TransferInternationalWizardAmount.tsx index 098bf3287..26ce2ea4d 100644 --- a/clients/banking/src/components/TransferInternationalWizardAmount.tsx +++ b/clients/banking/src/components/TransferInternationalWizardAmount.tsx @@ -1,6 +1,7 @@ import { AsyncData, Result } from "@swan-io/boxed"; import { Box } from "@swan-io/lake/src/components/Box"; import { Fill } from "@swan-io/lake/src/components/Fill"; +import { LakeAlert } from "@swan-io/lake/src/components/LakeAlert"; import { LakeButton, LakeButtonGroup } from "@swan-io/lake/src/components/LakeButton"; import { LakeHeading } from "@swan-io/lake/src/components/LakeHeading"; import { LakeLabel } from "@swan-io/lake/src/components/LakeLabel"; @@ -22,6 +23,7 @@ import { GetInternationalCreditTransferQuoteQuery, } from "../graphql/partner"; import { Currency, currencies, formatCurrency, formatNestedMessage, t } from "../utils/i18n"; +import { isCombinedError } from "../utils/urql"; import { ErrorView } from "./ErrorView"; const styles = StyleSheet.create({ @@ -109,6 +111,27 @@ export const TransferInternationalWizardAmount = ({ ); }, [listenFields]); + const errors = match(quote) + .with(AsyncData.P.Done(Result.P.Error(P.select())), error => { + if (isCombinedError(error)) { + return match(error) + .with( + { + graphQLErrors: P.array({ + extensions: { + code: "QuoteValidationError", + errors: P.array({ message: P.select(P.string) }), + }, + }), + }, + ([messages]) => messages ?? [], + ) + .otherwise(() => []); + } + return []; + }) + .otherwise(() => []); + return ( @@ -152,7 +175,7 @@ export const TransferInternationalWizardAmount = ({ error={error} valid={valid} onChangeText={nextValue => { - onChange({ currency, value: nextValue }); + onChange({ currency, value: nextValue.replace(/,/g, ".") }); }} onBlur={onBlur} units={currencies.toSorted() as unknown as string[]} @@ -169,18 +192,23 @@ export const TransferInternationalWizardAmount = ({ - {match(quote) - .with(AsyncData.P.NotAsked, () => null) - .with(AsyncData.P.Loading, () => ) - .with( - AsyncData.P.Done( - Result.P.Ok({ internationalCreditTransferQuote: P.select(P.not(P.nullish)) }), - ), - quote => , - ) - .otherwise(() => ( - - ))} + {errors.length + ? errors.map((message, i) => ( + + + + + )) + : match(quote) + .with(AsyncData.P.NotAsked, () => null) + .with(AsyncData.P.Loading, () => ) + .with( + AsyncData.P.Done( + Result.P.Ok({ internationalCreditTransferQuote: P.select(P.not(P.nullish)) }), + ), + quote => , + ) + .otherwise(() => )} @@ -195,6 +223,7 @@ export const TransferInternationalWizardAmount = ({ + errors?.length === 0 && submitForm(values => { if (hasDefinedKeys(values, ["amount"])) { onSave({