diff options
Diffstat (limited to 'packages/merchant-backoffice-ui/src/hooks/otp.ts')
-rw-r--r-- | packages/merchant-backoffice-ui/src/hooks/otp.ts | 45 |
1 files changed, 15 insertions, 30 deletions
diff --git a/packages/merchant-backoffice-ui/src/hooks/otp.ts b/packages/merchant-backoffice-ui/src/hooks/otp.ts index 76ece7055..4b45dcf06 100644 --- a/packages/merchant-backoffice-ui/src/hooks/otp.ts +++ b/packages/merchant-backoffice-ui/src/hooks/otp.ts @@ -20,35 +20,20 @@ import { RequestError, } from "@gnu-taler/web-util/browser"; import { useEffect, useState } from "preact/hooks"; -import { MerchantBackend } from "../declaration.js"; 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 } from "swr"; const useSWR = _useSWR as unknown as SWRHook; -const MOCKED_DEVICES: Record<string, MerchantBackend.OTP.OtpDeviceAddDetails> = { - "1": { - otp_device_description: "first device", - otp_algorithm: 1, - otp_device_id: "1", - otp_key: "123", - }, - "2": { - otp_device_description: "second device", - otp_algorithm: 0, - otp_device_id: "2", - otp_key: "456", - } -} - export function useOtpDeviceAPI(): OtpDeviceAPI { const mutateAll = useMatchMutate(); const { request } = useBackendInstanceRequest(); const createOtpDevice = async ( - data: MerchantBackend.OTP.OtpDeviceAddDetails, + data: TalerMerchantApi.OtpDeviceAddDetails, ): Promise<HttpResponseOk<void>> => { // MOCKED_DEVICES[data.otp_device_id] = data // return Promise.resolve({ ok: true, data: undefined }); @@ -62,7 +47,7 @@ export function useOtpDeviceAPI(): OtpDeviceAPI { const updateOtpDevice = async ( deviceId: string, - data: MerchantBackend.OTP.OtpDevicePatchDetails, + data: TalerMerchantApi.OtpDevicePatchDetails, ): Promise<HttpResponseOk<void>> => { // MOCKED_DEVICES[deviceId].otp_algorithm = data.otp_algorithm // MOCKED_DEVICES[deviceId].otp_ctr = data.otp_ctr @@ -98,11 +83,11 @@ export function useOtpDeviceAPI(): OtpDeviceAPI { export interface OtpDeviceAPI { createOtpDevice: ( - data: MerchantBackend.OTP.OtpDeviceAddDetails, + data: TalerMerchantApi.OtpDeviceAddDetails, ) => Promise<HttpResponseOk<void>>; updateOtpDevice: ( id: string, - data: MerchantBackend.OTP.OtpDevicePatchDetails, + data: TalerMerchantApi.OtpDevicePatchDetails, ) => Promise<HttpResponseOk<void>>; deleteOtpDevice: (id: string) => Promise<HttpResponseOk<void>>; } @@ -114,8 +99,8 @@ export function useInstanceOtpDevices( args?: InstanceOtpDeviceFilter, updatePosition?: (id: string) => void, ): HttpResponsePaginated< - MerchantBackend.OTP.OtpDeviceSummaryResponse, - MerchantBackend.ErrorDetail + TalerMerchantApi.OtpDeviceSummaryResponse, + TalerErrorDetail > { // return { // ok: true, @@ -139,14 +124,14 @@ export function useInstanceOtpDevices( error: afterError, isValidating: loadingAfter, } = useSWR< - HttpResponseOk<MerchantBackend.OTP.OtpDeviceSummaryResponse>, - RequestError<MerchantBackend.ErrorDetail> + HttpResponseOk<TalerMerchantApi.OtpDeviceSummaryResponse>, + RequestError<TalerErrorDetail> >([`/private/otp-devices`], fetcher); const [lastAfter, setLastAfter] = useState< HttpResponse< - MerchantBackend.OTP.OtpDeviceSummaryResponse, - MerchantBackend.ErrorDetail + TalerMerchantApi.OtpDeviceSummaryResponse, + TalerErrorDetail > >({ loading: true }); useEffect(() => { @@ -190,8 +175,8 @@ export function useInstanceOtpDevices( export function useOtpDeviceDetails( deviceId: string, ): HttpResponse< - MerchantBackend.OTP.OtpDeviceDetails, - MerchantBackend.ErrorDetail + TalerMerchantApi.OtpDeviceDetails, + TalerErrorDetail > { // return { // ok: true, @@ -204,8 +189,8 @@ export function useOtpDeviceDetails( const { fetcher } = useBackendInstanceRequest(); const { data, error, isValidating } = useSWR< - HttpResponseOk<MerchantBackend.OTP.OtpDeviceDetails>, - RequestError<MerchantBackend.ErrorDetail> + HttpResponseOk<TalerMerchantApi.OtpDeviceDetails>, + RequestError<TalerErrorDetail> >([`/private/otp-devices/${deviceId}`], fetcher, { refreshInterval: 0, refreshWhenHidden: false, |