aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-webextension
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2024-04-04 16:24:55 -0300
committerSebastian <sebasjm@gmail.com>2024-04-04 16:25:08 -0300
commit072ac43b9f69807b8514eb11f8214637561a2573 (patch)
treeb5b464682589f2b80dc4d8f547e9d549a4df353a /packages/taler-wallet-webextension
parent01838bfcc74a2e4e828885d5ab0d6f64cc96f328 (diff)
fix some API differences including whatwg-url params
Diffstat (limited to 'packages/taler-wallet-webextension')
-rw-r--r--packages/taler-wallet-webextension/src/wallet/AddExchange/index.ts5
-rw-r--r--packages/taler-wallet-webextension/src/wallet/AddExchange/state.ts11
-rw-r--r--packages/taler-wallet-webextension/src/wallet/AddExchange/views.tsx113
3 files changed, 86 insertions, 43 deletions
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 <http://www.gnu.org/licenses/>
*/
-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 <http://www.gnu.org/licenses/>
*/
-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<CheckExchangeErrors>("not-found", undefined)
+ }
if (!api.isCompatible(config.body.version)) {
return opKnownFailureWithBody<CheckExchangeErrors>("invalid-version", config.body.version)
}
@@ -155,7 +158,7 @@ function useDebounce<T>(
const [result, setResult] = useState<T | undefined>(undefined);
const [error, setError] = useState<Error | undefined>(undefined);
- const [handler, setHandler] = useState<any | undefined>(undefined);
+ const [handler, setHandler] = useState<number | undefined>(undefined);
if (!disabled) {
useEffect(() => {
@@ -180,7 +183,7 @@ function useDebounce<T>(
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 <LightText>
- <i18n.Translate>
- An exchange has been found! Review the information and click next
- </i18n.Translate>
- </LightText>
+ return (
+ <LightText>
+ <i18n.Translate>
+ An exchange has been found! Review the information and click
+ next
+ </i18n.Translate>
+ </LightText>
+ );
}
switch (result.case) {
case "already-active": {
- return <WarningBox>
- <i18n.Translate>This exchange is already in your list.</i18n.Translate>
- </WarningBox>
+ return (
+ <WarningBox>
+ <i18n.Translate>
+ This exchange is already in your list.
+ </i18n.Translate>
+ </WarningBox>
+ );
}
case "invalid-protocol": {
- return <WarningBox>
- <i18n.Translate>Only exchange accessible through "http" and "https" are allowed.</i18n.Translate>
- </WarningBox>
+ return (
+ <WarningBox>
+ <i18n.Translate>
+ Only exchange accessible through "http" and "https" are
+ allowed.
+ </i18n.Translate>
+ </WarningBox>
+ );
}
case "invalid-version": {
- return <WarningBox>
- <i18n.Translate>This exchange protocol version is not supported: "{result.body}".</i18n.Translate>
- </WarningBox>
+ return (
+ <WarningBox>
+ <i18n.Translate>
+ This exchange protocol version is not supported: "
+ {result.body}".
+ </i18n.Translate>
+ </WarningBox>
+ );
}
case "invalid-currency": {
- return <WarningBox>
- <i18n.Translate>This exchange currency "{result.body}" doesn&apos;t match the expected currency {expectedCurrency}.</i18n.Translate>
- </WarningBox>
+ return (
+ <WarningBox>
+ <i18n.Translate>
+ This exchange currency "{result.body}" doesn&apos;t match
+ the expected currency {expectedCurrency}.
+ </i18n.Translate>
+ </WarningBox>
+ );
+ }
+ case "not-found": {
+ return (
+ <WarningBox>
+ <i18n.Translate>
+ No exchange found in that URL.
+ </i18n.Translate>
+ </WarningBox>
+ );
}
default: {
- assertUnreachable(result.case)
+ assertUnreachable(result.case);
}
}
})()}
<p>
- <Input invalid={result && result.type !== "ok"} >
+ <Input invalid={result && result.type !== "ok"}>
<label>URL</label>
<input
type="text"
@@ -98,7 +134,7 @@ export function VerifyView({
value={url.value}
onInput={(e) => {
if (url.onInput) {
- url.onInput(e.currentTarget.value)
+ url.onInput(e.currentTarget.value);
}
}}
/>
@@ -138,10 +174,7 @@ export function VerifyView({
</Button>
<Button
variant="contained"
- disabled={
- !result ||
- result.type !== "ok"
- }
+ disabled={!result || result.type !== "ok"}
onClick={onAccept}
>
<i18n.Translate>Next</i18n.Translate>
@@ -149,14 +182,22 @@ export function VerifyView({
</footer>
<section>
<ul>
- {knownExchanges.map(ex => {
- return <li><a href="#" onClick={(e) => {
- if (url.onInput) {
- url.onInput(ex.href)
- }
- e.preventDefault()
- }}>
- {ex.href}</a></li>
+ {knownExchanges.map((ex) => {
+ return (
+ <li key={ex.href}>
+ <a
+ href="#"
+ onClick={(e) => {
+ if (url.onInput) {
+ url.onInput(ex.href);
+ }
+ e.preventDefault();
+ }}
+ >
+ {ex.href}
+ </a>
+ </li>
+ );
})}
</ul>
</section>
@@ -164,7 +205,6 @@ export function VerifyView({
);
}
-
export function ConfirmView({
url,
onCancel,
@@ -186,8 +226,7 @@ export function ConfirmView({
</div>
</section>
-
- <TermsOfService key="terms" exchangeUrl={url} >
+ <TermsOfService key="terms" exchangeUrl={url}>
<footer>
<Button
key="cancel"