diff options
author | Sebastian <sebasjm@gmail.com> | 2024-03-21 12:11:31 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2024-03-26 16:57:55 -0300 |
commit | 8aa9ce6d20b41b7eb9b438a56ccd34cb0da35f80 (patch) | |
tree | 5cec8219a136469f2c689c47a74b28e52eb5992b /packages/bank-ui/src/pages/regional | |
parent | 5a1f528d8806bcb15d5c4c8364554502c11931a7 (diff) | |
download | wallet-core-8aa9ce6d20b41b7eb9b438a56ccd34cb0da35f80.tar.xz |
wip
Diffstat (limited to 'packages/bank-ui/src/pages/regional')
3 files changed, 21 insertions, 152 deletions
diff --git a/packages/bank-ui/src/pages/regional/ConversionConfig.tsx b/packages/bank-ui/src/pages/regional/ConversionConfig.tsx index 014142e97..7527290d0 100644 --- a/packages/bank-ui/src/pages/regional/ConversionConfig.tsx +++ b/packages/bank-ui/src/pages/regional/ConversionConfig.tsx @@ -35,7 +35,7 @@ import { } from "@gnu-taler/web-util/browser"; import { Fragment, VNode, h } from "preact"; import { useEffect, useState } from "preact/hooks"; -import { useBankCoreApiContext } from "../../context/config.js"; +import { useBankCoreApiContext } from "@gnu-taler/web-util/browser"; import { useSessionState } from "../../hooks/session.js"; import { TransferCalculation, @@ -43,7 +43,7 @@ import { useCashoutEstimator, useConversionInfo, } from "../../hooks/regional.js"; -import { RouteDefinition } from "../../route.js"; +import { RouteDefinition } from "@gnu-taler/web-util/browser"; import { undefinedIfEmpty } from "../../utils.js"; import { InputAmount, RenderAmount } from "../PaytoWireTransferForm.js"; import { ProfileNavigation } from "../ProfileNavigation.js"; @@ -104,7 +104,7 @@ function useComponentState({ return function afterComponentLoads() { const { i18n } = useTranslationContext(); - const { conversion } = useBankCoreApiContext(); + const { lib: { conversion } } = useBankCoreApiContext(); const [notification, notify, handleError] = useLocalNotification(); @@ -519,8 +519,8 @@ function useComponentState({ </div> {cashoutCalc && - status.status === "ok" && - Amounts.cmp(status.result.amount, cashoutCalc.credit) < + status.status === "ok" && + Amounts.cmp(status.result.amount, cashoutCalc.credit) < 0 ? ( <div class="p-4"> <Attention 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> diff --git a/packages/bank-ui/src/pages/regional/ShowCashoutDetails.tsx b/packages/bank-ui/src/pages/regional/ShowCashoutDetails.tsx index 849da77aa..eaefeab12 100644 --- a/packages/bank-ui/src/pages/regional/ShowCashoutDetails.tsx +++ b/packages/bank-ui/src/pages/regional/ShowCashoutDetails.tsx @@ -29,7 +29,7 @@ import { VNode, h } from "preact"; import { ErrorLoadingWithDebug } from "../../components/ErrorLoadingWithDebug.js"; import { Time } from "../../components/Time.js"; import { useCashoutDetails, useConversionInfo } from "../../hooks/regional.js"; -import { RouteDefinition } from "../../route.js"; +import { RouteDefinition } from "@gnu-taler/web-util/browser"; import { RenderAmount } from "../PaytoWireTransferForm.js"; interface Props { @@ -138,7 +138,7 @@ export function ShowCashoutDetails({ id, routeClose }: Props): VNode { timestamp={AbsoluteTime.fromProtocolTimestamp( result.body.creation_time, )} - // relative={Duration.fromSpec({ days: 1 })} + // relative={Duration.fromSpec({ days: 1 })} /> </dd> </div> |