diff options
author | Sebastian <sebasjm@gmail.com> | 2023-01-09 20:20:09 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2023-01-09 20:20:09 -0300 |
commit | 4a781bd0dd8828ce152f6ab2c3f1bbd6b5e826f7 (patch) | |
tree | 5c16976f99eb973ff62d78ed64107ca01df57b99 /packages/taler-wallet-webextension/src/components/TermsOfService | |
parent | 8a70edb2f8e235c3462127b0aa4e1b65aa1aee0b (diff) | |
download | wallet-core-4a781bd0dd8828ce152f6ab2c3f1bbd6b5e826f7.tar.gz wallet-core-4a781bd0dd8828ce152f6ab2c3f1bbd6b5e826f7.tar.bz2 wallet-core-4a781bd0dd8828ce152f6ab2c3f1bbd6b5e826f7.zip |
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
Diffstat (limited to 'packages/taler-wallet-webextension/src/components/TermsOfService')
-rw-r--r-- | packages/taler-wallet-webextension/src/components/TermsOfService/state.ts | 42 | ||||
-rw-r--r-- | packages/taler-wallet-webextension/src/components/TermsOfService/stories.tsx | 4 |
2 files changed, 21 insertions, 25 deletions
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<boolean>(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<void> { 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); - }, + }), }, }, }; diff --git a/packages/taler-wallet-webextension/src/components/TermsOfService/stories.tsx b/packages/taler-wallet-webextension/src/components/TermsOfService/stories.tsx index 2479274cb..9ef1c4298 100644 --- a/packages/taler-wallet-webextension/src/components/TermsOfService/stories.tsx +++ b/packages/taler-wallet-webextension/src/components/TermsOfService/stories.tsx @@ -19,11 +19,11 @@ * @author Sebastian Javier Marchano (sebasjm) */ -import { createExample } from "../../test-utils.js"; +import { tests } from "@gnu-taler/web-util/lib/index.browser"; // import { ReadyView } from "./views.js"; export default { title: "TermsOfService", }; -// export const Ready = createExample(ReadyView, {}); +// export const Ready = tests.createExample(ReadyView, {}); |