diff options
author | Sebastian <sebasjm@gmail.com> | 2023-10-21 20:25:38 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2023-10-21 20:25:50 -0300 |
commit | 2ac73949e7cb8de44e56f2fecae617efab15671e (patch) | |
tree | 144a97d71bc9fa964675ef0cc764087ceb14e8eb /packages/demobank-ui/src/hooks | |
parent | 4b98b693d696d90f30f0a6546b0e1f4bc181a5f2 (diff) | |
download | wallet-core-2ac73949e7cb8de44e56f2fecae617efab15671e.tar.xz |
more ui
Diffstat (limited to 'packages/demobank-ui/src/hooks')
-rw-r--r-- | packages/demobank-ui/src/hooks/access.ts | 24 | ||||
-rw-r--r-- | packages/demobank-ui/src/hooks/circuit.ts | 14 |
2 files changed, 17 insertions, 21 deletions
diff --git a/packages/demobank-ui/src/hooks/access.ts b/packages/demobank-ui/src/hooks/access.ts index 7023b8803..da9812ffa 100644 --- a/packages/demobank-ui/src/hooks/access.ts +++ b/packages/demobank-ui/src/hooks/access.ts @@ -61,7 +61,7 @@ export function useWithdrawalDetails(wid: string) { // const { state: credentials } = useBackendState(); const { api } = useBankCoreApiContext(); - async function fetcher(wid: string) { + async function fetcher([wid]: [string]) { return await api.getWithdrawalById(wid) } @@ -114,7 +114,7 @@ export function usePublicAccounts(initial?: number) { const [offset, setOffset] = useState<number | undefined>(initial); const { api } = useBankCoreApiContext(); - async function fetcher(txid: number | undefined) { + async function fetcher([txid]: [number | undefined]) { return await api.getPublicAccounts({ limit: MAX_RESULT_SIZE, offset: txid ? String(txid) : undefined, @@ -124,16 +124,16 @@ export function usePublicAccounts(initial?: number) { const { data, error } = useSWR<TalerCoreBankResultByMethod<"getPublicAccounts">, TalerHttpError>( [offset, "getPublicAccounts"], fetcher, { - refreshInterval: 0, - refreshWhenHidden: false, - revalidateOnFocus: false, - revalidateOnReconnect: false, - refreshWhenOffline: false, - errorRetryCount: 0, - errorRetryInterval: 1, - shouldRetryOnError: false, - keepPreviousData: true, - }); + refreshInterval: 0, + refreshWhenHidden: false, + revalidateOnFocus: false, + revalidateOnReconnect: false, + refreshWhenOffline: false, + errorRetryCount: 0, + errorRetryInterval: 1, + shouldRetryOnError: false, + keepPreviousData: true, + }); const isLastPage = data && data.body.public_accounts.length < PAGE_SIZE; diff --git a/packages/demobank-ui/src/hooks/circuit.ts b/packages/demobank-ui/src/hooks/circuit.ts index 0f7af5fe5..06e068d6d 100644 --- a/packages/demobank-ui/src/hooks/circuit.ts +++ b/packages/demobank-ui/src/hooks/circuit.ts @@ -15,16 +15,15 @@ */ import { useState } from "preact/hooks"; -import { useBackendContext } from "../context/backend.js"; import { MAX_RESULT_SIZE, PAGE_SIZE } from "../utils.js"; import { useBackendState } from "./backend.js"; -// FIX default import https://github.com/microsoft/TypeScript/issues/49189 import { AccessToken, AmountJson, Amounts, OperationOk, TalerCoreBankResultByMethod, TalerCorebankApi, TalerError, TalerHttpError } from "@gnu-taler/taler-util"; import _useSWR, { SWRHook } from "swr"; import { useBankCoreApiContext } from "../context/config.js"; import { assertUnreachable } from "../pages/HomePage.js"; +// FIX default import https://github.com/microsoft/TypeScript/issues/49189 const useSWR = _useSWR as unknown as SWRHook; export type TransferCalculation = { @@ -44,12 +43,8 @@ type CashoutEstimators = { }; export function useEstimator(): CashoutEstimators { - const { state } = useBackendContext(); + const { state } = useBackendState(); const { api } = useBankCoreApiContext(); - const creds = - state.status !== "loggedIn" - ? undefined - : state.token; return { estimateByCredit: async (amount, fee, rate) => { const resp = await api.getCashoutRate({ @@ -101,13 +96,14 @@ export function useEstimator(): CashoutEstimators { } export function useRatiosAndFeeConfig() { - const { api } = useBankCoreApiContext(); + const { api, config } = useBankCoreApiContext(); + function fetcher() { return api.getConversionRates() } const { data, error } = useSWR<TalerCoreBankResultByMethod<"getConversionRates">, TalerHttpError>( - [, "getConversionRates"], fetcher, { + !config.have_cashout || !config.fiat_currency ? false : [, "getConversionRates"], fetcher, { refreshInterval: 60 * 1000, refreshWhenHidden: false, revalidateOnFocus: false, |