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/context | |
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/context')
-rw-r--r-- | packages/taler-wallet-webextension/src/context/backend.ts | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/packages/taler-wallet-webextension/src/context/backend.ts b/packages/taler-wallet-webextension/src/context/backend.ts new file mode 100644 index 000000000..3e9e1f0ab --- /dev/null +++ b/packages/taler-wallet-webextension/src/context/backend.ts @@ -0,0 +1,53 @@ +/* + This file is part of GNU Taler + (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 + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + 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/> + */ + +/** + * + * @author Sebastian Javier Marchano (sebasjm) + */ + +import { ComponentChildren, createContext, h, VNode } from "preact"; +import { useContext } from "preact/hooks"; +import { wxApi, WxApiType } from "../wxApi.js"; + +type Type = WxApiType + +const initial = wxApi; + +const Context = createContext<Type>(initial); + +type Props = Partial<WxApiType> & { + children: ComponentChildren; +} + +export const BackendProvider = ({ + wallet, + background, + listener, + children, +}: Props): VNode => { + + return h(Context.Provider, { + value: { + wallet: wallet ?? initial.wallet, + background: background ?? initial.background, + listener: listener ?? initial.listener + }, + children, + }); +}; + +export const useBackendContext = (): Type => useContext(Context); |