workaround swr default import
This commit is contained in:
parent
d49960639a
commit
88e5634c97
@ -18,18 +18,21 @@ import {
|
|||||||
HttpResponse,
|
HttpResponse,
|
||||||
HttpResponseOk,
|
HttpResponseOk,
|
||||||
HttpResponsePaginated,
|
HttpResponsePaginated,
|
||||||
RequestError,
|
RequestError
|
||||||
} from "@gnu-taler/web-util/lib/index.browser";
|
} from "@gnu-taler/web-util/lib/index.browser";
|
||||||
import { useEffect, useState } from "preact/hooks";
|
import { useEffect, useState } from "preact/hooks";
|
||||||
import useSWR from "swr";
|
|
||||||
import { useBackendContext } from "../context/backend.js";
|
import { useBackendContext } from "../context/backend.js";
|
||||||
import { MAX_RESULT_SIZE, PAGE_SIZE } from "../utils.js";
|
import { MAX_RESULT_SIZE, PAGE_SIZE } from "../utils.js";
|
||||||
import {
|
import {
|
||||||
useAuthenticatedBackend,
|
useAuthenticatedBackend,
|
||||||
useMatchMutate,
|
useMatchMutate,
|
||||||
usePublicBackend,
|
usePublicBackend
|
||||||
} from "./backend.js";
|
} from "./backend.js";
|
||||||
|
|
||||||
|
// FIX default import https://github.com/microsoft/TypeScript/issues/49189
|
||||||
|
import _useSWR, { SWRHook } from 'swr';
|
||||||
|
const useSWR = _useSWR as unknown as SWRHook
|
||||||
|
|
||||||
export function useAccessAPI(): AccessAPI {
|
export function useAccessAPI(): AccessAPI {
|
||||||
const mutateAll = useMatchMutate();
|
const mutateAll = useMatchMutate();
|
||||||
const { request } = useAuthenticatedBackend();
|
const { request } = useAuthenticatedBackend();
|
||||||
@ -162,7 +165,7 @@ export function useAccountDetails(
|
|||||||
> {
|
> {
|
||||||
const { fetcher } = useAuthenticatedBackend();
|
const { fetcher } = useAuthenticatedBackend();
|
||||||
|
|
||||||
const { data, error } = useSWR.default<
|
const { data, error } = useSWR<
|
||||||
HttpResponseOk<SandboxBackend.Access.BankAccountBalanceResponse>,
|
HttpResponseOk<SandboxBackend.Access.BankAccountBalanceResponse>,
|
||||||
RequestError<SandboxBackend.SandboxError>
|
RequestError<SandboxBackend.SandboxError>
|
||||||
>([`access-api/accounts/${account}`], fetcher, {
|
>([`access-api/accounts/${account}`], fetcher, {
|
||||||
@ -192,7 +195,7 @@ export function useWithdrawalDetails(
|
|||||||
> {
|
> {
|
||||||
const { fetcher } = useAuthenticatedBackend();
|
const { fetcher } = useAuthenticatedBackend();
|
||||||
|
|
||||||
const { data, error } = useSWR.default<
|
const { data, error } = useSWR<
|
||||||
HttpResponseOk<SandboxBackend.Access.BankAccountGetWithdrawalResponse>,
|
HttpResponseOk<SandboxBackend.Access.BankAccountGetWithdrawalResponse>,
|
||||||
RequestError<SandboxBackend.SandboxError>
|
RequestError<SandboxBackend.SandboxError>
|
||||||
>([`access-api/accounts/${account}/withdrawals/${wid}`], fetcher, {
|
>([`access-api/accounts/${account}/withdrawals/${wid}`], fetcher, {
|
||||||
@ -222,7 +225,7 @@ export function useTransactionDetails(
|
|||||||
> {
|
> {
|
||||||
const { fetcher } = useAuthenticatedBackend();
|
const { fetcher } = useAuthenticatedBackend();
|
||||||
|
|
||||||
const { data, error } = useSWR.default<
|
const { data, error } = useSWR<
|
||||||
HttpResponseOk<SandboxBackend.Access.BankAccountTransactionInfo>,
|
HttpResponseOk<SandboxBackend.Access.BankAccountTransactionInfo>,
|
||||||
RequestError<SandboxBackend.SandboxError>
|
RequestError<SandboxBackend.SandboxError>
|
||||||
>([`access-api/accounts/${account}/transactions/${tid}`], fetcher, {
|
>([`access-api/accounts/${account}/transactions/${tid}`], fetcher, {
|
||||||
@ -261,7 +264,7 @@ export function usePublicAccounts(
|
|||||||
data: afterData,
|
data: afterData,
|
||||||
error: afterError,
|
error: afterError,
|
||||||
isValidating: loadingAfter,
|
isValidating: loadingAfter,
|
||||||
} = useSWR.default<
|
} = useSWR<
|
||||||
HttpResponseOk<SandboxBackend.Access.PublicAccountsResponse>,
|
HttpResponseOk<SandboxBackend.Access.PublicAccountsResponse>,
|
||||||
RequestError<SandboxBackend.SandboxError>
|
RequestError<SandboxBackend.SandboxError>
|
||||||
>([`public-accounts`, args?.page, PAGE_SIZE], paginatedFetcher);
|
>([`public-accounts`, args?.page, PAGE_SIZE], paginatedFetcher);
|
||||||
@ -329,7 +332,7 @@ export function useTransactions(
|
|||||||
data: afterData,
|
data: afterData,
|
||||||
error: afterError,
|
error: afterError,
|
||||||
isValidating: loadingAfter,
|
isValidating: loadingAfter,
|
||||||
} = useSWR.default<
|
} = useSWR<
|
||||||
HttpResponseOk<SandboxBackend.Access.BankAccountTransactionsResponse>,
|
HttpResponseOk<SandboxBackend.Access.BankAccountTransactionsResponse>,
|
||||||
RequestError<SandboxBackend.SandboxError>
|
RequestError<SandboxBackend.SandboxError>
|
||||||
>(
|
>(
|
||||||
|
@ -22,11 +22,14 @@ import {
|
|||||||
useApiContext,
|
useApiContext,
|
||||||
} from "@gnu-taler/web-util/lib/index.browser";
|
} from "@gnu-taler/web-util/lib/index.browser";
|
||||||
import { useEffect, useMemo, useState } from "preact/hooks";
|
import { useEffect, useMemo, useState } from "preact/hooks";
|
||||||
import useSWR from "swr";
|
|
||||||
import { useBackendContext } from "../context/backend.js";
|
import { useBackendContext } from "../context/backend.js";
|
||||||
import { MAX_RESULT_SIZE, PAGE_SIZE } from "../utils.js";
|
import { MAX_RESULT_SIZE, PAGE_SIZE } from "../utils.js";
|
||||||
import { useAuthenticatedBackend, useMatchMutate } from "./backend.js";
|
import { useAuthenticatedBackend, useMatchMutate } from "./backend.js";
|
||||||
|
|
||||||
|
// FIX default import https://github.com/microsoft/TypeScript/issues/49189
|
||||||
|
import _useSWR, { SWRHook } from 'swr';
|
||||||
|
const useSWR = _useSWR as unknown as SWRHook
|
||||||
|
|
||||||
export function useAdminAccountAPI(): AdminAccountAPI {
|
export function useAdminAccountAPI(): AdminAccountAPI {
|
||||||
const { request } = useAuthenticatedBackend();
|
const { request } = useAuthenticatedBackend();
|
||||||
const mutateAll = useMatchMutate();
|
const mutateAll = useMatchMutate();
|
||||||
@ -194,7 +197,7 @@ export function useBusinessAccountDetails(
|
|||||||
> {
|
> {
|
||||||
const { fetcher } = useAuthenticatedBackend();
|
const { fetcher } = useAuthenticatedBackend();
|
||||||
|
|
||||||
const { data, error } = useSWR.default<
|
const { data, error } = useSWR<
|
||||||
HttpResponseOk<SandboxBackend.Circuit.CircuitAccountData>,
|
HttpResponseOk<SandboxBackend.Circuit.CircuitAccountData>,
|
||||||
RequestError<SandboxBackend.SandboxError>
|
RequestError<SandboxBackend.SandboxError>
|
||||||
>([`circuit-api/accounts/${account}`], fetcher, {
|
>([`circuit-api/accounts/${account}`], fetcher, {
|
||||||
@ -232,7 +235,7 @@ export function useBusinessAccounts(
|
|||||||
data: afterData,
|
data: afterData,
|
||||||
error: afterError,
|
error: afterError,
|
||||||
// isValidating: loadingAfter,
|
// isValidating: loadingAfter,
|
||||||
} = useSWR.default<
|
} = useSWR<
|
||||||
HttpResponseOk<SandboxBackend.Circuit.CircuitAccounts>,
|
HttpResponseOk<SandboxBackend.Circuit.CircuitAccounts>,
|
||||||
RequestError<SandboxBackend.SandboxError>
|
RequestError<SandboxBackend.SandboxError>
|
||||||
>(
|
>(
|
||||||
@ -302,7 +305,8 @@ export function useCashouts(): HttpResponse<
|
|||||||
> {
|
> {
|
||||||
const { fetcher, multiFetcher } = useAuthenticatedBackend();
|
const { fetcher, multiFetcher } = useAuthenticatedBackend();
|
||||||
|
|
||||||
const { data: list, error: listError } = useSWR.default<
|
|
||||||
|
const { data: list, error: listError } = useSWR<
|
||||||
HttpResponseOk<SandboxBackend.Circuit.Cashouts>,
|
HttpResponseOk<SandboxBackend.Circuit.Cashouts>,
|
||||||
RequestError<SandboxBackend.SandboxError>
|
RequestError<SandboxBackend.SandboxError>
|
||||||
>([`circuit-api/cashouts`], fetcher, {
|
>([`circuit-api/cashouts`], fetcher, {
|
||||||
@ -316,7 +320,7 @@ export function useCashouts(): HttpResponse<
|
|||||||
const paths = (list?.data.cashouts || []).map(
|
const paths = (list?.data.cashouts || []).map(
|
||||||
(cashoutId) => `circuit-api/cashouts/${cashoutId}`,
|
(cashoutId) => `circuit-api/cashouts/${cashoutId}`,
|
||||||
);
|
);
|
||||||
const { data: cashouts, error: productError } = useSWR.default<
|
const { data: cashouts, error: productError } = useSWR<
|
||||||
HttpResponseOk<SandboxBackend.Circuit.CashoutStatusResponse>[],
|
HttpResponseOk<SandboxBackend.Circuit.CashoutStatusResponse>[],
|
||||||
RequestError<SandboxBackend.SandboxError>
|
RequestError<SandboxBackend.SandboxError>
|
||||||
>([paths], multiFetcher, {
|
>([paths], multiFetcher, {
|
||||||
|
Loading…
Reference in New Issue
Block a user