aboutsummaryrefslogtreecommitdiff
path: root/packages/bank-ui/src/hooks/regional.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/bank-ui/src/hooks/regional.ts')
-rw-r--r--packages/bank-ui/src/hooks/regional.ts58
1 files changed, 37 insertions, 21 deletions
diff --git a/packages/bank-ui/src/hooks/regional.ts b/packages/bank-ui/src/hooks/regional.ts
index bf948d293..51f3edad4 100644
--- a/packages/bank-ui/src/hooks/regional.ts
+++ b/packages/bank-ui/src/hooks/regional.ts
@@ -31,18 +31,20 @@ import {
TalerHttpError,
opFixedSuccess,
} from "@gnu-taler/taler-util";
+import { useState } from "preact/hooks";
import _useSWR, { SWRHook, mutate } from "swr";
import { useBankCoreApiContext } from "../context/config.js";
-import { useState } from "preact/hooks";
// FIX default import https://github.com/microsoft/TypeScript/issues/49189
const useSWR = _useSWR as unknown as SWRHook;
-export type TransferCalculation = {
- debit: AmountJson;
- credit: AmountJson;
- beforeFee: AmountJson;
-} | "amount-is-too-small";
+export type TransferCalculation =
+ | {
+ debit: AmountJson;
+ credit: AmountJson;
+ beforeFee: AmountJson;
+ }
+ | "amount-is-too-small";
type EstimatorFunction = (
amount: AmountJson,
fee: AmountJson,
@@ -95,7 +97,7 @@ export function useCashinEstimator(): ConversionEstimators {
if (resp.type === "fail") {
switch (resp.case) {
case HttpStatusCode.Conflict: {
- return "amount-is-too-small"
+ return "amount-is-too-small";
}
// this below can't happen
case HttpStatusCode.NotImplemented: //it should not be able to call this function
@@ -120,7 +122,7 @@ export function useCashinEstimator(): ConversionEstimators {
if (resp.type === "fail") {
switch (resp.case) {
case HttpStatusCode.Conflict: {
- return "amount-is-too-small"
+ return "amount-is-too-small";
}
// this below can't happen
case HttpStatusCode.NotImplemented: //it should not be able to call this function
@@ -142,7 +144,7 @@ export function useCashinEstimator(): ConversionEstimators {
}
export function useCashoutEstimator(): ConversionEstimators {
- const { bank, conversion } = useBankCoreApiContext();
+ const { conversion } = useBankCoreApiContext();
return {
estimateByCredit: async (fiatAmount, fee) => {
const resp = await conversion.getCashoutRate({
@@ -151,7 +153,7 @@ export function useCashoutEstimator(): ConversionEstimators {
if (resp.type === "fail") {
switch (resp.case) {
case HttpStatusCode.Conflict: {
- return "amount-is-too-small"
+ return "amount-is-too-small";
}
// this below can't happen
case HttpStatusCode.NotImplemented: //it should not be able to call this function
@@ -176,7 +178,7 @@ export function useCashoutEstimator(): ConversionEstimators {
if (resp.type === "fail") {
switch (resp.case) {
case HttpStatusCode.Conflict: {
- return "amount-is-too-small"
+ return "amount-is-too-small";
}
// this below can't happen
case HttpStatusCode.NotImplemented: //it should not be able to call this function
@@ -201,11 +203,15 @@ export function useCashoutEstimator(): ConversionEstimators {
* @deprecated use useCashoutEstimator
*/
export function useEstimator(): ConversionEstimators {
- return useCashoutEstimator()
+ return useCashoutEstimator();
}
export async function revalidateBusinessAccounts() {
- return mutate((key) => Array.isArray(key) && key[key.length - 1] === "getAccounts", undefined, { revalidate: true });
+ return mutate(
+ (key) => Array.isArray(key) && key[key.length - 1] === "getAccounts",
+ undefined,
+ { revalidate: true },
+ );
}
export function useBusinessAccounts() {
const { state: credentials } = useSessionState();
@@ -247,9 +253,10 @@ export function useBusinessAccounts() {
data && data.type === "ok" && data.body.accounts.length <= PAGE_SIZE;
const isFirstPage = !offset;
- const result = data && data.type == "ok" ? structuredClone(data.body.accounts) : []
+ const result =
+ data && data.type == "ok" ? structuredClone(data.body.accounts) : [];
if (result.length == PAGE_SIZE + 1) {
- result.pop()
+ result.pop();
}
const pagination = {
result,
@@ -276,7 +283,9 @@ function notUndefined(c: CashoutWithId | undefined): c is CashoutWithId {
export function revalidateOnePendingCashouts() {
return mutate(
(key) =>
- Array.isArray(key) && key[key.length - 1] === "useOnePendingCashouts", undefined, { revalidate: true }
+ Array.isArray(key) && key[key.length - 1] === "useOnePendingCashouts",
+ undefined,
+ { revalidate: true },
);
}
export function useOnePendingCashouts(account: string) {
@@ -290,7 +299,8 @@ export function useOnePendingCashouts(account: string) {
if (list.type !== "ok") {
return list;
}
- const pendingCashout = list.body.cashouts.length > 0 ? list.body.cashouts[0] : undefined;
+ const pendingCashout =
+ list.body.cashouts.length > 0 ? list.body.cashouts[0] : undefined;
if (!pendingCashout) return opFixedSuccess(undefined);
const cashoutInfo = await api.getCashoutById(
{ username, token },
@@ -334,7 +344,9 @@ export function useOnePendingCashouts(account: string) {
}
export function revalidateCashouts() {
- return mutate((key) => Array.isArray(key) && key[key.length - 1] === "useCashouts");
+ return mutate(
+ (key) => Array.isArray(key) && key[key.length - 1] === "useCashouts",
+ );
}
export function useCashouts(account: string) {
const { state: credentials } = useSessionState();
@@ -357,7 +369,7 @@ export function useCashouts(account: string) {
}),
);
const cashouts = all.filter(notUndefined);
- return { type: "ok" as const, body: { cashouts }};
+ return { type: "ok" as const, body: { cashouts } };
}
const { data, error } = useSWR<
| OperationOk<{ cashouts: CashoutWithId[] }>
@@ -386,7 +398,9 @@ export function useCashouts(account: string) {
export function revalidateCashoutDetails() {
return mutate(
- (key) => Array.isArray(key) && key[key.length - 1] === "getCashoutById", undefined, { revalidate: true }
+ (key) => Array.isArray(key) && key[key.length - 1] === "getCashoutById",
+ undefined,
+ { revalidate: true },
);
}
export function useCashoutDetails(cashoutId: number | undefined) {
@@ -435,7 +449,9 @@ export type LastMonitor = {
};
export function revalidateLastMonitorInfo() {
return mutate(
- (key) => Array.isArray(key) && key[key.length - 1] === "useLastMonitorInfo", undefined, { revalidate: true }
+ (key) => Array.isArray(key) && key[key.length - 1] === "useLastMonitorInfo",
+ undefined,
+ { revalidate: true },
);
}
export function useLastMonitorInfo(