diff options
author | Sebastian <sebasjm@gmail.com> | 2024-03-11 14:56:25 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2024-03-11 14:57:48 -0300 |
commit | 37f46f4d6b821d163c3e4db5c374b1120212ac74 (patch) | |
tree | 641c5bccd6d1b77fa440e67b80543eec9378ef4a /packages/bank-ui/src/pages/regional/CreateCashout.tsx | |
parent | 4cbe754aca72b6edee922e3a84f251030293f088 (diff) | |
download | wallet-core-37f46f4d6b821d163c3e4db5c374b1120212ac74.tar.xz |
obs and cancel request, plus lint
Diffstat (limited to 'packages/bank-ui/src/pages/regional/CreateCashout.tsx')
-rw-r--r-- | packages/bank-ui/src/pages/regional/CreateCashout.tsx | 104 |
1 files changed, 69 insertions, 35 deletions
diff --git a/packages/bank-ui/src/pages/regional/CreateCashout.tsx b/packages/bank-ui/src/pages/regional/CreateCashout.tsx index 2f15d16b4..a76179b4d 100644 --- a/packages/bank-ui/src/pages/regional/CreateCashout.tsx +++ b/packages/bank-ui/src/pages/regional/CreateCashout.tsx @@ -39,9 +39,13 @@ import { useEffect, useState } from "preact/hooks"; import { ErrorLoadingWithDebug } from "../../components/ErrorLoadingWithDebug.js"; import { VersionHint, useBankCoreApiContext } from "../../context/config.js"; import { useAccountDetails } from "../../hooks/account.js"; -import { useSessionState } from "../../hooks/session.js"; import { useBankState } from "../../hooks/bank-state.js"; -import { TransferCalculation, useCashoutEstimator, useConversionInfo, useEstimator } from "../../hooks/regional.js"; +import { + TransferCalculation, + useCashoutEstimator, + useConversionInfo, +} from "../../hooks/regional.js"; +import { useSessionState } from "../../hooks/session.js"; import { RouteDefinition } from "../../route.js"; import { TanChannel, undefinedIfEmpty } from "../../utils.js"; import { LoginForm } from "../LoginForm.js"; @@ -141,11 +145,11 @@ export function CreateCashout({ switch (info.case) { case HttpStatusCode.NotImplemented: { return ( - <Attention - type="danger" - title={i18n.str`Cashout are disabled`} - > - <i18n.Translate>Cashout should be enable by configuration and the conversion rate should be initialized with fee, ratio and rounding mode.</i18n.Translate> + <Attention type="danger" title={i18n.str`Cashout are disabled`}> + <i18n.Translate> + Cashout should be enable by configuration and the conversion rate + should be initialized with fee, ratio and rounding mode. + </i18n.Translate> </Attention> ); } @@ -185,7 +189,8 @@ export function CreateCashout({ credit: fiatZero, beforeFee: fiatZero, }; - const [calculationResult, setCalculation] = useState<TransferCalculation>(zeroCalc); + const [calculationResult, setCalculation] = + useState<TransferCalculation>(zeroCalc); const sellFee = Amounts.parseOrThrow(conversionInfo.cashout_fee); const sellRate = conversionInfo.cashout_ratio; /** @@ -193,30 +198,33 @@ 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 }`, ); useEffect(() => { async function doAsync() { await handleError(async () => { - const higerThanMin = form.isDebit ? - Amounts.cmp(inputAmount, conversionInfo.cashout_min_amount) === 1 : true; - const notZero = Amounts.isNonZero(inputAmount) + const higerThanMin = form.isDebit + ? Amounts.cmp(inputAmount, conversionInfo.cashout_min_amount) === 1 + : true; + const notZero = Amounts.isNonZero(inputAmount); if (notZero && higerThanMin) { const resp = await (form.isDebit ? calculateFromDebit(inputAmount, sellFee) : calculateFromCredit(inputAmount, sellFee)); setCalculation(resp); } else { - setCalculation(zeroCalc) + setCalculation(zeroCalc); } }); } doAsync(); }, [form.amount, form.isDebit]); - const calc = calculationResult === "amount-is-too-small" ? zeroCalc : calculationResult + const calc = + calculationResult === "amount-is-too-small" ? zeroCalc : calculationResult; const balanceAfter = Amounts.sub(account.balance, calc.debit).amount; @@ -231,8 +239,14 @@ export function CreateCashout({ ? i18n.str`Invalid` : 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}` + : 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 + }` : calculationResult === "amount-is-too-small" ? i18n.str`Amount needs to be higher` : Amounts.isZero(calc.credit) @@ -280,6 +294,7 @@ export function CreateCashout({ title: i18n.str`Account not found`, description: resp.detail.hint as TranslatedString, debug: resp.detail, + when: AbsoluteTime.now(), }); case TalerErrorCode.BANK_TRANSFER_REQUEST_UID_REUSED: return notify({ @@ -287,6 +302,7 @@ export function CreateCashout({ title: i18n.str`Duplicated request detected, check if the operation succeeded or try again.`, description: resp.detail.hint as TranslatedString, debug: resp.detail, + when: AbsoluteTime.now(), }); case TalerErrorCode.BANK_BAD_CONVERSION: return notify({ @@ -294,6 +310,7 @@ export function CreateCashout({ title: i18n.str`The conversion rate was incorrectly applied`, description: resp.detail.hint as TranslatedString, debug: resp.detail, + when: AbsoluteTime.now(), }); case TalerErrorCode.BANK_UNALLOWED_DEBIT: return notify({ @@ -301,6 +318,7 @@ export function CreateCashout({ title: i18n.str`The account does not have sufficient funds`, description: resp.detail.hint as TranslatedString, debug: resp.detail, + when: AbsoluteTime.now(), }); case HttpStatusCode.NotImplemented: return notify({ @@ -308,6 +326,7 @@ export function CreateCashout({ title: i18n.str`Cashout are disabled`, description: resp.detail.hint as TranslatedString, debug: resp.detail, + when: AbsoluteTime.now(), }); case TalerErrorCode.BANK_CONFIRM_INCOMPLETE: return notify({ @@ -315,6 +334,7 @@ export function CreateCashout({ title: i18n.str`Missing cashout URI in the profile`, description: resp.detail.hint as TranslatedString, debug: resp.detail, + when: AbsoluteTime.now(), }); case TalerErrorCode.BANK_TAN_CHANNEL_SCRIPT_FAILED: return notify({ @@ -322,6 +342,7 @@ export function CreateCashout({ title: i18n.str`Sending the confirmation message failed, retry later or contact the administrator.`, description: resp.detail.hint as TranslatedString, debug: resp.detail, + when: AbsoluteTime.now(), }); } assertUnreachable(resp); @@ -406,7 +427,10 @@ export function CreateCashout({ <dd class="text-sm text-gray-900">{cashoutLegalName}</dd> </div> <p class="mt-2 text-sm text-gray-500"> - <i18n.Translate>If this name doesn't match the account holder's name your transaction may fail.</i18n.Translate> + <i18n.Translate> + If this name doesn't match the account holder's name your + transaction may fail. + </i18n.Translate> </p> </Fragment> ) : ( @@ -482,7 +506,7 @@ export function CreateCashout({ updateForm(structuredClone(form)); }} > - {form.isDebit ? + {form.isDebit ? ( <svg class="self-center flex-none h-5 w-5 text-indigo-600" viewBox="0 0 20 20" @@ -495,12 +519,17 @@ export function CreateCashout({ clip-rule="evenodd" /> </svg> - - : - <svg fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-5 h-5"> + ) : ( + <svg + fill="none" + viewBox="0 0 24 24" + stroke-width="1.5" + stroke="currentColor" + class="w-5 h-5" + > <path d="M15 12H9m12 0a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z" /> </svg> - } + )} <i18n.Translate>Send {regional_currency}</i18n.Translate> </button> @@ -514,7 +543,7 @@ export function CreateCashout({ updateForm(structuredClone(form)); }} > - {!form.isDebit ? + {!form.isDebit ? ( <svg class="self-center flex-none h-5 w-5 text-indigo-600" viewBox="0 0 20 20" @@ -527,12 +556,17 @@ export function CreateCashout({ clip-rule="evenodd" /> </svg> - - : - <svg fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="w-5 h-5"> + ) : ( + <svg + fill="none" + viewBox="0 0 24 24" + stroke-width="1.5" + stroke="currentColor" + class="w-5 h-5" + > <path d="M15 12H9m12 0a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z" /> </svg> - } + )} <i18n.Translate>Receive {fiat_currency}</i18n.Translate> </button> @@ -579,9 +613,9 @@ export function CreateCashout({ cashoutDisabled ? undefined : (value) => { - form.amount = value; - updateForm(structuredClone(form)); - } + form.amount = value; + updateForm(structuredClone(form)); + } } /> <ShowInputErrorLabel @@ -622,7 +656,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> @@ -655,7 +689,7 @@ export function CreateCashout({ {/* channel, not shown if new cashout api */} {!OLD_CASHOUT_API ? undefined : config.supported_tan_channels - .length === 0 ? ( + .length === 0 ? ( <div class="sm:col-span-5"> <Attention type="warning" @@ -727,7 +761,7 @@ export function CreateCashout({ )} {config.supported_tan_channels.indexOf(TanChannel.SMS) === - -1 ? undefined : ( + -1 ? undefined : ( <label onClick={() => { if (!resultAccount.body.contact_data?.phone) return; @@ -803,7 +837,7 @@ export function CreateCashout({ </button> </div> </form> - </div > - </div > + </div> + </div> ); } |