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 | 36 |
1 files changed, 12 insertions, 24 deletions
diff --git a/packages/taler-wallet-webextension/src/components/TermsOfService/state.ts b/packages/taler-wallet-webextension/src/components/TermsOfService/state.ts index 3b75965d3..c25c0ed13 100644 --- a/packages/taler-wallet-webextension/src/components/TermsOfService/state.ts +++ b/packages/taler-wallet-webextension/src/components/TermsOfService/state.ts @@ -16,7 +16,9 @@ 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 { useAsyncAsHook } from "../../hooks/useAsyncAsHook.js"; import { Props, State } from "./index.js"; import { buildTermsOfServiceState } from "./utils.js"; @@ -25,9 +27,8 @@ export function useComponentState({ exchangeUrl, onChange }: Props): State { const api = useBackendContext(); const readOnly = !onChange; const [showContent, setShowContent] = useState<boolean>(readOnly); - const [errorAccepting, setErrorAccepting] = useState<Error | undefined>( - undefined, - ); + const { i18n } = useTranslationContext(); + const { pushAlert } = useAlertContext(); /** * For the exchange selected, bring the status of the terms of service @@ -54,22 +55,13 @@ export function useComponentState({ exchangeUrl, onChange }: Props): State { } if (terms.hasError) { return { - status: "loading-error", - error: terms, + status: "error", + error: alertFromError( + i18n.str`Could not load the status of the term of service`, + terms, + ), }; } - - if (errorAccepting) { - return { - status: "error-accepting", - error: { - hasError: true, - operational: false, - message: errorAccepting.message, - }, - }; - } - const { state } = terms.response; async function onUpdate(accepted: boolean): Promise<void> { @@ -77,13 +69,13 @@ export function useComponentState({ exchangeUrl, onChange }: Props): State { try { if (accepted) { - api.wallet.call(WalletApiOperation.SetExchangeTosAccepted, { + await api.wallet.call(WalletApiOperation.SetExchangeTosAccepted, { exchangeBaseUrl: exchangeUrl, etag: state.version, }); } else { // mark as not accepted - api.wallet.call(WalletApiOperation.SetExchangeTosAccepted, { + await api.wallet.call(WalletApiOperation.SetExchangeTosAccepted, { exchangeBaseUrl: exchangeUrl, etag: undefined, }); @@ -91,11 +83,7 @@ export function useComponentState({ exchangeUrl, onChange }: Props): State { // setAccepted(accepted); if (!readOnly) onChange(accepted); //external update } catch (e) { - if (e instanceof Error) { - //FIXME: uncomment this and display error - // setErrorAccepting(e.message); - setErrorAccepting(e); - } + pushAlert(alertFromError(i18n.str`Could not accept terms of service`, e)); } } |