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/wallet/AddBackupProvider/state.ts | |
parent | 8a70edb2f8e235c3462127b0aa4e1b65aa1aee0b (diff) | |
download | wallet-core-4a781bd0dd8828ce152f6ab2c3f1bbd6b5e826f7.tar.xz |
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/wallet/AddBackupProvider/state.ts')
-rw-r--r-- | packages/taler-wallet-webextension/src/wallet/AddBackupProvider/state.ts | 33 |
1 files changed, 13 insertions, 20 deletions
diff --git a/packages/taler-wallet-webextension/src/wallet/AddBackupProvider/state.ts b/packages/taler-wallet-webextension/src/wallet/AddBackupProvider/state.ts index 1b30ed0cd..cf35abac7 100644 --- a/packages/taler-wallet-webextension/src/wallet/AddBackupProvider/state.ts +++ b/packages/taler-wallet-webextension/src/wallet/AddBackupProvider/state.ts @@ -14,16 +14,13 @@ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ -import { - canonicalizeBaseUrl, - Codec, - TalerErrorDetail, -} from "@gnu-taler/taler-util"; +import { canonicalizeBaseUrl, Codec } from "@gnu-taler/taler-util"; import { codecForSyncTermsOfServiceResponse, WalletApiOperation, } from "@gnu-taler/taler-wallet-core"; import { useEffect, useState } from "preact/hooks"; +import { useAlertContext } from "../../context/alert.js"; import { useBackendContext } from "../../context/backend.js"; import { assertUnreachable } from "../../utils/index.js"; import { Props, State } from "./index.js"; @@ -152,17 +149,15 @@ export function useComponentState({ const [url, setHost] = useState<string | undefined>(); const [name, setName] = useState<string | undefined>(); const [tos, setTos] = useState(false); + const { pushAlertOnError } = useAlertContext(); const urlState = useUrlState( url, "config", codecForSyncTermsOfServiceResponse(), ); - const [operationError, setOperationError] = useState< - TalerErrorDetail | undefined - >(); const [showConfirm, setShowConfirm] = useState(false); - async function addBackupProvider() { + async function addBackupProvider(): Promise<void> { if (!url || !name) return; const resp = await api.wallet.call(WalletApiOperation.AddBackupProvider, { @@ -178,8 +173,6 @@ export function useComponentState({ } else { return onComplete(url); } - case "error": - return setOperationError(resp.error); case "ok": return onComplete(url); default: @@ -190,18 +183,18 @@ export function useComponentState({ if (showConfirm && urlState && urlState.status === "ok") { return { status: "confirm-provider", - error: operationError, + error: undefined, onAccept: { - onClick: !tos ? undefined : addBackupProvider, + onClick: !tos ? undefined : pushAlertOnError(addBackupProvider), }, onCancel: { - onClick: onBack, + onClick: pushAlertOnError(onBack), }, provider: urlState.result, tos: { value: tos, button: { - onClick: async () => setTos(!tos), + onClick: pushAlertOnError(async () => setTos(!tos)), }, }, url: url ?? "", @@ -213,25 +206,25 @@ export function useComponentState({ error: undefined, name: { value: name || "", - onInput: async (e) => setName(e), + onInput: pushAlertOnError(async (e) => setName(e)), error: name === undefined ? undefined : !name ? "Can't be empty" : undefined, }, onCancel: { - onClick: onBack, + onClick: pushAlertOnError(onBack), }, onConfirm: { onClick: !urlState || urlState.status !== "ok" || !name ? undefined - : async () => { + : pushAlertOnError(async () => { setShowConfirm(true); - }, + }), }, urlOk: urlState?.status === "ok", url: { value: url || "", - onInput: async (e) => setHost(e), + onInput: pushAlertOnError(async (e) => setHost(e)), error: errorString(urlState), }, }; |