/* This file is part of GNU Taler (C) 2022 Taler Systems S.A. GNU Taler is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version. GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Taler; see the file COPYING. If not, see */ /** * Popup shown to the user when they click * the Taler browser action button. * * @author sebasjm */ /** * Imports. */ import { h, VNode } from "preact"; import { JustInDevMode } from "./components/JustInDevMode.js"; import { NavigationHeader, NavigationHeaderHolder, SvgIcon, } from "./components/styled/index.js"; import { useTranslationContext } from "./context/translation.js"; import settingsIcon from "./svg/settings_black_24dp.svg"; /** * List of pages used by the wallet * * @author sebasjm */ type PageLocation = { pattern: string; (params: DynamicPart): string; }; function replaceAll( pattern: string, vars: Record, values: Record, ): string { let result = pattern; for (const v in vars) { result = result.replace(vars[v], !values[v] ? "" : values[v]); } return result; } function pageDefinition(pattern: string): PageLocation { const patternParams = pattern.match(/(:[\w?]*)/g); if (!patternParams) throw Error( `page definition pattern ${pattern} doesn't have any parameter`, ); const vars = patternParams.reduce((prev, cur) => { const pName = cur.match(/(\w+)/g); //skip things like :? in the path pattern if (!pName || !pName[0]) return prev; const name = pName[0]; return { ...prev, [name]: cur }; }, {} as Record); const f = (values: T): string => replaceAll(pattern, vars, values); f.pattern = pattern; return f; } export const Pages = { welcome: "/welcome", balance: "/balance", balanceHistory: pageDefinition<{ currency?: string }>( "/balance/history/:currency?", ), balanceManualWithdraw: pageDefinition<{ currency?: string }>( "/balance/manual-withdraw/:currency?", ), balanceDeposit: pageDefinition<{ currency: string }>( "/balance/deposit/:currency", ), balanceTransaction: pageDefinition<{ tid: string }>( "/balance/transaction/:tid", ), dev: "/dev", backup: "/backup", backupProviderDetail: pageDefinition<{ pid: string }>( "/backup/provider/:pid", ), backupProviderAdd: "/backup/provider/add", settings: "/settings", settingsExchangeAdd: pageDefinition<{ currency?: string }>( "/settings/exchange/add/:currency?", ), cta: pageDefinition<{ action: string }>("/cta/:action"), ctaPay: "/cta/pay", ctaRefund: "/cta/refund", ctaTips: "/cta/tip", ctaWithdraw: "/cta/withdraw", ctaDeposit: "/cta/deposit", }; export function PopupNavBar({ path = "" }: { path?: string }): VNode { const { i18n } = useTranslationContext(); return ( Balance Backup ); } export function WalletNavBar({ path = "" }: { path?: string }): VNode { const { i18n } = useTranslationContext(); return ( Balance Backup Dev Settings ); }