aboutsummaryrefslogtreecommitdiff
path: root/packages/merchant-backoffice-ui/src/hooks
diff options
context:
space:
mode:
Diffstat (limited to 'packages/merchant-backoffice-ui/src/hooks')
-rw-r--r--packages/merchant-backoffice-ui/src/hooks/backend.ts6
-rw-r--r--packages/merchant-backoffice-ui/src/hooks/bank.ts120
-rw-r--r--packages/merchant-backoffice-ui/src/hooks/merchant.ts211
-rw-r--r--packages/merchant-backoffice-ui/src/hooks/order.test.ts37
-rw-r--r--packages/merchant-backoffice-ui/src/hooks/order.ts190
-rw-r--r--packages/merchant-backoffice-ui/src/hooks/otp.ts126
-rw-r--r--packages/merchant-backoffice-ui/src/hooks/product.test.ts22
-rw-r--r--packages/merchant-backoffice-ui/src/hooks/product.ts156
-rw-r--r--packages/merchant-backoffice-ui/src/hooks/templates.ts160
-rw-r--r--packages/merchant-backoffice-ui/src/hooks/transfer.test.ts7
-rw-r--r--packages/merchant-backoffice-ui/src/hooks/transfer.ts64
-rw-r--r--packages/merchant-backoffice-ui/src/hooks/webhooks.ts105
12 files changed, 495 insertions, 709 deletions
diff --git a/packages/merchant-backoffice-ui/src/hooks/backend.ts b/packages/merchant-backoffice-ui/src/hooks/backend.ts
index e4e50c8ad..8c54f70db 100644
--- a/packages/merchant-backoffice-ui/src/hooks/backend.ts
+++ b/packages/merchant-backoffice-ui/src/hooks/backend.ts
@@ -24,8 +24,6 @@ import {
TalerMerchantApi
} from "@gnu-taler/taler-util";
import {
- EmptyObject,
- HttpError,
HttpResponse,
HttpResponseOk,
RequestError,
@@ -186,7 +184,7 @@ type YesOrNo = "yes" | "no";
export function useBackendBaseRequest(): useBackendBaseRequestType {
const { request: requestHandler } = useApiContext();
const { state } = useSessionContext();
- const token = state.status === "loggedIn" ? state.token : undefined;
+ const token = state.token;
const baseUrl = state.backendUrl;
const request = useCallback(
@@ -212,7 +210,7 @@ export function useBackendInstanceRequest(): useBackendInstanceRequestType {
const { request: requestHandler } = useApiContext();
const { state } = useSessionContext();
- const token = state.status === "loggedIn" ? state.token : undefined;
+ const token = state.token;
const baseUrl = state.backendUrl;
const request = useCallback(
diff --git a/packages/merchant-backoffice-ui/src/hooks/bank.ts b/packages/merchant-backoffice-ui/src/hooks/bank.ts
index 3cf9c7846..9ad4c3069 100644
--- a/packages/merchant-backoffice-ui/src/hooks/bank.ts
+++ b/packages/merchant-backoffice-ui/src/hooks/bank.ts
@@ -41,67 +41,67 @@ const useSWR = _useSWR as unknown as SWRHook;
// },
// }
-export function useBankAccountAPI(): BankAccountAPI {
- const mutateAll = useMatchMutate();
- const { request } = useBackendInstanceRequest();
-
- const createBankAccount = async (
- data: TalerMerchantApi.AccountAddDetails,
- ): Promise<HttpResponseOk<void>> => {
- // MOCKED_ACCOUNTS[data.h_wire] = data
- // return Promise.resolve({ ok: true, data: undefined });
- const res = await request<void>(`/private/accounts`, {
- method: "POST",
- data,
- });
- await mutateAll(/.*private\/accounts.*/);
- return res;
- };
-
- const updateBankAccount = async (
- h_wire: string,
- data: TalerMerchantApi.AccountPatchDetails,
- ): Promise<HttpResponseOk<void>> => {
- // MOCKED_ACCOUNTS[h_wire].credit_facade_credentials = data.credit_facade_credentials
- // MOCKED_ACCOUNTS[h_wire].credit_facade_url = data.credit_facade_url
- // return Promise.resolve({ ok: true, data: undefined });
- const res = await request<void>(`/private/accounts/${h_wire}`, {
- method: "PATCH",
- data,
- });
- await mutateAll(/.*private\/accounts.*/);
- return res;
- };
-
- const deleteBankAccount = async (
- h_wire: string,
- ): Promise<HttpResponseOk<void>> => {
- // delete MOCKED_ACCOUNTS[h_wire]
- // return Promise.resolve({ ok: true, data: undefined });
- const res = await request<void>(`/private/accounts/${h_wire}`, {
- method: "DELETE",
- });
- await mutateAll(/.*private\/accounts.*/);
- return res;
- };
-
- return {
- createBankAccount,
- updateBankAccount,
- deleteBankAccount,
- };
-}
+// export function useBankAccountAPI(): BankAccountAPI {
+// const mutateAll = useMatchMutate();
+// const { request } = useBackendInstanceRequest();
+
+// const createBankAccount = async (
+// data: TalerMerchantApi.AccountAddDetails,
+// ): Promise<HttpResponseOk<void>> => {
+// // MOCKED_ACCOUNTS[data.h_wire] = data
+// // return Promise.resolve({ ok: true, data: undefined });
+// const res = await request<void>(`/private/accounts`, {
+// method: "POST",
+// data,
+// });
+// await mutateAll(/.*private\/accounts.*/);
+// return res;
+// };
+
+// const updateBankAccount = async (
+// h_wire: string,
+// data: TalerMerchantApi.AccountPatchDetails,
+// ): Promise<HttpResponseOk<void>> => {
+// // MOCKED_ACCOUNTS[h_wire].credit_facade_credentials = data.credit_facade_credentials
+// // MOCKED_ACCOUNTS[h_wire].credit_facade_url = data.credit_facade_url
+// // return Promise.resolve({ ok: true, data: undefined });
+// const res = await request<void>(`/private/accounts/${h_wire}`, {
+// method: "PATCH",
+// data,
+// });
+// await mutateAll(/.*private\/accounts.*/);
+// return res;
+// };
+
+// const deleteBankAccount = async (
+// h_wire: string,
+// ): Promise<HttpResponseOk<void>> => {
+// // delete MOCKED_ACCOUNTS[h_wire]
+// // return Promise.resolve({ ok: true, data: undefined });
+// const res = await request<void>(`/private/accounts/${h_wire}`, {
+// method: "DELETE",
+// });
+// await mutateAll(/.*private\/accounts.*/);
+// return res;
+// };
+
+// return {
+// createBankAccount,
+// updateBankAccount,
+// deleteBankAccount,
+// };
+// }
-export interface BankAccountAPI {
- createBankAccount: (
- data: TalerMerchantApi.AccountAddDetails,
- ) => Promise<HttpResponseOk<void>>;
- updateBankAccount: (
- id: string,
- data: TalerMerchantApi.AccountPatchDetails,
- ) => Promise<HttpResponseOk<void>>;
- deleteBankAccount: (id: string) => Promise<HttpResponseOk<void>>;
-}
+// export interface BankAccountAPI {
+// createBankAccount: (
+// data: TalerMerchantApi.AccountAddDetails,
+// ) => Promise<HttpResponseOk<void>>;
+// updateBankAccount: (
+// id: string,
+// data: TalerMerchantApi.AccountPatchDetails,
+// ) => Promise<HttpResponseOk<void>>;
+// deleteBankAccount: (id: string) => Promise<HttpResponseOk<void>>;
+// }
export interface InstanceBankAccountFilter {
}
diff --git a/packages/merchant-backoffice-ui/src/hooks/merchant.ts b/packages/merchant-backoffice-ui/src/hooks/merchant.ts
deleted file mode 100644
index 47d9e5624..000000000
--- a/packages/merchant-backoffice-ui/src/hooks/merchant.ts
+++ /dev/null
@@ -1,211 +0,0 @@
-/*
- This file is part of GNU Taler
- (C) 2021-2024 Taler Systems S.A.
-
- GNU Taler is free software; you can redistribute it and/or modify it under the
- terms of the GNU General Public License as published by the Free Software
- Foundation; either version 3, or (at your option) any later version.
-
- GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- A PARTICULAR PURPOSE. See the GNU General Public License for more details.
-
- 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/>
- */
-import {
- HttpResponse,
- HttpResponseOk,
- HttpResponsePaginated,
- RequestError,
-} from "@gnu-taler/web-util/browser";
-import { useEffect, useState } from "preact/hooks";
-import { MAX_RESULT_SIZE, PAGE_SIZE } from "../utils/constants.js";
-import { useBackendInstanceRequest, useMatchMutate } from "./backend.js";
-
-// FIX default import https://github.com/microsoft/TypeScript/issues/49189
-import { TalerErrorDetail, TalerMerchantApi } from "@gnu-taler/taler-util";
-import _useSWR, { SWRHook, mutate } from "swr";
-const useSWR = _useSWR as unknown as SWRHook;
-
-// const MOCKED_ACCOUNTS: Record<string, TalerMerchantApi.AccountAddDetails> = {
-// "hwire1": {
-// h_wire: "hwire1",
-// payto_uri: "payto://fake/iban/123",
-// salt: "qwe",
-// },
-// "hwire2": {
-// h_wire: "hwire2",
-// payto_uri: "payto://fake/iban/123",
-// salt: "qwe2",
-// },
-// }
-
-export function useBankAccountAPI(): BankAccountAPI {
- const mutateAll = useMatchMutate();
- const { request } = useBackendInstanceRequest();
-
- const createBankAccount = async (
- data: TalerMerchantApi.AccountAddDetails,
- ): Promise<HttpResponseOk<void>> => {
- // MOCKED_ACCOUNTS[data.h_wire] = data
- // return Promise.resolve({ ok: true, data: undefined });
- const res = await request<void>(`/private/accounts`, {
- method: "POST",
- data,
- });
- await mutateAll(/.*private\/accounts.*/);
- return res;
- };
-
- const updateBankAccount = async (
- h_wire: string,
- data: TalerMerchantApi.AccountPatchDetails,
- ): Promise<HttpResponseOk<void>> => {
- // MOCKED_ACCOUNTS[h_wire].credit_facade_credentials = data.credit_facade_credentials
- // MOCKED_ACCOUNTS[h_wire].credit_facade_url = data.credit_facade_url
- // return Promise.resolve({ ok: true, data: undefined });
- const res = await request<void>(`/private/accounts/${h_wire}`, {
- method: "PATCH",
- data,
- });
- await mutateAll(/.*private\/accounts.*/);
- return res;
- };
-
- const deleteBankAccount = async (
- h_wire: string,
- ): Promise<HttpResponseOk<void>> => {
- // delete MOCKED_ACCOUNTS[h_wire]
- // return Promise.resolve({ ok: true, data: undefined });
- const res = await request<void>(`/private/accounts/${h_wire}`, {
- method: "DELETE",
- });
- await mutateAll(/.*private\/accounts.*/);
- return res;
- };
-
- return {
- createBankAccount,
- updateBankAccount,
- deleteBankAccount,
- };
-}
-
-export interface BankAccountAPI {
- createBankAccount: (
- data: TalerMerchantApi.AccountAddDetails,
- ) => Promise<HttpResponseOk<void>>;
- updateBankAccount: (
- id: string,
- data: TalerMerchantApi.AccountPatchDetails,
- ) => Promise<HttpResponseOk<void>>;
- deleteBankAccount: (id: string) => Promise<HttpResponseOk<void>>;
-}
-
-export interface InstanceBankAccountFilter {
-}
-
-export function revalidateInstanceBankAccounts() {
- // mutate(key => key instanceof)
- return mutate((key) => Array.isArray(key) && key[key.length - 1] === "/private/accounts", undefined, { revalidate: true });
-}
-export function useInstanceBankAccounts(
- args?: InstanceBankAccountFilter,
- updatePosition?: (id: string) => void,
-): HttpResponsePaginated<
- TalerMerchantApi.AccountsSummaryResponse,
- TalerErrorDetail
-> {
-
- const { fetcher } = useBackendInstanceRequest();
-
- const [pageAfter, setPageAfter] = useState(1);
-
- const totalAfter = pageAfter * PAGE_SIZE;
- const {
- data: afterData,
- error: afterError,
- isValidating: loadingAfter,
- } = useSWR<
- HttpResponseOk<TalerMerchantApi.AccountsSummaryResponse>,
- RequestError<TalerErrorDetail>
- >([`/private/accounts`], fetcher);
-
- const [lastAfter, setLastAfter] = useState<
- HttpResponse<
- TalerMerchantApi.AccountsSummaryResponse,
- TalerErrorDetail
- >
- >({ loading: true });
- useEffect(() => {
- if (afterData) setLastAfter(afterData);
- }, [afterData /*, beforeData*/]);
-
- if (afterError) return afterError.cause;
-
- // if the query returns less that we ask, then we have reach the end or beginning
- const isReachingEnd =
- afterData && afterData.data.accounts.length < totalAfter;
- const isReachingStart = false;
-
- const pagination = {
- isReachingEnd,
- isReachingStart,
- loadMore: () => {
- if (!afterData || isReachingEnd) return;
- if (afterData.data.accounts.length < MAX_RESULT_SIZE) {
- setPageAfter(pageAfter + 1);
- } else {
- const from = `${afterData.data.accounts[afterData.data.accounts.length - 1]
- .h_wire
- }`;
- if (from && updatePosition) updatePosition(from);
- }
- },
- loadMorePrev: () => {
- },
- };
-
- const accounts = !afterData ? [] : (afterData || lastAfter).data.accounts;
- if (loadingAfter /* || loadingBefore */)
- return { loading: true, data: { accounts } };
- if (/*beforeData &&*/ afterData) {
- return { ok: true, data: { accounts }, ...pagination };
- }
- return { loading: true };
-}
-
-export function useBankAccountDetails(
- h_wire: string,
-): HttpResponse<
- TalerMerchantApi.BankAccountEntry,
- TalerErrorDetail
-> {
- // return {
- // ok: true,
- // data: {
- // ...MOCKED_ACCOUNTS[h_wire],
- // active: true,
- // }
- // }
- const { fetcher } = useBackendInstanceRequest();
-
- const { data, error, isValidating } = useSWR<
- HttpResponseOk<TalerMerchantApi.BankAccountEntry>,
- RequestError<TalerErrorDetail>
- >([`/private/accounts/${h_wire}`], fetcher, {
- refreshInterval: 0,
- refreshWhenHidden: false,
- revalidateOnFocus: false,
- revalidateOnReconnect: false,
- refreshWhenOffline: false,
- });
-
- if (isValidating) return { loading: true, data: data?.data };
- if (data) {
- return data;
- }
- if (error) return error.cause;
- return { loading: true };
-}
diff --git a/packages/merchant-backoffice-ui/src/hooks/order.test.ts b/packages/merchant-backoffice-ui/src/hooks/order.test.ts
index 0d4199875..3d4f2809f 100644
--- a/packages/merchant-backoffice-ui/src/hooks/order.test.ts
+++ b/packages/merchant-backoffice-ui/src/hooks/order.test.ts
@@ -22,7 +22,7 @@
import { AmountString, TalerMerchantApi } from "@gnu-taler/taler-util";
import * as tests from "@gnu-taler/web-util/testing";
import { expect } from "chai";
-import { useInstanceOrders, useOrderAPI, useOrderDetails } from "./order.js";
+import { useInstanceOrders, useOrderDetails } from "./order.js";
import { ApiMockEnvironment } from "./testing.js";
import {
API_CREATE_ORDER,
@@ -32,6 +32,7 @@ import {
API_LIST_ORDERS,
API_REFUND_ORDER_BY_ID,
} from "./urls.js";
+import { useMerchantApiContext } from "@gnu-taler/web-util/browser";
describe("order api interaction with listing", () => {
it("should evict cache when creating an order", async () => {
@@ -51,7 +52,7 @@ describe("order api interaction with listing", () => {
const hookBehavior = await tests.hookBehaveLikeThis(
() => {
const query = useInstanceOrders({ paid: "yes" }, newDate);
- const api = useOrderAPI();
+ const { lib: api } = useMerchantApiContext()
return { query, api };
},
{},
@@ -85,9 +86,9 @@ describe("order api interaction with listing", () => {
},
});
- api.createOrder({
- order: { amount: "ARS:12", summary: "pay me" },
- } as any);
+ api.management.createOrder(undefined, {
+ order: { amount: "ARS:12" as AmountString, summary: "pay me" },
+ })
},
({ query, api }) => {
expect(env.assertJustExpectedRequestWereMade()).deep.eq({
@@ -129,7 +130,7 @@ describe("order api interaction with listing", () => {
const hookBehavior = await tests.hookBehaveLikeThis(
() => {
const query = useInstanceOrders({ paid: "yes" }, newDate);
- const api = useOrderAPI();
+ const { lib: api } = useMerchantApiContext()
return { query, api };
},
{},
@@ -170,10 +171,10 @@ describe("order api interaction with listing", () => {
},
});
- api.refundOrder("1", {
+ api.management.addRefund(undefined, "1", {
reason: "double pay",
refund: "EUR:1" as AmountString,
- });
+ })
},
({ query, api }) => {
expect(env.assertJustExpectedRequestWereMade()).deep.eq({
@@ -218,7 +219,7 @@ describe("order api interaction with listing", () => {
const hookBehavior = await tests.hookBehaveLikeThis(
() => {
const query = useInstanceOrders({ paid: "yes" }, newDate);
- const api = useOrderAPI();
+ const { lib: api } = useMerchantApiContext()
return { query, api };
},
{},
@@ -246,7 +247,7 @@ describe("order api interaction with listing", () => {
},
});
- api.deleteOrder("1");
+ api.management.deleteOrder(undefined, "1")
},
({ query, api }) => {
expect(env.assertJustExpectedRequestWereMade()).deep.eq({
@@ -286,7 +287,7 @@ describe("order api interaction with details", () => {
const hookBehavior = await tests.hookBehaveLikeThis(
() => {
const query = useOrderDetails("1");
- const api = useOrderAPI();
+ const { lib: api } = useMerchantApiContext()
return { query, api };
},
{},
@@ -319,10 +320,10 @@ describe("order api interaction with details", () => {
} as unknown as TalerMerchantApi.CheckPaymentPaidResponse,
});
- api.refundOrder("1", {
+ api.management.addRefund(undefined, "1", {
reason: "double pay",
refund: "EUR:1" as AmountString,
- });
+ })
},
({ query, api }) => {
expect(env.assertJustExpectedRequestWereMade()).deep.eq({
@@ -362,7 +363,7 @@ describe("order api interaction with details", () => {
const hookBehavior = await tests.hookBehaveLikeThis(
() => {
const query = useOrderDetails("1");
- const api = useOrderAPI();
+ const { lib: api } = useMerchantApiContext()
return { query, api };
},
{},
@@ -393,9 +394,9 @@ describe("order api interaction with details", () => {
} as unknown as TalerMerchantApi.CheckPaymentPaidResponse,
});
- api.forgetOrder("1", {
+ api.management.forgetOrder(undefined, "1", {
fields: ["$.summary"],
- });
+ })
},
({ query, api }) => {
expect(env.assertJustExpectedRequestWereMade()).deep.eq({
@@ -441,7 +442,7 @@ describe("order listing pagination", () => {
() => {
const date = new Date(12000);
const query = useInstanceOrders({ wired: "yes", date }, newDate);
- const api = useOrderAPI();
+ const { lib: api } = useMerchantApiContext()
return { query, api };
},
{},
@@ -507,7 +508,7 @@ describe("order listing pagination", () => {
() => {
const date = new Date(12000);
const query = useInstanceOrders({ wired: "yes", date }, newDate);
- const api = useOrderAPI();
+ const { lib: api } = useMerchantApiContext()
return { query, api };
},
{},
diff --git a/packages/merchant-backoffice-ui/src/hooks/order.ts b/packages/merchant-backoffice-ui/src/hooks/order.ts
index 39bc1725b..94e66795b 100644
--- a/packages/merchant-backoffice-ui/src/hooks/order.ts
+++ b/packages/merchant-backoffice-ui/src/hooks/order.ts
@@ -28,106 +28,106 @@ import { TalerErrorDetail, TalerMerchantApi } from "@gnu-taler/taler-util";
import _useSWR, { SWRHook } from "swr";
const useSWR = _useSWR as unknown as SWRHook;
-export interface OrderAPI {
- //FIXME: add OutOfStockResponse on 410
- createOrder: (
- data: TalerMerchantApi.PostOrderRequest,
- ) => Promise<HttpResponseOk<TalerMerchantApi.PostOrderResponse>>;
- forgetOrder: (
- id: string,
- data: TalerMerchantApi.ForgetRequest,
- ) => Promise<HttpResponseOk<void>>;
- refundOrder: (
- id: string,
- data: TalerMerchantApi.RefundRequest,
- ) => Promise<HttpResponseOk<TalerMerchantApi.MerchantRefundResponse>>;
- deleteOrder: (id: string) => Promise<HttpResponseOk<void>>;
- getPaymentURL: (id: string) => Promise<HttpResponseOk<string>>;
-}
+// export interface OrderAPI {
+// //FIXME: add OutOfStockResponse on 410
+// createOrder: (
+// data: TalerMerchantApi.PostOrderRequest,
+// ) => Promise<HttpResponseOk<TalerMerchantApi.PostOrderResponse>>;
+// forgetOrder: (
+// id: string,
+// data: TalerMerchantApi.ForgetRequest,
+// ) => Promise<HttpResponseOk<void>>;
+// refundOrder: (
+// id: string,
+// data: TalerMerchantApi.RefundRequest,
+// ) => Promise<HttpResponseOk<TalerMerchantApi.MerchantRefundResponse>>;
+// deleteOrder: (id: string) => Promise<HttpResponseOk<void>>;
+// getPaymentURL: (id: string) => Promise<HttpResponseOk<string>>;
+// }
type YesOrNo = "yes" | "no";
-export function useOrderAPI(): OrderAPI {
- const mutateAll = useMatchMutate();
- const { request } = useBackendInstanceRequest();
+// export function useOrderAPI(): OrderAPI {
+// const mutateAll = useMatchMutate();
+// const { request } = useBackendInstanceRequest();
- const createOrder = async (
- data: TalerMerchantApi.PostOrderRequest,
- ): Promise<HttpResponseOk<TalerMerchantApi.PostOrderResponse>> => {
- const res = await request<TalerMerchantApi.PostOrderResponse>(
- `/private/orders`,
- {
- method: "POST",
- data,
- },
- );
- await mutateAll(/.*private\/orders.*/);
- // mutate('')
- return res;
- };
- const refundOrder = async (
- orderId: string,
- data: TalerMerchantApi.RefundRequest,
- ): Promise<HttpResponseOk<TalerMerchantApi.MerchantRefundResponse>> => {
- mutateAll(/@"\/private\/orders"@/);
- const res = request<TalerMerchantApi.MerchantRefundResponse>(
- `/private/orders/${orderId}/refund`,
- {
- method: "POST",
- data,
- },
- );
+// const createOrder = async (
+// data: TalerMerchantApi.PostOrderRequest,
+// ): Promise<HttpResponseOk<TalerMerchantApi.PostOrderResponse>> => {
+// const res = await request<TalerMerchantApi.PostOrderResponse>(
+// `/private/orders`,
+// {
+// method: "POST",
+// data,
+// },
+// );
+// await mutateAll(/.*private\/orders.*/);
+// // mutate('')
+// return res;
+// };
+// const refundOrder = async (
+// orderId: string,
+// data: TalerMerchantApi.RefundRequest,
+// ): Promise<HttpResponseOk<TalerMerchantApi.MerchantRefundResponse>> => {
+// mutateAll(/@"\/private\/orders"@/);
+// const res = request<TalerMerchantApi.MerchantRefundResponse>(
+// `/private/orders/${orderId}/refund`,
+// {
+// method: "POST",
+// data,
+// },
+// );
- // order list returns refundable information, so we must evict everything
- await mutateAll(/.*private\/orders.*/);
- return res;
- };
+// // order list returns refundable information, so we must evict everything
+// await mutateAll(/.*private\/orders.*/);
+// return res;
+// };
- const forgetOrder = async (
- orderId: string,
- data: TalerMerchantApi.ForgetRequest,
- ): Promise<HttpResponseOk<void>> => {
- mutateAll(/@"\/private\/orders"@/);
- const res = request<void>(`/private/orders/${orderId}/forget`, {
- method: "PATCH",
- data,
- });
- // we may be forgetting some fields that are pare of the listing, so we must evict everything
- await mutateAll(/.*private\/orders.*/);
- return res;
- };
- const deleteOrder = async (
- orderId: string,
- ): Promise<HttpResponseOk<void>> => {
- mutateAll(/@"\/private\/orders"@/);
- const res = request<void>(`/private/orders/${orderId}`, {
- method: "DELETE",
- });
- await mutateAll(/.*private\/orders.*/);
- return res;
- };
+// const forgetOrder = async (
+// orderId: string,
+// data: TalerMerchantApi.ForgetRequest,
+// ): Promise<HttpResponseOk<void>> => {
+// mutateAll(/@"\/private\/orders"@/);
+// const res = request<void>(`/private/orders/${orderId}/forget`, {
+// method: "PATCH",
+// data,
+// });
+// // we may be forgetting some fields that are pare of the listing, so we must evict everything
+// await mutateAll(/.*private\/orders.*/);
+// return res;
+// };
+// const deleteOrder = async (
+// orderId: string,
+// ): Promise<HttpResponseOk<void>> => {
+// mutateAll(/@"\/private\/orders"@/);
+// const res = request<void>(`/private/orders/${orderId}`, {
+// method: "DELETE",
+// });
+// await mutateAll(/.*private\/orders.*/);
+// return res;
+// };
- const getPaymentURL = async (
- orderId: string,
- ): Promise<HttpResponseOk<string>> => {
- return request<TalerMerchantApi.MerchantOrderStatusResponse>(
- `/private/orders/${orderId}`,
- {
- method: "GET",
- },
- ).then((res) => {
- const url =
- res.data.order_status === "unpaid"
- ? res.data.taler_pay_uri
- : res.data.contract_terms.fulfillment_url;
- const response: HttpResponseOk<string> = res as any;
- response.data = url || "";
- return response;
- });
- };
+// const getPaymentURL = async (
+// orderId: string,
+// ): Promise<HttpResponseOk<string>> => {
+// return request<TalerMerchantApi.MerchantOrderStatusResponse>(
+// `/private/orders/${orderId}`,
+// {
+// method: "GET",
+// },
+// ).then((res) => {
+// const url =
+// res.data.order_status === "unpaid"
+// ? res.data.taler_pay_uri
+// : res.data.contract_terms.fulfillment_url;
+// const response: HttpResponseOk<string> = res as any;
+// response.data = url || "";
+// return response;
+// });
+// };
- return { createOrder, forgetOrder, deleteOrder, refundOrder, getPaymentURL };
-}
+// return { createOrder, forgetOrder, deleteOrder, refundOrder, getPaymentURL };
+// }
export function useOrderDetails(
oderId: string,
@@ -278,9 +278,9 @@ export function useInstanceOrders(
!beforeData || !afterData
? []
: (beforeData || lastBefore).data.orders
- .slice()
- .reverse()
- .concat((afterData || lastAfter).data.orders);
+ .slice()
+ .reverse()
+ .concat((afterData || lastAfter).data.orders);
if (loadingAfter || loadingBefore) return { loading: true, data: { orders } };
if (beforeData && afterData) {
return { ok: true, data: { orders }, ...pagination };
diff --git a/packages/merchant-backoffice-ui/src/hooks/otp.ts b/packages/merchant-backoffice-ui/src/hooks/otp.ts
index 4b45dcf06..36db2ea90 100644
--- a/packages/merchant-backoffice-ui/src/hooks/otp.ts
+++ b/packages/merchant-backoffice-ui/src/hooks/otp.ts
@@ -28,69 +28,69 @@ import { TalerErrorDetail, TalerMerchantApi } from "@gnu-taler/taler-util";
import _useSWR, { SWRHook } from "swr";
const useSWR = _useSWR as unknown as SWRHook;
-export function useOtpDeviceAPI(): OtpDeviceAPI {
- const mutateAll = useMatchMutate();
- const { request } = useBackendInstanceRequest();
-
- const createOtpDevice = async (
- data: TalerMerchantApi.OtpDeviceAddDetails,
- ): Promise<HttpResponseOk<void>> => {
- // MOCKED_DEVICES[data.otp_device_id] = data
- // return Promise.resolve({ ok: true, data: undefined });
- const res = await request<void>(`/private/otp-devices`, {
- method: "POST",
- data,
- });
- await mutateAll(/.*private\/otp-devices.*/);
- return res;
- };
-
- const updateOtpDevice = async (
- deviceId: string,
- data: TalerMerchantApi.OtpDevicePatchDetails,
- ): Promise<HttpResponseOk<void>> => {
- // MOCKED_DEVICES[deviceId].otp_algorithm = data.otp_algorithm
- // MOCKED_DEVICES[deviceId].otp_ctr = data.otp_ctr
- // MOCKED_DEVICES[deviceId].otp_device_description = data.otp_device_description
- // MOCKED_DEVICES[deviceId].otp_key = data.otp_key
- // return Promise.resolve({ ok: true, data: undefined });
- const res = await request<void>(`/private/otp-devices/${deviceId}`, {
- method: "PATCH",
- data,
- });
- await mutateAll(/.*private\/otp-devices.*/);
- return res;
- };
-
- const deleteOtpDevice = async (
- deviceId: string,
- ): Promise<HttpResponseOk<void>> => {
- // delete MOCKED_DEVICES[deviceId]
- // return Promise.resolve({ ok: true, data: undefined });
- const res = await request<void>(`/private/otp-devices/${deviceId}`, {
- method: "DELETE",
- });
- await mutateAll(/.*private\/otp-devices.*/);
- return res;
- };
-
- return {
- createOtpDevice,
- updateOtpDevice,
- deleteOtpDevice,
- };
-}
-
-export interface OtpDeviceAPI {
- createOtpDevice: (
- data: TalerMerchantApi.OtpDeviceAddDetails,
- ) => Promise<HttpResponseOk<void>>;
- updateOtpDevice: (
- id: string,
- data: TalerMerchantApi.OtpDevicePatchDetails,
- ) => Promise<HttpResponseOk<void>>;
- deleteOtpDevice: (id: string) => Promise<HttpResponseOk<void>>;
-}
+// export function useOtpDeviceAPI(): OtpDeviceAPI {
+// const mutateAll = useMatchMutate();
+// const { request } = useBackendInstanceRequest();
+
+// const createOtpDevice = async (
+// data: TalerMerchantApi.OtpDeviceAddDetails,
+// ): Promise<HttpResponseOk<void>> => {
+// // MOCKED_DEVICES[data.otp_device_id] = data
+// // return Promise.resolve({ ok: true, data: undefined });
+// const res = await request<void>(`/private/otp-devices`, {
+// method: "POST",
+// data,
+// });
+// await mutateAll(/.*private\/otp-devices.*/);
+// return res;
+// };
+
+// const updateOtpDevice = async (
+// deviceId: string,
+// data: TalerMerchantApi.OtpDevicePatchDetails,
+// ): Promise<HttpResponseOk<void>> => {
+// // MOCKED_DEVICES[deviceId].otp_algorithm = data.otp_algorithm
+// // MOCKED_DEVICES[deviceId].otp_ctr = data.otp_ctr
+// // MOCKED_DEVICES[deviceId].otp_device_description = data.otp_device_description
+// // MOCKED_DEVICES[deviceId].otp_key = data.otp_key
+// // return Promise.resolve({ ok: true, data: undefined });
+// const res = await request<void>(`/private/otp-devices/${deviceId}`, {
+// method: "PATCH",
+// data,
+// });
+// await mutateAll(/.*private\/otp-devices.*/);
+// return res;
+// };
+
+// const deleteOtpDevice = async (
+// deviceId: string,
+// ): Promise<HttpResponseOk<void>> => {
+// // delete MOCKED_DEVICES[deviceId]
+// // return Promise.resolve({ ok: true, data: undefined });
+// const res = await request<void>(`/private/otp-devices/${deviceId}`, {
+// method: "DELETE",
+// });
+// await mutateAll(/.*private\/otp-devices.*/);
+// return res;
+// };
+
+// return {
+// createOtpDevice,
+// updateOtpDevice,
+// deleteOtpDevice,
+// };
+// }
+
+// export interface OtpDeviceAPI {
+// createOtpDevice: (
+// data: TalerMerchantApi.OtpDeviceAddDetails,
+// ) => Promise<HttpResponseOk<void>>;
+// updateOtpDevice: (
+// id: string,
+// data: TalerMerchantApi.OtpDevicePatchDetails,
+// ) => Promise<HttpResponseOk<void>>;
+// deleteOtpDevice: (id: string) => Promise<HttpResponseOk<void>>;
+// }
export interface InstanceOtpDeviceFilter {
}
diff --git a/packages/merchant-backoffice-ui/src/hooks/product.test.ts b/packages/merchant-backoffice-ui/src/hooks/product.test.ts
index 64dbd0103..c819c739e 100644
--- a/packages/merchant-backoffice-ui/src/hooks/product.test.ts
+++ b/packages/merchant-backoffice-ui/src/hooks/product.test.ts
@@ -23,7 +23,6 @@ import * as tests from "@gnu-taler/web-util/testing";
import { expect } from "chai";
import {
useInstanceProducts,
- useProductAPI,
useProductDetails,
} from "./product.js";
import { ApiMockEnvironment } from "./testing.js";
@@ -35,6 +34,7 @@ import {
API_UPDATE_PRODUCT_BY_ID,
} from "./urls.js";
import { TalerMerchantApi } from "@gnu-taler/taler-util";
+import { useMerchantApiContext } from "@gnu-taler/web-util/browser";
describe("product api interaction with listing", () => {
it("should evict cache when creating a product", async () => {
@@ -52,7 +52,7 @@ describe("product api interaction with listing", () => {
const hookBehavior = await tests.hookBehaveLikeThis(
() => {
const query = useInstanceProducts();
- const api = useProductAPI();
+ const { lib: api } = useMerchantApiContext();
return { query, api };
},
{},
@@ -70,7 +70,7 @@ describe("product api interaction with listing", () => {
expect(query.loading).undefined;
expect(query.ok).true;
if (!query.ok) return;
- expect(query.data).deep.equals([{ id: "1234" , price: "ARS:12" }]);
+ expect(query.data).deep.equals([{ id: "1234", price: "ARS:12" }]);
env.addRequestExpectation(API_CREATE_PRODUCT, {
request: {
@@ -99,7 +99,7 @@ describe("product api interaction with listing", () => {
} as TalerMerchantApi.ProductDetail,
});
- api.createProduct({
+ api.management.addProduct(undefined, {
price: "ARS:23",
} as any);
},
@@ -150,7 +150,7 @@ describe("product api interaction with listing", () => {
const hookBehavior = await tests.hookBehaveLikeThis(
() => {
const query = useInstanceProducts();
- const api = useProductAPI();
+ const { lib: api } = useMerchantApiContext();
return { query, api };
},
{},
@@ -187,7 +187,7 @@ describe("product api interaction with listing", () => {
} as TalerMerchantApi.ProductDetail,
});
- api.updateProduct("1234", {
+ api.management.updateProduct(undefined, "1234", {
price: "ARS:13",
} as any);
},
@@ -218,7 +218,7 @@ describe("product api interaction with listing", () => {
env.addRequestExpectation(API_LIST_PRODUCTS, {
response: {
- products: [{ product_id: "1234" , product_serial: 1}, { product_id: "2345", product_serial: 2 }],
+ products: [{ product_id: "1234", product_serial: 1 }, { product_id: "2345", product_serial: 2 }],
},
});
env.addRequestExpectation(API_GET_PRODUCT_BY_ID("1234"), {
@@ -231,7 +231,7 @@ describe("product api interaction with listing", () => {
const hookBehavior = await tests.hookBehaveLikeThis(
() => {
const query = useInstanceProducts();
- const api = useProductAPI();
+ const { lib: api } = useMerchantApiContext();
return { query, api };
},
{},
@@ -267,7 +267,7 @@ describe("product api interaction with listing", () => {
price: "ARS:12",
} as TalerMerchantApi.ProductDetail,
});
- api.deleteProduct("2345");
+ api.management.deleteProduct(undefined, "2345");
},
({ query, api }) => {
expect(env.assertJustExpectedRequestWereMade()).deep.eq({
@@ -306,7 +306,7 @@ describe("product api interaction with details", () => {
const hookBehavior = await tests.hookBehaveLikeThis(
() => {
const query = useProductDetails("12");
- const api = useProductAPI();
+ const { lib: api } = useMerchantApiContext();
return { query, api };
},
{},
@@ -337,7 +337,7 @@ describe("product api interaction with details", () => {
} as TalerMerchantApi.ProductDetail,
});
- api.updateProduct("12", {
+ api.management.updateProduct(undefined, "12", {
description: "other description",
} as any);
},
diff --git a/packages/merchant-backoffice-ui/src/hooks/product.ts b/packages/merchant-backoffice-ui/src/hooks/product.ts
index c0ace0d32..0eb54f717 100644
--- a/packages/merchant-backoffice-ui/src/hooks/product.ts
+++ b/packages/merchant-backoffice-ui/src/hooks/product.ts
@@ -25,84 +25,84 @@ import _useSWR, { SWRHook, useSWRConfig } from "swr";
import { TalerErrorDetail, TalerMerchantApi } from "@gnu-taler/taler-util";
const useSWR = _useSWR as unknown as SWRHook;
-export interface ProductAPI {
- getProduct: (
- id: string,
- ) => Promise<void>;
- createProduct: (
- data: TalerMerchantApi.ProductAddDetail,
- ) => Promise<void>;
- updateProduct: (
- id: string,
- data: TalerMerchantApi.ProductPatchDetail,
- ) => Promise<void>;
- deleteProduct: (id: string) => Promise<void>;
- lockProduct: (
- id: string,
- data: TalerMerchantApi.LockRequest,
- ) => Promise<void>;
-}
-
-export function useProductAPI(): ProductAPI {
- const mutateAll = useMatchMutate();
- const { mutate } = useSWRConfig();
-
- const { request } = useBackendInstanceRequest();
-
- const createProduct = async (
- data: TalerMerchantApi.ProductAddDetail,
- ): Promise<void> => {
- const res = await request(`/private/products`, {
- method: "POST",
- data,
- });
-
- return await mutateAll(/.*\/private\/products.*/);
- };
-
- const updateProduct = async (
- productId: string,
- data: TalerMerchantApi.ProductPatchDetail,
- ): Promise<void> => {
- const r = await request(`/private/products/${productId}`, {
- method: "PATCH",
- data,
- });
-
- return await mutateAll(/.*\/private\/products.*/);
- };
-
- const deleteProduct = async (productId: string): Promise<void> => {
- await request(`/private/products/${productId}`, {
- method: "DELETE",
- });
- await mutate([`/private/products`]);
- };
-
- const lockProduct = async (
- productId: string,
- data: TalerMerchantApi.LockRequest,
- ): Promise<void> => {
- await request(`/private/products/${productId}/lock`, {
- method: "POST",
- data,
- });
-
- return await mutateAll(/.*"\/private\/products.*/);
- };
-
- const getProduct = async (
- productId: string,
- ): Promise<void> => {
- await request(`/private/products/${productId}`, {
- method: "GET",
- });
-
- return
- };
-
- return { createProduct, updateProduct, deleteProduct, lockProduct, getProduct };
-}
+// export interface ProductAPI {
+// getProduct: (
+// id: string,
+// ) => Promise<void>;
+// createProduct: (
+// data: TalerMerchantApi.ProductAddDetail,
+// ) => Promise<void>;
+// updateProduct: (
+// id: string,
+// data: TalerMerchantApi.ProductPatchDetail,
+// ) => Promise<void>;
+// deleteProduct: (id: string) => Promise<void>;
+// lockProduct: (
+// id: string,
+// data: TalerMerchantApi.LockRequest,
+// ) => Promise<void>;
+// }
+
+// export function useProductAPI(): ProductAPI {
+// const mutateAll = useMatchMutate();
+// const { mutate } = useSWRConfig();
+
+// const { request } = useBackendInstanceRequest();
+
+// const createProduct = async (
+// data: TalerMerchantApi.ProductAddDetail,
+// ): Promise<void> => {
+// const res = await request(`/private/products`, {
+// method: "POST",
+// data,
+// });
+
+// return await mutateAll(/.*\/private\/products.*/);
+// };
+
+// const updateProduct = async (
+// productId: string,
+// data: TalerMerchantApi.ProductPatchDetail,
+// ): Promise<void> => {
+// const r = await request(`/private/products/${productId}`, {
+// method: "PATCH",
+// data,
+// });
+
+// return await mutateAll(/.*\/private\/products.*/);
+// };
+
+// const deleteProduct = async (productId: string): Promise<void> => {
+// await request(`/private/products/${productId}`, {
+// method: "DELETE",
+// });
+// await mutate([`/private/products`]);
+// };
+
+// const lockProduct = async (
+// productId: string,
+// data: TalerMerchantApi.LockRequest,
+// ): Promise<void> => {
+// await request(`/private/products/${productId}/lock`, {
+// method: "POST",
+// data,
+// });
+
+// return await mutateAll(/.*"\/private\/products.*/);
+// };
+
+// const getProduct = async (
+// productId: string,
+// ): Promise<void> => {
+// await request(`/private/products/${productId}`, {
+// method: "GET",
+// });
+
+// return
+// };
+
+// return { createProduct, updateProduct, deleteProduct, lockProduct, getProduct };
+// }
export function useInstanceProducts(): HttpResponse<
(TalerMerchantApi.ProductDetail & WithId)[],
diff --git a/packages/merchant-backoffice-ui/src/hooks/templates.ts b/packages/merchant-backoffice-ui/src/hooks/templates.ts
index 2da02e3c7..ff0461a67 100644
--- a/packages/merchant-backoffice-ui/src/hooks/templates.ts
+++ b/packages/merchant-backoffice-ui/src/hooks/templates.ts
@@ -28,94 +28,94 @@ import { TalerErrorDetail, TalerMerchantApi } from "@gnu-taler/taler-util";
import _useSWR, { SWRHook } from "swr";
const useSWR = _useSWR as unknown as SWRHook;
-export function useTemplateAPI(): TemplateAPI {
- const mutateAll = useMatchMutate();
- const { request } = useBackendInstanceRequest();
+// export function useTemplateAPI(): TemplateAPI {
+// const mutateAll = useMatchMutate();
+// const { request } = useBackendInstanceRequest();
- const createTemplate = async (
- data: TalerMerchantApi.TemplateAddDetails,
- ): Promise<HttpResponseOk<void>> => {
- const res = await request<void>(`/private/templates`, {
- method: "POST",
- data,
- });
- await mutateAll(/.*private\/templates.*/);
- return res;
- };
+// const createTemplate = async (
+// data: TalerMerchantApi.TemplateAddDetails,
+// ): Promise<HttpResponseOk<void>> => {
+// const res = await request<void>(`/private/templates`, {
+// method: "POST",
+// data,
+// });
+// await mutateAll(/.*private\/templates.*/);
+// return res;
+// };
- const updateTemplate = async (
- templateId: string,
- data: TalerMerchantApi.TemplatePatchDetails,
- ): Promise<HttpResponseOk<void>> => {
- const res = await request<void>(`/private/templates/${templateId}`, {
- method: "PATCH",
- data,
- });
- await mutateAll(/.*private\/templates.*/);
- return res;
- };
+// const updateTemplate = async (
+// templateId: string,
+// data: TalerMerchantApi.TemplatePatchDetails,
+// ): Promise<HttpResponseOk<void>> => {
+// const res = await request<void>(`/private/templates/${templateId}`, {
+// method: "PATCH",
+// data,
+// });
+// await mutateAll(/.*private\/templates.*/);
+// return res;
+// };
- const deleteTemplate = async (
- templateId: string,
- ): Promise<HttpResponseOk<void>> => {
- const res = await request<void>(`/private/templates/${templateId}`, {
- method: "DELETE",
- });
- await mutateAll(/.*private\/templates.*/);
- return res;
- };
+// const deleteTemplate = async (
+// templateId: string,
+// ): Promise<HttpResponseOk<void>> => {
+// const res = await request<void>(`/private/templates/${templateId}`, {
+// method: "DELETE",
+// });
+// await mutateAll(/.*private\/templates.*/);
+// return res;
+// };
- const createOrderFromTemplate = async (
- templateId: string,
- data: TalerMerchantApi.UsingTemplateDetails,
- ): Promise<
- HttpResponseOk<TalerMerchantApi.PostOrderResponse>
- > => {
- const res = await request<TalerMerchantApi.PostOrderResponse>(
- `/templates/${templateId}`,
- {
- method: "POST",
- data,
- },
- );
- await mutateAll(/.*private\/templates.*/);
- return res;
- };
+// const createOrderFromTemplate = async (
+// templateId: string,
+// data: TalerMerchantApi.UsingTemplateDetails,
+// ): Promise<
+// HttpResponseOk<TalerMerchantApi.PostOrderResponse>
+// > => {
+// const res = await request<TalerMerchantApi.PostOrderResponse>(
+// `/templates/${templateId}`,
+// {
+// method: "POST",
+// data,
+// },
+// );
+// await mutateAll(/.*private\/templates.*/);
+// return res;
+// };
- const testTemplateExist = async (
- templateId: string,
- ): Promise<HttpResponseOk<void>> => {
- const res = await request<void>(`/private/templates/${templateId}`, { method: "GET", });
- return res;
- };
+// const testTemplateExist = async (
+// templateId: string,
+// ): Promise<HttpResponseOk<void>> => {
+// const res = await request<void>(`/private/templates/${templateId}`, { method: "GET", });
+// return res;
+// };
- return {
- createTemplate,
- updateTemplate,
- deleteTemplate,
- testTemplateExist,
- createOrderFromTemplate,
- };
-}
+// return {
+// createTemplate,
+// updateTemplate,
+// deleteTemplate,
+// testTemplateExist,
+// createOrderFromTemplate,
+// };
+// }
-export interface TemplateAPI {
- createTemplate: (
- data: TalerMerchantApi.TemplateAddDetails,
- ) => Promise<HttpResponseOk<void>>;
- updateTemplate: (
- id: string,
- data: TalerMerchantApi.TemplatePatchDetails,
- ) => Promise<HttpResponseOk<void>>;
- testTemplateExist: (
- id: string
- ) => Promise<HttpResponseOk<void>>;
- deleteTemplate: (id: string) => Promise<HttpResponseOk<void>>;
- createOrderFromTemplate: (
- id: string,
- data: TalerMerchantApi.UsingTemplateDetails,
- ) => Promise<HttpResponseOk<TalerMerchantApi.PostOrderResponse>>;
-}
+// export interface TemplateAPI {
+// createTemplate: (
+// data: TalerMerchantApi.TemplateAddDetails,
+// ) => Promise<HttpResponseOk<void>>;
+// updateTemplate: (
+// id: string,
+// data: TalerMerchantApi.TemplatePatchDetails,
+// ) => Promise<HttpResponseOk<void>>;
+// testTemplateExist: (
+// id: string
+// ) => Promise<HttpResponseOk<void>>;
+// deleteTemplate: (id: string) => Promise<HttpResponseOk<void>>;
+// createOrderFromTemplate: (
+// id: string,
+// data: TalerMerchantApi.UsingTemplateDetails,
+// ) => Promise<HttpResponseOk<TalerMerchantApi.PostOrderResponse>>;
+// }
export interface InstanceTemplateFilter {
//FIXME: add filter to the template list
diff --git a/packages/merchant-backoffice-ui/src/hooks/transfer.test.ts b/packages/merchant-backoffice-ui/src/hooks/transfer.test.ts
index ee987af7e..5f1cf51a7 100644
--- a/packages/merchant-backoffice-ui/src/hooks/transfer.test.ts
+++ b/packages/merchant-backoffice-ui/src/hooks/transfer.test.ts
@@ -23,8 +23,9 @@ import { AmountString, PaytoString, TalerMerchantApi } from "@gnu-taler/taler-ut
import * as tests from "@gnu-taler/web-util/testing";
import { expect } from "chai";
import { ApiMockEnvironment } from "./testing.js";
-import { useInstanceTransfers, useTransferAPI } from "./transfer.js";
+import { useInstanceTransfers } from "./transfer.js";
import { API_INFORM_TRANSFERS, API_LIST_TRANSFERS } from "./urls.js";
+import { useMerchantApiContext } from "@gnu-taler/web-util/browser";
describe("transfer api interaction with listing", () => {
it("should evict cache when informing a transfer", async () => {
@@ -44,7 +45,7 @@ describe("transfer api interaction with listing", () => {
const hookBehavior = await tests.hookBehaveLikeThis(
() => {
const query = useInstanceTransfers({}, moveCursor);
- const api = useTransferAPI();
+ const { lib: api } = useMerchantApiContext();
return { query, api };
},
{},
@@ -81,7 +82,7 @@ describe("transfer api interaction with listing", () => {
},
});
- api.informTransfer({
+ api.management.informWireTransfer(undefined, {
wtid: "3",
credit_amount: "EUR:1" as AmountString,
exchange_url: "exchange.url",
diff --git a/packages/merchant-backoffice-ui/src/hooks/transfer.ts b/packages/merchant-backoffice-ui/src/hooks/transfer.ts
index 20062a5e2..af62af0fa 100644
--- a/packages/merchant-backoffice-ui/src/hooks/transfer.ts
+++ b/packages/merchant-backoffice-ui/src/hooks/transfer.ts
@@ -28,30 +28,30 @@ import { TalerErrorDetail, TalerMerchantApi } from "@gnu-taler/taler-util";
import _useSWR, { SWRHook } from "swr";
const useSWR = _useSWR as unknown as SWRHook;
-export function useTransferAPI(): TransferAPI {
- const mutateAll = useMatchMutate();
- const { request } = useBackendInstanceRequest();
-
- const informTransfer = async (
- data: TalerMerchantApi.TransferInformation,
- ): Promise<HttpResponseOk<{}>> => {
- const res = await request<{}>(`/private/transfers`, {
- method: "POST",
- data,
- });
-
- await mutateAll(/.*private\/transfers.*/);
- return res;
- };
-
- return { informTransfer };
-}
-
-export interface TransferAPI {
- informTransfer: (
- data: TalerMerchantApi.TransferInformation,
- ) => Promise<HttpResponseOk<{}>>;
-}
+// export function useTransferAPI(): TransferAPI {
+// const mutateAll = useMatchMutate();
+// const { request } = useBackendInstanceRequest();
+
+// const informTransfer = async (
+// data: TalerMerchantApi.TransferInformation,
+// ): Promise<HttpResponseOk<{}>> => {
+// const res = await request<{}>(`/private/transfers`, {
+// method: "POST",
+// data,
+// });
+
+// await mutateAll(/.*private\/transfers.*/);
+// return res;
+// };
+
+// return { informTransfer };
+// }
+
+// export interface TransferAPI {
+// informTransfer: (
+// data: TalerMerchantApi.TransferInformation,
+// ) => Promise<HttpResponseOk<{}>>;
+// }
export interface InstanceTransferFilter {
payto_uri?: string;
@@ -151,10 +151,9 @@ export function useInstanceTransfers(
if (afterData.data.transfers.length < MAX_RESULT_SIZE) {
setPageAfter(pageAfter + 1);
} else {
- const from = `${
- afterData.data.transfers[afterData.data.transfers.length - 1]
+ const from = `${afterData.data.transfers[afterData.data.transfers.length - 1]
.transfer_serial_id
- }`;
+ }`;
if (from && updatePosition) updatePosition(from);
}
},
@@ -163,10 +162,9 @@ export function useInstanceTransfers(
if (beforeData.data.transfers.length < MAX_RESULT_SIZE) {
setPageBefore(pageBefore + 1);
} else if (beforeData) {
- const from = `${
- beforeData.data.transfers[beforeData.data.transfers.length - 1]
+ const from = `${beforeData.data.transfers[beforeData.data.transfers.length - 1]
.transfer_serial_id
- }`;
+ }`;
if (from && updatePosition) updatePosition(from);
}
},
@@ -176,9 +174,9 @@ export function useInstanceTransfers(
!beforeData || !afterData
? []
: (beforeData || lastBefore).data.transfers
- .slice()
- .reverse()
- .concat((afterData || lastAfter).data.transfers);
+ .slice()
+ .reverse()
+ .concat((afterData || lastAfter).data.transfers);
if (loadingAfter || loadingBefore)
return { loading: true, data: { transfers } };
if (beforeData && afterData) {
diff --git a/packages/merchant-backoffice-ui/src/hooks/webhooks.ts b/packages/merchant-backoffice-ui/src/hooks/webhooks.ts
index 4e62a81c9..cc817b84e 100644
--- a/packages/merchant-backoffice-ui/src/hooks/webhooks.ts
+++ b/packages/merchant-backoffice-ui/src/hooks/webhooks.ts
@@ -28,56 +28,56 @@ import { TalerErrorDetail, TalerMerchantApi } from "@gnu-taler/taler-util";
import _useSWR, { SWRHook } from "swr";
const useSWR = _useSWR as unknown as SWRHook;
-export function useWebhookAPI(): WebhookAPI {
- const mutateAll = useMatchMutate();
- const { request } = useBackendInstanceRequest();
-
- const createWebhook = async (
- data: TalerMerchantApi.WebhookAddDetails,
- ): Promise<HttpResponseOk<void>> => {
- const res = await request<void>(`/private/webhooks`, {
- method: "POST",
- data,
- });
- await mutateAll(/.*private\/webhooks.*/);
- return res;
- };
-
- const updateWebhook = async (
- webhookId: string,
- data: TalerMerchantApi.WebhookPatchDetails,
- ): Promise<HttpResponseOk<void>> => {
- const res = await request<void>(`/private/webhooks/${webhookId}`, {
- method: "PATCH",
- data,
- });
- await mutateAll(/.*private\/webhooks.*/);
- return res;
- };
-
- const deleteWebhook = async (
- webhookId: string,
- ): Promise<HttpResponseOk<void>> => {
- const res = await request<void>(`/private/webhooks/${webhookId}`, {
- method: "DELETE",
- });
- await mutateAll(/.*private\/webhooks.*/);
- return res;
- };
-
- return { createWebhook, updateWebhook, deleteWebhook };
-}
-
-export interface WebhookAPI {
- createWebhook: (
- data: TalerMerchantApi.WebhookAddDetails,
- ) => Promise<HttpResponseOk<void>>;
- updateWebhook: (
- id: string,
- data: TalerMerchantApi.WebhookPatchDetails,
- ) => Promise<HttpResponseOk<void>>;
- deleteWebhook: (id: string) => Promise<HttpResponseOk<void>>;
-}
+// export function useWebhookAPI(): WebhookAPI {
+// const mutateAll = useMatchMutate();
+// const { request } = useBackendInstanceRequest();
+
+// const createWebhook = async (
+// data: TalerMerchantApi.WebhookAddDetails,
+// ): Promise<HttpResponseOk<void>> => {
+// const res = await request<void>(`/private/webhooks`, {
+// method: "POST",
+// data,
+// });
+// await mutateAll(/.*private\/webhooks.*/);
+// return res;
+// };
+
+// const updateWebhook = async (
+// webhookId: string,
+// data: TalerMerchantApi.WebhookPatchDetails,
+// ): Promise<HttpResponseOk<void>> => {
+// const res = await request<void>(`/private/webhooks/${webhookId}`, {
+// method: "PATCH",
+// data,
+// });
+// await mutateAll(/.*private\/webhooks.*/);
+// return res;
+// };
+
+// const deleteWebhook = async (
+// webhookId: string,
+// ): Promise<HttpResponseOk<void>> => {
+// const res = await request<void>(`/private/webhooks/${webhookId}`, {
+// method: "DELETE",
+// });
+// await mutateAll(/.*private\/webhooks.*/);
+// return res;
+// };
+
+// return { createWebhook, updateWebhook, deleteWebhook };
+// }
+
+// export interface WebhookAPI {
+// createWebhook: (
+// data: TalerMerchantApi.WebhookAddDetails,
+// ) => Promise<HttpResponseOk<void>>;
+// updateWebhook: (
+// id: string,
+// data: TalerMerchantApi.WebhookPatchDetails,
+// ) => Promise<HttpResponseOk<void>>;
+// deleteWebhook: (id: string) => Promise<HttpResponseOk<void>>;
+// }
export interface InstanceWebhookFilter {
//FIXME: add filter to the webhook list
@@ -133,9 +133,8 @@ export function useInstanceWebhooks(
if (afterData.data.webhooks.length < MAX_RESULT_SIZE) {
setPageAfter(pageAfter + 1);
} else {
- const from = `${
- afterData.data.webhooks[afterData.data.webhooks.length - 1].webhook_id
- }`;
+ const from = `${afterData.data.webhooks[afterData.data.webhooks.length - 1].webhook_id
+ }`;
if (from && updatePosition) updatePosition(from);
}
},