summaryrefslogtreecommitdiff
path: root/packages/bank-ui/src/pages/regional/CreateCashout.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'packages/bank-ui/src/pages/regional/CreateCashout.tsx')
-rw-r--r--packages/bank-ui/src/pages/regional/CreateCashout.tsx159
1 files changed, 14 insertions, 145 deletions
diff --git a/packages/bank-ui/src/pages/regional/CreateCashout.tsx b/packages/bank-ui/src/pages/regional/CreateCashout.tsx
index 20d6b0bff..393240dee 100644
--- a/packages/bank-ui/src/pages/regional/CreateCashout.tsx
+++ b/packages/bank-ui/src/pages/regional/CreateCashout.tsx
@@ -37,7 +37,7 @@ import {
import { Fragment, VNode, h } from "preact";
import { useEffect, useState } from "preact/hooks";
import { ErrorLoadingWithDebug } from "../../components/ErrorLoadingWithDebug.js";
-import { VersionHint, useBankCoreApiContext } from "../../context/config.js";
+import { useBankCoreApiContext } from "@gnu-taler/web-util/browser";
import { useAccountDetails } from "../../hooks/account.js";
import { useBankState } from "../../hooks/bank-state.js";
import {
@@ -46,7 +46,7 @@ import {
useConversionInfo,
} from "../../hooks/regional.js";
import { useSessionState } from "../../hooks/session.js";
-import { RouteDefinition } from "../../route.js";
+import { RouteDefinition } from "@gnu-taler/web-util/browser";
import { TanChannel, undefinedIfEmpty } from "../../utils.js";
import { LoginForm } from "../LoginForm.js";
import {
@@ -90,7 +90,7 @@ export function CreateCashout({
const creds = credentials.status !== "loggedIn" ? undefined : credentials;
const [, updateBankState] = useBankState();
- const { bank: api, config, hints } = useBankCoreApiContext();
+ const { lib: { bank: api }, config, hints } = useBankCoreApiContext();
const [form, setForm] = useState<Partial<FormType>>({ isDebit: true });
const [notification, notify, handleError] = useLocalNotification();
const info = useConversionInfo();
@@ -116,8 +116,6 @@ export function CreateCashout({
);
}
- const OLD_CASHOUT_API = hints.indexOf(VersionHint.CASHOUT_BEFORE_2FA) !== -1;
-
if (!resultAccount) {
return <Loading />;
}
@@ -198,8 +196,7 @@ export function CreateCashout({
* depending on the isDebit flag
*/
const inputAmount = Amounts.parseOrThrow(
- `${form.isDebit ? regional_currency : fiat_currency}:${
- !form.amount ? "0" : form.amount
+ `${form.isDebit ? regional_currency : fiat_currency}:${!form.amount ? "0" : form.amount
}`,
);
@@ -240,19 +237,17 @@ export function CreateCashout({
: Amounts.cmp(limit, calc.debit) === -1
? i18n.str`Balance is not enough`
: form.isDebit &&
- Amounts.cmp(inputAmount, conversionInfo.cashout_min_amount) < 1
- ? i18n.str`Needs to be higher than ${
- Amounts.stringifyValueWithSpec(
- Amounts.parseOrThrow(conversionInfo.cashout_min_amount),
- regional_currency_specification,
- ).normal
+ Amounts.cmp(inputAmount, conversionInfo.cashout_min_amount) < 1
+ ? i18n.str`Needs to be higher than ${Amounts.stringifyValueWithSpec(
+ Amounts.parseOrThrow(conversionInfo.cashout_min_amount),
+ regional_currency_specification,
+ ).normal
}`
: calculationResult === "amount-is-too-small"
? i18n.str`Amount needs to be higher`
: Amounts.isZero(calc.credit)
? i18n.str`The total transfer at destination will be zero`
: undefined,
- channel: OLD_CASHOUT_API && !form.channel ? i18n.str`Required` : undefined,
});
const trimmedAmountStr = form.amount?.trim();
@@ -260,9 +255,7 @@ export function CreateCashout({
const request_uid = encodeCrock(getRandomBytes(32));
await handleError(async () => {
// new cashout api doesn't require channel
- const validChannel =
- !OLD_CASHOUT_API ||
- config.supported_tan_channels.length === 0 ||
+ const validChannel = config.supported_tan_channels.length === 0 ||
form.channel;
if (!creds || !form.subject || !validChannel) return;
@@ -613,9 +606,9 @@ export function CreateCashout({
cashoutDisabled
? undefined
: (value) => {
- form.amount = value;
- updateForm(structuredClone(form));
- }
+ form.amount = value;
+ updateForm(structuredClone(form));
+ }
}
/>
<ShowInputErrorLabel
@@ -656,7 +649,7 @@ export function CreateCashout({
</dd>
</div>
{Amounts.isZero(sellFee) ||
- Amounts.isZero(calc.beforeFee) ? undefined : (
+ Amounts.isZero(calc.beforeFee) ? undefined : (
<div class="flex items-center justify-between border-t-2 afu pt-4">
<dt class="flex items-center text-sm text-gray-600">
<span>
@@ -687,130 +680,6 @@ export function CreateCashout({
</div>
)}
- {/* channel, not shown if new cashout api */}
- {!OLD_CASHOUT_API ? 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"
- for="channel"
- >
- {i18n.str`Second factor authentication`}
- </label>
- <div class="mt-2 max-w-xl text-sm text-gray-500">
- <div class="px-4 mt-4 grid grid-cols-1 gap-y-6">
- {config.supported_tan_channels.indexOf(
- TanChannel.EMAIL,
- ) === -1 ? undefined : (
- <label
- onClick={() => {
- if (!resultAccount.body.contact_data?.email) return;
- form.channel = TanChannel.EMAIL;
- updateForm(structuredClone(form));
- }}
- data-disabled={
- !resultAccount.body.contact_data?.email
- }
- data-selected={form.channel === TanChannel.EMAIL}
- class="relative flex data-[disabled=false]:cursor-pointer rounded-lg border bg-white data-[disabled=true]:bg-gray-200 p-4 shadow-sm focus:outline-none border-gray-300 data-[selected=true]:ring-2 data-[selected=true]:ring-indigo-600"
- >
- <input
- type="radio"
- name="channel"
- value="Newsletter"
- class="sr-only"
- />
- <span class="flex flex-1">
- <span class="flex flex-col">
- <span
- id="project-type-0-label"
- class="block text-sm font-medium text-gray-900 "
- >
- <i18n.Translate>Email</i18n.Translate>
- </span>
- {!resultAccount.body.contact_data?.email &&
- i18n.str`Add a email in your profile to enable this option`}
- </span>
- </span>
- <svg
- data-selected={form.channel === TanChannel.EMAIL}
- class="h-5 w-5 text-indigo-600 data-[selected=false]:hidden"
- viewBox="0 0 20 20"
- fill="currentColor"
- aria-hidden="true"
- >
- <path
- fill-rule="evenodd"
- d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.857-9.809a.75.75 0 00-1.214-.882l-3.483 4.79-1.88-1.88a.75.75 0 10-1.06 1.061l2.5 2.5a.75.75 0 001.137-.089l4-5.5z"
- clip-rule="evenodd"
- />
- </svg>
- </label>
- )}
-
- {config.supported_tan_channels.indexOf(TanChannel.SMS) ===
- -1 ? undefined : (
- <label
- onClick={() => {
- if (!resultAccount.body.contact_data?.phone) return;
- form.channel = TanChannel.SMS;
- updateForm(structuredClone(form));
- }}
- data-disabled={
- !resultAccount.body.contact_data?.phone
- }
- data-selected={form.channel === TanChannel.SMS}
- class="relative flex data-[disabled=false]:cursor-pointer rounded-lg border data-[disabled=true]:bg-gray-200 p-4 shadow-sm focus:outline-none border-gray-300 data-[selected=true]:ring-2 data-[selected=true]:ring-indigo-600"
- >
- <input
- type="radio"
- name="channel"
- value="Existing Customers"
- class="sr-only"
- />
- <span class="flex flex-1">
- <span class="flex flex-col">
- <span
- id="project-type-1-label"
- class="block text-sm font-medium text-gray-900"
- >
- <i18n.Translate>SMS</i18n.Translate>
- </span>
- {!resultAccount.body.contact_data?.phone &&
- i18n.str`Add a phone number in your profile to enable this option`}
- </span>
- </span>
- <svg
- data-selected={form.channel === TanChannel.SMS}
- class="h-5 w-5 text-indigo-600 data-[selected=false]:hidden"
- viewBox="0 0 20 20"
- fill="currentColor"
- aria-hidden="true"
- >
- <path
- fill-rule="evenodd"
- d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.857-9.809a.75.75 0 00-1.214-.882l-3.483 4.79-1.88-1.88a.75.75 0 10-1.06 1.061l2.5 2.5a.75.75 0 001.137-.089l4-5.5z"
- clip-rule="evenodd"
- />
- </svg>
- </label>
- )}
- </div>
- </div>
- </div>
- )}
</div>
</div>