From 6e060da237af35796b1b34dce108f05eef44ceb3 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Fri, 14 Apr 2023 14:16:08 -0300 Subject: some changes using transaction context from web utils alertContext.safely api change (easier to integrate) using lang and localstorage from web utils removing auto permission, from UI adding settings --- .../src/NavigationBar.tsx | 2 +- .../src/components/AmountField.stories.tsx | 2 +- .../src/components/AmountField.tsx | 2 +- .../src/components/BankDetailsByPaytoType.tsx | 2 +- .../src/components/CurrentAlerts.tsx | 2 +- .../src/components/Diagnostics.tsx | 2 +- .../src/components/EditableText.tsx | 2 +- .../src/components/Loading.tsx | 2 +- .../src/components/Part.tsx | 2 +- .../src/components/PaymentButtons.tsx | 2 +- .../src/components/PendingTransactions.tsx | 2 +- .../src/components/ProductList.tsx | 2 +- .../src/components/SelectList.tsx | 2 +- .../src/components/ShowFullContractTermPopup.tsx | 2 +- .../src/components/TermsOfService/state.ts | 2 +- .../src/components/TermsOfService/views.tsx | 2 +- .../src/components/TransactionItem.tsx | 2 +- .../taler-wallet-webextension/src/context/alert.ts | 11 +-- .../src/context/translation.ts | 92 ---------------------- .../src/cta/Deposit/state.ts | 2 +- .../src/cta/Deposit/views.tsx | 2 +- .../src/cta/InvoiceCreate/state.ts | 2 +- .../src/cta/InvoiceCreate/views.tsx | 2 +- .../src/cta/InvoicePay/state.ts | 2 +- .../src/cta/InvoicePay/views.tsx | 2 +- .../src/cta/Payment/state.ts | 2 +- .../src/cta/Payment/test.ts | 2 +- .../src/cta/Payment/views.tsx | 2 +- .../src/cta/PaymentTemplate/state.ts | 4 +- .../src/cta/PaymentTemplate/test.ts | 2 +- .../src/cta/PaymentTemplate/views.tsx | 2 +- .../src/cta/Recovery/state.ts | 2 +- .../src/cta/Recovery/views.tsx | 2 +- .../src/cta/Refund/state.ts | 2 +- .../src/cta/Refund/test.ts | 2 +- .../src/cta/Refund/views.tsx | 2 +- .../taler-wallet-webextension/src/cta/Tip/state.ts | 2 +- .../taler-wallet-webextension/src/cta/Tip/test.ts | 2 +- .../src/cta/Tip/views.tsx | 2 +- .../src/cta/TransferCreate/state.ts | 2 +- .../src/cta/TransferCreate/views.tsx | 2 +- .../src/cta/TransferPickup/state.ts | 2 +- .../src/cta/TransferPickup/views.tsx | 2 +- .../src/cta/Withdraw/state.ts | 2 +- .../src/cta/Withdraw/test.ts | 2 +- .../src/cta/Withdraw/views.tsx | 2 +- .../src/hooks/useAutoOpenPermissions.ts | 70 ---------------- .../taler-wallet-webextension/src/hooks/useLang.ts | 31 -------- .../src/hooks/useLocalStorage.ts | 83 ------------------- .../src/hooks/useSettings.ts | 51 ++++++++++++ .../src/mui/Typography.tsx | 2 +- .../src/popup/Application.tsx | 5 +- .../src/popup/BalancePage.tsx | 2 +- .../src/popup/NoBalanceHelp.tsx | 2 +- .../src/popup/TalerActionFound.tsx | 2 +- .../taler-wallet-webextension/src/test-utils.ts | 11 ++- .../src/wallet/AddBackupProvider/test.ts | 2 +- .../src/wallet/AddBackupProvider/views.tsx | 2 +- .../src/wallet/AddNewActionView.tsx | 2 +- .../src/wallet/Application.tsx | 5 +- .../src/wallet/BackupPage.tsx | 2 +- .../src/wallet/DepositPage/state.ts | 2 +- .../src/wallet/DepositPage/test.ts | 2 +- .../src/wallet/DepositPage/views.tsx | 2 +- .../src/wallet/DestinationSelection/state.ts | 2 +- .../src/wallet/DestinationSelection/test.ts | 2 +- .../src/wallet/DestinationSelection/views.tsx | 2 +- .../src/wallet/DeveloperPage.tsx | 2 +- .../src/wallet/EmptyComponentExample/views.tsx | 2 +- .../src/wallet/ExchangeAddConfirm.tsx | 2 +- .../src/wallet/ExchangeSelection/state.ts | 2 +- .../src/wallet/ExchangeSelection/views.tsx | 2 +- .../src/wallet/ExchangeSetUrl.tsx | 2 +- .../src/wallet/History.tsx | 2 +- .../src/wallet/ManageAccount/state.ts | 2 +- .../src/wallet/ManageAccount/views.tsx | 2 +- .../src/wallet/Notifications/state.ts | 2 +- .../src/wallet/Notifications/views.tsx | 2 +- .../src/wallet/ProviderAddPage.tsx | 2 +- .../src/wallet/ProviderDetailPage.tsx | 2 +- .../src/wallet/QrReader.tsx | 2 +- .../src/wallet/ReserveCreated.tsx | 2 +- .../src/wallet/Settings.tsx | 65 +++++++-------- .../src/wallet/Transaction.tsx | 21 ++--- .../src/wallet/Welcome.tsx | 28 ++++--- packages/taler-wallet-webextension/tsconfig.json | 3 - 86 files changed, 200 insertions(+), 424 deletions(-) delete mode 100644 packages/taler-wallet-webextension/src/context/translation.ts delete mode 100644 packages/taler-wallet-webextension/src/hooks/useAutoOpenPermissions.ts delete mode 100644 packages/taler-wallet-webextension/src/hooks/useLang.ts delete mode 100644 packages/taler-wallet-webextension/src/hooks/useLocalStorage.ts create mode 100644 packages/taler-wallet-webextension/src/hooks/useSettings.ts (limited to 'packages/taler-wallet-webextension') diff --git a/packages/taler-wallet-webextension/src/NavigationBar.tsx b/packages/taler-wallet-webextension/src/NavigationBar.tsx index b73704c70..d6b22ba28 100644 --- a/packages/taler-wallet-webextension/src/NavigationBar.tsx +++ b/packages/taler-wallet-webextension/src/NavigationBar.tsx @@ -33,12 +33,12 @@ import { SvgIcon, } from "./components/styled/index.js"; import { useBackendContext } from "./context/backend.js"; -import { useTranslationContext } from "./context/translation.js"; import { useAsyncAsHook } from "./hooks/useAsyncAsHook.js"; import qrIcon from "./svg/qr_code_24px.svg"; import settingsIcon from "./svg/settings_black_24dp.svg"; import warningIcon from "./svg/warning_24px.svg"; import { parseTalerUri, TalerUriAction } from "@gnu-taler/taler-util"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; /** * List of pages used by the wallet diff --git a/packages/taler-wallet-webextension/src/components/AmountField.stories.tsx b/packages/taler-wallet-webextension/src/components/AmountField.stories.tsx index 9ac17155c..ed3be6579 100644 --- a/packages/taler-wallet-webextension/src/components/AmountField.stories.tsx +++ b/packages/taler-wallet-webextension/src/components/AmountField.stories.tsx @@ -22,7 +22,7 @@ import { AmountJson, Amounts } from "@gnu-taler/taler-util"; import { Fragment, h, VNode } from "preact"; import { useState } from "preact/hooks"; -import { useTranslationContext } from "../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { AmountFieldHandler, nullFunction, withSafe } from "../mui/handlers.js"; import { AmountField } from "./AmountField.js"; diff --git a/packages/taler-wallet-webextension/src/components/AmountField.tsx b/packages/taler-wallet-webextension/src/components/AmountField.tsx index 88ac71dd8..db7afb053 100644 --- a/packages/taler-wallet-webextension/src/components/AmountField.tsx +++ b/packages/taler-wallet-webextension/src/components/AmountField.tsx @@ -25,7 +25,7 @@ import { } from "@gnu-taler/taler-util"; import { Fragment, h, VNode } from "preact"; import { useState } from "preact/hooks"; -import { useTranslationContext } from "../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { AmountFieldHandler } from "../mui/handlers.js"; import { TextField } from "../mui/TextField.js"; diff --git a/packages/taler-wallet-webextension/src/components/BankDetailsByPaytoType.tsx b/packages/taler-wallet-webextension/src/components/BankDetailsByPaytoType.tsx index d233547a4..cd9a25a03 100644 --- a/packages/taler-wallet-webextension/src/components/BankDetailsByPaytoType.tsx +++ b/packages/taler-wallet-webextension/src/components/BankDetailsByPaytoType.tsx @@ -23,7 +23,7 @@ import { } from "@gnu-taler/taler-util"; import { Fragment, h, VNode } from "preact"; import { useEffect, useRef, useState } from "preact/hooks"; -import { useTranslationContext } from "../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { CopiedIcon, CopyIcon } from "../svg/index.js"; import { Amount } from "./Amount.js"; import { ButtonBox, TooltipLeft } from "./styled/index.js"; diff --git a/packages/taler-wallet-webextension/src/components/CurrentAlerts.tsx b/packages/taler-wallet-webextension/src/components/CurrentAlerts.tsx index 0f12b8afa..25114d5a9 100644 --- a/packages/taler-wallet-webextension/src/components/CurrentAlerts.tsx +++ b/packages/taler-wallet-webextension/src/components/CurrentAlerts.tsx @@ -16,12 +16,12 @@ import { ComponentChildren, Fragment, h, VNode } from "preact"; import { useState } from "preact/hooks"; -import { useTranslationContext } from "../../../web-util/src/index.browser.js"; import { Alert as AlertNotification, useAlertContext, } from "../context/alert.js"; import { Alert } from "../mui/Alert.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; /** * diff --git a/packages/taler-wallet-webextension/src/components/Diagnostics.tsx b/packages/taler-wallet-webextension/src/components/Diagnostics.tsx index 886a44752..dfbb20be2 100644 --- a/packages/taler-wallet-webextension/src/components/Diagnostics.tsx +++ b/packages/taler-wallet-webextension/src/components/Diagnostics.tsx @@ -16,7 +16,7 @@ import { WalletDiagnostics } from "@gnu-taler/taler-util"; import { Fragment, h, VNode } from "preact"; -import { useTranslationContext } from "../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; interface Props { timedOut: boolean; diff --git a/packages/taler-wallet-webextension/src/components/EditableText.tsx b/packages/taler-wallet-webextension/src/components/EditableText.tsx index c32ec158d..198527fb2 100644 --- a/packages/taler-wallet-webextension/src/components/EditableText.tsx +++ b/packages/taler-wallet-webextension/src/components/EditableText.tsx @@ -16,7 +16,7 @@ import { h, VNode } from "preact"; import { useRef, useState } from "preact/hooks"; -import { useTranslationContext } from "../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; interface Props { value: string; diff --git a/packages/taler-wallet-webextension/src/components/Loading.tsx b/packages/taler-wallet-webextension/src/components/Loading.tsx index 3a6daaaa6..507e36183 100644 --- a/packages/taler-wallet-webextension/src/components/Loading.tsx +++ b/packages/taler-wallet-webextension/src/components/Loading.tsx @@ -16,7 +16,7 @@ import { css } from "@linaria/core"; import { Fragment, h, VNode } from "preact"; import { useEffect, useState } from "preact/hooks"; -import { useTranslationContext } from "../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import ProgressIcon from "../svg/progress.svg"; import { CenteredText } from "./styled/index.js"; diff --git a/packages/taler-wallet-webextension/src/components/Part.tsx b/packages/taler-wallet-webextension/src/components/Part.tsx index 1449bcac6..370cea539 100644 --- a/packages/taler-wallet-webextension/src/components/Part.tsx +++ b/packages/taler-wallet-webextension/src/components/Part.tsx @@ -97,7 +97,7 @@ const CollasibleBox = styled.div` } `; import arrowDown from "../svg/chevron-down.svg"; -import { useTranslationContext } from "../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; export function PartCollapsible({ text, title, big, showSign }: Props): VNode { const Text = big ? ExtraLargeText : LargeText; diff --git a/packages/taler-wallet-webextension/src/components/PaymentButtons.tsx b/packages/taler-wallet-webextension/src/components/PaymentButtons.tsx index 67aaccf53..2846a8cec 100644 --- a/packages/taler-wallet-webextension/src/components/PaymentButtons.tsx +++ b/packages/taler-wallet-webextension/src/components/PaymentButtons.tsx @@ -28,7 +28,7 @@ import { Amount } from "./Amount.js"; import { Part } from "./Part.js"; import { QR } from "./QR.js"; import { LinkSuccess, WarningBox } from "./styled/index.js"; -import { useTranslationContext } from "../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { Button } from "../mui/Button.js"; import { ButtonHandler } from "../mui/handlers.js"; import { assertUnreachable } from "../utils/index.js"; diff --git a/packages/taler-wallet-webextension/src/components/PendingTransactions.tsx b/packages/taler-wallet-webextension/src/components/PendingTransactions.tsx index f9b30907d..228a717a1 100644 --- a/packages/taler-wallet-webextension/src/components/PendingTransactions.tsx +++ b/packages/taler-wallet-webextension/src/components/PendingTransactions.tsx @@ -24,7 +24,7 @@ import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { Fragment, h, JSX, VNode } from "preact"; import { useEffect } from "preact/hooks"; import { useBackendContext } from "../context/backend.js"; -import { useTranslationContext } from "../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { useAsyncAsHook } from "../hooks/useAsyncAsHook.js"; import { Avatar } from "../mui/Avatar.js"; import { Grid } from "../mui/Grid.js"; diff --git a/packages/taler-wallet-webextension/src/components/ProductList.tsx b/packages/taler-wallet-webextension/src/components/ProductList.tsx index a78733179..faede20e0 100644 --- a/packages/taler-wallet-webextension/src/components/ProductList.tsx +++ b/packages/taler-wallet-webextension/src/components/ProductList.tsx @@ -17,7 +17,7 @@ import { Amounts, Product } from "@gnu-taler/taler-util"; import { Fragment, h, VNode } from "preact"; import { SmallLightText } from "./styled/index.js"; -import { useTranslationContext } from "../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; export function ProductList({ products }: { products: Product[] }): VNode { const { i18n } = useTranslationContext(); diff --git a/packages/taler-wallet-webextension/src/components/SelectList.tsx b/packages/taler-wallet-webextension/src/components/SelectList.tsx index 809698711..01da1c1da 100644 --- a/packages/taler-wallet-webextension/src/components/SelectList.tsx +++ b/packages/taler-wallet-webextension/src/components/SelectList.tsx @@ -16,7 +16,7 @@ import { TranslatedString } from "@gnu-taler/taler-util"; import { Fragment, h, VNode } from "preact"; -import { useTranslationContext } from "../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { NiceSelect } from "./styled/index.js"; interface Props { diff --git a/packages/taler-wallet-webextension/src/components/ShowFullContractTermPopup.tsx b/packages/taler-wallet-webextension/src/components/ShowFullContractTermPopup.tsx index a5127cd88..317d0d1c7 100644 --- a/packages/taler-wallet-webextension/src/components/ShowFullContractTermPopup.tsx +++ b/packages/taler-wallet-webextension/src/components/ShowFullContractTermPopup.tsx @@ -26,7 +26,7 @@ import { Modal } from "../components/Modal.js"; import { Time } from "../components/Time.js"; import { alertFromError, useAlertContext } from "../context/alert.js"; import { useBackendContext } from "../context/backend.js"; -import { useTranslationContext } from "../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { HookError, useAsyncAsHook } from "../hooks/useAsyncAsHook.js"; import { ButtonHandler } from "../mui/handlers.js"; import { compose, StateViewMap } from "../utils/index.js"; diff --git a/packages/taler-wallet-webextension/src/components/TermsOfService/state.ts b/packages/taler-wallet-webextension/src/components/TermsOfService/state.ts index 541b2d39e..4ebc615f4 100644 --- a/packages/taler-wallet-webextension/src/components/TermsOfService/state.ts +++ b/packages/taler-wallet-webextension/src/components/TermsOfService/state.ts @@ -15,10 +15,10 @@ */ import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { useState } from "preact/hooks"; import { alertFromError, useAlertContext } from "../../context/alert.js"; import { useBackendContext } from "../../context/backend.js"; -import { useTranslationContext } from "../../context/translation.js"; import { useAsyncAsHook } from "../../hooks/useAsyncAsHook.js"; import { Props, State } from "./index.js"; import { buildTermsOfServiceState } from "./utils.js"; diff --git a/packages/taler-wallet-webextension/src/components/TermsOfService/views.tsx b/packages/taler-wallet-webextension/src/components/TermsOfService/views.tsx index 415ee1605..b8ce2f220 100644 --- a/packages/taler-wallet-webextension/src/components/TermsOfService/views.tsx +++ b/packages/taler-wallet-webextension/src/components/TermsOfService/views.tsx @@ -24,7 +24,7 @@ import { WarningBox, WarningText, } from "../../components/styled/index.js"; -import { useTranslationContext } from "../../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { Button } from "../../mui/Button.js"; import { State } from "./index.js"; diff --git a/packages/taler-wallet-webextension/src/components/TransactionItem.tsx b/packages/taler-wallet-webextension/src/components/TransactionItem.tsx index 7ddaee9f3..009256001 100644 --- a/packages/taler-wallet-webextension/src/components/TransactionItem.tsx +++ b/packages/taler-wallet-webextension/src/components/TransactionItem.tsx @@ -25,7 +25,7 @@ import { ExtendedStatus, } from "@gnu-taler/taler-util"; import { h, VNode } from "preact"; -import { useTranslationContext } from "../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { Avatar } from "../mui/Avatar.js"; import { Pages } from "../NavigationBar.js"; import { assertUnreachable } from "../utils/index.js"; diff --git a/packages/taler-wallet-webextension/src/context/alert.ts b/packages/taler-wallet-webextension/src/context/alert.ts index 2b088abd3..b8918dc58 100644 --- a/packages/taler-wallet-webextension/src/context/alert.ts +++ b/packages/taler-wallet-webextension/src/context/alert.ts @@ -25,6 +25,7 @@ import { useContext, useState } from "preact/hooks"; import { HookError } from "../hooks/useAsyncAsHook.js"; import { SafeHandler, withSafe } from "../mui/handlers.js"; import { BackgroundError } from "../wxApi.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; export type AlertType = "info" | "warning" | "error" | "success"; @@ -55,10 +56,7 @@ type Type = { * @deprecated use safely */ pushAlertOnError: (h: (p: T) => Promise) => SafeHandler; - safely: ( - h: (p: T) => Promise, - error: TranslatedString, - ) => SafeHandler; + safely: (name: string, h: (p: T) => Promise) => SafeHandler; }; const initial: Type = { @@ -113,10 +111,13 @@ export const AlertProvider = ({ children }: Props): VNode => { }); } + const { i18n } = useTranslationContext(); + function safely( + name: string, handler: (p: T) => Promise, - message: TranslatedString, ): SafeHandler { + const message = i18n.str`Error was thrown trying to: "${name}"`; return withSafe(handler, (e) => { const a = alertFromError(message, e); pushAlert(a); diff --git a/packages/taler-wallet-webextension/src/context/translation.ts b/packages/taler-wallet-webextension/src/context/translation.ts deleted file mode 100644 index bc7e4bee2..000000000 --- a/packages/taler-wallet-webextension/src/context/translation.ts +++ /dev/null @@ -1,92 +0,0 @@ -/* - 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 - */ - -/** - * - * @author Sebastian Javier Marchano (sebasjm) - */ - -import { i18n, setupI18n } from "@gnu-taler/taler-util"; -import { createContext, h, VNode } from "preact"; -import { useContext, useEffect } from "preact/hooks"; -import { useLang } from "../hooks/useLang.js"; -import { strings } from "../i18n/strings.js"; - -interface Type { - lang: string; - supportedLang: { [id in keyof typeof supportedLang]: string }; - changeLanguage: (l: string) => void; - i18n: typeof i18n; - isSaved: boolean; -} - -const supportedLang = { - es: "Español [es]", - ja: "日本語 [ja]", - en: "English [en]", - fr: "Français [fr]", - de: "Deutsch [de]", - sv: "Svenska [sv]", - it: "Italiano [it]", - // ko: "한국어 [ko]", - // ru: "Ру́сский язы́к [ru]", - tr: "Türk [tr]", - navigator: "Defined by navigator", -}; - -const initial = { - lang: "en", - supportedLang, - changeLanguage: () => { - // do not change anything - }, - i18n, - isSaved: false, -}; -const Context = createContext(initial); - -interface Props { - initial?: string; - children: any; - forceLang?: string; -} - -export const TranslationProvider = ({ - initial, - children, - forceLang, -}: Props): VNode => { - const [lang, changeLanguage, isSaved] = useLang(initial); - useEffect(() => { - if (forceLang) { - changeLanguage(forceLang); - } - }); - useEffect(() => { - setupI18n(lang, strings); - }, [lang]); - if (forceLang) { - setupI18n(forceLang, strings); - } else { - setupI18n(lang, strings); - } - return h(Context.Provider, { - value: { lang, changeLanguage, supportedLang, i18n, isSaved }, - children, - }); -}; - -export const useTranslationContext = (): Type => useContext(Context); diff --git a/packages/taler-wallet-webextension/src/cta/Deposit/state.ts b/packages/taler-wallet-webextension/src/cta/Deposit/state.ts index 3e09597a2..eff713ab5 100644 --- a/packages/taler-wallet-webextension/src/cta/Deposit/state.ts +++ b/packages/taler-wallet-webextension/src/cta/Deposit/state.ts @@ -18,7 +18,7 @@ import { Amounts } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { alertFromError, useAlertContext } from "../../context/alert.js"; import { useBackendContext } from "../../context/backend.js"; -import { useTranslationContext } from "../../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { useAsyncAsHook } from "../../hooks/useAsyncAsHook.js"; import { Props, State } from "./index.js"; diff --git a/packages/taler-wallet-webextension/src/cta/Deposit/views.tsx b/packages/taler-wallet-webextension/src/cta/Deposit/views.tsx index db0120882..84ec3ca1f 100644 --- a/packages/taler-wallet-webextension/src/cta/Deposit/views.tsx +++ b/packages/taler-wallet-webextension/src/cta/Deposit/views.tsx @@ -20,7 +20,7 @@ import { Amount } from "../../components/Amount.js"; import { LogoHeader } from "../../components/LogoHeader.js"; import { Part } from "../../components/Part.js"; import { SubTitle, WalletAction } from "../../components/styled/index.js"; -import { useTranslationContext } from "../../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { Button } from "../../mui/Button.js"; import { State } from "./index.js"; diff --git a/packages/taler-wallet-webextension/src/cta/InvoiceCreate/state.ts b/packages/taler-wallet-webextension/src/cta/InvoiceCreate/state.ts index 73cb61b52..3403b304d 100644 --- a/packages/taler-wallet-webextension/src/cta/InvoiceCreate/state.ts +++ b/packages/taler-wallet-webextension/src/cta/InvoiceCreate/state.ts @@ -21,7 +21,7 @@ import { isFuture, parse } from "date-fns"; import { useState } from "preact/hooks"; import { alertFromError, useAlertContext } from "../../context/alert.js"; import { useBackendContext } from "../../context/backend.js"; -import { useTranslationContext } from "../../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { useAsyncAsHook } from "../../hooks/useAsyncAsHook.js"; import { useSelectedExchange } from "../../hooks/useSelectedExchange.js"; import { RecursiveState } from "../../utils/index.js"; diff --git a/packages/taler-wallet-webextension/src/cta/InvoiceCreate/views.tsx b/packages/taler-wallet-webextension/src/cta/InvoiceCreate/views.tsx index 3866fb6ef..c9c5eda5c 100644 --- a/packages/taler-wallet-webextension/src/cta/InvoiceCreate/views.tsx +++ b/packages/taler-wallet-webextension/src/cta/InvoiceCreate/views.tsx @@ -24,7 +24,7 @@ import { SvgIcon, WalletAction, } from "../../components/styled/index.js"; -import { useTranslationContext } from "../../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { Button } from "../../mui/Button.js"; import { TextField } from "../../mui/TextField.js"; import editIcon from "../../svg/edit_24px.svg"; diff --git a/packages/taler-wallet-webextension/src/cta/InvoicePay/state.ts b/packages/taler-wallet-webextension/src/cta/InvoicePay/state.ts index 7d8089814..2da9c6571 100644 --- a/packages/taler-wallet-webextension/src/cta/InvoicePay/state.ts +++ b/packages/taler-wallet-webextension/src/cta/InvoicePay/state.ts @@ -26,7 +26,7 @@ import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { useEffect } from "preact/hooks"; import { alertFromError, useAlertContext } from "../../context/alert.js"; import { useBackendContext } from "../../context/backend.js"; -import { useTranslationContext } from "../../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { useAsyncAsHook } from "../../hooks/useAsyncAsHook.js"; import { Props, State } from "./index.js"; diff --git a/packages/taler-wallet-webextension/src/cta/InvoicePay/views.tsx b/packages/taler-wallet-webextension/src/cta/InvoicePay/views.tsx index b10c06924..caddf7460 100644 --- a/packages/taler-wallet-webextension/src/cta/InvoicePay/views.tsx +++ b/packages/taler-wallet-webextension/src/cta/InvoicePay/views.tsx @@ -21,7 +21,7 @@ import { Part } from "../../components/Part.js"; import { PaymentButtons } from "../../components/PaymentButtons.js"; import { SubTitle, WalletAction } from "../../components/styled/index.js"; import { Time } from "../../components/Time.js"; -import { useTranslationContext } from "../../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { getAmountWithFee, InvoiceDetails } from "../../wallet/Transaction.js"; import { State } from "./index.js"; diff --git a/packages/taler-wallet-webextension/src/cta/Payment/state.ts b/packages/taler-wallet-webextension/src/cta/Payment/state.ts index 0f1388ea5..b3d2e6e81 100644 --- a/packages/taler-wallet-webextension/src/cta/Payment/state.ts +++ b/packages/taler-wallet-webextension/src/cta/Payment/state.ts @@ -24,7 +24,7 @@ import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { useEffect } from "preact/hooks"; import { alertFromError, useAlertContext } from "../../context/alert.js"; import { useBackendContext } from "../../context/backend.js"; -import { useTranslationContext } from "../../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { useAsyncAsHook } from "../../hooks/useAsyncAsHook.js"; import { ButtonHandler } from "../../mui/handlers.js"; import { Props, State } from "./index.js"; diff --git a/packages/taler-wallet-webextension/src/cta/Payment/test.ts b/packages/taler-wallet-webextension/src/cta/Payment/test.ts index f4b63955d..70557a3c8 100644 --- a/packages/taler-wallet-webextension/src/cta/Payment/test.ts +++ b/packages/taler-wallet-webextension/src/cta/Payment/test.ts @@ -31,7 +31,7 @@ import { } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { expect } from "chai"; -import { tests } from "../../../../web-util/src/index.browser.js"; +import { tests } from "@gnu-taler/web-util/lib/index.browser"; import { ErrorAlert, useAlertContext } from "../../context/alert.js"; import { nullFunction } from "../../mui/handlers.js"; import { createWalletApiMock } from "../../test-utils.js"; diff --git a/packages/taler-wallet-webextension/src/cta/Payment/views.tsx b/packages/taler-wallet-webextension/src/cta/Payment/views.tsx index f5a354786..8032068f9 100644 --- a/packages/taler-wallet-webextension/src/cta/Payment/views.tsx +++ b/packages/taler-wallet-webextension/src/cta/Payment/views.tsx @@ -26,7 +26,7 @@ import { Part } from "../../components/Part.js"; import { PaymentButtons } from "../../components/PaymentButtons.js"; import { SuccessBox, WarningBox } from "../../components/styled/index.js"; import { Time } from "../../components/Time.js"; -import { useTranslationContext } from "../../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { getAmountWithFee, MerchantDetails, diff --git a/packages/taler-wallet-webextension/src/cta/PaymentTemplate/state.ts b/packages/taler-wallet-webextension/src/cta/PaymentTemplate/state.ts index abcf040b7..7700dfbce 100644 --- a/packages/taler-wallet-webextension/src/cta/PaymentTemplate/state.ts +++ b/packages/taler-wallet-webextension/src/cta/PaymentTemplate/state.ts @@ -19,7 +19,7 @@ import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { useState } from "preact/hooks"; import { alertFromError, useAlertContext } from "../../context/alert.js"; import { useBackendContext } from "../../context/backend.js"; -import { useTranslationContext } from "../../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { useAsyncAsHook } from "../../hooks/useAsyncAsHook.js"; import { AmountFieldHandler, TextFieldHandler } from "../../mui/handlers.js"; import { Props, State } from "./index.js"; @@ -157,7 +157,7 @@ export function useComponentState({ onCreate: { onClick: errors ? undefined - : safely(createOrder, i18n.str`Could not create order`), + : safely("create order for pay template", createOrder), }, }; } diff --git a/packages/taler-wallet-webextension/src/cta/PaymentTemplate/test.ts b/packages/taler-wallet-webextension/src/cta/PaymentTemplate/test.ts index 72fbb6853..47def9cec 100644 --- a/packages/taler-wallet-webextension/src/cta/PaymentTemplate/test.ts +++ b/packages/taler-wallet-webextension/src/cta/PaymentTemplate/test.ts @@ -20,7 +20,7 @@ */ import { expect } from "chai"; -import { tests } from "../../../../web-util/src/index.browser.js"; +import { tests } from "@gnu-taler/web-util/lib/index.browser"; import { nullFunction } from "../../mui/handlers.js"; import { createWalletApiMock } from "../../test-utils.js"; import { useComponentState } from "./state.js"; diff --git a/packages/taler-wallet-webextension/src/cta/PaymentTemplate/views.tsx b/packages/taler-wallet-webextension/src/cta/PaymentTemplate/views.tsx index 9f4c0f28c..42e51014f 100644 --- a/packages/taler-wallet-webextension/src/cta/PaymentTemplate/views.tsx +++ b/packages/taler-wallet-webextension/src/cta/PaymentTemplate/views.tsx @@ -17,7 +17,7 @@ import { Fragment, h, VNode } from "preact"; import { AmountField } from "../../components/AmountField.js"; import { Part } from "../../components/Part.js"; -import { useTranslationContext } from "../../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { Button } from "../../mui/Button.js"; import { TextField } from "../../mui/TextField.js"; import { State } from "./index.js"; diff --git a/packages/taler-wallet-webextension/src/cta/Recovery/state.ts b/packages/taler-wallet-webextension/src/cta/Recovery/state.ts index aa4942c4e..dd949ee8a 100644 --- a/packages/taler-wallet-webextension/src/cta/Recovery/state.ts +++ b/packages/taler-wallet-webextension/src/cta/Recovery/state.ts @@ -18,7 +18,7 @@ import { parseRestoreUri } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { useAlertContext } from "../../context/alert.js"; import { useBackendContext } from "../../context/backend.js"; -import { useTranslationContext } from "../../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { Props, State } from "./index.js"; export function useComponentState({ diff --git a/packages/taler-wallet-webextension/src/cta/Recovery/views.tsx b/packages/taler-wallet-webextension/src/cta/Recovery/views.tsx index 6353d33ce..243c61d75 100644 --- a/packages/taler-wallet-webextension/src/cta/Recovery/views.tsx +++ b/packages/taler-wallet-webextension/src/cta/Recovery/views.tsx @@ -17,7 +17,7 @@ import { Fragment, h, VNode } from "preact"; import { LogoHeader } from "../../components/LogoHeader.js"; import { SubTitle, WalletAction } from "../../components/styled/index.js"; -import { useTranslationContext } from "../../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { Button } from "../../mui/Button.js"; import { State } from "./index.js"; diff --git a/packages/taler-wallet-webextension/src/cta/Refund/state.ts b/packages/taler-wallet-webextension/src/cta/Refund/state.ts index 4c411ec04..600a73413 100644 --- a/packages/taler-wallet-webextension/src/cta/Refund/state.ts +++ b/packages/taler-wallet-webextension/src/cta/Refund/state.ts @@ -19,7 +19,7 @@ import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { useEffect, useState } from "preact/hooks"; import { alertFromError, useAlertContext } from "../../context/alert.js"; import { useBackendContext } from "../../context/backend.js"; -import { useTranslationContext } from "../../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { useAsyncAsHook } from "../../hooks/useAsyncAsHook.js"; import { Props, State } from "./index.js"; diff --git a/packages/taler-wallet-webextension/src/cta/Refund/test.ts b/packages/taler-wallet-webextension/src/cta/Refund/test.ts index a07158e1a..670534f40 100644 --- a/packages/taler-wallet-webextension/src/cta/Refund/test.ts +++ b/packages/taler-wallet-webextension/src/cta/Refund/test.ts @@ -26,7 +26,7 @@ import { } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { expect } from "chai"; -import { tests } from "../../../../web-util/src/index.browser.js"; +import { tests } from "@gnu-taler/web-util/lib/index.browser"; import { nullFunction } from "../../mui/handlers.js"; import { createWalletApiMock } from "../../test-utils.js"; import { useComponentState } from "./state.js"; diff --git a/packages/taler-wallet-webextension/src/cta/Refund/views.tsx b/packages/taler-wallet-webextension/src/cta/Refund/views.tsx index cdc593dd9..c0cbc780a 100644 --- a/packages/taler-wallet-webextension/src/cta/Refund/views.tsx +++ b/packages/taler-wallet-webextension/src/cta/Refund/views.tsx @@ -21,7 +21,7 @@ import { LogoHeader } from "../../components/LogoHeader.js"; import { Part } from "../../components/Part.js"; import { ProductList } from "../../components/ProductList.js"; import { Link, SubTitle, WalletAction } from "../../components/styled/index.js"; -import { useTranslationContext } from "../../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { Button } from "../../mui/Button.js"; import { State } from "./index.js"; diff --git a/packages/taler-wallet-webextension/src/cta/Tip/state.ts b/packages/taler-wallet-webextension/src/cta/Tip/state.ts index 3b9abf5a3..911ec25ed 100644 --- a/packages/taler-wallet-webextension/src/cta/Tip/state.ts +++ b/packages/taler-wallet-webextension/src/cta/Tip/state.ts @@ -18,7 +18,7 @@ import { Amounts } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { alertFromError, useAlertContext } from "../../context/alert.js"; import { useBackendContext } from "../../context/backend.js"; -import { useTranslationContext } from "../../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { useAsyncAsHook } from "../../hooks/useAsyncAsHook.js"; import { Props, State } from "./index.js"; diff --git a/packages/taler-wallet-webextension/src/cta/Tip/test.ts b/packages/taler-wallet-webextension/src/cta/Tip/test.ts index 44a6f9b0b..87f397ff4 100644 --- a/packages/taler-wallet-webextension/src/cta/Tip/test.ts +++ b/packages/taler-wallet-webextension/src/cta/Tip/test.ts @@ -22,7 +22,7 @@ import { Amounts } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { expect } from "chai"; -import { tests } from "../../../../web-util/src/index.browser.js"; +import { tests } from "@gnu-taler/web-util/lib/index.browser"; import { nullFunction } from "../../mui/handlers.js"; import { createWalletApiMock } from "../../test-utils.js"; import { Props } from "./index.js"; diff --git a/packages/taler-wallet-webextension/src/cta/Tip/views.tsx b/packages/taler-wallet-webextension/src/cta/Tip/views.tsx index 52ece4ba6..1fd9c2098 100644 --- a/packages/taler-wallet-webextension/src/cta/Tip/views.tsx +++ b/packages/taler-wallet-webextension/src/cta/Tip/views.tsx @@ -20,7 +20,7 @@ import { Amount } from "../../components/Amount.js"; import { LogoHeader } from "../../components/LogoHeader.js"; import { Part } from "../../components/Part.js"; import { Link, SubTitle, WalletAction } from "../../components/styled/index.js"; -import { useTranslationContext } from "../../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { Button } from "../../mui/Button.js"; import { State } from "./index.js"; diff --git a/packages/taler-wallet-webextension/src/cta/TransferCreate/state.ts b/packages/taler-wallet-webextension/src/cta/TransferCreate/state.ts index c45e495d9..7625dadeb 100644 --- a/packages/taler-wallet-webextension/src/cta/TransferCreate/state.ts +++ b/packages/taler-wallet-webextension/src/cta/TransferCreate/state.ts @@ -20,7 +20,7 @@ import { isFuture, parse } from "date-fns"; import { useState } from "preact/hooks"; import { alertFromError, useAlertContext } from "../../context/alert.js"; import { useBackendContext } from "../../context/backend.js"; -import { useTranslationContext } from "../../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { useAsyncAsHook } from "../../hooks/useAsyncAsHook.js"; import { Props, State } from "./index.js"; diff --git a/packages/taler-wallet-webextension/src/cta/TransferCreate/views.tsx b/packages/taler-wallet-webextension/src/cta/TransferCreate/views.tsx index 3dd1eaf3b..51d36c0cf 100644 --- a/packages/taler-wallet-webextension/src/cta/TransferCreate/views.tsx +++ b/packages/taler-wallet-webextension/src/cta/TransferCreate/views.tsx @@ -21,7 +21,7 @@ import { ErrorTalerOperation } from "../../components/ErrorTalerOperation.js"; import { LogoHeader } from "../../components/LogoHeader.js"; import { Part } from "../../components/Part.js"; import { Link, SubTitle, WalletAction } from "../../components/styled/index.js"; -import { useTranslationContext } from "../../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { Button } from "../../mui/Button.js"; import { TextField } from "../../mui/TextField.js"; import { getAmountWithFee, TransferDetails } from "../../wallet/Transaction.js"; diff --git a/packages/taler-wallet-webextension/src/cta/TransferPickup/state.ts b/packages/taler-wallet-webextension/src/cta/TransferPickup/state.ts index 0d873b61f..292a4e867 100644 --- a/packages/taler-wallet-webextension/src/cta/TransferPickup/state.ts +++ b/packages/taler-wallet-webextension/src/cta/TransferPickup/state.ts @@ -22,7 +22,7 @@ import { import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { alertFromError, useAlertContext } from "../../context/alert.js"; import { useBackendContext } from "../../context/backend.js"; -import { useTranslationContext } from "../../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { useAsyncAsHook } from "../../hooks/useAsyncAsHook.js"; import { Props, State } from "./index.js"; diff --git a/packages/taler-wallet-webextension/src/cta/TransferPickup/views.tsx b/packages/taler-wallet-webextension/src/cta/TransferPickup/views.tsx index c1c8c9bca..aa757e587 100644 --- a/packages/taler-wallet-webextension/src/cta/TransferPickup/views.tsx +++ b/packages/taler-wallet-webextension/src/cta/TransferPickup/views.tsx @@ -21,7 +21,7 @@ import { LogoHeader } from "../../components/LogoHeader.js"; import { Part } from "../../components/Part.js"; import { Link, SubTitle, WalletAction } from "../../components/styled/index.js"; import { Time } from "../../components/Time.js"; -import { useTranslationContext } from "../../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { Button } from "../../mui/Button.js"; import { getAmountWithFee, TransferDetails } from "../../wallet/Transaction.js"; import { State } from "./index.js"; diff --git a/packages/taler-wallet-webextension/src/cta/Withdraw/state.ts b/packages/taler-wallet-webextension/src/cta/Withdraw/state.ts index 4de026190..a4f9ebe09 100644 --- a/packages/taler-wallet-webextension/src/cta/Withdraw/state.ts +++ b/packages/taler-wallet-webextension/src/cta/Withdraw/state.ts @@ -26,7 +26,7 @@ import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { useState } from "preact/hooks"; import { alertFromError, useAlertContext } from "../../context/alert.js"; import { useBackendContext } from "../../context/backend.js"; -import { useTranslationContext } from "../../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { useAsyncAsHook } from "../../hooks/useAsyncAsHook.js"; import { useSelectedExchange } from "../../hooks/useSelectedExchange.js"; import { RecursiveState } from "../../utils/index.js"; diff --git a/packages/taler-wallet-webextension/src/cta/Withdraw/test.ts b/packages/taler-wallet-webextension/src/cta/Withdraw/test.ts index d90fc72ac..5850c7ab8 100644 --- a/packages/taler-wallet-webextension/src/cta/Withdraw/test.ts +++ b/packages/taler-wallet-webextension/src/cta/Withdraw/test.ts @@ -27,7 +27,7 @@ import { } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { expect } from "chai"; -import { tests } from "../../../../web-util/src/index.browser.js"; +import { tests } from "@gnu-taler/web-util/lib/index.browser"; import { createWalletApiMock } from "../../test-utils.js"; import { useComponentStateFromURI } from "./state.js"; diff --git a/packages/taler-wallet-webextension/src/cta/Withdraw/views.tsx b/packages/taler-wallet-webextension/src/cta/Withdraw/views.tsx index 4fb65f06c..278dab840 100644 --- a/packages/taler-wallet-webextension/src/cta/Withdraw/views.tsx +++ b/packages/taler-wallet-webextension/src/cta/Withdraw/views.tsx @@ -23,7 +23,7 @@ import { QR } from "../../components/QR.js"; import { SelectList } from "../../components/SelectList.js"; import { Input, LinkSuccess, SvgIcon } from "../../components/styled/index.js"; import { TermsOfService } from "../../components/TermsOfService/index.js"; -import { useTranslationContext } from "../../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { Button } from "../../mui/Button.js"; import editIcon from "../../svg/edit_24px.svg"; import { diff --git a/packages/taler-wallet-webextension/src/hooks/useAutoOpenPermissions.ts b/packages/taler-wallet-webextension/src/hooks/useAutoOpenPermissions.ts deleted file mode 100644 index e0a34f690..000000000 --- a/packages/taler-wallet-webextension/src/hooks/useAutoOpenPermissions.ts +++ /dev/null @@ -1,70 +0,0 @@ -/* - 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 - */ - -import { useEffect, useState } from "preact/hooks"; -import { useAlertContext } from "../context/alert.js"; -import { useBackendContext } from "../context/backend.js"; -import { ToggleHandler } from "../mui/handlers.js"; -import { platform } from "../platform/foreground.js"; - -export function useAutoOpenPermissions(): ToggleHandler { - const api = useBackendContext(); - const { pushAlertOnError } = useAlertContext(); - const [enabled, setEnabled] = useState(false); - - async function handleAutoOpenPerm(): Promise { - if (!enabled) { - // We set permissions here, since apparently FF wants this to be done - // as the result of an input event ... - let granted: boolean; - try { - granted = await platform.getPermissionsApi().requestHostPermissions(); - } catch (lastError) { - setEnabled(false); - throw lastError; - } - const res = await api.background.call("toggleHeaderListener", granted); - setEnabled(res.newValue); - } else { - try { - await api.background - .call("toggleHeaderListener", false) - .then((r) => setEnabled(r.newValue)); - } catch (e) { - console.log(e); - } - } - return; - } - - useEffect(() => { - async function getValue(): Promise { - const res = await api.background.call( - "containsHeaderListener", - undefined, - ); - setEnabled(res.newValue); - } - getValue(); - }, []); - - return { - value: enabled, - button: { - onClick: pushAlertOnError(handleAutoOpenPerm), - }, - }; -} diff --git a/packages/taler-wallet-webextension/src/hooks/useLang.ts b/packages/taler-wallet-webextension/src/hooks/useLang.ts deleted file mode 100644 index b1aa40015..000000000 --- a/packages/taler-wallet-webextension/src/hooks/useLang.ts +++ /dev/null @@ -1,31 +0,0 @@ -/* - 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 - */ - -import { useNotNullLocalStorage } from "./useLocalStorage.js"; - -function getBrowserLang(): string | undefined { - if (typeof window === "undefined") return undefined; - if (window.navigator.languages) return window.navigator.languages[0]; - if (window.navigator.language) return window.navigator.language; - return undefined; -} - -export function useLang( - initial?: string, -): [string, (s: string) => void, boolean] { - const defaultLang = (getBrowserLang() || initial || "en").substring(0, 2); - return useNotNullLocalStorage("lang-preference", defaultLang); -} diff --git a/packages/taler-wallet-webextension/src/hooks/useLocalStorage.ts b/packages/taler-wallet-webextension/src/hooks/useLocalStorage.ts deleted file mode 100644 index 387798c96..000000000 --- a/packages/taler-wallet-webextension/src/hooks/useLocalStorage.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* - 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 - */ - -/** - * - * @author Sebastian Javier Marchano (sebasjm) - */ - -import { StateUpdater, useState } from "preact/hooks"; - -export function useLocalStorage( - key: string, - initialValue?: string, -): [string | undefined, StateUpdater] { - const [storedValue, setStoredValue] = useState( - (): string | undefined => { - return typeof window !== "undefined" - ? window.localStorage.getItem(key) || initialValue - : initialValue; - }, - ); - - const setValue = ( - value?: string | ((val?: string) => string | undefined), - ): void => { - setStoredValue((p) => { - const toStore = value instanceof Function ? value(p) : value; - if (typeof window !== "undefined") { - if (!toStore) { - window.localStorage.removeItem(key); - } else { - window.localStorage.setItem(key, toStore); - } - } - return toStore; - }); - }; - - return [storedValue, setValue]; -} - -//TODO: merge with the above function -export function useNotNullLocalStorage( - key: string, - initialValue: string, -): [string, StateUpdater, boolean] { - const [storedValue, setStoredValue] = useState((): string => { - return typeof window !== "undefined" - ? window.localStorage.getItem(key) || initialValue - : initialValue; - }); - - const setValue = (value: string | ((val: string) => string)): void => { - const valueToStore = value instanceof Function ? value(storedValue) : value; - setStoredValue(valueToStore); - if (typeof window !== "undefined") { - if (!valueToStore) { - window.localStorage.removeItem(key); - } else { - window.localStorage.setItem(key, valueToStore); - } - } - }; - - const isSaved = - typeof window === "undefined" - ? false - : window.localStorage.getItem(key) !== null; - return [storedValue, setValue, isSaved]; -} diff --git a/packages/taler-wallet-webextension/src/hooks/useSettings.ts b/packages/taler-wallet-webextension/src/hooks/useSettings.ts new file mode 100644 index 000000000..04bce236a --- /dev/null +++ b/packages/taler-wallet-webextension/src/hooks/useSettings.ts @@ -0,0 +1,51 @@ +/* + 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 + */ + +import { useLocalStorage } from "@gnu-taler/web-util/lib/index.browser"; + +interface Settings { + injectTalerSupport: boolean; +} + +const defaultSettings: Settings = { + injectTalerSupport: false, +}; + +function parse_json_or_undefined(str: string | undefined): T | undefined { + if (str === undefined) return undefined; + try { + return JSON.parse(str); + } catch { + return undefined; + } +} + +export function useSettings(): [ + Readonly, + (key: T, value: Settings[T]) => void, +] { + const { value, update } = useLocalStorage("wallet-settings"); + + const parsed: Settings = parse_json_or_undefined(value) ?? defaultSettings; + function updateField(k: T, v: Settings[T]) { + const newValue = { ...parsed, [k]: v }; + console.log("should update", k, v, parsed, newValue); + const json = JSON.stringify(newValue); + console.log(json); + update(json); + } + return [parsed, updateField]; +} diff --git a/packages/taler-wallet-webextension/src/mui/Typography.tsx b/packages/taler-wallet-webextension/src/mui/Typography.tsx index 3b4357918..eaff8c4fd 100644 --- a/packages/taler-wallet-webextension/src/mui/Typography.tsx +++ b/packages/taler-wallet-webextension/src/mui/Typography.tsx @@ -15,7 +15,7 @@ */ import { css } from "@linaria/core"; import { ComponentChildren, h, VNode } from "preact"; -import { useTranslationContext } from "../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; // eslint-disable-next-line import/extensions import { theme } from "./style.js"; diff --git a/packages/taler-wallet-webextension/src/popup/Application.tsx b/packages/taler-wallet-webextension/src/popup/Application.tsx index acb16b1d5..c03360486 100644 --- a/packages/taler-wallet-webextension/src/popup/Application.tsx +++ b/packages/taler-wallet-webextension/src/popup/Application.tsx @@ -32,7 +32,7 @@ import { IoCProviderForRuntime } from "../context/iocContext.js"; import { TranslationProvider, useTranslationContext, -} from "../context/translation.js"; +} from "@gnu-taler/web-util/lib/index.browser"; import { useTalerActionURL } from "../hooks/useTalerActionURL.js"; import { Pages, PopupNavBar, PopupNavBarOptions } from "../NavigationBar.js"; import { platform } from "../platform/foreground.js"; @@ -40,10 +40,11 @@ import { BackupPage } from "../wallet/BackupPage.js"; import { ProviderDetailPage } from "../wallet/ProviderDetailPage.js"; import { BalancePage } from "./BalancePage.js"; import { TalerActionFound } from "./TalerActionFound.js"; +import { strings } from "../i18n/strings.js"; export function Application(): VNode { return ( - + diff --git a/packages/taler-wallet-webextension/src/popup/BalancePage.tsx b/packages/taler-wallet-webextension/src/popup/BalancePage.tsx index 87767d008..e3492c5f5 100644 --- a/packages/taler-wallet-webextension/src/popup/BalancePage.tsx +++ b/packages/taler-wallet-webextension/src/popup/BalancePage.tsx @@ -28,7 +28,7 @@ import { useAlertContext, } from "../context/alert.js"; import { useBackendContext } from "../context/backend.js"; -import { useTranslationContext } from "../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { useAsyncAsHook } from "../hooks/useAsyncAsHook.js"; import { Button } from "../mui/Button.js"; import { ButtonHandler } from "../mui/handlers.js"; diff --git a/packages/taler-wallet-webextension/src/popup/NoBalanceHelp.tsx b/packages/taler-wallet-webextension/src/popup/NoBalanceHelp.tsx index 5eb31ba46..4034a49d5 100644 --- a/packages/taler-wallet-webextension/src/popup/NoBalanceHelp.tsx +++ b/packages/taler-wallet-webextension/src/popup/NoBalanceHelp.tsx @@ -15,7 +15,7 @@ */ import { css } from "@linaria/core"; import { Fragment, h, VNode } from "preact"; -import { useTranslationContext } from "../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { Alert } from "../mui/Alert.js"; import { Button } from "../mui/Button.js"; import { ButtonHandler } from "../mui/handlers.js"; diff --git a/packages/taler-wallet-webextension/src/popup/TalerActionFound.tsx b/packages/taler-wallet-webextension/src/popup/TalerActionFound.tsx index 205e42d20..b7984e4b8 100644 --- a/packages/taler-wallet-webextension/src/popup/TalerActionFound.tsx +++ b/packages/taler-wallet-webextension/src/popup/TalerActionFound.tsx @@ -22,7 +22,7 @@ import { classifyTalerUri, TalerUriType } from "@gnu-taler/taler-util"; import { Fragment, h, VNode } from "preact"; import { Title } from "../components/styled/index.js"; -import { useTranslationContext } from "../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { Button } from "../mui/Button.js"; import { platform } from "../platform/foreground.js"; diff --git a/packages/taler-wallet-webextension/src/test-utils.ts b/packages/taler-wallet-webextension/src/test-utils.ts index 085055a7e..d85d992b1 100644 --- a/packages/taler-wallet-webextension/src/test-utils.ts +++ b/packages/taler-wallet-webextension/src/test-utils.ts @@ -25,17 +25,18 @@ import { ComponentChildren, Fragment, FunctionalComponent, + VNode, h as create, options, render as renderIntoDom, - VNode, } from "preact"; import { render as renderToString } from "preact-render-to-string"; import { AlertProvider } from "./context/alert.js"; import { BackendProvider } from "./context/backend.js"; -import { TranslationProvider } from "./context/translation.js"; import { nullFunction } from "./mui/handlers.js"; import { BackgroundApiClient, wxApi } from "./wxApi.js"; +import { TranslationProvider } from "@gnu-taler/web-util/lib/index.browser"; +import { strings } from "./i18n/strings.js"; // When doing tests we want the requestAnimationFrame to be as fast as possible. // without this option the RAF will timeout after 100ms making the tests slower @@ -368,7 +369,11 @@ export function createWalletApiMock(): { }): VNode { let children = _cs; children = create(AlertProvider, { children }, children); - children = create(TranslationProvider, { children }, children); + children = create( + TranslationProvider, + { children, source: strings, initial: "en", forceLang: "en" }, + children, + ); return create( BackendProvider, { diff --git a/packages/taler-wallet-webextension/src/wallet/AddBackupProvider/test.ts b/packages/taler-wallet-webextension/src/wallet/AddBackupProvider/test.ts index a939c9268..8738e7cb4 100644 --- a/packages/taler-wallet-webextension/src/wallet/AddBackupProvider/test.ts +++ b/packages/taler-wallet-webextension/src/wallet/AddBackupProvider/test.ts @@ -20,7 +20,7 @@ */ import { expect } from "chai"; -import { tests } from "../../../../web-util/src/index.browser.js"; +import { tests } from "@gnu-taler/web-util/lib/index.browser"; import { nullFunction } from "../../mui/handlers.js"; import { createWalletApiMock } from "../../test-utils.js"; import { Props } from "./index.js"; diff --git a/packages/taler-wallet-webextension/src/wallet/AddBackupProvider/views.tsx b/packages/taler-wallet-webextension/src/wallet/AddBackupProvider/views.tsx index c3afc0d33..ae105656b 100644 --- a/packages/taler-wallet-webextension/src/wallet/AddBackupProvider/views.tsx +++ b/packages/taler-wallet-webextension/src/wallet/AddBackupProvider/views.tsx @@ -23,7 +23,7 @@ import { SubTitle, Title, } from "../../components/styled/index.js"; -import { useTranslationContext } from "../../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { Button } from "../../mui/Button.js"; import { TextField } from "../../mui/TextField.js"; import { State } from "./index.js"; diff --git a/packages/taler-wallet-webextension/src/wallet/AddNewActionView.tsx b/packages/taler-wallet-webextension/src/wallet/AddNewActionView.tsx index 666334214..68a90f8b5 100644 --- a/packages/taler-wallet-webextension/src/wallet/AddNewActionView.tsx +++ b/packages/taler-wallet-webextension/src/wallet/AddNewActionView.tsx @@ -18,7 +18,7 @@ import { Fragment, h, VNode } from "preact"; import { useState } from "preact/hooks"; import { platform } from "../platform/foreground.js"; import { InputWithLabel } from "../components/styled/index.js"; -import { useTranslationContext } from "../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { Button } from "../mui/Button.js"; export interface Props { diff --git a/packages/taler-wallet-webextension/src/wallet/Application.tsx b/packages/taler-wallet-webextension/src/wallet/Application.tsx index d960794e0..ff8cf0314 100644 --- a/packages/taler-wallet-webextension/src/wallet/Application.tsx +++ b/packages/taler-wallet-webextension/src/wallet/Application.tsx @@ -44,7 +44,7 @@ import { IoCProviderForRuntime } from "../context/iocContext.js"; import { TranslationProvider, useTranslationContext, -} from "../context/translation.js"; +} from "@gnu-taler/web-util/lib/index.browser"; import { DepositPage as DepositPageCTA } from "../cta/Deposit/index.js"; import { InvoiceCreatePage } from "../cta/InvoiceCreate/index.js"; import { InvoicePayPage } from "../cta/InvoicePay/index.js"; @@ -80,6 +80,7 @@ import { QrReaderPage } from "./QrReader.js"; import { SettingsPage } from "./Settings.js"; import { TransactionPage } from "./Transaction.js"; import { WelcomePage } from "./Welcome.js"; +import { strings } from "../i18n/strings.js"; export function Application(): VNode { const { i18n } = useTranslationContext(); @@ -89,7 +90,7 @@ export function Application(): VNode { redirectTo(Pages.balanceTransaction({ tid })); } return ( - + diff --git a/packages/taler-wallet-webextension/src/wallet/BackupPage.tsx b/packages/taler-wallet-webextension/src/wallet/BackupPage.tsx index ea1adbc73..52b9f7a10 100644 --- a/packages/taler-wallet-webextension/src/wallet/BackupPage.tsx +++ b/packages/taler-wallet-webextension/src/wallet/BackupPage.tsx @@ -48,7 +48,7 @@ import { } from "../components/styled/index.js"; import { alertFromError } from "../context/alert.js"; import { useBackendContext } from "../context/backend.js"; -import { useTranslationContext } from "../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { useAsyncAsHook } from "../hooks/useAsyncAsHook.js"; import { Button } from "../mui/Button.js"; import { Pages } from "../NavigationBar.js"; diff --git a/packages/taler-wallet-webextension/src/wallet/DepositPage/state.ts b/packages/taler-wallet-webextension/src/wallet/DepositPage/state.ts index 42a3ba847..fce214d73 100644 --- a/packages/taler-wallet-webextension/src/wallet/DepositPage/state.ts +++ b/packages/taler-wallet-webextension/src/wallet/DepositPage/state.ts @@ -27,7 +27,7 @@ import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { useState } from "preact/hooks"; import { alertFromError, useAlertContext } from "../../context/alert.js"; import { useBackendContext } from "../../context/backend.js"; -import { useTranslationContext } from "../../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { useAsyncAsHook } from "../../hooks/useAsyncAsHook.js"; import { RecursiveState } from "../../utils/index.js"; import { Props, State } from "./index.js"; diff --git a/packages/taler-wallet-webextension/src/wallet/DepositPage/test.ts b/packages/taler-wallet-webextension/src/wallet/DepositPage/test.ts index a06b1ae75..03ca01201 100644 --- a/packages/taler-wallet-webextension/src/wallet/DepositPage/test.ts +++ b/packages/taler-wallet-webextension/src/wallet/DepositPage/test.ts @@ -29,7 +29,7 @@ import { } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { expect } from "chai"; -import { tests } from "../../../../web-util/src/index.browser.js"; +import { tests } from "@gnu-taler/web-util/lib/index.browser"; import { nullFunction } from "../../mui/handlers.js"; import { createWalletApiMock } from "../../test-utils.js"; diff --git a/packages/taler-wallet-webextension/src/wallet/DepositPage/views.tsx b/packages/taler-wallet-webextension/src/wallet/DepositPage/views.tsx index 0d827db43..1a1a0c847 100644 --- a/packages/taler-wallet-webextension/src/wallet/DepositPage/views.tsx +++ b/packages/taler-wallet-webextension/src/wallet/DepositPage/views.tsx @@ -20,7 +20,7 @@ import { AmountField } from "../../components/AmountField.js"; import { ErrorMessage } from "../../components/ErrorMessage.js"; import { SelectList } from "../../components/SelectList.js"; import { Input, SubTitle, WarningBox } from "../../components/styled/index.js"; -import { useTranslationContext } from "../../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { Button } from "../../mui/Button.js"; import { Grid } from "../../mui/Grid.js"; import { State } from "./index.js"; diff --git a/packages/taler-wallet-webextension/src/wallet/DestinationSelection/state.ts b/packages/taler-wallet-webextension/src/wallet/DestinationSelection/state.ts index a921d32cb..2d843a17e 100644 --- a/packages/taler-wallet-webextension/src/wallet/DestinationSelection/state.ts +++ b/packages/taler-wallet-webextension/src/wallet/DestinationSelection/state.ts @@ -19,7 +19,7 @@ import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { useState } from "preact/hooks"; import { alertFromError, useAlertContext } from "../../context/alert.js"; import { useBackendContext } from "../../context/backend.js"; -import { useTranslationContext } from "../../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { useAsyncAsHook } from "../../hooks/useAsyncAsHook.js"; import { assertUnreachable, RecursiveState } from "../../utils/index.js"; import { Contact, Props, State } from "./index.js"; diff --git a/packages/taler-wallet-webextension/src/wallet/DestinationSelection/test.ts b/packages/taler-wallet-webextension/src/wallet/DestinationSelection/test.ts index c6a57270b..c3ca3cc83 100644 --- a/packages/taler-wallet-webextension/src/wallet/DestinationSelection/test.ts +++ b/packages/taler-wallet-webextension/src/wallet/DestinationSelection/test.ts @@ -27,7 +27,7 @@ import { } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { expect } from "chai"; -import { tests } from "../../../../web-util/src/index.browser.js"; +import { tests } from "@gnu-taler/web-util/lib/index.browser"; import { nullFunction } from "../../mui/handlers.js"; import { createWalletApiMock } from "../../test-utils.js"; import { useComponentState } from "./state.js"; diff --git a/packages/taler-wallet-webextension/src/wallet/DestinationSelection/views.tsx b/packages/taler-wallet-webextension/src/wallet/DestinationSelection/views.tsx index 0649fd12f..7f239f33d 100644 --- a/packages/taler-wallet-webextension/src/wallet/DestinationSelection/views.tsx +++ b/packages/taler-wallet-webextension/src/wallet/DestinationSelection/views.tsx @@ -25,7 +25,7 @@ import { LinkPrimary, SvgIcon, } from "../../components/styled/index.js"; -import { useTranslationContext } from "../../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { Button } from "../../mui/Button.js"; import { Grid } from "../../mui/Grid.js"; import { Paper } from "../../mui/Paper.js"; diff --git a/packages/taler-wallet-webextension/src/wallet/DeveloperPage.tsx b/packages/taler-wallet-webextension/src/wallet/DeveloperPage.tsx index 339e69213..1b9767c68 100644 --- a/packages/taler-wallet-webextension/src/wallet/DeveloperPage.tsx +++ b/packages/taler-wallet-webextension/src/wallet/DeveloperPage.tsx @@ -34,7 +34,7 @@ import { SelectList } from "../components/SelectList.js"; import { NotifyUpdateFadeOut } from "../components/styled/index.js"; import { Time } from "../components/Time.js"; import { useBackendContext } from "../context/backend.js"; -import { useTranslationContext } from "../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { useAsyncAsHook } from "../hooks/useAsyncAsHook.js"; import { useDiagnostics } from "../hooks/useDiagnostics.js"; import { Button } from "../mui/Button.js"; diff --git a/packages/taler-wallet-webextension/src/wallet/EmptyComponentExample/views.tsx b/packages/taler-wallet-webextension/src/wallet/EmptyComponentExample/views.tsx index dc8a42b84..b4efcdce5 100644 --- a/packages/taler-wallet-webextension/src/wallet/EmptyComponentExample/views.tsx +++ b/packages/taler-wallet-webextension/src/wallet/EmptyComponentExample/views.tsx @@ -15,7 +15,7 @@ */ import { h, VNode } from "preact"; -import { useTranslationContext } from "../../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { State } from "./index.js"; export function ReadyView({ error }: State.Ready): VNode { diff --git a/packages/taler-wallet-webextension/src/wallet/ExchangeAddConfirm.tsx b/packages/taler-wallet-webextension/src/wallet/ExchangeAddConfirm.tsx index 2118c8984..ccea259e8 100644 --- a/packages/taler-wallet-webextension/src/wallet/ExchangeAddConfirm.tsx +++ b/packages/taler-wallet-webextension/src/wallet/ExchangeAddConfirm.tsx @@ -17,7 +17,7 @@ import { Fragment, h, VNode } from "preact"; import { useState } from "preact/hooks"; import { Title } from "../components/styled/index.js"; import { TermsOfService } from "../components/TermsOfService/index.js"; -import { useTranslationContext } from "../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { Button } from "../mui/Button.js"; export interface Props { diff --git a/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/state.ts b/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/state.ts index ff3800ee8..22faddb93 100644 --- a/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/state.ts +++ b/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/state.ts @@ -22,7 +22,7 @@ import { import { useState } from "preact/hooks"; import { alertFromError, useAlertContext } from "../../context/alert.js"; import { useBackendContext } from "../../context/backend.js"; -import { useTranslationContext } from "../../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { useAsyncAsHook } from "../../hooks/useAsyncAsHook.js"; import { Props, State } from "./index.js"; diff --git a/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/views.tsx b/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/views.tsx index 242a8e823..98ded067b 100644 --- a/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/views.tsx +++ b/packages/taler-wallet-webextension/src/wallet/ExchangeSelection/views.tsx @@ -25,7 +25,7 @@ import { SelectList } from "../../components/SelectList.js"; import { Input, SvgIcon } from "../../components/styled/index.js"; import { TermsOfService } from "../../components/TermsOfService/index.js"; import { Time } from "../../components/Time.js"; -import { useTranslationContext } from "../../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { State as SelectExchangeState } from "../../hooks/useSelectedExchange.js"; import { Button } from "../../mui/Button.js"; import arrowDown from "../../svg/chevron-down.svg"; diff --git a/packages/taler-wallet-webextension/src/wallet/ExchangeSetUrl.tsx b/packages/taler-wallet-webextension/src/wallet/ExchangeSetUrl.tsx index 404fc8bee..0b6016761 100644 --- a/packages/taler-wallet-webextension/src/wallet/ExchangeSetUrl.tsx +++ b/packages/taler-wallet-webextension/src/wallet/ExchangeSetUrl.tsx @@ -27,7 +27,7 @@ import { Title, WarningBox, } from "../components/styled/index.js"; -import { useTranslationContext } from "../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { Button } from "../mui/Button.js"; export interface Props { diff --git a/packages/taler-wallet-webextension/src/wallet/History.tsx b/packages/taler-wallet-webextension/src/wallet/History.tsx index e0e2d3af9..71f5c2e19 100644 --- a/packages/taler-wallet-webextension/src/wallet/History.tsx +++ b/packages/taler-wallet-webextension/src/wallet/History.tsx @@ -35,7 +35,7 @@ import { Time } from "../components/Time.js"; import { TransactionItem } from "../components/TransactionItem.js"; import { alertFromError, useAlertContext } from "../context/alert.js"; import { useBackendContext } from "../context/backend.js"; -import { useTranslationContext } from "../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { useAsyncAsHook } from "../hooks/useAsyncAsHook.js"; import { Button } from "../mui/Button.js"; import { NoBalanceHelp } from "../popup/NoBalanceHelp.js"; diff --git a/packages/taler-wallet-webextension/src/wallet/ManageAccount/state.ts b/packages/taler-wallet-webextension/src/wallet/ManageAccount/state.ts index d7c7d2b48..1f8ab4883 100644 --- a/packages/taler-wallet-webextension/src/wallet/ManageAccount/state.ts +++ b/packages/taler-wallet-webextension/src/wallet/ManageAccount/state.ts @@ -24,7 +24,7 @@ import { useState } from "preact/hooks"; import { alertFromError, useAlertContext } from "../../context/alert.js"; import { useBackendContext } from "../../context/backend.js"; import { useDevContext } from "../../context/devContext.js"; -import { useTranslationContext } from "../../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { useAsyncAsHook } from "../../hooks/useAsyncAsHook.js"; import { AccountByType, Props, State } from "./index.js"; diff --git a/packages/taler-wallet-webextension/src/wallet/ManageAccount/views.tsx b/packages/taler-wallet-webextension/src/wallet/ManageAccount/views.tsx index fb32e5a59..c3e11e30d 100644 --- a/packages/taler-wallet-webextension/src/wallet/ManageAccount/views.tsx +++ b/packages/taler-wallet-webextension/src/wallet/ManageAccount/views.tsx @@ -29,7 +29,7 @@ import { useState } from "preact/hooks"; import { ErrorMessage } from "../../components/ErrorMessage.js"; import { SelectList } from "../../components/SelectList.js"; import { Input, SubTitle, SvgIcon } from "../../components/styled/index.js"; -import { useTranslationContext } from "../../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { Button } from "../../mui/Button.js"; import { TextFieldHandler } from "../../mui/handlers.js"; import { TextField } from "../../mui/TextField.js"; diff --git a/packages/taler-wallet-webextension/src/wallet/Notifications/state.ts b/packages/taler-wallet-webextension/src/wallet/Notifications/state.ts index 0e06a1e75..dbfadad26 100644 --- a/packages/taler-wallet-webextension/src/wallet/Notifications/state.ts +++ b/packages/taler-wallet-webextension/src/wallet/Notifications/state.ts @@ -17,7 +17,7 @@ import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { alertFromError } from "../../context/alert.js"; import { useBackendContext } from "../../context/backend.js"; -import { useTranslationContext } from "../../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { useAsyncAsHook } from "../../hooks/useAsyncAsHook.js"; import { Props, State } from "./index.js"; diff --git a/packages/taler-wallet-webextension/src/wallet/Notifications/views.tsx b/packages/taler-wallet-webextension/src/wallet/Notifications/views.tsx index 8d0bb34c0..ea0b1c623 100644 --- a/packages/taler-wallet-webextension/src/wallet/Notifications/views.tsx +++ b/packages/taler-wallet-webextension/src/wallet/Notifications/views.tsx @@ -28,7 +28,7 @@ import { SmallLightText, } from "../../components/styled/index.js"; import { Time } from "../../components/Time.js"; -import { useTranslationContext } from "../../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { Avatar } from "../../mui/Avatar.js"; import { Button } from "../../mui/Button.js"; import { Grid } from "../../mui/Grid.js"; diff --git a/packages/taler-wallet-webextension/src/wallet/ProviderAddPage.tsx b/packages/taler-wallet-webextension/src/wallet/ProviderAddPage.tsx index 286a2a88d..3ac7254d5 100644 --- a/packages/taler-wallet-webextension/src/wallet/ProviderAddPage.tsx +++ b/packages/taler-wallet-webextension/src/wallet/ProviderAddPage.tsx @@ -32,7 +32,7 @@ import { Title, } from "../components/styled/index.js"; import { useBackendContext } from "../context/backend.js"; -import { useTranslationContext } from "../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { Button } from "../mui/Button.js"; import { queryToSlashConfig } from "../utils/index.js"; diff --git a/packages/taler-wallet-webextension/src/wallet/ProviderDetailPage.tsx b/packages/taler-wallet-webextension/src/wallet/ProviderDetailPage.tsx index 789465a87..94bcfe2fb 100644 --- a/packages/taler-wallet-webextension/src/wallet/ProviderDetailPage.tsx +++ b/packages/taler-wallet-webextension/src/wallet/ProviderDetailPage.tsx @@ -30,7 +30,7 @@ import { PaymentStatus, SmallLightText } from "../components/styled/index.js"; import { Time } from "../components/Time.js"; import { alertFromError } from "../context/alert.js"; import { useBackendContext } from "../context/backend.js"; -import { useTranslationContext } from "../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { useAsyncAsHook } from "../hooks/useAsyncAsHook.js"; import { Button } from "../mui/Button.js"; diff --git a/packages/taler-wallet-webextension/src/wallet/QrReader.tsx b/packages/taler-wallet-webextension/src/wallet/QrReader.tsx index 6a31da959..99c42edec 100644 --- a/packages/taler-wallet-webextension/src/wallet/QrReader.tsx +++ b/packages/taler-wallet-webextension/src/wallet/QrReader.tsx @@ -23,7 +23,7 @@ import { styled } from "@linaria/react"; import { css } from "@linaria/core"; import { Fragment, h, VNode } from "preact"; import { Ref, useEffect, useMemo, useRef, useState } from "preact/hooks"; -import { useTranslationContext } from "../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { Alert } from "../mui/Alert.js"; import { Button } from "../mui/Button.js"; import { TextField } from "../mui/TextField.js"; diff --git a/packages/taler-wallet-webextension/src/wallet/ReserveCreated.tsx b/packages/taler-wallet-webextension/src/wallet/ReserveCreated.tsx index c366f014f..2b05b0a36 100644 --- a/packages/taler-wallet-webextension/src/wallet/ReserveCreated.tsx +++ b/packages/taler-wallet-webextension/src/wallet/ReserveCreated.tsx @@ -21,7 +21,7 @@ import { CopyButton } from "../components/CopyButton.js"; import { ErrorMessage } from "../components/ErrorMessage.js"; import { QR } from "../components/QR.js"; import { Title, WarningBox } from "../components/styled/index.js"; -import { useTranslationContext } from "../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { Button } from "../mui/Button.js"; export interface Props { reservePub: string; diff --git a/packages/taler-wallet-webextension/src/wallet/Settings.tsx b/packages/taler-wallet-webextension/src/wallet/Settings.tsx index 3109e8947..eea1ffb49 100644 --- a/packages/taler-wallet-webextension/src/wallet/Settings.tsx +++ b/packages/taler-wallet-webextension/src/wallet/Settings.tsx @@ -36,9 +36,9 @@ import { import { useAlertContext } from "../context/alert.js"; import { useBackendContext } from "../context/backend.js"; import { useDevContext } from "../context/devContext.js"; -import { useTranslationContext } from "../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { useAsyncAsHook } from "../hooks/useAsyncAsHook.js"; -import { useAutoOpenPermissions } from "../hooks/useAutoOpenPermissions.js"; +import { useSettings } from "../hooks/useSettings.js"; import { useBackupDeviceName } from "../hooks/useBackupDeviceName.js"; import { useClipboardPermissions } from "../hooks/useClipboardPermissions.js"; import { ToggleHandler } from "../mui/handlers.js"; @@ -48,9 +48,10 @@ import { platform } from "../platform/foreground.js"; const GIT_HASH = typeof __GIT_HASH__ !== "undefined" ? __GIT_HASH__ : undefined; export function SettingsPage(): VNode { - const autoOpenToggle = useAutoOpenPermissions(); + const [settings, updateSettings] = useSettings(); const clipboardToggle = useClipboardPermissions(); const { devMode, toggle } = useDevContext(); + const { safely } = useAlertContext(); const { name, update } = useBackupDeviceName(); const { pushAlertOnError } = useAlertContext(); const webex = platform.getWalletWebExVersion(); @@ -71,7 +72,15 @@ export function SettingsPage(): VNode { knownExchanges={exchanges} deviceName={name} setDeviceName={update} - autoOpenToggle={autoOpenToggle} + autoOpenToggle={{ + value: settings.injectTalerSupport, + button: { + onClick: safely("update support injection", async () => { + console.log("click", settings.injectTalerSupport); + updateSettings("injectTalerSupport", !settings.injectTalerSupport); + }), + }, + }} clipboardToggle={clipboardToggle} devModeToggle={{ value: devMode, @@ -115,21 +124,6 @@ export function SettingsView({ return (
- {/* - Enabling this option below will make using the wallet faster, but - requires more permissions from your browser. - - } - enabled={clipboardToggle.value!} - onToggle={clipboardToggle.button.onClick!} - /> */} - Trust @@ -273,23 +267,22 @@ export function SettingsView({ enabled={devModeToggle.value!} onToggle={devModeToggle.button.onClick!} /> - - - Navigator - - - Enabling this option below will make using the wallet faster, - but requires more permissions from your browser. - - } - enabled={autoOpenToggle.value!} - onToggle={autoOpenToggle.button.onClick!} - /> - + + Navigator + + + Disabling this option will make some web application not able to + trigger the wallet when clicking links but you will be able to + open the wallet using the keyboard shortcut + + } + enabled={autoOpenToggle.value!} + onToggle={autoOpenToggle.button.onClick!} + />
); diff --git a/packages/taler-wallet-webextension/src/wallet/Transaction.tsx b/packages/taler-wallet-webextension/src/wallet/Transaction.tsx index d34e57f58..1ef0f0b79 100644 --- a/packages/taler-wallet-webextension/src/wallet/Transaction.tsx +++ b/packages/taler-wallet-webextension/src/wallet/Transaction.tsx @@ -61,7 +61,7 @@ import { import { Time } from "../components/Time.js"; import { alertFromError, useAlertContext } from "../context/alert.js"; import { useBackendContext } from "../context/backend.js"; -import { useTranslationContext } from "../context/translation.js"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { useAsyncAsHook } from "../hooks/useAsyncAsHook.js"; import { Button } from "../mui/Button.js"; import { SafeHandler } from "../mui/handlers.js"; @@ -283,10 +283,7 @@ function TransactionTemplate({ @@ -322,10 +319,7 @@ function TransactionTemplate({ @@ -340,7 +334,7 @@ function TransactionTemplate({ {showSend ? ( @@ -350,7 +344,7 @@ function TransactionTemplate({ {showRetry ? ( @@ -627,9 +621,8 @@ export function TransactionView({