fix: request error is whats being thrown
This commit is contained in:
parent
7a591c39d7
commit
53af8b486f
@ -47,8 +47,7 @@ export function useMatchMutate(): (
|
|||||||
const allKeys = Array.from(cache.keys());
|
const allKeys = Array.from(cache.keys());
|
||||||
const keys = allKeys.filter((key) => re.test(key));
|
const keys = allKeys.filter((key) => re.test(key));
|
||||||
const mutations = keys.map((key) => {
|
const mutations = keys.map((key) => {
|
||||||
// console.log(key)
|
return mutate(key, value, true);
|
||||||
mutate(key, value, true);
|
|
||||||
});
|
});
|
||||||
return Promise.all(mutations);
|
return Promise.all(mutations);
|
||||||
};
|
};
|
||||||
|
@ -13,14 +13,14 @@
|
|||||||
You should have received a copy of the GNU General Public License along with
|
You should have received a copy of the GNU General Public License along with
|
||||||
GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
|
GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
|
||||||
*/
|
*/
|
||||||
|
import {
|
||||||
|
HttpResponse,
|
||||||
|
HttpResponseOk,
|
||||||
|
RequestError,
|
||||||
|
} from "@gnu-taler/web-util/lib/index.browser";
|
||||||
import useSWR, { useSWRConfig } from "swr";
|
import useSWR, { useSWRConfig } from "swr";
|
||||||
import { useBackendContext } from "../context/backend.js";
|
import { useBackendContext } from "../context/backend.js";
|
||||||
import { MerchantBackend } from "../declaration.js";
|
import { MerchantBackend } from "../declaration.js";
|
||||||
import {
|
|
||||||
HttpError,
|
|
||||||
HttpResponse,
|
|
||||||
HttpResponseOk,
|
|
||||||
} from "@gnu-taler/web-util/lib/index.browser";
|
|
||||||
import {
|
import {
|
||||||
useBackendBaseRequest,
|
useBackendBaseRequest,
|
||||||
useBackendInstanceRequest,
|
useBackendInstanceRequest,
|
||||||
@ -188,7 +188,7 @@ export function useInstanceDetails(): HttpResponse<
|
|||||||
|
|
||||||
const { data, error, isValidating } = useSWR<
|
const { data, error, isValidating } = useSWR<
|
||||||
HttpResponseOk<MerchantBackend.Instances.QueryInstancesResponse>,
|
HttpResponseOk<MerchantBackend.Instances.QueryInstancesResponse>,
|
||||||
HttpError<MerchantBackend.ErrorDetail>
|
RequestError<MerchantBackend.ErrorDetail>
|
||||||
>([`/private/`], fetcher, {
|
>([`/private/`], fetcher, {
|
||||||
refreshInterval: 0,
|
refreshInterval: 0,
|
||||||
refreshWhenHidden: false,
|
refreshWhenHidden: false,
|
||||||
@ -202,7 +202,7 @@ export function useInstanceDetails(): HttpResponse<
|
|||||||
|
|
||||||
if (isValidating) return { loading: true, data: data?.data };
|
if (isValidating) return { loading: true, data: data?.data };
|
||||||
if (data) return data;
|
if (data) return data;
|
||||||
if (error) return error;
|
if (error) return error.info;
|
||||||
return { loading: true };
|
return { loading: true };
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,7 +218,7 @@ export function useInstanceKYCDetails(): HttpResponse<
|
|||||||
|
|
||||||
const { data, error } = useSWR<
|
const { data, error } = useSWR<
|
||||||
HttpResponseOk<MerchantBackend.Instances.AccountKycRedirects>,
|
HttpResponseOk<MerchantBackend.Instances.AccountKycRedirects>,
|
||||||
HttpError<MerchantBackend.ErrorDetail>
|
RequestError<MerchantBackend.ErrorDetail>
|
||||||
>([`/private/kyc`], fetcher, {
|
>([`/private/kyc`], fetcher, {
|
||||||
refreshInterval: 5000,
|
refreshInterval: 5000,
|
||||||
refreshWhenHidden: false,
|
refreshWhenHidden: false,
|
||||||
@ -235,7 +235,7 @@ export function useInstanceKYCDetails(): HttpResponse<
|
|||||||
return { ok: true, data: { type: "redirect", status: data.data } };
|
return { ok: true, data: { type: "redirect", status: data.data } };
|
||||||
return { ok: true, data: { type: "ok" } };
|
return { ok: true, data: { type: "ok" } };
|
||||||
}
|
}
|
||||||
if (error) return error;
|
if (error) return error.info;
|
||||||
return { loading: true };
|
return { loading: true };
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -249,7 +249,7 @@ export function useManagedInstanceDetails(
|
|||||||
|
|
||||||
const { data, error, isValidating } = useSWR<
|
const { data, error, isValidating } = useSWR<
|
||||||
HttpResponseOk<MerchantBackend.Instances.QueryInstancesResponse>,
|
HttpResponseOk<MerchantBackend.Instances.QueryInstancesResponse>,
|
||||||
HttpError<MerchantBackend.ErrorDetail>
|
RequestError<MerchantBackend.ErrorDetail>
|
||||||
>([`/management/instances/${instanceId}`], request, {
|
>([`/management/instances/${instanceId}`], request, {
|
||||||
refreshInterval: 0,
|
refreshInterval: 0,
|
||||||
refreshWhenHidden: false,
|
refreshWhenHidden: false,
|
||||||
@ -263,7 +263,7 @@ export function useManagedInstanceDetails(
|
|||||||
|
|
||||||
if (isValidating) return { loading: true, data: data?.data };
|
if (isValidating) return { loading: true, data: data?.data };
|
||||||
if (data) return data;
|
if (data) return data;
|
||||||
if (error) return error;
|
if (error) return error.info;
|
||||||
return { loading: true };
|
return { loading: true };
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -275,11 +275,11 @@ export function useBackendInstances(): HttpResponse<
|
|||||||
|
|
||||||
const { data, error, isValidating } = useSWR<
|
const { data, error, isValidating } = useSWR<
|
||||||
HttpResponseOk<MerchantBackend.Instances.InstancesResponse>,
|
HttpResponseOk<MerchantBackend.Instances.InstancesResponse>,
|
||||||
HttpError<MerchantBackend.ErrorDetail>
|
RequestError<MerchantBackend.ErrorDetail>
|
||||||
>(["/management/instances"], request);
|
>(["/management/instances"], request);
|
||||||
|
|
||||||
if (isValidating) return { loading: true, data: data?.data };
|
if (isValidating) return { loading: true, data: data?.data };
|
||||||
if (data) return data;
|
if (data) return data;
|
||||||
if (error) return error;
|
if (error) return error.info;
|
||||||
return { loading: true };
|
return { loading: true };
|
||||||
}
|
}
|
||||||
|
@ -13,16 +13,16 @@
|
|||||||
You should have received a copy of the GNU General Public License along with
|
You should have received a copy of the GNU General Public License along with
|
||||||
GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
|
GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
|
||||||
*/
|
*/
|
||||||
|
import {
|
||||||
|
HttpResponse,
|
||||||
|
HttpResponseOk,
|
||||||
|
HttpResponsePaginated,
|
||||||
|
RequestError,
|
||||||
|
} 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 useSWR from "swr";
|
||||||
import { MerchantBackend } from "../declaration.js";
|
import { MerchantBackend } from "../declaration.js";
|
||||||
import { MAX_RESULT_SIZE, PAGE_SIZE } from "../utils/constants.js";
|
import { MAX_RESULT_SIZE, PAGE_SIZE } from "../utils/constants.js";
|
||||||
import {
|
|
||||||
HttpError,
|
|
||||||
HttpResponse,
|
|
||||||
HttpResponseOk,
|
|
||||||
HttpResponsePaginated,
|
|
||||||
} from "@gnu-taler/web-util/lib/index.browser";
|
|
||||||
import { useBackendInstanceRequest, useMatchMutate } from "./backend.js";
|
import { useBackendInstanceRequest, useMatchMutate } from "./backend.js";
|
||||||
|
|
||||||
export interface OrderAPI {
|
export interface OrderAPI {
|
||||||
@ -136,7 +136,7 @@ export function useOrderDetails(
|
|||||||
|
|
||||||
const { data, error, isValidating } = useSWR<
|
const { data, error, isValidating } = useSWR<
|
||||||
HttpResponseOk<MerchantBackend.Orders.MerchantOrderStatusResponse>,
|
HttpResponseOk<MerchantBackend.Orders.MerchantOrderStatusResponse>,
|
||||||
HttpError<MerchantBackend.ErrorDetail>
|
RequestError<MerchantBackend.ErrorDetail>
|
||||||
>([`/private/orders/${oderId}`], fetcher, {
|
>([`/private/orders/${oderId}`], fetcher, {
|
||||||
refreshInterval: 0,
|
refreshInterval: 0,
|
||||||
refreshWhenHidden: false,
|
refreshWhenHidden: false,
|
||||||
@ -147,7 +147,7 @@ export function useOrderDetails(
|
|||||||
|
|
||||||
if (isValidating) return { loading: true, data: data?.data };
|
if (isValidating) return { loading: true, data: data?.data };
|
||||||
if (data) return data;
|
if (data) return data;
|
||||||
if (error) return error;
|
if (error) return error.info;
|
||||||
return { loading: true };
|
return { loading: true };
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,7 +185,7 @@ export function useInstanceOrders(
|
|||||||
isValidating: loadingBefore,
|
isValidating: loadingBefore,
|
||||||
} = useSWR<
|
} = useSWR<
|
||||||
HttpResponseOk<MerchantBackend.Orders.OrderHistory>,
|
HttpResponseOk<MerchantBackend.Orders.OrderHistory>,
|
||||||
HttpError<MerchantBackend.ErrorDetail>
|
RequestError<MerchantBackend.ErrorDetail>
|
||||||
>(
|
>(
|
||||||
[
|
[
|
||||||
`/private/orders`,
|
`/private/orders`,
|
||||||
@ -203,7 +203,7 @@ export function useInstanceOrders(
|
|||||||
isValidating: loadingAfter,
|
isValidating: loadingAfter,
|
||||||
} = useSWR<
|
} = useSWR<
|
||||||
HttpResponseOk<MerchantBackend.Orders.OrderHistory>,
|
HttpResponseOk<MerchantBackend.Orders.OrderHistory>,
|
||||||
HttpError<MerchantBackend.ErrorDetail>
|
RequestError<MerchantBackend.ErrorDetail>
|
||||||
>(
|
>(
|
||||||
[
|
[
|
||||||
`/private/orders`,
|
`/private/orders`,
|
||||||
@ -234,8 +234,8 @@ export function useInstanceOrders(
|
|||||||
if (beforeData) setLastBefore(beforeData);
|
if (beforeData) setLastBefore(beforeData);
|
||||||
}, [afterData, beforeData]);
|
}, [afterData, beforeData]);
|
||||||
|
|
||||||
if (beforeError) return beforeError;
|
if (beforeError) return beforeError.info;
|
||||||
if (afterError) return afterError;
|
if (afterError) return afterError.info;
|
||||||
|
|
||||||
// if the query returns less that we ask, then we have reach the end or beginning
|
// if the query returns less that we ask, then we have reach the end or beginning
|
||||||
const isReachingEnd = afterData && afterData.data.orders.length < totalAfter;
|
const isReachingEnd = afterData && afterData.data.orders.length < totalAfter;
|
||||||
|
@ -13,13 +13,13 @@
|
|||||||
You should have received a copy of the GNU General Public License along with
|
You should have received a copy of the GNU General Public License along with
|
||||||
GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
|
GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
|
||||||
*/
|
*/
|
||||||
import useSWR, { useSWRConfig } from "swr";
|
|
||||||
import { MerchantBackend, WithId } from "../declaration.js";
|
|
||||||
import {
|
import {
|
||||||
HttpError,
|
|
||||||
HttpResponse,
|
HttpResponse,
|
||||||
HttpResponseOk,
|
HttpResponseOk,
|
||||||
|
RequestError,
|
||||||
} from "@gnu-taler/web-util/lib/index.browser";
|
} from "@gnu-taler/web-util/lib/index.browser";
|
||||||
|
import useSWR, { useSWRConfig } from "swr";
|
||||||
|
import { MerchantBackend, WithId } from "../declaration.js";
|
||||||
import { useBackendInstanceRequest, useMatchMutate } from "./backend.js";
|
import { useBackendInstanceRequest, useMatchMutate } from "./backend.js";
|
||||||
|
|
||||||
export interface ProductAPI {
|
export interface ProductAPI {
|
||||||
@ -96,7 +96,7 @@ export function useInstanceProducts(): HttpResponse<
|
|||||||
|
|
||||||
const { data: list, error: listError } = useSWR<
|
const { data: list, error: listError } = useSWR<
|
||||||
HttpResponseOk<MerchantBackend.Products.InventorySummaryResponse>,
|
HttpResponseOk<MerchantBackend.Products.InventorySummaryResponse>,
|
||||||
HttpError<MerchantBackend.ErrorDetail>
|
RequestError<MerchantBackend.ErrorDetail>
|
||||||
>([`/private/products`], fetcher, {
|
>([`/private/products`], fetcher, {
|
||||||
refreshInterval: 0,
|
refreshInterval: 0,
|
||||||
refreshWhenHidden: false,
|
refreshWhenHidden: false,
|
||||||
@ -110,7 +110,7 @@ export function useInstanceProducts(): HttpResponse<
|
|||||||
);
|
);
|
||||||
const { data: products, error: productError } = useSWR<
|
const { data: products, error: productError } = useSWR<
|
||||||
HttpResponseOk<MerchantBackend.Products.ProductDetail>[],
|
HttpResponseOk<MerchantBackend.Products.ProductDetail>[],
|
||||||
HttpError<MerchantBackend.ErrorDetail>
|
RequestError<MerchantBackend.ErrorDetail>
|
||||||
>([paths], multiFetcher, {
|
>([paths], multiFetcher, {
|
||||||
refreshInterval: 0,
|
refreshInterval: 0,
|
||||||
refreshWhenHidden: false,
|
refreshWhenHidden: false,
|
||||||
@ -119,8 +119,8 @@ export function useInstanceProducts(): HttpResponse<
|
|||||||
refreshWhenOffline: false,
|
refreshWhenOffline: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (listError) return listError;
|
if (listError) return listError.info;
|
||||||
if (productError) return productError;
|
if (productError) return productError.info;
|
||||||
|
|
||||||
if (products) {
|
if (products) {
|
||||||
const dataWithId = products.map((d) => {
|
const dataWithId = products.map((d) => {
|
||||||
@ -145,7 +145,7 @@ export function useProductDetails(
|
|||||||
|
|
||||||
const { data, error, isValidating } = useSWR<
|
const { data, error, isValidating } = useSWR<
|
||||||
HttpResponseOk<MerchantBackend.Products.ProductDetail>,
|
HttpResponseOk<MerchantBackend.Products.ProductDetail>,
|
||||||
HttpError<MerchantBackend.ErrorDetail>
|
RequestError<MerchantBackend.ErrorDetail>
|
||||||
>([`/private/products/${productId}`], fetcher, {
|
>([`/private/products/${productId}`], fetcher, {
|
||||||
refreshInterval: 0,
|
refreshInterval: 0,
|
||||||
refreshWhenHidden: false,
|
refreshWhenHidden: false,
|
||||||
@ -156,6 +156,6 @@ export function useProductDetails(
|
|||||||
|
|
||||||
if (isValidating) return { loading: true, data: data?.data };
|
if (isValidating) return { loading: true, data: data?.data };
|
||||||
if (data) return data;
|
if (data) return data;
|
||||||
if (error) return error;
|
if (error) return error.info;
|
||||||
return { loading: true };
|
return { loading: true };
|
||||||
}
|
}
|
||||||
|
@ -13,13 +13,13 @@
|
|||||||
You should have received a copy of the GNU General Public License along with
|
You should have received a copy of the GNU General Public License along with
|
||||||
GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
|
GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
|
||||||
*/
|
*/
|
||||||
import useSWR, { useSWRConfig } from "swr";
|
|
||||||
import { MerchantBackend } from "../declaration.js";
|
|
||||||
import {
|
import {
|
||||||
HttpError,
|
|
||||||
HttpResponse,
|
HttpResponse,
|
||||||
HttpResponseOk,
|
HttpResponseOk,
|
||||||
|
RequestError,
|
||||||
} from "@gnu-taler/web-util/lib/index.browser";
|
} from "@gnu-taler/web-util/lib/index.browser";
|
||||||
|
import useSWR, { useSWRConfig } from "swr";
|
||||||
|
import { MerchantBackend } from "../declaration.js";
|
||||||
import { useBackendInstanceRequest, useMatchMutate } from "./backend.js";
|
import { useBackendInstanceRequest, useMatchMutate } from "./backend.js";
|
||||||
|
|
||||||
export function useReservesAPI(): ReserveMutateAPI {
|
export function useReservesAPI(): ReserveMutateAPI {
|
||||||
@ -121,12 +121,12 @@ export function useInstanceReserves(): HttpResponse<
|
|||||||
|
|
||||||
const { data, error, isValidating } = useSWR<
|
const { data, error, isValidating } = useSWR<
|
||||||
HttpResponseOk<MerchantBackend.Tips.TippingReserveStatus>,
|
HttpResponseOk<MerchantBackend.Tips.TippingReserveStatus>,
|
||||||
HttpError<MerchantBackend.ErrorDetail>
|
RequestError<MerchantBackend.ErrorDetail>
|
||||||
>([`/private/reserves`], fetcher);
|
>([`/private/reserves`], fetcher);
|
||||||
|
|
||||||
if (isValidating) return { loading: true, data: data?.data };
|
if (isValidating) return { loading: true, data: data?.data };
|
||||||
if (data) return data;
|
if (data) return data;
|
||||||
if (error) return error;
|
if (error) return error.info;
|
||||||
return { loading: true };
|
return { loading: true };
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,7 +140,7 @@ export function useReserveDetails(
|
|||||||
|
|
||||||
const { data, error, isValidating } = useSWR<
|
const { data, error, isValidating } = useSWR<
|
||||||
HttpResponseOk<MerchantBackend.Tips.ReserveDetail>,
|
HttpResponseOk<MerchantBackend.Tips.ReserveDetail>,
|
||||||
HttpError<MerchantBackend.ErrorDetail>
|
RequestError<MerchantBackend.ErrorDetail>
|
||||||
>([`/private/reserves/${reserveId}`], reserveDetailFetcher, {
|
>([`/private/reserves/${reserveId}`], reserveDetailFetcher, {
|
||||||
refreshInterval: 0,
|
refreshInterval: 0,
|
||||||
refreshWhenHidden: false,
|
refreshWhenHidden: false,
|
||||||
@ -151,7 +151,7 @@ export function useReserveDetails(
|
|||||||
|
|
||||||
if (isValidating) return { loading: true, data: data?.data };
|
if (isValidating) return { loading: true, data: data?.data };
|
||||||
if (data) return data;
|
if (data) return data;
|
||||||
if (error) return error;
|
if (error) return error.info;
|
||||||
return { loading: true };
|
return { loading: true };
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,7 +162,7 @@ export function useTipDetails(
|
|||||||
|
|
||||||
const { data, error, isValidating } = useSWR<
|
const { data, error, isValidating } = useSWR<
|
||||||
HttpResponseOk<MerchantBackend.Tips.TipDetails>,
|
HttpResponseOk<MerchantBackend.Tips.TipDetails>,
|
||||||
HttpError<MerchantBackend.ErrorDetail>
|
RequestError<MerchantBackend.ErrorDetail>
|
||||||
>([`/private/tips/${tipId}`], tipsDetailFetcher, {
|
>([`/private/tips/${tipId}`], tipsDetailFetcher, {
|
||||||
refreshInterval: 0,
|
refreshInterval: 0,
|
||||||
refreshWhenHidden: false,
|
refreshWhenHidden: false,
|
||||||
@ -173,6 +173,6 @@ export function useTipDetails(
|
|||||||
|
|
||||||
if (isValidating) return { loading: true, data: data?.data };
|
if (isValidating) return { loading: true, data: data?.data };
|
||||||
if (data) return data;
|
if (data) return data;
|
||||||
if (error) return error;
|
if (error) return error.info;
|
||||||
return { loading: true };
|
return { loading: true };
|
||||||
}
|
}
|
||||||
|
@ -13,17 +13,17 @@
|
|||||||
You should have received a copy of the GNU General Public License along with
|
You should have received a copy of the GNU General Public License along with
|
||||||
GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
|
GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
|
||||||
*/
|
*/
|
||||||
import { MerchantBackend } from "../declaration.js";
|
|
||||||
import { useMatchMutate, useBackendInstanceRequest } from "./backend.js";
|
|
||||||
import useSWR from "swr";
|
|
||||||
import { MAX_RESULT_SIZE, PAGE_SIZE } from "../utils/constants.js";
|
|
||||||
import { useEffect, useState } from "preact/hooks";
|
|
||||||
import {
|
import {
|
||||||
HttpError,
|
|
||||||
HttpResponse,
|
HttpResponse,
|
||||||
HttpResponseOk,
|
HttpResponseOk,
|
||||||
HttpResponsePaginated,
|
HttpResponsePaginated,
|
||||||
|
RequestError,
|
||||||
} from "@gnu-taler/web-util/lib/index.browser";
|
} from "@gnu-taler/web-util/lib/index.browser";
|
||||||
|
import { useEffect, useState } from "preact/hooks";
|
||||||
|
import useSWR from "swr";
|
||||||
|
import { MerchantBackend } from "../declaration.js";
|
||||||
|
import { MAX_RESULT_SIZE, PAGE_SIZE } from "../utils/constants.js";
|
||||||
|
import { useBackendInstanceRequest, useMatchMutate } from "./backend.js";
|
||||||
|
|
||||||
export function useTemplateAPI(): TemplateAPI {
|
export function useTemplateAPI(): TemplateAPI {
|
||||||
const mutateAll = useMatchMutate();
|
const mutateAll = useMatchMutate();
|
||||||
@ -148,7 +148,7 @@ export function useInstanceTemplates(
|
|||||||
isValidating: loadingAfter,
|
isValidating: loadingAfter,
|
||||||
} = useSWR<
|
} = useSWR<
|
||||||
HttpResponseOk<MerchantBackend.Template.TemplateSummaryResponse>,
|
HttpResponseOk<MerchantBackend.Template.TemplateSummaryResponse>,
|
||||||
HttpError<MerchantBackend.ErrorDetail>
|
RequestError<MerchantBackend.ErrorDetail>
|
||||||
>([`/private/templates`, args?.position, -totalAfter], templateFetcher);
|
>([`/private/templates`, args?.position, -totalAfter], templateFetcher);
|
||||||
|
|
||||||
//this will save last result
|
//this will save last result
|
||||||
@ -167,7 +167,7 @@ export function useInstanceTemplates(
|
|||||||
}, [afterData /*, beforeData*/]);
|
}, [afterData /*, beforeData*/]);
|
||||||
|
|
||||||
// if (beforeError) return beforeError;
|
// if (beforeError) return beforeError;
|
||||||
if (afterError) return afterError;
|
if (afterError) return afterError.info;
|
||||||
|
|
||||||
// if the query returns less that we ask, then we have reach the end or beginning
|
// if the query returns less that we ask, then we have reach the end or beginning
|
||||||
const isReachingEnd =
|
const isReachingEnd =
|
||||||
@ -231,7 +231,7 @@ export function useTemplateDetails(
|
|||||||
|
|
||||||
const { data, error, isValidating } = useSWR<
|
const { data, error, isValidating } = useSWR<
|
||||||
HttpResponseOk<MerchantBackend.Template.TemplateDetails>,
|
HttpResponseOk<MerchantBackend.Template.TemplateDetails>,
|
||||||
HttpError<MerchantBackend.ErrorDetail>
|
RequestError<MerchantBackend.ErrorDetail>
|
||||||
>([`/private/templates/${templateId}`], templateFetcher, {
|
>([`/private/templates/${templateId}`], templateFetcher, {
|
||||||
refreshInterval: 0,
|
refreshInterval: 0,
|
||||||
refreshWhenHidden: false,
|
refreshWhenHidden: false,
|
||||||
@ -242,6 +242,6 @@ export function useTemplateDetails(
|
|||||||
|
|
||||||
if (isValidating) return { loading: true, data: data?.data };
|
if (isValidating) return { loading: true, data: data?.data };
|
||||||
if (data) return data;
|
if (data) return data;
|
||||||
if (error) return error;
|
if (error) return error.info;
|
||||||
return { loading: true };
|
return { loading: true };
|
||||||
}
|
}
|
||||||
|
@ -13,16 +13,16 @@
|
|||||||
You should have received a copy of the GNU General Public License along with
|
You should have received a copy of the GNU General Public License along with
|
||||||
GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
|
GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
|
||||||
*/
|
*/
|
||||||
|
import {
|
||||||
|
HttpResponse,
|
||||||
|
HttpResponseOk,
|
||||||
|
HttpResponsePaginated,
|
||||||
|
RequestError,
|
||||||
|
} 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 useSWR from "swr";
|
||||||
import { MerchantBackend } from "../declaration.js";
|
import { MerchantBackend } from "../declaration.js";
|
||||||
import { MAX_RESULT_SIZE, PAGE_SIZE } from "../utils/constants.js";
|
import { MAX_RESULT_SIZE, PAGE_SIZE } from "../utils/constants.js";
|
||||||
import {
|
|
||||||
HttpError,
|
|
||||||
HttpResponse,
|
|
||||||
HttpResponseOk,
|
|
||||||
HttpResponsePaginated,
|
|
||||||
} from "@gnu-taler/web-util/lib/index.browser";
|
|
||||||
import { useBackendInstanceRequest, useMatchMutate } from "./backend.js";
|
import { useBackendInstanceRequest, useMatchMutate } from "./backend.js";
|
||||||
|
|
||||||
export function useTransferAPI(): TransferAPI {
|
export function useTransferAPI(): TransferAPI {
|
||||||
@ -91,7 +91,7 @@ export function useInstanceTransfers(
|
|||||||
isValidating: loadingBefore,
|
isValidating: loadingBefore,
|
||||||
} = useSWR<
|
} = useSWR<
|
||||||
HttpResponseOk<MerchantBackend.Transfers.TransferList>,
|
HttpResponseOk<MerchantBackend.Transfers.TransferList>,
|
||||||
HttpError<MerchantBackend.ErrorDetail>
|
RequestError<MerchantBackend.ErrorDetail>
|
||||||
>(
|
>(
|
||||||
[
|
[
|
||||||
`/private/transfers`,
|
`/private/transfers`,
|
||||||
@ -108,7 +108,7 @@ export function useInstanceTransfers(
|
|||||||
isValidating: loadingAfter,
|
isValidating: loadingAfter,
|
||||||
} = useSWR<
|
} = useSWR<
|
||||||
HttpResponseOk<MerchantBackend.Transfers.TransferList>,
|
HttpResponseOk<MerchantBackend.Transfers.TransferList>,
|
||||||
HttpError<MerchantBackend.ErrorDetail>
|
RequestError<MerchantBackend.ErrorDetail>
|
||||||
>(
|
>(
|
||||||
[
|
[
|
||||||
`/private/transfers`,
|
`/private/transfers`,
|
||||||
@ -138,8 +138,8 @@ export function useInstanceTransfers(
|
|||||||
if (beforeData) setLastBefore(beforeData);
|
if (beforeData) setLastBefore(beforeData);
|
||||||
}, [afterData, beforeData]);
|
}, [afterData, beforeData]);
|
||||||
|
|
||||||
if (beforeError) return beforeError;
|
if (beforeError) return beforeError.info;
|
||||||
if (afterError) return afterError;
|
if (afterError) return afterError.info;
|
||||||
|
|
||||||
// if the query returns less that we ask, then we have reach the end or beginning
|
// if the query returns less that we ask, then we have reach the end or beginning
|
||||||
const isReachingEnd =
|
const isReachingEnd =
|
||||||
|
@ -13,17 +13,17 @@
|
|||||||
You should have received a copy of the GNU General Public License along with
|
You should have received a copy of the GNU General Public License along with
|
||||||
GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
|
GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
|
||||||
*/
|
*/
|
||||||
import { MerchantBackend } from "../declaration.js";
|
|
||||||
import { useMatchMutate, useBackendInstanceRequest } from "./backend.js";
|
|
||||||
import useSWR from "swr";
|
|
||||||
import { MAX_RESULT_SIZE, PAGE_SIZE } from "../utils/constants.js";
|
|
||||||
import { useEffect, useState } from "preact/hooks";
|
|
||||||
import {
|
import {
|
||||||
HttpError,
|
|
||||||
HttpResponse,
|
HttpResponse,
|
||||||
HttpResponseOk,
|
HttpResponseOk,
|
||||||
HttpResponsePaginated,
|
HttpResponsePaginated,
|
||||||
|
RequestError,
|
||||||
} from "@gnu-taler/web-util/lib/index.browser";
|
} from "@gnu-taler/web-util/lib/index.browser";
|
||||||
|
import { useEffect, useState } from "preact/hooks";
|
||||||
|
import useSWR from "swr";
|
||||||
|
import { MerchantBackend } from "../declaration.js";
|
||||||
|
import { MAX_RESULT_SIZE, PAGE_SIZE } from "../utils/constants.js";
|
||||||
|
import { useBackendInstanceRequest, useMatchMutate } from "./backend.js";
|
||||||
|
|
||||||
export function useWebhookAPI(): WebhookAPI {
|
export function useWebhookAPI(): WebhookAPI {
|
||||||
const mutateAll = useMatchMutate();
|
const mutateAll = useMatchMutate();
|
||||||
@ -100,7 +100,7 @@ export function useInstanceWebhooks(
|
|||||||
isValidating: loadingAfter,
|
isValidating: loadingAfter,
|
||||||
} = useSWR<
|
} = useSWR<
|
||||||
HttpResponseOk<MerchantBackend.Webhooks.WebhookSummaryResponse>,
|
HttpResponseOk<MerchantBackend.Webhooks.WebhookSummaryResponse>,
|
||||||
HttpError<MerchantBackend.ErrorDetail>
|
RequestError<MerchantBackend.ErrorDetail>
|
||||||
>([`/private/webhooks`, args?.position, -totalAfter], webhookFetcher);
|
>([`/private/webhooks`, args?.position, -totalAfter], webhookFetcher);
|
||||||
|
|
||||||
const [lastAfter, setLastAfter] = useState<
|
const [lastAfter, setLastAfter] = useState<
|
||||||
@ -113,7 +113,7 @@ export function useInstanceWebhooks(
|
|||||||
if (afterData) setLastAfter(afterData);
|
if (afterData) setLastAfter(afterData);
|
||||||
}, [afterData]);
|
}, [afterData]);
|
||||||
|
|
||||||
if (afterError) return afterError;
|
if (afterError) return afterError.info;
|
||||||
|
|
||||||
const isReachingEnd =
|
const isReachingEnd =
|
||||||
afterData && afterData.data.webhooks.length < totalAfter;
|
afterData && afterData.data.webhooks.length < totalAfter;
|
||||||
@ -157,7 +157,7 @@ export function useWebhookDetails(
|
|||||||
|
|
||||||
const { data, error, isValidating } = useSWR<
|
const { data, error, isValidating } = useSWR<
|
||||||
HttpResponseOk<MerchantBackend.Webhooks.WebhookDetails>,
|
HttpResponseOk<MerchantBackend.Webhooks.WebhookDetails>,
|
||||||
HttpError<MerchantBackend.ErrorDetail>
|
RequestError<MerchantBackend.ErrorDetail>
|
||||||
>([`/private/webhooks/${webhookId}`], webhookFetcher, {
|
>([`/private/webhooks/${webhookId}`], webhookFetcher, {
|
||||||
refreshInterval: 0,
|
refreshInterval: 0,
|
||||||
refreshWhenHidden: false,
|
refreshWhenHidden: false,
|
||||||
@ -168,6 +168,6 @@ export function useWebhookDetails(
|
|||||||
|
|
||||||
if (isValidating) return { loading: true, data: data?.data };
|
if (isValidating) return { loading: true, data: data?.data };
|
||||||
if (data) return data;
|
if (data) return data;
|
||||||
if (error) return error;
|
if (error) return error.info;
|
||||||
return { loading: true };
|
return { loading: true };
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user