diff options
Diffstat (limited to 'packages/taler-wallet-webextension/src/wallet')
3 files changed, 28 insertions, 28 deletions
diff --git a/packages/taler-wallet-webextension/src/wallet/AddNewActionView.tsx b/packages/taler-wallet-webextension/src/wallet/AddNewActionView.tsx index 68a90f8b5..7f142f58b 100644 --- a/packages/taler-wallet-webextension/src/wallet/AddNewActionView.tsx +++ b/packages/taler-wallet-webextension/src/wallet/AddNewActionView.tsx @@ -13,13 +13,13 @@ You should have received a copy of the GNU General Public License along with GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ -import { classifyTalerUri, TalerUriType } from "@gnu-taler/taler-util"; +import { parseTalerUri, TalerUriAction } from "@gnu-taler/taler-util"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { Fragment, h, VNode } from "preact"; import { useState } from "preact/hooks"; -import { platform } from "../platform/foreground.js"; import { InputWithLabel } from "../components/styled/index.js"; -import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { Button } from "../mui/Button.js"; +import { platform } from "../platform/foreground.js"; export interface Props { onCancel: () => Promise<void>; @@ -27,19 +27,17 @@ export interface Props { export function AddNewActionView({ onCancel }: Props): VNode { const [url, setUrl] = useState(""); - const uriType = classifyTalerUri(url); + const uri = parseTalerUri(url); const { i18n } = useTranslationContext(); async function redirectToWallet(): Promise<void> { - platform.openWalletURIFromPopup(url); + platform.openWalletURIFromPopup(uri!); } return ( <Fragment> <section> - <InputWithLabel - invalid={url !== "" && uriType === TalerUriType.Unknown} - > + <InputWithLabel invalid={url !== "" && !uri}> <label>GNU Taler URI</label> <div> <input @@ -56,21 +54,21 @@ export function AddNewActionView({ onCancel }: Props): VNode { <Button variant="contained" color="secondary" onClick={onCancel}> <i18n.Translate>Cancel</i18n.Translate> </Button> - {uriType !== TalerUriType.Unknown && ( + {uri && ( <Button variant="contained" color="success" onClick={redirectToWallet} > {(() => { - switch (uriType) { - case TalerUriType.TalerPay: + switch (uri.type) { + case TalerUriAction.Pay: return <i18n.Translate>Open pay page</i18n.Translate>; - case TalerUriType.TalerRefund: + case TalerUriAction.Refund: return <i18n.Translate>Open refund page</i18n.Translate>; - case TalerUriType.TalerTip: + case TalerUriAction.Tip: return <i18n.Translate>Open tip page</i18n.Translate>; - case TalerUriType.TalerWithdraw: + case TalerUriAction.Withdraw: return <i18n.Translate>Open withdraw page</i18n.Translate>; } return <Fragment />; diff --git a/packages/taler-wallet-webextension/src/wallet/Application.tsx b/packages/taler-wallet-webextension/src/wallet/Application.tsx index 5c75b734b..6541625c5 100644 --- a/packages/taler-wallet-webextension/src/wallet/Application.tsx +++ b/packages/taler-wallet-webextension/src/wallet/Application.tsx @@ -20,7 +20,7 @@ * @author sebasjm */ -import { TranslatedString } from "@gnu-taler/taler-util"; +import { TalerUri, TranslatedString } from "@gnu-taler/taler-util"; import { TranslationProvider, useTranslationContext, @@ -102,7 +102,7 @@ export function Application(): VNode { component={() => ( <WalletTemplate goToTransaction={redirectToTxInfo}> <QrReaderPage - onDetected={(talerActionUrl: string) => { + onDetected={(talerActionUrl: TalerUri) => { platform.openWalletURIFromPopup(talerActionUrl); }} /> diff --git a/packages/taler-wallet-webextension/src/wallet/QrReader.tsx b/packages/taler-wallet-webextension/src/wallet/QrReader.tsx index 10916496c..81f879a62 100644 --- a/packages/taler-wallet-webextension/src/wallet/QrReader.tsx +++ b/packages/taler-wallet-webextension/src/wallet/QrReader.tsx @@ -15,22 +15,21 @@ */ import { - classifyTalerUri, - TalerUriType, + parseTalerUri, + TalerUri, TranslatedString, } from "@gnu-taler/taler-util"; -import { styled } from "@linaria/react"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { css } from "@linaria/core"; +import { styled } from "@linaria/react"; +import jsQR, * as pr from "jsqr"; import { Fragment, h, VNode } from "preact"; -import { Ref, useEffect, useMemo, useRef, useState } from "preact/hooks"; -import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; +import { useRef, useState } from "preact/hooks"; import { Alert } from "../mui/Alert.js"; import { Button } from "../mui/Button.js"; -import { TextField } from "../mui/TextField.js"; -import jsQR, * as pr from "jsqr"; -import { InputFile } from "../mui/InputFile.js"; import { Grid } from "../mui/Grid.js"; -import { notDeepEqual } from "assert"; +import { InputFile } from "../mui/InputFile.js"; +import { TextField } from "../mui/TextField.js"; const QrCanvas = css` width: 80%; @@ -51,7 +50,7 @@ const Container = styled.div` `; export interface Props { - onDetected: (url: string) => void; + onDetected: (url: TalerUri) => void; } type XY = { x: number; y: number }; @@ -214,7 +213,7 @@ export function QrReaderPage({ onDetected }: Props): VNode { function onChange(str: string) { if (!!str) { - if (classifyTalerUri(str) === TalerUriType.Unknown) { + if (!parseTalerUri(str)) { setError( i18n.str`URI is not valid. Taler URI should start with "taler://"`, ); @@ -318,7 +317,10 @@ export function QrReaderPage({ onDetected }: Props): VNode { disabled={!!error} variant="contained" color="success" - onClick={async () => onDetected(value)} + onClick={async () => { + const uri = parseTalerUri(value); + if (uri) onDetected(uri); + }} > <i18n.Translate>Open</i18n.Translate> </Button> |