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/popupEntryPoint.tsx | 31 +++++++++++++--------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'packages/taler-wallet-webextension/src/popupEntryPoint.tsx') diff --git a/packages/taler-wallet-webextension/src/popupEntryPoint.tsx b/packages/taler-wallet-webextension/src/popupEntryPoint.tsx index 7ee6c8e4b..dfb12666b 100644 --- a/packages/taler-wallet-webextension/src/popupEntryPoint.tsx +++ b/packages/taler-wallet-webextension/src/popupEntryPoint.tsx @@ -17,7 +17,7 @@ /** * Main entry point for extension pages. * - * @author sebasjm + * @author sebasjm */ import { setupI18n } from "@gnu-taler/taler-util"; @@ -37,6 +37,9 @@ import { import { useTalerActionURL } from "./hooks/useTalerActionURL"; import { strings } from "./i18n/strings"; import { Pages, PopupNavBar } from "./NavigationBar"; +import { platform, setupPlatform } from "./platform/api"; +import chromeAPI from "./platform/chrome"; +import firefoxAPI from "./platform/firefox"; import { BalancePage } from "./popup/BalancePage"; import { TalerActionFound } from "./popup/TalerActionFound"; import { BackupPage } from "./wallet/BackupPage"; @@ -59,6 +62,17 @@ function main(): void { setupI18n("en", strings); +//FIXME: create different entry point for any platform instead of +//switching in runtime +const isFirefox = typeof (window as any)["InstallTrigger"] !== "undefined"; +if (isFirefox) { + console.log("Wallet setup for Firefox API"); + setupPlatform(firefoxAPI); +} else { + console.log("Wallet setup for Chrome API"); + setupPlatform(chromeAPI); +} + if (document.readyState === "loading") { document.addEventListener("DOMContentLoaded", main); } else { @@ -106,7 +120,7 @@ function Application(): VNode { route(Pages.balance_deposit.replace(":currency", currency)) } goToWalletHistory={(currency: string) => - route(Pages.balance_history.replace(":currency", currency)) + route(Pages.balance_history.replace(":currency?", currency)) } /> @@ -180,19 +194,10 @@ function Application(): VNode { } function RedirectToWalletPage(): VNode { - const page = document.location.hash || "#/"; + const page = (document.location.hash || "#/").replace("#", ""); const [showText, setShowText] = useState(false); useEffect(() => { - chrome.tabs.create( - { - active: true, - // eslint-disable-next-line no-undef - url: chrome.runtime.getURL(`/static/wallet.html${page}`), - }, - () => { - window.close(); - }, - ); + platform.openWalletPageFromPopup(page); setTimeout(() => { setShowText(true); }, 250); -- cgit v1.2.3