diff options
Diffstat (limited to 'packages/taler-wallet-webextension/src/hooks/useProviderStatus.ts')
-rw-r--r-- | packages/taler-wallet-webextension/src/hooks/useProviderStatus.ts | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/packages/taler-wallet-webextension/src/hooks/useProviderStatus.ts b/packages/taler-wallet-webextension/src/hooks/useProviderStatus.ts index 6520848a5..e2ba5b285 100644 --- a/packages/taler-wallet-webextension/src/hooks/useProviderStatus.ts +++ b/packages/taler-wallet-webextension/src/hooks/useProviderStatus.ts @@ -1,6 +1,6 @@ /* This file is part of GNU Taler - (C) 2021 Taler Systems S.A. + (C) 2022 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 @@ -14,9 +14,10 @@ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ -import { ProviderInfo } from "@gnu-taler/taler-wallet-core"; +import { ProviderInfo } from "@gnu-taler/taler-util"; +import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { useEffect, useState } from "preact/hooks"; -import * as wxApi from "../wxApi"; +import { useBackendContext } from "../context/backend.js"; export interface ProviderStatus { info?: ProviderInfo; @@ -26,31 +27,40 @@ export interface ProviderStatus { export function useProviderStatus(url: string): ProviderStatus | undefined { const [status, setStatus] = useState<ProviderStatus | undefined>(undefined); - + const api = useBackendContext(); useEffect(() => { - async function run() { + async function run(): Promise<void> { //create a first list of backup info by currency - const status = await wxApi.getBackupInfo(); + const status = await api.wallet.call( + WalletApiOperation.GetBackupInfo, + {}, + ); - const providers = status.providers.filter(p => p.syncProviderBaseUrl === url); + const providers = status.providers.filter( + (p) => p.syncProviderBaseUrl === url, + ); const info = providers.length ? providers[0] : undefined; - async function sync() { + async function sync(): Promise<void> { if (info) { - await wxApi.syncOneProvider(info.syncProviderBaseUrl); + await api.wallet.call(WalletApiOperation.RunBackupCycle, { + providers: [info.syncProviderBaseUrl], + }); } } - async function remove() { + async function remove(): Promise<void> { if (info) { - await wxApi.removeProvider(info.syncProviderBaseUrl); + await api.wallet.call(WalletApiOperation.RemoveBackupProvider, { + provider: info.syncProviderBaseUrl, + }); } } setStatus({ info, sync, remove }); } run(); - }, []); + }); return status; } |