From 32f6409ac312f31821f791c3a376168289f0e4f4 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Wed, 23 Mar 2022 10:50:12 -0300 Subject: all the browser related code move into one place, making it easy for specific platform code or mocking for testing --- .../src/popup/DeveloperPage.tsx | 20 -------- .../src/popup/TalerActionFound.tsx | 53 ++++------------------ 2 files changed, 9 insertions(+), 64 deletions(-) (limited to 'packages/taler-wallet-webextension/src/popup') diff --git a/packages/taler-wallet-webextension/src/popup/DeveloperPage.tsx b/packages/taler-wallet-webextension/src/popup/DeveloperPage.tsx index 3deea032d..d47b8ce7b 100644 --- a/packages/taler-wallet-webextension/src/popup/DeveloperPage.tsx +++ b/packages/taler-wallet-webextension/src/popup/DeveloperPage.tsx @@ -375,16 +375,6 @@ function toBase64(str: string): string { ); } -export function reload(): void { - try { - // eslint-disable-next-line no-undef - chrome.runtime.reload(); - window.close(); - } catch (e) { - // Functionality missing in firefox, ignore! - } -} - function runIntegrationTest() {} export async function confirmReset( @@ -395,13 +385,3 @@ export async function confirmReset( window.close(); } } - -export function openExtensionPage(page: string) { - return () => { - // eslint-disable-next-line no-undef - chrome.tabs.create({ - // eslint-disable-next-line no-undef - url: chrome.runtime.getURL(page), - }); - }; -} diff --git a/packages/taler-wallet-webextension/src/popup/TalerActionFound.tsx b/packages/taler-wallet-webextension/src/popup/TalerActionFound.tsx index 9ac83a578..a1082ad92 100644 --- a/packages/taler-wallet-webextension/src/popup/TalerActionFound.tsx +++ b/packages/taler-wallet-webextension/src/popup/TalerActionFound.tsx @@ -21,36 +21,21 @@ import { classifyTalerUri, TalerUriType } from "@gnu-taler/taler-util"; import { Fragment, h } from "preact"; +import { platform } from "../platform/api"; import { ButtonPrimary, ButtonSuccess } from "../components/styled"; import { useTranslationContext } from "../context/translation"; -import { actionForTalerUri } from "../utils/index"; export interface Props { url: string; onDismiss: () => void; } -async function getCurrentTab(): Promise { - let queryOptions = { active: true, currentWindow: true }; - const tab = await new Promise((res, rej) => { - chrome.tabs.query(queryOptions, (tabs) => { - res(tabs[0]); - }); - }); - return tab; -} - -async function navigateTo(url?: string) { - if (!url) return; - const tab = await getCurrentTab(); - if (!tab.id) return; - await chrome.tabs.update(tab.id, { url }); - window.close(); -} - export function TalerActionFound({ url, onDismiss }: Props) { const uriType = classifyTalerUri(url); const { i18n } = useTranslationContext(); + function redirectToWallet() { + platform.openWalletURIFromPopup(uriType, url); + } return (
@@ -62,11 +47,7 @@ export function TalerActionFound({ url, onDismiss }: Props) {

This page has pay action.

- { - navigateTo(actionForTalerUri(uriType, url)); - }} - > + Open pay page @@ -78,11 +59,7 @@ export function TalerActionFound({ url, onDismiss }: Props) { This page has a withdrawal action.

- { - navigateTo(actionForTalerUri(uriType, url)); - }} - > + Open withdraw page @@ -92,11 +69,7 @@ export function TalerActionFound({ url, onDismiss }: Props) {

This page has a tip action.

- { - navigateTo(actionForTalerUri(uriType, url)); - }} - > + Open tip page @@ -108,11 +81,7 @@ export function TalerActionFound({ url, onDismiss }: Props) { This page has a notify reserve action.

- { - navigateTo(actionForTalerUri(uriType, url)); - }} - > + Notify @@ -122,11 +91,7 @@ export function TalerActionFound({ url, onDismiss }: Props) {

This page has a refund action.

- { - navigateTo(actionForTalerUri(uriType, url)); - }} - > + Open refund page -- cgit v1.2.3