From f5771cc7b99dc938fd606dcbee350b66ec8027c9 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Tue, 9 Jan 2024 18:51:49 -0300 Subject: prepare for 2fa impl --- .../src/pages/business/CreateCashout.tsx | 44 +++++++++++++++------- 1 file changed, 31 insertions(+), 13 deletions(-) (limited to 'packages/demobank-ui/src/pages/business/CreateCashout.tsx') diff --git a/packages/demobank-ui/src/pages/business/CreateCashout.tsx b/packages/demobank-ui/src/pages/business/CreateCashout.tsx index 92c80ea38..c3921cbd0 100644 --- a/packages/demobank-ui/src/pages/business/CreateCashout.tsx +++ b/packages/demobank-ui/src/pages/business/CreateCashout.tsx @@ -15,7 +15,9 @@ */ import { Amounts, + HttpStatusCode, TalerError, + TalerErrorCode, TranslatedString, encodeCrock, getRandomBytes, @@ -99,8 +101,8 @@ export function CreateCashout({ } if (resultAccount.type === "fail") { switch (resultAccount.case) { - case "unauthorized": return - case "not-found": return + case HttpStatusCode.Unauthorized: return + case HttpStatusCode.NotFound: return default: assertUnreachable(resultAccount) } } @@ -181,8 +183,9 @@ export function CreateCashout({ async function createCashout() { const request_uid = encodeCrock(getRandomBytes(32)) await handleError(async () => { - if (!creds || !form.subject || !form.channel) return; + const validChannel = config.supported_tan_channels.length === 0 || form.channel + if (!creds || !form.subject || !validChannel) return; const resp = await api.createCashout(creds, { request_uid, amount_credit: Amounts.stringify(calc.credit), @@ -194,47 +197,55 @@ export function CreateCashout({ notifyInfo(i18n.str`Cashout created`) } else { switch (resp.case) { - case "account-not-found": return notify({ + case HttpStatusCode.NotFound: return notify({ type: "error", title: i18n.str`Account not found`, description: resp.detail.hint as TranslatedString, debug: resp.detail, }); - case "request-already-used": return notify({ + case TalerErrorCode.BANK_TRANSFER_REQUEST_UID_REUSED: return notify({ type: "error", title: i18n.str`Duplicated request detected, check if the operation succeded or try again.`, description: resp.detail.hint as TranslatedString, debug: resp.detail, }); - case "incorrect-exchange-rate": return notify({ + case TalerErrorCode.BANK_BAD_CONVERSION: return notify({ type: "error", title: i18n.str`The exchange rate was incorrectly applied`, description: resp.detail.hint as TranslatedString, debug: resp.detail, }); - case "no-enough-balance": return notify({ + case TalerErrorCode.BANK_UNALLOWED_DEBIT: return notify({ type: "error", title: i18n.str`The account does not have sufficient funds`, description: resp.detail.hint as TranslatedString, debug: resp.detail, }); - case "cashout-not-supported": return notify({ + case HttpStatusCode.NotImplemented: return notify({ type: "error", title: i18n.str`Cashouts are not supported`, description: resp.detail.hint as TranslatedString, debug: resp.detail, }); - case "no-cashout-uri": return notify({ + case TalerErrorCode.BANK_CONFIRM_INCOMPLETE: return notify({ type: "error", title: i18n.str`Missing cashout URI in the profile`, description: resp.detail.hint as TranslatedString, debug: resp.detail, }); + case TalerErrorCode.BANK_TAN_CHANNEL_SCRIPT_FAILED: return notify({ + type: "error", + title: i18n.str`Sending the confirmation message failed, retry later or contact the administrator.`, + description: resp.detail.hint as TranslatedString, + debug: resp.detail, + }); } assertUnreachable(resp) } }) } + const cashoutDisabled = config.supported_tan_channels.length < 1 || !resultAccount.body.cashout_payto_uri + console.log("disab", cashoutDisabled) const cashoutAccount = !resultAccount.body.cashout_payto_uri ? undefined : parsePaytoUri(resultAccount.body.cashout_payto_uri); const cashoutAccountName = !cashoutAccount ? undefined : cashoutAccount.targetPath @@ -317,7 +328,7 @@ export function CreateCashout({ class="block w-full rounded-md disabled:bg-gray-200 border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 data-[error=true]:ring-red-500 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6" name="subject" id="subject" - disabled={!resultAccount.body.cashout_payto_uri} + disabled={cashoutDisabled} data-error={!!errors?.subject && form.subject !== undefined} value={form.subject ?? ""} onChange={(e) => { @@ -360,7 +371,7 @@ export function CreateCashout({ left currency={limit.currency} value={trimmedAmountStr} - onChange={!resultAccount.body.cashout_payto_uri ? undefined : (value) => { + onChange={cashoutDisabled ? undefined : (value) => { form.amount = value; updateForm(structuredClone(form)); }} @@ -424,7 +435,15 @@ export function CreateCashout({ )} {/* channel */} - {config.supported_tan_channels.length === 0 ? undefined : + {config.supported_tan_channels.length === 0 ? +
+ + + Before doing a cashout the server need to provide an second channel to confirm the operation + + +
+ :
- ); } -- cgit v1.2.3