From d58945c830a33910dd93bc159c1ffe5d490df846 Mon Sep 17 00:00:00 2001
From: Sebastian <sebasjm@gmail.com>
Date: Wed, 16 Jun 2021 17:17:12 -0300
Subject: split wallet/popup components. created hooks, components, context
 folder

---
 .../src/hooks/useExtendedPermissions.tsx           | 24 ++++++++++++++++++++++
 1 file changed, 24 insertions(+)
 create mode 100644 packages/taler-wallet-webextension/src/hooks/useExtendedPermissions.tsx

(limited to 'packages/taler-wallet-webextension/src/hooks/useExtendedPermissions.tsx')

diff --git a/packages/taler-wallet-webextension/src/hooks/useExtendedPermissions.tsx b/packages/taler-wallet-webextension/src/hooks/useExtendedPermissions.tsx
new file mode 100644
index 000000000..f5c788cf6
--- /dev/null
+++ b/packages/taler-wallet-webextension/src/hooks/useExtendedPermissions.tsx
@@ -0,0 +1,24 @@
+import { useState, useEffect } from "preact/hooks";
+import * as wxApi from "../wxApi";
+import { handleExtendedPerm } from "../wallet/welcome";
+
+
+export function useExtendedPermissions(): [boolean, () => void] {
+  const [enabled, setEnabled] = useState(false);
+
+  const toggle = () => {
+    setEnabled(v => !v);
+    handleExtendedPerm(enabled).then(result => {
+      setEnabled(result);
+    });
+  };
+
+  useEffect(() => {
+    async function getExtendedPermValue(): Promise<void> {
+      const res = await wxApi.getExtendedPermissions();
+      setEnabled(res.newValue);
+    }
+    getExtendedPermValue();
+  }, []);
+  return [enabled, toggle];
+}
-- 
cgit v1.2.3

