diff options
Diffstat (limited to 'packages/taler-wallet-webextension/src/components/TermsOfService/state.ts')
-rw-r--r-- | packages/taler-wallet-webextension/src/components/TermsOfService/state.ts | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/packages/taler-wallet-webextension/src/components/TermsOfService/state.ts b/packages/taler-wallet-webextension/src/components/TermsOfService/state.ts index ed4715301..ac7896fbe 100644 --- a/packages/taler-wallet-webextension/src/components/TermsOfService/state.ts +++ b/packages/taler-wallet-webextension/src/components/TermsOfService/state.ts @@ -16,7 +16,7 @@ import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { useTranslationContext } from "@gnu-taler/web-util/browser"; -import { useState } from "preact/hooks"; +import { useState, useEffect } from "preact/hooks"; import { alertFromError, useAlertContext } from "../../context/alert.js"; import { useBackendContext } from "../../context/backend.js"; import { useAsyncAsHook } from "../../hooks/useAsyncAsHook.js"; @@ -26,9 +26,11 @@ import { buildTermsOfServiceState } from "./utils.js"; export function useComponentState({ showEvenIfaccepted, exchangeUrl, readOnly, children }: Props): State { const api = useBackendContext(); const [showContent, setShowContent] = useState<boolean>(!!readOnly); - const { i18n } = useTranslationContext(); + const { i18n, lang } = useTranslationContext(); + const [tosLang, setTosLang] = useState<string>() const { pushAlertOnError } = useAlertContext(); + const acceptedLang = tosLang ?? lang /** * For the exchange selected, bring the status of the terms of service */ @@ -38,13 +40,19 @@ export function useComponentState({ showEvenIfaccepted, exchangeUrl, readOnly, c { exchangeBaseUrl: exchangeUrl, acceptedFormat: ["text/xml"], + acceptLanguage: acceptedLang, }, ); + const supportedLangs = exchangeTos.tosAvailableLanguages.reduce((prev, cur) => { + prev[cur] = cur + return prev; + }, {} as Record<string, string>) + const state = buildTermsOfServiceState(exchangeTos); - return { state }; - }, []); + return { state, supportedLangs }; + }, [acceptedLang]); if (!terms) { return { @@ -61,7 +69,7 @@ export function useComponentState({ showEvenIfaccepted, exchangeUrl, readOnly, c ), }; } - const { state } = terms.response; + const { state, supportedLangs } = terms.response; async function onUpdate(accepted: boolean): Promise<void> { if (!state) return; @@ -121,6 +129,13 @@ export function useComponentState({ showEvenIfaccepted, exchangeUrl, readOnly, c terms: state, showingTermsOfService: readOnly ? undefined : base.showingTermsOfService, termsAccepted: base.termsAccepted, + tosLang: { + onChange: pushAlertOnError(async (s) => { + setTosLang(s) + }), + list: supportedLangs, + value: tosLang ?? lang + } }; } //showing buttons |