diff options
Diffstat (limited to 'packages/demobank-ui/src/pages/business')
-rw-r--r-- | packages/demobank-ui/src/pages/business/CreateCashout.tsx | 44 | ||||
-rw-r--r-- | packages/demobank-ui/src/pages/business/ShowCashoutDetails.tsx | 29 |
2 files changed, 47 insertions, 26 deletions
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 <LoginForm currentUser={accountName} /> - case "not-found": return <LoginForm currentUser={accountName} /> + case HttpStatusCode.Unauthorized: return <LoginForm currentUser={accountName} /> + case HttpStatusCode.NotFound: return <LoginForm currentUser={accountName} /> 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 ? + <div class="sm:col-span-5"> + <Attention type="warning" title={i18n.str`No cashout channel available`}> + <i18n.Translate> + Before doing a cashout the server need to provide an second channel to confirm the operation + </i18n.Translate> + </Attention> + </div> + : <div class="sm:col-span-5"> <label class="block text-sm font-medium leading-6 text-gray-900" @@ -507,7 +526,6 @@ export function CreateCashout({ </div> </form> </div> - </div> ); } diff --git a/packages/demobank-ui/src/pages/business/ShowCashoutDetails.tsx b/packages/demobank-ui/src/pages/business/ShowCashoutDetails.tsx index 3ef835574..5d8db5aee 100644 --- a/packages/demobank-ui/src/pages/business/ShowCashoutDetails.tsx +++ b/packages/demobank-ui/src/pages/business/ShowCashoutDetails.tsx @@ -15,7 +15,9 @@ */ import { Amounts, + HttpStatusCode, TalerError, + TalerErrorCode, TranslatedString } from "@gnu-taler/taler-util"; import { @@ -73,9 +75,9 @@ export function ShowCashoutDetails({ } if (result.type === "fail") { switch (result.case) { - case "not-found": return <Attention type="warning" title={i18n.str`This cashout not found. Maybe already aborted.`}> + case HttpStatusCode.NotFound: return <Attention type="warning" title={i18n.str`This cashout not found. Maybe already aborted.`}> </Attention> - case "cashout-not-supported": return <Attention type="warning" title={i18n.str`Cashouts are not supported`}> + case HttpStatusCode.NotImplemented: return <Attention type="warning" title={i18n.str`Cashouts are not supported`}> </Attention> default: assertUnreachable(result) } @@ -93,6 +95,7 @@ export function ShowCashoutDetails({ }); const isPending = String(result.body.status).toUpperCase() === "PENDING"; const { fiat_currency_specification, regional_currency_specification } = info.body + // won't implement in retry in old API 3:0:3 since request_uid is missing async function doAbortCashout() { if (!creds) return; await handleError(async () => { @@ -101,19 +104,19 @@ export function ShowCashoutDetails({ onCancel(); } else { switch (resp.case) { - case "not-found": return notify({ + case HttpStatusCode.NotFound: return notify({ type: "error", title: i18n.str`Cashout not found. It may be also mean that it was already aborted.`, description: resp.detail.hint as TranslatedString, debug: resp.detail, }) - case "already-confirmed": return notify({ + case HttpStatusCode.Conflict: return notify({ type: "error", title: i18n.str`Cashout was already confimed.`, 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`Cashout operation is not supported.`, description: resp.detail.hint as TranslatedString, @@ -136,49 +139,49 @@ export function ShowCashoutDetails({ mutate(() => true)//clean cashout state } else { switch (resp.case) { - case "not-found": return notify({ + case HttpStatusCode.NotFound: return notify({ type: "error", title: i18n.str`Cashout not found. It may be also mean that it was already aborted.`, 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 "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 "already-aborted": return notify({ + case TalerErrorCode.BANK_CONFIRM_ABORT_CONFLICT: return notify({ type: "error", title: i18n.str`The cashout operation is already aborted.`, description: resp.detail.hint as TranslatedString, debug: resp.detail, }); - case "no-cashout-payto": return notify({ + case TalerErrorCode.BANK_CONFIRM_INCOMPLETE: return notify({ type: "error", title: i18n.str`Missing destination account.`, description: resp.detail.hint as TranslatedString, debug: resp.detail, }) - case "too-many-attempts": return notify({ + case HttpStatusCode.TooManyRequests: return notify({ type: "error", title: i18n.str`Too many failed attempts.`, 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`Cashout operation is not supported.`, description: resp.detail.hint as TranslatedString, debug: resp.detail, }) - case "invalid-code": return notify({ + case TalerErrorCode.BANK_TAN_CHALLENGE_FAILED: return notify({ type: "error", title: i18n.str`The code for this cashout is invalid.`, description: resp.detail.hint as TranslatedString, |