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 | 42 |
1 files changed, 19 insertions, 23 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); - }, + }), }, }, }; |