diff options
Diffstat (limited to 'packages/taler-wallet-webextension/src/hooks/useExtendedPermissions.tsx')
-rw-r--r-- | packages/taler-wallet-webextension/src/hooks/useExtendedPermissions.tsx | 24 |
1 files changed, 24 insertions, 0 deletions
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]; +} |