aboutsummaryrefslogtreecommitdiff
path: root/packages/merchant-backoffice-ui/src/hooks
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2024-07-08 15:36:20 -0300
committerSebastian <sebasjm@gmail.com>2024-07-08 15:36:20 -0300
commitc6f5d2f5b0bebe6e2b762e2f83f11f29a1ca09ed (patch)
tree01ceed866d86360f39d4cb65dbb5cc3cfe24d2c9 /packages/merchant-backoffice-ui/src/hooks
parent586d68c9daccb116c7b47d56ff95571c04586d9d (diff)
check error on rest api and some i18n strings
Diffstat (limited to 'packages/merchant-backoffice-ui/src/hooks')
-rw-r--r--packages/merchant-backoffice-ui/src/hooks/bank.ts19
-rw-r--r--packages/merchant-backoffice-ui/src/hooks/instance.ts44
-rw-r--r--packages/merchant-backoffice-ui/src/hooks/order.ts14
-rw-r--r--packages/merchant-backoffice-ui/src/hooks/otp.ts14
-rw-r--r--packages/merchant-backoffice-ui/src/hooks/product.ts16
-rw-r--r--packages/merchant-backoffice-ui/src/hooks/templates.ts17
-rw-r--r--packages/merchant-backoffice-ui/src/hooks/tokenfamily.ts15
-rw-r--r--packages/merchant-backoffice-ui/src/hooks/transfer.ts7
-rw-r--r--packages/merchant-backoffice-ui/src/hooks/webhooks.ts14
9 files changed, 70 insertions, 90 deletions
diff --git a/packages/merchant-backoffice-ui/src/hooks/bank.ts b/packages/merchant-backoffice-ui/src/hooks/bank.ts
index 4c917fe9e..0a1d63449 100644
--- a/packages/merchant-backoffice-ui/src/hooks/bank.ts
+++ b/packages/merchant-backoffice-ui/src/hooks/bank.ts
@@ -13,7 +13,6 @@
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 { useMerchantApiContext } from "@gnu-taler/web-util/browser";
// FIX default import https://github.com/microsoft/TypeScript/issues/49189
import {
@@ -35,15 +34,12 @@ export function revalidateInstanceBankAccounts() {
);
}
export function useInstanceBankAccounts() {
- const { state: session } = useSessionContext();
- const {
- lib: { instance },
- } = useSessionContext();
+ const { state, lib } = useSessionContext();
// const [offset, setOffset] = useState<string | undefined>();
async function fetcher([token, _bid]: [AccessToken, string]) {
- return await instance.listBankAccounts(token, {
+ return await lib.instance.listBankAccounts(token, {
// limit: PAGINATED_LIST_REQUEST,
// offset: bid,
// order: "dec",
@@ -53,7 +49,7 @@ export function useInstanceBankAccounts() {
const { data, error } = useSWR<
TalerMerchantManagementResultByMethod<"listBankAccounts">,
TalerHttpError
- >([session.token, "offset", "listBankAccounts"], fetcher);
+ >([state.token, "offset", "listBankAccounts"], fetcher);
if (error) return error;
if (data === undefined) return undefined;
@@ -74,19 +70,16 @@ export function revalidateBankAccountDetails() {
);
}
export function useBankAccountDetails(h_wire: string) {
- const { state: session } = useSessionContext();
- const {
- lib: { instance },
- } = useSessionContext();
+ const { state, lib } = useSessionContext();
async function fetcher([token, wireId]: [AccessToken, string]) {
- return await instance.getBankAccountDetails(token, wireId);
+ return await lib.instance.getBankAccountDetails(token, wireId);
}
const { data, error } = useSWR<
TalerMerchantManagementResultByMethod<"getBankAccountDetails">,
TalerHttpError
- >([session.token, h_wire, "getBankAccountDetails"], fetcher);
+ >([state.token, h_wire, "getBankAccountDetails"], fetcher);
if (data) return data;
if (error) return error;
diff --git a/packages/merchant-backoffice-ui/src/hooks/instance.ts b/packages/merchant-backoffice-ui/src/hooks/instance.ts
index f5f8893cd..a25b33f46 100644
--- a/packages/merchant-backoffice-ui/src/hooks/instance.ts
+++ b/packages/merchant-backoffice-ui/src/hooks/instance.ts
@@ -15,31 +15,34 @@
*/
// FIX default import https://github.com/microsoft/TypeScript/issues/49189
-import { AccessToken, TalerHttpError, TalerMerchantManagementResultByMethod } from "@gnu-taler/taler-util";
+import {
+ AccessToken,
+ TalerHttpError,
+ TalerMerchantManagementResultByMethod,
+} from "@gnu-taler/taler-util";
import _useSWR, { SWRHook, mutate } from "swr";
import { useSessionContext } from "../context/session.js";
const useSWR = _useSWR as unknown as SWRHook;
-
export function revalidateInstanceDetails() {
return mutate(
- (key) => Array.isArray(key) && key[key.length - 1] === "getCurrentInstanceDetails",
+ (key) =>
+ Array.isArray(key) && key[key.length - 1] === "getCurrentInstanceDetails",
undefined,
{ revalidate: true },
);
}
export function useInstanceDetails() {
- const { state: session } = useSessionContext();
- const { lib: { instance } } = useSessionContext();
+ const { state, lib } = useSessionContext();
async function fetcher([token]: [AccessToken]) {
- return await instance.getCurrentInstanceDetails(token);
+ return await lib.instance.getCurrentInstanceDetails(token);
}
const { data, error } = useSWR<
TalerMerchantManagementResultByMethod<"getCurrentInstanceDetails">,
TalerHttpError
- >([session.token, "getCurrentInstanceDetails"], fetcher);
+ >([state.token, "getCurrentInstanceDetails"], fetcher);
if (data) return data;
if (error) return error;
@@ -48,29 +51,28 @@ export function useInstanceDetails() {
export function revalidateInstanceKYCDetails() {
return mutate(
- (key) => Array.isArray(key) && key[key.length - 1] === "getCurrentIntanceKycStatus",
+ (key) =>
+ Array.isArray(key) &&
+ key[key.length - 1] === "getCurrentIntanceKycStatus",
undefined,
{ revalidate: true },
);
}
export function useInstanceKYCDetails() {
- const { state: session } = useSessionContext();
- const { lib: { instance } } = useSessionContext();
+ const { state, lib } = useSessionContext();
async function fetcher([token]: [AccessToken]) {
- return await instance.getCurrentIntanceKycStatus(token, {});
+ return await lib.instance.getCurrentIntanceKycStatus(token, {});
}
const { data, error } = useSWR<
TalerMerchantManagementResultByMethod<"getCurrentIntanceKycStatus">,
TalerHttpError
- >([session.token, "getCurrentIntanceKycStatus"], fetcher);
+ >([state.token, "getCurrentIntanceKycStatus"], fetcher);
if (data) return data;
if (error) return error;
return undefined;
-
-
}
export function revalidateManagedInstanceDetails() {
@@ -81,17 +83,16 @@ export function revalidateManagedInstanceDetails() {
);
}
export function useManagedInstanceDetails(instanceId: string) {
- const { state: session } = useSessionContext();
- const { lib: { instance } } = useSessionContext();
+ const { state, lib } = useSessionContext();
async function fetcher([token, instanceId]: [AccessToken, string]) {
- return await instance.getInstanceDetails(token, instanceId);
+ return await lib.instance.getInstanceDetails(token, instanceId);
}
const { data, error } = useSWR<
TalerMerchantManagementResultByMethod<"getInstanceDetails">,
TalerHttpError
- >([session.token, instanceId, "getInstanceDetails"], fetcher);
+ >([state.token, instanceId, "getInstanceDetails"], fetcher);
if (data) return data;
if (error) return error;
@@ -106,17 +107,16 @@ export function revalidateBackendInstances() {
);
}
export function useBackendInstances() {
- const { state: session } = useSessionContext();
- const { lib: { instance } } = useSessionContext();
+ const { state, lib } = useSessionContext();
async function fetcher([token]: [AccessToken]) {
- return await instance.listInstances(token);
+ return await lib.instance.listInstances(token);
}
const { data, error } = useSWR<
TalerMerchantManagementResultByMethod<"listInstances">,
TalerHttpError
- >([session.token, "listInstances"], fetcher);
+ >([state.token, "listInstances"], fetcher);
if (data) return data;
if (error) return error;
diff --git a/packages/merchant-backoffice-ui/src/hooks/order.ts b/packages/merchant-backoffice-ui/src/hooks/order.ts
index d0513dc40..ecdcd5f45 100644
--- a/packages/merchant-backoffice-ui/src/hooks/order.ts
+++ b/packages/merchant-backoffice-ui/src/hooks/order.ts
@@ -32,17 +32,16 @@ export function revalidateOrderDetails() {
);
}
export function useOrderDetails(oderId: string) {
- const { state: session } = useSessionContext();
- const { lib: { instance } } = useSessionContext();
+ const { state, lib } = useSessionContext();
async function fetcher([dId, token]: [string, AccessToken]) {
- return await instance.getOrderDetails(token, dId);
+ return await lib.instance.getOrderDetails(token, dId);
}
const { data, error } = useSWR<
TalerMerchantManagementResultByMethod<"getOrderDetails">,
TalerHttpError
- >([oderId, session.token, "getOrderDetails"], fetcher);
+ >([oderId, state.token, "getOrderDetails"], fetcher);
if (data) return data;
if (error) return error;
@@ -68,13 +67,12 @@ export function useInstanceOrders(
args?: InstanceOrderFilter,
updatePosition: (d: string | undefined) => void = () => { },
) {
- const { state: session } = useSessionContext();
- const { lib: { instance } } = useSessionContext();
+ const { state, lib } = useSessionContext();
// const [offset, setOffset] = useState<string | undefined>(args?.position);
async function fetcher([token, o, p, r, w, d]: [AccessToken, string, boolean, boolean, boolean, AbsoluteTime]) {
- return await instance.listOrders(token, {
+ return await lib.instance.listOrders(token, {
limit: PAGINATED_LIST_REQUEST,
offset: o,
order: "dec",
@@ -88,7 +86,7 @@ export function useInstanceOrders(
const { data, error } = useSWR<
TalerMerchantManagementResultByMethod<"listOrders">,
TalerHttpError
- >([session.token, args?.position, args?.paid, args?.refunded, args?.wired, args?.date, "listOrders"], fetcher);
+ >([state.token, args?.position, args?.paid, args?.refunded, args?.wired, args?.date, "listOrders"], fetcher);
if (error) return error;
if (data === undefined) return undefined;
diff --git a/packages/merchant-backoffice-ui/src/hooks/otp.ts b/packages/merchant-backoffice-ui/src/hooks/otp.ts
index 41ed89f70..d181198db 100644
--- a/packages/merchant-backoffice-ui/src/hooks/otp.ts
+++ b/packages/merchant-backoffice-ui/src/hooks/otp.ts
@@ -28,13 +28,12 @@ export function revalidateInstanceOtpDevices() {
);
}
export function useInstanceOtpDevices() {
- const { state: session } = useSessionContext();
- const { lib: { instance } } = useSessionContext();
+ const { state, lib } = useSessionContext();
// const [offset, setOffset] = useState<string | undefined>();
async function fetcher([token, _bid]: [AccessToken, string]) {
- return await instance.listOtpDevices(token, {
+ return await lib.instance.listOtpDevices(token, {
// limit: PAGINATED_LIST_REQUEST,
// offset: bid,
// order: "dec",
@@ -44,7 +43,7 @@ export function useInstanceOtpDevices() {
const { data, error } = useSWR<
TalerMerchantManagementResultByMethod<"listOtpDevices">,
TalerHttpError
- >([session.token, "offset", "listOtpDevices"], fetcher);
+ >([state.token, "offset", "listOtpDevices"], fetcher);
if (error) return error;
if (data === undefined) return undefined;
@@ -62,17 +61,16 @@ export function revalidateOtpDeviceDetails() {
);
}
export function useOtpDeviceDetails(deviceId: string) {
- const { state: session } = useSessionContext();
- const { lib: { instance } } = useSessionContext();
+ const { state, lib } = useSessionContext();
async function fetcher([dId, token]: [string, AccessToken]) {
- return await instance.getOtpDeviceDetails(token, dId);
+ return await lib.instance.getOtpDeviceDetails(token, dId);
}
const { data, error } = useSWR<
TalerMerchantManagementResultByMethod<"getOtpDeviceDetails">,
TalerHttpError
- >([deviceId, session.token, "getOtpDeviceDetails"], fetcher);
+ >([deviceId, state.token, "getOtpDeviceDetails"], fetcher);
if (data) return data;
if (error) return error;
diff --git a/packages/merchant-backoffice-ui/src/hooks/product.ts b/packages/merchant-backoffice-ui/src/hooks/product.ts
index defda5552..50e8adc9f 100644
--- a/packages/merchant-backoffice-ui/src/hooks/product.ts
+++ b/packages/merchant-backoffice-ui/src/hooks/product.ts
@@ -36,13 +36,12 @@ export function revalidateInstanceProducts() {
);
}
export function useInstanceProducts() {
- const { state: session } = useSessionContext();
- const { lib: { instance } } = useSessionContext();
+ const { state, lib } = useSessionContext();
const [offset, setOffset] = useState<number | undefined>();
async function fetcher([token, bid]: [AccessToken, number]) {
- const list = await instance.listProducts(token, {
+ const list = await lib.instance.listProducts(token, {
limit: PAGINATED_LIST_REQUEST,
offset: bid === undefined ? undefined: String(bid),
order: "dec",
@@ -52,7 +51,7 @@ export function useInstanceProducts() {
}
const all: Array<ProductWithId | undefined> = await Promise.all(
list.body.products.map(async (c) => {
- const r = await instance.getProductDetails(token, c.product_id);
+ const r = await lib.instance.getProductDetails(token, c.product_id);
if (r.type === "fail") {
return undefined;
}
@@ -68,7 +67,7 @@ export function useInstanceProducts() {
OperationOk<{ products: ProductWithId[] }> |
TalerMerchantManagementErrorsByMethod<"listProducts">,
TalerHttpError
- >([session.token, offset, "listProductsWithId"], fetcher);
+ >([state.token, offset, "listProductsWithId"], fetcher);
if (error) return error;
if (data === undefined) return undefined;
@@ -85,17 +84,16 @@ export function revalidateProductDetails() {
);
}
export function useProductDetails(productId: string) {
- const { state: session } = useSessionContext();
- const { lib: { instance } } = useSessionContext();
+ const { state, lib } = useSessionContext();
async function fetcher([pid, token]: [string, AccessToken]) {
- return await instance.getProductDetails(token, pid);
+ return await lib.instance.getProductDetails(token, pid);
}
const { data, error } = useSWR<
TalerMerchantManagementResultByMethod<"getProductDetails">,
TalerHttpError
- >([productId, session.token, "getProductDetails"], fetcher);
+ >([productId, state.token, "getProductDetails"], fetcher);
if (data) return data;
if (error) return error;
diff --git a/packages/merchant-backoffice-ui/src/hooks/templates.ts b/packages/merchant-backoffice-ui/src/hooks/templates.ts
index 500a94a48..e4ee04f49 100644
--- a/packages/merchant-backoffice-ui/src/hooks/templates.ts
+++ b/packages/merchant-backoffice-ui/src/hooks/templates.ts
@@ -20,7 +20,6 @@ import { PAGINATED_LIST_REQUEST } from "../utils/constants.js";
import { AccessToken, TalerHttpError, TalerMerchantManagementResultByMethod } from "@gnu-taler/taler-util";
import _useSWR, { SWRHook, mutate } from "swr";
import { useSessionContext } from "../context/session.js";
-import { buildPaginatedResult } from "./webhooks.js";
const useSWR = _useSWR as unknown as SWRHook;
@@ -35,13 +34,12 @@ export function revalidateInstanceTemplates() {
);
}
export function useInstanceTemplates() {
- const { state: session } = useSessionContext();
- const { lib: { instance } } = useSessionContext();
+ const { state, lib } = useSessionContext();
- const [offset, setOffset] = useState<string | undefined>();
+ const [offset] = useState<string | undefined>();
async function fetcher([token, bid]: [AccessToken, string]) {
- return await instance.listTemplates(token, {
+ return await lib.instance.listTemplates(token, {
limit: PAGINATED_LIST_REQUEST,
offset: bid,
order: "dec",
@@ -51,7 +49,7 @@ export function useInstanceTemplates() {
const { data, error } = useSWR<
TalerMerchantManagementResultByMethod<"listTemplates">,
TalerHttpError
- >([session.token, offset, "listTemplates"], fetcher);
+ >([state.token, offset, "listTemplates"], fetcher);
if (error) return error;
if (data === undefined) return undefined;
@@ -70,17 +68,16 @@ export function revalidateTemplateDetails() {
);
}
export function useTemplateDetails(templateId: string) {
- const { state: session } = useSessionContext();
- const { lib: { instance } } = useSessionContext();
+ const { state, lib } = useSessionContext();
async function fetcher([tid, token]: [string, AccessToken]) {
- return await instance.getTemplateDetails(token, tid);
+ return await lib.instance.getTemplateDetails(token, tid);
}
const { data, error } = useSWR<
TalerMerchantManagementResultByMethod<"getTemplateDetails">,
TalerHttpError
- >([templateId, session.token, "getTemplateDetails"], fetcher);
+ >([templateId, state.token, "getTemplateDetails"], fetcher);
if (data) return data;
if (error) return error;
diff --git a/packages/merchant-backoffice-ui/src/hooks/tokenfamily.ts b/packages/merchant-backoffice-ui/src/hooks/tokenfamily.ts
index e0b0293d3..e0241031f 100644
--- a/packages/merchant-backoffice-ui/src/hooks/tokenfamily.ts
+++ b/packages/merchant-backoffice-ui/src/hooks/tokenfamily.ts
@@ -21,12 +21,12 @@ import _useSWR, { SWRHook } from "swr";
const useSWR = _useSWR as unknown as SWRHook;
export function useInstanceTokenFamilies() {
- const { state: session, lib: { instance } } = useSessionContext();
+ const { state, lib } = useSessionContext();
// const [offset, setOffset] = useState<number | undefined>();
- async function fetcher([token, bid]: [AccessToken, number]) {
- return await instance.listTokenFamilies(token, {
+ async function fetcher([token, _bid]: [AccessToken, number]) {
+ return await lib.instance.listTokenFamilies(token, {
// limit: PAGINATED_LIST_REQUEST,
// offset: bid === undefined ? undefined: String(bid),
// order: "dec",
@@ -36,7 +36,7 @@ export function useInstanceTokenFamilies() {
const { data, error } = useSWR<
TalerMerchantManagementResultByMethod<"listTokenFamilies">,
TalerHttpError
- >([session.token, "offset", "listTokenFamilies"], fetcher);
+ >([state.token, "offset", "listTokenFamilies"], fetcher);
if (error) return error;
if (data === undefined) return undefined;
@@ -46,17 +46,16 @@ export function useInstanceTokenFamilies() {
}
export function useTokenFamilyDetails(tokenFamilySlug: string) {
- const { state: session } = useSessionContext();
- const { lib: { instance } } = useSessionContext();
+ const { state, lib } = useSessionContext();
async function fetcher([slug, token]: [string, AccessToken]) {
- return await instance.getTokenFamilyDetails(token, slug);
+ return await lib.instance.getTokenFamilyDetails(token, slug);
}
const { data, error } = useSWR<
TalerMerchantManagementResultByMethod<"getTokenFamilyDetails">,
TalerHttpError
- >([tokenFamilySlug, session.token, "getTokenFamilyDetails"], fetcher);
+ >([tokenFamilySlug, state.token, "getTokenFamilyDetails"], fetcher);
if (error) return error;
if (data === undefined) return undefined;
diff --git a/packages/merchant-backoffice-ui/src/hooks/transfer.ts b/packages/merchant-backoffice-ui/src/hooks/transfer.ts
index 6f77369c2..02d91c496 100644
--- a/packages/merchant-backoffice-ui/src/hooks/transfer.ts
+++ b/packages/merchant-backoffice-ui/src/hooks/transfer.ts
@@ -39,13 +39,12 @@ export function useInstanceTransfers(
args?: InstanceTransferFilter,
updatePosition: (id: string | undefined) => void = (() => { }),
) {
- const { state: session } = useSessionContext();
- const { lib: { instance } } = useSessionContext();
+ const { state, lib } = useSessionContext();
// const [offset, setOffset] = useState<string | undefined>(args?.position);
async function fetcher([token, o, p, v]: [AccessToken, string, string, boolean]) {
- return await instance.listWireTransfers(token, {
+ return await lib.instance.listWireTransfers(token, {
paytoURI: p,
verified: v,
limit: PAGINATED_LIST_REQUEST,
@@ -57,7 +56,7 @@ export function useInstanceTransfers(
const { data, error } = useSWR<
TalerMerchantManagementResultByMethod<"listWireTransfers">,
TalerHttpError
- >([session.token, args?.position, args?.payto_uri, args?.verified, "listWireTransfers"], fetcher);
+ >([state.token, args?.position, args?.payto_uri, args?.verified, "listWireTransfers"], fetcher);
if (error) return error;
if (data === undefined) return undefined;
diff --git a/packages/merchant-backoffice-ui/src/hooks/webhooks.ts b/packages/merchant-backoffice-ui/src/hooks/webhooks.ts
index fe37162aa..3c3744b33 100644
--- a/packages/merchant-backoffice-ui/src/hooks/webhooks.ts
+++ b/packages/merchant-backoffice-ui/src/hooks/webhooks.ts
@@ -32,13 +32,12 @@ export function revalidateInstanceWebhooks() {
);
}
export function useInstanceWebhooks() {
- const { state: session } = useSessionContext();
- const { lib: { instance } } = useSessionContext();
+ const { state, lib } = useSessionContext();
// const [offset, setOffset] = useState<string | undefined>();
async function fetcher([token, _bid]: [AccessToken, string]) {
- return await instance.listWebhooks(token, {
+ return await lib.instance.listWebhooks(token, {
// limit: PAGINATED_LIST_REQUEST,
// offset: bid,
// order: "dec",
@@ -48,7 +47,7 @@ export function useInstanceWebhooks() {
const { data, error } = useSWR<
TalerMerchantManagementResultByMethod<"listWebhooks">,
TalerHttpError
- >([session.token, "offset", "listWebhooks"], fetcher);
+ >([state.token, "offset", "listWebhooks"], fetcher);
if (error) return error;
if (data === undefined) return undefined;
@@ -100,17 +99,16 @@ export function revalidateWebhookDetails() {
);
}
export function useWebhookDetails(webhookId: string) {
- const { state: session } = useSessionContext();
- const { lib: { instance } } = useSessionContext();
+ const { state, lib } = useSessionContext();
async function fetcher([hookId, token]: [string, AccessToken]) {
- return await instance.getWebhookDetails(token, hookId);
+ return await lib.instance.getWebhookDetails(token, hookId);
}
const { data, error } = useSWR<
TalerMerchantManagementResultByMethod<"getWebhookDetails">,
TalerHttpError
- >([webhookId, session.token, "getWebhookDetails"], fetcher);
+ >([webhookId, state.token, "getWebhookDetails"], fetcher);
if (data) return data;
if (error) return error;