diff options
author | Sebastian <sebasjm@gmail.com> | 2022-10-25 12:23:08 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2022-10-25 19:19:09 -0300 |
commit | a286649b0a611d87916a178a795c1acd2917741c (patch) | |
tree | 86d0a8eefb791ffebc877a88d6876d1ff764cf2b /packages/taler-wallet-webextension/src/hooks | |
parent | 5fcd434f662bcef7e9e043763766c8b104ad6b97 (diff) | |
download | wallet-core-a286649b0a611d87916a178a795c1acd2917741c.tar.xz |
cherry-pick: using new wallet typed api missing test
Diffstat (limited to 'packages/taler-wallet-webextension/src/hooks')
8 files changed, 38 insertions, 34 deletions
diff --git a/packages/taler-wallet-webextension/src/hooks/useAsyncAsHook.ts b/packages/taler-wallet-webextension/src/hooks/useAsyncAsHook.ts index f24896bf3..1b2929317 100644 --- a/packages/taler-wallet-webextension/src/hooks/useAsyncAsHook.ts +++ b/packages/taler-wallet-webextension/src/hooks/useAsyncAsHook.ts @@ -13,10 +13,9 @@ 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 { NotificationType, TalerErrorDetail } from "@gnu-taler/taler-util"; +import { TalerErrorDetail } from "@gnu-taler/taler-util"; import { TalerError } from "@gnu-taler/taler-wallet-core"; import { useEffect, useMemo, useState } from "preact/hooks"; -import * as wxApi from "../wxApi.js"; export interface HookOk<T> { hasError: false; diff --git a/packages/taler-wallet-webextension/src/hooks/useAutoOpenPermissions.ts b/packages/taler-wallet-webextension/src/hooks/useAutoOpenPermissions.ts index 727d653af..5a0194db8 100644 --- a/packages/taler-wallet-webextension/src/hooks/useAutoOpenPermissions.ts +++ b/packages/taler-wallet-webextension/src/hooks/useAutoOpenPermissions.ts @@ -14,11 +14,11 @@ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ -import { useState, useEffect } from "preact/hooks"; -import * as wxApi from "../wxApi.js"; -import { platform } from "../platform/api.js"; -import { ToggleHandler } from "../mui/handlers.js"; import { TalerError } from "@gnu-taler/taler-wallet-core"; +import { useEffect, useState } from "preact/hooks"; +import { ToggleHandler } from "../mui/handlers.js"; +import { platform } from "../platform/api.js"; +import { wxApi } from "../wxApi.js"; export function useAutoOpenPermissions(): ToggleHandler { const [enabled, setEnabled] = useState(false); @@ -31,7 +31,7 @@ export function useAutoOpenPermissions(): ToggleHandler { useEffect(() => { async function getValue(): Promise<void> { - const res = await wxApi.containsHeaderListener(); + const res = await wxApi.background.containsHeaderListener(); setEnabled(res.newValue); } getValue(); @@ -59,11 +59,11 @@ async function handleAutoOpenPerm( onChange(false); throw lastError; } - const res = await wxApi.toggleHeaderListener(granted); + const res = await wxApi.background.toggleHeaderListener(granted); onChange(res.newValue); } else { try { - await wxApi.toggleHeaderListener(false).then((r) => onChange(r.newValue)); + await wxApi.background.toggleHeaderListener(false).then((r) => onChange(r.newValue)); } catch (e) { console.log(e); } diff --git a/packages/taler-wallet-webextension/src/hooks/useBackupDeviceName.ts b/packages/taler-wallet-webextension/src/hooks/useBackupDeviceName.ts index da3b05df4..7339a876a 100644 --- a/packages/taler-wallet-webextension/src/hooks/useBackupDeviceName.ts +++ b/packages/taler-wallet-webextension/src/hooks/useBackupDeviceName.ts @@ -14,8 +14,9 @@ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ +import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { useEffect, useState } from "preact/hooks"; -import * as wxApi from "../wxApi.js"; +import { wxApi } from "../wxApi.js"; export interface BackupDeviceName { name: string; @@ -31,10 +32,10 @@ export function useBackupDeviceName(): BackupDeviceName { useEffect(() => { async function run(): Promise<void> { //create a first list of backup info by currency - const status = await wxApi.getBackupInfo(); + const status = await wxApi.wallet.call(WalletApiOperation.GetBackupInfo, {}); async function update(newName: string): Promise<void> { - await wxApi.setWalletDeviceId(newName); + await wxApi.wallet.call(WalletApiOperation.SetWalletDeviceId, { walletDeviceId: newName }); setStatus((old) => ({ ...old, name: newName })); } diff --git a/packages/taler-wallet-webextension/src/hooks/useClipboardPermissions.ts b/packages/taler-wallet-webextension/src/hooks/useClipboardPermissions.ts index 3e9629dcb..3d284fb5a 100644 --- a/packages/taler-wallet-webextension/src/hooks/useClipboardPermissions.ts +++ b/packages/taler-wallet-webextension/src/hooks/useClipboardPermissions.ts @@ -14,11 +14,11 @@ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ -import { useState, useEffect } from "preact/hooks"; -import * as wxApi from "../wxApi.js"; -import { platform } from "../platform/api.js"; -import { ToggleHandler } from "../mui/handlers.js"; import { TalerError } from "@gnu-taler/taler-wallet-core"; +import { useEffect, useState } from "preact/hooks"; +import { ToggleHandler } from "../mui/handlers.js"; +import { platform } from "../platform/api.js"; +import { wxApi } from "../wxApi.js"; export function useClipboardPermissions(): ToggleHandler { const [enabled, setEnabled] = useState(false); @@ -31,7 +31,7 @@ export function useClipboardPermissions(): ToggleHandler { useEffect(() => { async function getValue(): Promise<void> { - const res = await wxApi.containsHeaderListener(); + const res = await wxApi.background.containsHeaderListener(); setEnabled(res.newValue); } getValue(); @@ -66,7 +66,7 @@ async function handleClipboardPerm( onChange(granted); } else { try { - await wxApi.toggleHeaderListener(false).then((r) => onChange(r.newValue)); + await wxApi.background.toggleHeaderListener(false).then((r) => onChange(r.newValue)); } catch (e) { console.log(e); } diff --git a/packages/taler-wallet-webextension/src/hooks/useDiagnostics.ts b/packages/taler-wallet-webextension/src/hooks/useDiagnostics.ts index a61fe7965..a8564fddb 100644 --- a/packages/taler-wallet-webextension/src/hooks/useDiagnostics.ts +++ b/packages/taler-wallet-webextension/src/hooks/useDiagnostics.ts @@ -16,7 +16,7 @@ import { WalletDiagnostics } from "@gnu-taler/taler-util"; import { useEffect, useState } from "preact/hooks"; -import * as wxApi from "../wxApi.js"; +import { wxApi } from "../wxApi.js"; export function useDiagnostics(): [WalletDiagnostics | undefined, boolean] { const [timedOut, setTimedOut] = useState(false); @@ -33,7 +33,7 @@ export function useDiagnostics(): [WalletDiagnostics | undefined, boolean] { } }, 1000); const doFetch = async (): Promise<void> => { - const d = await wxApi.getDiagnostics(); + const d = await wxApi.background.getDiagnostics(); gotDiagnostics = true; setDiagnostics(d); }; diff --git a/packages/taler-wallet-webextension/src/hooks/useProviderStatus.ts b/packages/taler-wallet-webextension/src/hooks/useProviderStatus.ts index 187517b41..b73c9fc16 100644 --- a/packages/taler-wallet-webextension/src/hooks/useProviderStatus.ts +++ b/packages/taler-wallet-webextension/src/hooks/useProviderStatus.ts @@ -14,9 +14,9 @@ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ -import { ProviderInfo } from "@gnu-taler/taler-wallet-core"; +import { ProviderInfo, WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { useEffect, useState } from "preact/hooks"; -import * as wxApi from "../wxApi.js"; +import { wxApi } from "../wxApi.js"; export interface ProviderStatus { info?: ProviderInfo; @@ -30,7 +30,7 @@ export function useProviderStatus(url: string): ProviderStatus | undefined { useEffect(() => { async function run(): Promise<void> { //create a first list of backup info by currency - const status = await wxApi.getBackupInfo(); + const status = await wxApi.wallet.call(WalletApiOperation.GetBackupInfo, {}); const providers = status.providers.filter( (p) => p.syncProviderBaseUrl === url, @@ -39,13 +39,17 @@ export function useProviderStatus(url: string): ProviderStatus | undefined { async function sync(): Promise<void> { if (info) { - await wxApi.syncOneProvider(info.syncProviderBaseUrl); + await wxApi.wallet.call(WalletApiOperation.RunBackupCycle, { + providers: [info.syncProviderBaseUrl] + }); } } async function remove(): Promise<void> { if (info) { - await wxApi.removeProvider(info.syncProviderBaseUrl); + await wxApi.wallet.call(WalletApiOperation.RemoveBackupProvider, { + provider: info.syncProviderBaseUrl + }); } } diff --git a/packages/taler-wallet-webextension/src/hooks/useTalerActionURL.test.ts b/packages/taler-wallet-webextension/src/hooks/useTalerActionURL.test.ts index a7ad3e81b..8aabb8adf 100644 --- a/packages/taler-wallet-webextension/src/hooks/useTalerActionURL.test.ts +++ b/packages/taler-wallet-webextension/src/hooks/useTalerActionURL.test.ts @@ -31,18 +31,18 @@ describe("useTalerActionURL hook", () => { }); }; - const { getLastResultOrThrow, waitNextUpdate, assertNoPendingUpdate } = + const { pullLastResultOrThrow, waitForStateUpdate, assertNoPendingUpdate } = mountHook(useTalerActionURL, ctx); { - const [url] = getLastResultOrThrow(); + const [url] = pullLastResultOrThrow(); expect(url).undefined; } - await waitNextUpdate("waiting for useEffect"); + expect(await waitForStateUpdate()).true; { - const [url, setDismissed] = getLastResultOrThrow(); + const [url, setDismissed] = pullLastResultOrThrow(); expect(url).deep.equals({ location: "clipboard", uri: "qwe", @@ -50,10 +50,10 @@ describe("useTalerActionURL hook", () => { setDismissed(true); } - await waitNextUpdate("after dismiss"); + expect(await waitForStateUpdate()).true; { - const [url] = getLastResultOrThrow(); + const [url] = pullLastResultOrThrow(); if (url !== undefined) throw Error("invalid"); expect(url).undefined; } diff --git a/packages/taler-wallet-webextension/src/hooks/useWalletDevMode.ts b/packages/taler-wallet-webextension/src/hooks/useWalletDevMode.ts index 8021db686..8d4921392 100644 --- a/packages/taler-wallet-webextension/src/hooks/useWalletDevMode.ts +++ b/packages/taler-wallet-webextension/src/hooks/useWalletDevMode.ts @@ -15,7 +15,7 @@ */ import { useState, useEffect } from "preact/hooks"; -import { wxClient } from "../wxApi.js"; +import { wxApi } from "../wxApi.js"; import { ToggleHandler } from "../mui/handlers.js"; import { TalerError, WalletApiOperation } from "@gnu-taler/taler-wallet-core"; @@ -30,7 +30,7 @@ export function useWalletDevMode(): ToggleHandler { useEffect(() => { async function getValue(): Promise<void> { - const res = await wxClient.call(WalletApiOperation.GetVersion, {}); + const res = await wxApi.wallet.call(WalletApiOperation.GetVersion, {}); setEnabled(res.devMode); } getValue(); @@ -49,7 +49,7 @@ async function handleOpen( onChange: (value: boolean) => void, ): Promise<void> { const nextValue = !currentValue - await wxClient.call(WalletApiOperation.SetDevMode, { devModeEnabled: nextValue }); + await wxApi.wallet.call(WalletApiOperation.SetDevMode, { devModeEnabled: nextValue }); onChange(nextValue); return; } |