diff options
author | Sebastian <sebasjm@gmail.com> | 2024-02-15 17:00:46 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2024-02-15 17:00:46 -0300 |
commit | 53497d03bb329b05caf3a64fdd47ca3c5bc298f7 (patch) | |
tree | 6371fe72f91e51a2f3e0708af43c332bbda012ef /packages/taler-wallet-webextension/src/wallet/AddExchange/views.tsx | |
parent | fd45d189259cef0a3a51683bb12412cd8c6fb9eb (diff) | |
download | wallet-core-53497d03bb329b05caf3a64fdd47ca3c5bc298f7.tar.xz |
fix #8395
Diffstat (limited to 'packages/taler-wallet-webextension/src/wallet/AddExchange/views.tsx')
-rw-r--r-- | packages/taler-wallet-webextension/src/wallet/AddExchange/views.tsx | 77 |
1 files changed, 45 insertions, 32 deletions
diff --git a/packages/taler-wallet-webextension/src/wallet/AddExchange/views.tsx b/packages/taler-wallet-webextension/src/wallet/AddExchange/views.tsx index 53a46fe02..b8da718d9 100644 --- a/packages/taler-wallet-webextension/src/wallet/AddExchange/views.tsx +++ b/packages/taler-wallet-webextension/src/wallet/AddExchange/views.tsx @@ -16,12 +16,12 @@ import { useTranslationContext } from "@gnu-taler/web-util/browser"; import { Fragment, h, VNode } from "preact"; -import { useState } from "preact/hooks"; import { ErrorMessage } from "../../components/ErrorMessage.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({ @@ -29,6 +29,7 @@ export function VerifyView({ onCancel, onAccept, result, + loading, knownExchanges, url, }: State.Verify): VNode { @@ -53,29 +54,43 @@ export function VerifyView({ </i18n.Translate> </LightText> )} - {result && ( - <LightText> - <i18n.Translate> - An exchange has been found! Review the information and click next - </i18n.Translate> - </LightText> - )} - {result && result.ok && expectedCurrency && expectedCurrency !== result.data.currency_specification.currency && ( - <WarningBox> - <i18n.Translate> - This exchange doesn't match the expected currency - <b>{expectedCurrency}</b> - </i18n.Translate> - </WarningBox> - )} - {result && !result.ok && !result.loading && ( - <ErrorMessage - title={i18n.str`Unable to verify this exchange`} - description={result.message} - /> - )} + {(() => { + 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> + } + switch (result.case) { + case "already-active": { + return <WarningBox> + <i18n.Translate>This exchange is already in your list.</i18n.Translate> + </WarningBox> + } + case "invalid-protocol": { + return <WarningBox> + <i18n.Translate>Only exchange accesible 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> + } + case "invalid-currency": { + return <WarningBox> + <i18n.Translate>This exchange currency "{result.body}" doesn't match the expected currency {expectedCurrency}.</i18n.Translate> + </WarningBox> + } + default: { + assertUnreachable(result.case) + } + } + })()} <p> - <Input invalid={result && !result.ok} > + <Input invalid={result && result.type !== "ok"} > <label>URL</label> <input type="text" @@ -88,31 +103,31 @@ export function VerifyView({ }} /> </Input> - {result && result.loading && ( + {loading && ( <div> <i18n.Translate>loading</i18n.Translate>... </div> )} - {result && result.ok && !result.loading && ( + {result && result.type === "ok" && ( <Fragment> <Input> <label> <i18n.Translate>Version</i18n.Translate> </label> - <input type="text" disabled value={result.data.version} /> + <input type="text" disabled value={result.body.version} /> </Input> <Input> <label> <i18n.Translate>Currency</i18n.Translate> </label> - <input type="text" disabled value={result.data.currency_specification.currency} /> + <input type="text" disabled value={result.body.currency} /> </Input> </Fragment> )} </p> - {url.error && ( + {url.value && url.error && ( <ErrorMessage - title={i18n.str`Can't use this URL`} + title={i18n.str`Can't use the URL: "${url.value}"`} description={url.error} /> )} @@ -125,9 +140,7 @@ export function VerifyView({ variant="contained" disabled={ !result || - result.loading || - !result.ok || - (!!expectedCurrency && expectedCurrency !== result.data.currency_specification.currency) + result.type !== "ok" } onClick={onAccept} > |