diff options
author | Sebastian <sebasjm@gmail.com> | 2022-12-15 17:11:24 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2022-12-15 17:11:24 -0300 |
commit | f93bd51499ed34844b666bf6d333227adf4368bf (patch) | |
tree | ed3cf0c38b7db54276436d1743a6085c94f71977 /packages/taler-wallet-webextension/src/hooks/useWalletDevMode.ts | |
parent | 8d8d71807df6b775e5b0335eb1b2526a56d42ac6 (diff) | |
download | wallet-core-f93bd51499ed34844b666bf6d333227adf4368bf.tar.xz |
wxApi from context and using the new testing sdk
Diffstat (limited to 'packages/taler-wallet-webextension/src/hooks/useWalletDevMode.ts')
-rw-r--r-- | packages/taler-wallet-webextension/src/hooks/useWalletDevMode.ts | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/packages/taler-wallet-webextension/src/hooks/useWalletDevMode.ts b/packages/taler-wallet-webextension/src/hooks/useWalletDevMode.ts index d5743eb2e..6ae55da61 100644 --- a/packages/taler-wallet-webextension/src/hooks/useWalletDevMode.ts +++ b/packages/taler-wallet-webextension/src/hooks/useWalletDevMode.ts @@ -15,22 +15,24 @@ */ import { useState, useEffect } from "preact/hooks"; -import { wxApi } from "../wxApi.js"; import { ToggleHandler } from "../mui/handlers.js"; import { TalerError, WalletApiOperation } from "@gnu-taler/taler-wallet-core"; +import { useBackendContext } from "../context/backend.js"; export function useWalletDevMode(): ToggleHandler { const [enabled, setEnabled] = useState<undefined | boolean>(undefined); const [error, setError] = useState<TalerError | undefined>(); + const api = useBackendContext(); + const toggle = async (): Promise<void> => { - return handleOpen(enabled, setEnabled).catch((e) => { + return handleOpen(enabled, setEnabled, api).catch((e) => { setError(TalerError.fromException(e)); }); }; useEffect(() => { async function getValue(): Promise<void> { - const res = await wxApi.wallet.call(WalletApiOperation.GetVersion, {}); + const res = await api.wallet.call(WalletApiOperation.GetVersion, {}); setEnabled(res.devMode); } getValue(); @@ -47,9 +49,10 @@ export function useWalletDevMode(): ToggleHandler { async function handleOpen( currentValue: undefined | boolean, onChange: (value: boolean) => void, + api: ReturnType<typeof useBackendContext>, ): Promise<void> { const nextValue = !currentValue; - await wxApi.wallet.call(WalletApiOperation.SetDevMode, { + await api.wallet.call(WalletApiOperation.SetDevMode, { devModeEnabled: nextValue, }); onChange(nextValue); |