From 7b2de89444f27faa554bb40855da996a113ef5b9 Mon Sep 17 00:00:00 2001
From: Sebastian <sebasjm@gmail.com>
Date: Thu, 13 Apr 2023 12:21:39 -0300
Subject: use /taler-uri as redirection point to all taler uris

---
 .../src/NavigationBar.tsx                          | 30 ++++++++++++++++++++++
 1 file changed, 30 insertions(+)

(limited to 'packages/taler-wallet-webextension/src/NavigationBar.tsx')

diff --git a/packages/taler-wallet-webextension/src/NavigationBar.tsx b/packages/taler-wallet-webextension/src/NavigationBar.tsx
index e8ee4f475..b73704c70 100644
--- a/packages/taler-wallet-webextension/src/NavigationBar.tsx
+++ b/packages/taler-wallet-webextension/src/NavigationBar.tsx
@@ -38,6 +38,7 @@ import { useAsyncAsHook } from "./hooks/useAsyncAsHook.js";
 import qrIcon from "./svg/qr_code_24px.svg";
 import settingsIcon from "./svg/settings_black_24dp.svg";
 import warningIcon from "./svg/warning_24px.svg";
+import { parseTalerUri, TalerUriAction } from "@gnu-taler/taler-util";
 
 /**
  * List of pages used by the wallet
@@ -115,6 +116,7 @@ export const Pages = {
     "/settings/exchange/add/:currency?",
   ),
 
+  defaultCta: pageDefinition<{ uri: string }>("/taler-uri/:uri"),
   cta: pageDefinition<{ action: string }>("/cta/:action"),
   ctaPay: "/cta/pay",
   ctaPayTemplate: "/cta/pay/template",
@@ -136,6 +138,34 @@ export const Pages = {
   ),
 };
 
+const talerUriActionToPageName: {
+  [t in TalerUriAction]: keyof typeof Pages | undefined;
+} = {
+  [TalerUriAction.Withdraw]: "ctaWithdraw",
+  [TalerUriAction.Pay]: "ctaPay",
+  [TalerUriAction.Tip]: "ctaTips",
+  [TalerUriAction.Refund]: "ctaRefund",
+  [TalerUriAction.PayPull]: "ctaInvoicePay",
+  [TalerUriAction.PayPush]: "ctaTransferPickup",
+  [TalerUriAction.Restore]: "ctaRecovery",
+  [TalerUriAction.PayTemplate]: "ctaPayTemplate",
+  [TalerUriAction.DevExperiment]: undefined,
+  [TalerUriAction.Exchange]: undefined,
+  [TalerUriAction.Auditor]: undefined,
+};
+
+export function getPathnameForTalerURI(talerUri: string): string | undefined {
+  const uri = parseTalerUri(talerUri);
+  if (!uri) {
+    return undefined;
+  }
+  const pageName = talerUriActionToPageName[uri.type];
+  if (!pageName) {
+    return undefined;
+  }
+  return `${Pages[pageName]}?talerUri=${encodeURIComponent(talerUri)}`;
+}
+
 export type PopupNavBarOptions = "balance" | "backup" | "dev";
 export function PopupNavBar({ path }: { path?: PopupNavBarOptions }): VNode {
   const api = useBackendContext();
-- 
cgit v1.2.3

