summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-webextension/src/components/TermsOfService
diff options
context:
space:
mode:
Diffstat (limited to 'packages/taler-wallet-webextension/src/components/TermsOfService')
-rw-r--r--packages/taler-wallet-webextension/src/components/TermsOfService/state.ts42
-rw-r--r--packages/taler-wallet-webextension/src/components/TermsOfService/stories.tsx4
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, {});