From 9387eceb429169f437c216179948cb53861b46ed Mon Sep 17 00:00:00 2001 From: Sebastian Date: Sun, 16 Jun 2024 17:14:56 -0300 Subject: add skip tos when the exhange doesn't have tos --- .../src/components/TermsOfService/index.ts | 9 ++- .../src/components/TermsOfService/state.ts | 78 +++++++++++-------- .../src/components/TermsOfService/views.tsx | 90 +++++++++++----------- 3 files changed, 100 insertions(+), 77 deletions(-) (limited to 'packages/taler-wallet-webextension/src/components/TermsOfService') diff --git a/packages/taler-wallet-webextension/src/components/TermsOfService/index.ts b/packages/taler-wallet-webextension/src/components/TermsOfService/index.ts index 1585e3992..7ef5b95a1 100644 --- a/packages/taler-wallet-webextension/src/components/TermsOfService/index.ts +++ b/packages/taler-wallet-webextension/src/components/TermsOfService/index.ts @@ -17,7 +17,11 @@ import { ComponentChildren } from "preact"; import { Loading } from "../../components/Loading.js"; import { ErrorAlert } from "../../context/alert.js"; -import { SelectFieldHandler, ToggleHandler } from "../../mui/handlers.js"; +import { + ButtonHandler, + SelectFieldHandler, + ToggleHandler, +} from "../../mui/handlers.js"; import { StateViewMap, compose } from "../../utils/index.js"; import { ErrorAlertView } from "../CurrentAlerts.js"; import { useComponentState } from "./state.js"; @@ -61,6 +65,7 @@ export namespace State { status: "show-content"; termsAccepted: ToggleHandler; showingTermsOfService?: ToggleHandler; + skipTos: ButtonHandler; tosLang: SelectFieldHandler; tosFormat: SelectFieldHandler; } @@ -68,7 +73,7 @@ export namespace State { status: "show-buttons-accepted"; termsAccepted: ToggleHandler; showingTermsOfService: ToggleHandler; - children: ComponentChildren, + children: ComponentChildren; } export interface ShowButtonsNotAccepted extends BaseInfo { status: "show-buttons-not-accepted"; diff --git a/packages/taler-wallet-webextension/src/components/TermsOfService/state.ts b/packages/taler-wallet-webextension/src/components/TermsOfService/state.ts index 76524f0f4..96d14dadf 100644 --- a/packages/taler-wallet-webextension/src/components/TermsOfService/state.ts +++ b/packages/taler-wallet-webextension/src/components/TermsOfService/state.ts @@ -25,22 +25,28 @@ import { buildTermsOfServiceState } from "./utils.js"; const supportedFormats = { "text/html": "HTML", - "text/xml" : "XML", - "text/markdown" : "Markdown", - "text/plain" : "Plain text", - "text/pdf" : "PDF", -} - -export function useComponentState({ showEvenIfaccepted, exchangeUrl, readOnly, children }: Props): State { + "text/xml": "XML", + "text/markdown": "Markdown", + "text/plain": "Plain text", + "text/pdf": "PDF", +}; + +export function useComponentState({ + showEvenIfaccepted, + exchangeUrl, + readOnly, + children, +}: Props): State { const api = useBackendContext(); const [showContent, setShowContent] = useState(!!readOnly); const { i18n, lang } = useTranslationContext(); - const [tosLang, setTosLang] = useState() + const [forceAccepted, setForceAccepted] = useState(); + const [tosLang, setTosLang] = useState(); const { pushAlertOnError } = useAlertContext(); - const [format, setFormat] = useState("text/html") + const [format, setFormat] = useState("text/html"); - const acceptedLang = tosLang ?? lang + const acceptedLang = tosLang ?? lang; /** * For the exchange selected, bring the status of the terms of service */ @@ -54,10 +60,13 @@ export function useComponentState({ showEvenIfaccepted, exchangeUrl, readOnly, c }, ); - const supportedLangs = exchangeTos.tosAvailableLanguages.reduce((prev, cur) => { - prev[cur] = cur - return prev; - }, {} as Record) + const supportedLangs = exchangeTos.tosAvailableLanguages.reduce( + (prev, cur) => { + prev[cur] = cur; + return prev; + }, + {} as Record, + ); const state = buildTermsOfServiceState(exchangeTos); @@ -92,30 +101,35 @@ export function useComponentState({ showEvenIfaccepted, exchangeUrl, readOnly, c } else { // mark as not accepted } - terms?.retry() + terms?.retry(); } - const accepted = state.status === "accepted"; + const accepted = state.status === "accepted" || forceAccepted; const base = { error: undefined, showingTermsOfService: { value: showContent && (!accepted || showEvenIfaccepted), button: { - onClick: accepted && !showEvenIfaccepted ? undefined : pushAlertOnError(async () => { - setShowContent(!showContent); - }), + onClick: + accepted && !showEvenIfaccepted + ? undefined + : pushAlertOnError(async () => { + setShowContent(!showContent); + }), }, }, terms: state, termsAccepted: { value: accepted, button: { - onClick: readOnly ? undefined : pushAlertOnError(async () => { - const newValue = !accepted; //toggle - await onUpdate(newValue); - setShowContent(false); - }), + onClick: readOnly + ? undefined + : pushAlertOnError(async () => { + const newValue = !accepted; //toggle + await onUpdate(newValue); + setShowContent(false); + }), }, }, }; @@ -135,20 +149,25 @@ export function useComponentState({ showEvenIfaccepted, exchangeUrl, readOnly, c terms: state, showingTermsOfService: readOnly ? undefined : base.showingTermsOfService, termsAccepted: base.termsAccepted, + skipTos: { + onClick: pushAlertOnError(async () => { + setForceAccepted(true); + }), + }, tosFormat: { onChange: pushAlertOnError(async (s) => { - setFormat(s) + setFormat(s); }), list: supportedFormats, - value: format ?? "" + value: format ?? "", }, tosLang: { onChange: pushAlertOnError(async (s) => { - setTosLang(s) + setTosLang(s); }), list: supportedLangs, - value: tosLang ?? lang - } + value: tosLang ?? lang, + }, }; } //showing buttons @@ -156,5 +175,4 @@ export function useComponentState({ showEvenIfaccepted, exchangeUrl, readOnly, c status: "show-buttons-not-accepted", ...base, }; - } diff --git a/packages/taler-wallet-webextension/src/components/TermsOfService/views.tsx b/packages/taler-wallet-webextension/src/components/TermsOfService/views.tsx index 40cfba3bc..f3172a741 100644 --- a/packages/taler-wallet-webextension/src/components/TermsOfService/views.tsx +++ b/packages/taler-wallet-webextension/src/components/TermsOfService/views.tsx @@ -23,7 +23,7 @@ import { Input, LinkSuccess, TermsOfServiceStyle, - WarningBox + WarningBox, } from "../../components/styled/index.js"; import { Button } from "../../mui/Button.js"; import { State } from "./index.js"; @@ -50,7 +50,9 @@ export function ShowButtonsAcceptedTosView({ {termsAccepted.button.onClick !== undefined && ( -
+
- // {terms.status === ExchangeTosStatus.Pending && ( - //
- // - // - // Exchange doesn't have terms of service - // - // - //
- // )} - // - // ); - // } return ( - {/* {terms.status === ExchangeTosStatus.NotFound && ( -
- - - Exchange doesn't have terms of service - - -
- )} */}
+
+
+ ); + } return (
@@ -206,20 +205,21 @@ export function ShowTosContentView({
)} - {termsAccepted.button.onClick && terms.status !== ExchangeTosStatus.Accepted && ( -
- - I accept the exchange terms of service - - } - onToggle={termsAccepted.button.onClick} - /> -
- )} + {termsAccepted.button.onClick && + terms.status !== ExchangeTosStatus.Accepted && ( +
+ + I accept the exchange terms of service + + } + onToggle={termsAccepted.button.onClick} + /> +
+ )}
); } -- cgit v1.2.3