From 4a781bd0dd8828ce152f6ab2c3f1bbd6b5e826f7 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 9 Jan 2023 20:20:09 -0300 Subject: fix #7153: more error handling if handler do not trap error then fail at compile time, all safe handlers push alert on error errors are typed so they render good information --- .../src/components/TermsOfService/state.ts | 42 ++++++++++------------ 1 file changed, 19 insertions(+), 23 deletions(-) (limited to 'packages/taler-wallet-webextension/src/components/TermsOfService/state.ts') diff --git a/packages/taler-wallet-webextension/src/components/TermsOfService/state.ts b/packages/taler-wallet-webextension/src/components/TermsOfService/state.ts index c25c0ed13..541b2d39e 100644 --- a/packages/taler-wallet-webextension/src/components/TermsOfService/state.ts +++ b/packages/taler-wallet-webextension/src/components/TermsOfService/state.ts @@ -28,7 +28,7 @@ export function useComponentState({ exchangeUrl, onChange }: Props): State { const readOnly = !onChange; const [showContent, setShowContent] = useState(readOnly); const { i18n } = useTranslationContext(); - const { pushAlert } = useAlertContext(); + const { pushAlertOnError } = useAlertContext(); /** * For the exchange selected, bring the status of the terms of service @@ -67,24 +67,20 @@ export function useComponentState({ exchangeUrl, onChange }: Props): State { async function onUpdate(accepted: boolean): Promise { if (!state) return; - try { - if (accepted) { - await api.wallet.call(WalletApiOperation.SetExchangeTosAccepted, { - exchangeBaseUrl: exchangeUrl, - etag: state.version, - }); - } else { - // mark as not accepted - await api.wallet.call(WalletApiOperation.SetExchangeTosAccepted, { - exchangeBaseUrl: exchangeUrl, - etag: undefined, - }); - } - // setAccepted(accepted); - if (!readOnly) onChange(accepted); //external update - } catch (e) { - pushAlert(alertFromError(i18n.str`Could not accept terms of service`, e)); + if (accepted) { + await api.wallet.call(WalletApiOperation.SetExchangeTosAccepted, { + exchangeBaseUrl: exchangeUrl, + etag: state.version, + }); + } else { + // mark as not accepted + await api.wallet.call(WalletApiOperation.SetExchangeTosAccepted, { + exchangeBaseUrl: exchangeUrl, + etag: undefined, + }); } + // setAccepted(accepted); + if (!readOnly) onChange(accepted); //external update } const accepted = state.status === "accepted"; @@ -94,20 +90,20 @@ export function useComponentState({ exchangeUrl, onChange }: Props): State { showingTermsOfService: { value: showContent, button: { - onClick: async () => { + onClick: pushAlertOnError(async () => { setShowContent(!showContent); - }, + }), }, }, terms: state, termsAccepted: { value: accepted, button: { - onClick: async () => { + onClick: pushAlertOnError(async () => { const newValue = !accepted; //toggle - onUpdate(newValue); + await onUpdate(newValue); setShowContent(false); - }, + }), }, }, }; -- cgit v1.2.3