From a957e61a9ca05c35e6f40697a343f8c815b6edea Mon Sep 17 00:00:00 2001 From: Sebastian Date: Tue, 2 May 2023 09:56:44 -0300 Subject: fix #7828 --- .../taler-wallet-webextension/src/platform/api.ts | 8 ++- .../src/platform/chrome.ts | 17 ++---- .../taler-wallet-webextension/src/platform/dev.ts | 4 +- .../src/popup/TalerActionFound.tsx | 61 +++++++++++----------- .../src/wallet/AddNewActionView.tsx | 26 +++++---- .../src/wallet/Application.tsx | 4 +- .../src/wallet/QrReader.tsx | 26 ++++----- 7 files changed, 72 insertions(+), 74 deletions(-) (limited to 'packages/taler-wallet-webextension/src') diff --git a/packages/taler-wallet-webextension/src/platform/api.ts b/packages/taler-wallet-webextension/src/platform/api.ts index f8fa0a848..f985cc4f8 100644 --- a/packages/taler-wallet-webextension/src/platform/api.ts +++ b/packages/taler-wallet-webextension/src/platform/api.ts @@ -14,7 +14,11 @@ GNU Taler; see the file COPYING. If not, see */ -import { CoreApiResponse, NotificationType } from "@gnu-taler/taler-util"; +import { + CoreApiResponse, + NotificationType, + TalerUri, +} from "@gnu-taler/taler-util"; import { WalletConfig, WalletConfigParameter, @@ -229,7 +233,7 @@ export interface ForegroundPlatformAPI { * * @param talerUri */ - openWalletURIFromPopup(talerUri: string): void; + openWalletURIFromPopup(talerUri: TalerUri): void; /** * Popup API diff --git a/packages/taler-wallet-webextension/src/platform/chrome.ts b/packages/taler-wallet-webextension/src/platform/chrome.ts index 51cf2f64e..0f6b5fb0d 100644 --- a/packages/taler-wallet-webextension/src/platform/chrome.ts +++ b/packages/taler-wallet-webextension/src/platform/chrome.ts @@ -20,6 +20,8 @@ import { TalerUriAction, TalerError, parseTalerUri, + TalerUri, + stringifyTalerUri, } from "@gnu-taler/taler-util"; import { WalletOperations } from "@gnu-taler/taler-wallet-core"; import { BackgroundOperations } from "../wxApi.js"; @@ -247,17 +249,8 @@ function notifyWhenAppIsReady(): Promise { }); } -function openWalletURIFromPopup(maybeTalerUri: string): void { - const talerUri = maybeTalerUri.startsWith("ext+") - ? maybeTalerUri.substring(4) - : maybeTalerUri; - const uri = parseTalerUri(talerUri); - if (!uri) { - logger.warn( - `Response with HTTP 402 the Taler header but could not classify ${talerUri}`, - ); - return; - } +function openWalletURIFromPopup(uri: TalerUri): void { + const talerUri = stringifyTalerUri(uri); //FIXME: this should redirect to just one place // the target pathname should handle what happens if the endpoint is not there // like "trying to open from popup but this uri is not handled" @@ -335,7 +328,7 @@ function openWalletURIFromPopup(maybeTalerUri: string): void { } } - chrome.tabs.create({ active: true, url }, () => { + chrome.tabs.update({ active: true, url }, () => { window.close(); }); } diff --git a/packages/taler-wallet-webextension/src/platform/dev.ts b/packages/taler-wallet-webextension/src/platform/dev.ts index 1a4183bec..1d43ad549 100644 --- a/packages/taler-wallet-webextension/src/platform/dev.ts +++ b/packages/taler-wallet-webextension/src/platform/dev.ts @@ -14,7 +14,7 @@ GNU Taler; see the file COPYING. If not, see */ -import { CoreApiResponse } from "@gnu-taler/taler-util"; +import { CoreApiResponse, TalerUri } from "@gnu-taler/taler-util"; import { WalletOperations } from "@gnu-taler/taler-wallet-core"; import { BackgroundOperations } from "../wxApi.js"; import { @@ -73,7 +73,7 @@ const api: BackgroundPlatformAPI & ForegroundPlatformAPI = { window.parent.frames["wallet" as any].location = `/wallet.html#${page}`; window.location.href = "about:blank"; }, - openWalletURIFromPopup: (page: string) => { + openWalletURIFromPopup: (page: TalerUri) => { alert("openWalletURIFromPopup not implemented yet"); }, redirectTabToWalletPage: (tabId: number, page: string) => { diff --git a/packages/taler-wallet-webextension/src/popup/TalerActionFound.tsx b/packages/taler-wallet-webextension/src/popup/TalerActionFound.tsx index b7984e4b8..ffd883098 100644 --- a/packages/taler-wallet-webextension/src/popup/TalerActionFound.tsx +++ b/packages/taler-wallet-webextension/src/popup/TalerActionFound.tsx @@ -19,10 +19,10 @@ * @author Sebastian Javier Marchano (sebasjm) */ -import { classifyTalerUri, TalerUriType } from "@gnu-taler/taler-util"; +import { parseTalerUri, TalerUri, TalerUriAction } from "@gnu-taler/taler-util"; +import { useTranslationContext } from "@gnu-taler/web-util/lib/index.browser"; import { Fragment, h, VNode } from "preact"; import { Title } 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"; @@ -32,15 +32,15 @@ export interface Props { } function ContentByUriType({ - type, + uri, onConfirm, }: { - type: TalerUriType; + uri: TalerUri; onConfirm: () => Promise; }) { const { i18n } = useTranslationContext(); - switch (type) { - case TalerUriType.TalerWithdraw: + switch (uri.type) { + case TalerUriAction.Withdraw: return (

@@ -52,8 +52,8 @@ function ContentByUriType({

); - case TalerUriType.TalerPayTemplate: - case TalerUriType.TalerPay: + case TalerUriAction.PayTemplate: + case TalerUriAction.Pay: return (

@@ -64,7 +64,7 @@ function ContentByUriType({

); - case TalerUriType.TalerTip: + case TalerUriAction.Tip: return (

@@ -76,7 +76,7 @@ function ContentByUriType({

); - case TalerUriType.TalerRefund: + case TalerUriAction.Refund: return (

@@ -88,34 +88,25 @@ function ContentByUriType({

); - case TalerUriType.TalerDevExperiment: - case TalerUriType.TalerTemplate: - case TalerUriType.TalerPayPull: - case TalerUriType.TalerPayPush: - case TalerUriType.TalerRecovery: - case TalerUriType.Unknown: - return ( -
-

- - This page has a malformed taler uri. - -

-
- ); - + case TalerUriAction.DevExperiment: + case TalerUriAction.PayPull: + case TalerUriAction.PayPush: + case TalerUriAction.Restore: + case TalerUriAction.Auditor: + case TalerUriAction.Exchange: + return null; default: { - const error: never = type; + const error: never = uri; return null; } } } export function TalerActionFound({ url, onDismiss }: Props): VNode { - const uriType = classifyTalerUri(url); + const talerUri = parseTalerUri(url); const { i18n } = useTranslationContext(); async function redirectToWallet(): Promise { - platform.openWalletURIFromPopup(url); + platform.openWalletURIFromPopup(talerUri!); } return ( @@ -123,7 +114,17 @@ export function TalerActionFound({ url, onDismiss }: Props): VNode { <i18n.Translate>Taler Action</i18n.Translate> - + {!talerUri ? ( +
+

+ + This page has a malformed taler uri. + +

+
+ ) : ( + + )}