From 072ac43b9f69807b8514eb11f8214637561a2573 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Thu, 4 Apr 2024 16:24:55 -0300 Subject: fix some API differences including whatwg-url params --- .../src/wallet/AddExchange/index.ts | 5 +- .../src/wallet/AddExchange/state.ts | 11 +- .../src/wallet/AddExchange/views.tsx | 113 ++++++++++++++------- 3 files changed, 86 insertions(+), 43 deletions(-) (limited to 'packages/taler-wallet-webextension/src/wallet') diff --git a/packages/taler-wallet-webextension/src/wallet/AddExchange/index.ts b/packages/taler-wallet-webextension/src/wallet/AddExchange/index.ts index d59501212..3d5a105ec 100644 --- a/packages/taler-wallet-webextension/src/wallet/AddExchange/index.ts +++ b/packages/taler-wallet-webextension/src/wallet/AddExchange/index.ts @@ -14,12 +14,12 @@ GNU Taler; see the file COPYING. If not, see */ -import { OperationFailWithBody, OperationOk, OperationResult, TalerExchangeApi } from "@gnu-taler/taler-util"; +import { OperationFailWithBody, OperationOk, TalerExchangeApi } from "@gnu-taler/taler-util"; import { ErrorAlertView } from "../../components/CurrentAlerts.js"; import { Loading } from "../../components/Loading.js"; import { ErrorAlert } from "../../context/alert.js"; import { TextFieldHandler } from "../../mui/handlers.js"; -import { compose, StateViewMap } from "../../utils/index.js"; +import { StateViewMap, compose } from "../../utils/index.js"; import { useComponentState } from "./state.js"; import { ConfirmView, VerifyView } from "./views.js"; @@ -37,6 +37,7 @@ export type State = State.Loading export type CheckExchangeErrors = { "invalid-version": string; "invalid-currency": string; + "not-found": void; "already-active": void; "invalid-protocol": void; } diff --git a/packages/taler-wallet-webextension/src/wallet/AddExchange/state.ts b/packages/taler-wallet-webextension/src/wallet/AddExchange/state.ts index 5ae0aa8f4..4a04f762a 100644 --- a/packages/taler-wallet-webextension/src/wallet/AddExchange/state.ts +++ b/packages/taler-wallet-webextension/src/wallet/AddExchange/state.ts @@ -14,15 +14,15 @@ GNU Taler; see the file COPYING. If not, see */ -import { ExchangeEntryStatus, OperationFailWithBody, OperationOk, TalerExchangeApi, TalerExchangeHttpClient, canonicalizeBaseUrl, opKnownFailureWithBody } from "@gnu-taler/taler-util"; +import { ExchangeEntryStatus, TalerExchangeHttpClient, canonicalizeBaseUrl, opKnownFailureWithBody } from "@gnu-taler/taler-util"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; +import { BrowserFetchHttpLib } from "@gnu-taler/web-util/browser"; import { useCallback, useEffect, useState } from "preact/hooks"; import { useBackendContext } from "../../context/backend.js"; import { useAsyncAsHook } from "../../hooks/useAsyncAsHook.js"; import { withSafe } from "../../mui/handlers.js"; import { RecursiveState } from "../../utils/index.js"; import { CheckExchangeErrors, Props, State } from "./index.js"; -import { BrowserFetchHttpLib } from "@gnu-taler/web-util/browser"; function urlFromInput(str: string): URL { let result: URL; @@ -83,6 +83,9 @@ export function useComponentState({ onBack, currency, noDebounce }: Props): Recu */ const api = new TalerExchangeHttpClient(baseUrl.href, new BrowserFetchHttpLib() as any); const config = await api.getConfig() + if (config.type === "fail") { + return opKnownFailureWithBody("not-found", undefined) + } if (!api.isCompatible(config.body.version)) { return opKnownFailureWithBody("invalid-version", config.body.version) } @@ -155,7 +158,7 @@ function useDebounce( const [result, setResult] = useState(undefined); const [error, setError] = useState(undefined); - const [handler, setHandler] = useState(undefined); + const [handler, setHandler] = useState(undefined); if (!disabled) { useEffect(() => { @@ -180,7 +183,7 @@ function useDebounce( setResult(undefined); } }, 500); - setHandler(h); + setHandler(h as unknown as number); }, [value, setHandler, onTrigger]); } diff --git a/packages/taler-wallet-webextension/src/wallet/AddExchange/views.tsx b/packages/taler-wallet-webextension/src/wallet/AddExchange/views.tsx index 489d7eb3b..21309fd7b 100644 --- a/packages/taler-wallet-webextension/src/wallet/AddExchange/views.tsx +++ b/packages/taler-wallet-webextension/src/wallet/AddExchange/views.tsx @@ -17,13 +17,18 @@ import { useTranslationContext } from "@gnu-taler/web-util/browser"; import { Fragment, h, VNode } from "preact"; import { ErrorMessage } from "../../components/ErrorMessage.js"; -import { Input, LightText, SubTitle, Title, WarningBox } from "../../components/styled/index.js"; +import { + Input, + LightText, + SubTitle, + Title, + WarningBox, +} from "../../components/styled/index.js"; import { TermsOfService } from "../../components/TermsOfService/index.js"; import { Button } from "../../mui/Button.js"; import { State } from "./index.js"; import { assertUnreachable } from "@gnu-taler/taler-util"; - export function VerifyView({ expectedCurrency, onCancel, @@ -57,40 +62,71 @@ export function VerifyView({ {(() => { if (!result) return; if (result.type == "ok") { - return - - An exchange has been found! Review the information and click next - - + return ( + + + An exchange has been found! Review the information and click + next + + + ); } switch (result.case) { case "already-active": { - return - This exchange is already in your list. - + return ( + + + This exchange is already in your list. + + + ); } case "invalid-protocol": { - return - Only exchange accessible through "http" and "https" are allowed. - + return ( + + + Only exchange accessible through "http" and "https" are + allowed. + + + ); } case "invalid-version": { - return - This exchange protocol version is not supported: "{result.body}". - + return ( + + + This exchange protocol version is not supported: " + {result.body}". + + + ); } case "invalid-currency": { - return - This exchange currency "{result.body}" doesn't match the expected currency {expectedCurrency}. - + return ( + + + This exchange currency "{result.body}" doesn't match + the expected currency {expectedCurrency}. + + + ); + } + case "not-found": { + return ( + + + No exchange found in that URL. + + + ); } default: { - assertUnreachable(result.case) + assertUnreachable(result.case); } } })()}

- + { if (url.onInput) { - url.onInput(e.currentTarget.value) + url.onInput(e.currentTarget.value); } }} /> @@ -138,10 +174,7 @@ export function VerifyView({