2016-01-24 02:29:13 +01:00
|
|
|
/*
|
2022-06-06 17:05:26 +02:00
|
|
|
This file is part of GNU Taler
|
|
|
|
(C) 2022 Taler Systems S.A.
|
2016-01-24 02:29:13 +01:00
|
|
|
|
2022-06-06 17:05:26 +02:00
|
|
|
GNU Taler is free software; you can redistribute it and/or modify it under the
|
2016-01-24 02:29:13 +01:00
|
|
|
terms of the GNU General Public License as published by the Free Software
|
|
|
|
Foundation; either version 3, or (at your option) any later version.
|
|
|
|
|
2022-06-06 17:05:26 +02:00
|
|
|
GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
|
2016-01-24 02:29:13 +01:00
|
|
|
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
|
2022-06-06 17:05:26 +02:00
|
|
|
GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
|
2016-01-24 02:29:13 +01:00
|
|
|
*/
|
|
|
|
|
2016-03-01 19:46:20 +01:00
|
|
|
/**
|
|
|
|
* Popup shown to the user when they click
|
|
|
|
* the Taler browser action button.
|
|
|
|
*
|
2022-02-23 19:18:37 +01:00
|
|
|
* @author sebasjm
|
2016-03-01 19:46:20 +01:00
|
|
|
*/
|
|
|
|
|
2017-05-29 15:18:48 +02:00
|
|
|
/**
|
|
|
|
* Imports.
|
|
|
|
*/
|
2022-03-24 20:02:38 +01:00
|
|
|
import { h, VNode } from "preact";
|
2022-03-29 04:41:07 +02:00
|
|
|
import { JustInDevMode } from "./components/JustInDevMode.js";
|
2022-03-24 20:02:38 +01:00
|
|
|
import {
|
|
|
|
NavigationHeader,
|
|
|
|
NavigationHeaderHolder,
|
|
|
|
SvgIcon,
|
2022-03-29 04:41:07 +02:00
|
|
|
} from "./components/styled/index.js";
|
|
|
|
import { useTranslationContext } from "./context/translation.js";
|
2022-03-24 20:02:38 +01:00
|
|
|
import settingsIcon from "./svg/settings_black_24dp.svg";
|
2022-08-11 17:28:02 +02:00
|
|
|
import qrIcon from "./svg/qr_code_24px.svg";
|
2016-10-10 00:37:08 +02:00
|
|
|
|
2022-02-23 19:18:37 +01:00
|
|
|
/**
|
|
|
|
* List of pages used by the wallet
|
|
|
|
*
|
|
|
|
* @author sebasjm
|
|
|
|
*/
|
|
|
|
|
2022-06-02 17:20:36 +02:00
|
|
|
type PageLocation<DynamicPart extends object> = {
|
|
|
|
pattern: string;
|
|
|
|
(params: DynamicPart): string;
|
|
|
|
};
|
|
|
|
|
|
|
|
function replaceAll(
|
|
|
|
pattern: string,
|
|
|
|
vars: Record<string, string>,
|
|
|
|
values: Record<string, any>,
|
|
|
|
): string {
|
|
|
|
let result = pattern;
|
|
|
|
for (const v in vars) {
|
2022-06-09 15:04:30 +02:00
|
|
|
result = result.replace(vars[v], !values[v] ? "" : values[v]);
|
2022-06-02 17:20:36 +02:00
|
|
|
}
|
|
|
|
return result;
|
2021-06-16 22:01:06 +02:00
|
|
|
}
|
|
|
|
|
2022-06-02 17:20:36 +02:00
|
|
|
function pageDefinition<T extends object>(pattern: string): PageLocation<T> {
|
|
|
|
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<string, string>);
|
|
|
|
|
|
|
|
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?",
|
|
|
|
),
|
2022-08-16 02:18:39 +02:00
|
|
|
balanceManualWithdraw: pageDefinition<{ amount?: string }>(
|
|
|
|
"/balance/manual-withdraw/:amount?",
|
2022-06-02 17:20:36 +02:00
|
|
|
),
|
|
|
|
balanceDeposit: pageDefinition<{ currency: string }>(
|
|
|
|
"/balance/deposit/:currency",
|
|
|
|
),
|
|
|
|
balanceTransaction: pageDefinition<{ tid: string }>(
|
|
|
|
"/balance/transaction/:tid",
|
|
|
|
),
|
2022-08-16 02:18:39 +02:00
|
|
|
sendCash: pageDefinition<{ amount?: string }>("/destination/send/:amount"),
|
|
|
|
receiveCash: pageDefinition<{ amount?: string }>("/destination/get/:amount?"),
|
2022-06-02 17:20:36 +02:00
|
|
|
dev: "/dev",
|
|
|
|
|
|
|
|
backup: "/backup",
|
|
|
|
backupProviderDetail: pageDefinition<{ pid: string }>(
|
|
|
|
"/backup/provider/:pid",
|
|
|
|
),
|
|
|
|
backupProviderAdd: "/backup/provider/add",
|
|
|
|
|
2022-08-11 17:28:02 +02:00
|
|
|
qr: "/qr",
|
2022-06-02 17:20:36 +02:00
|
|
|
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",
|
|
|
|
};
|
|
|
|
|
2022-02-16 19:15:47 +01:00
|
|
|
export function PopupNavBar({ path = "" }: { path?: string }): VNode {
|
2022-03-14 16:15:41 +01:00
|
|
|
const { i18n } = useTranslationContext();
|
2016-10-10 00:37:08 +02:00
|
|
|
return (
|
2022-02-16 19:15:47 +01:00
|
|
|
<NavigationHeader>
|
2022-06-02 17:20:36 +02:00
|
|
|
<a
|
|
|
|
href={Pages.balance}
|
|
|
|
class={path.startsWith("/balance") ? "active" : ""}
|
|
|
|
>
|
2022-02-23 19:44:14 +01:00
|
|
|
<i18n.Translate>Balance</i18n.Translate>
|
2022-02-23 19:18:37 +01:00
|
|
|
</a>
|
2022-06-02 17:20:36 +02:00
|
|
|
<a href={Pages.backup} class={path.startsWith("/backup") ? "active" : ""}>
|
2022-02-23 19:44:14 +01:00
|
|
|
<i18n.Translate>Backup</i18n.Translate>
|
2022-02-23 19:18:37 +01:00
|
|
|
</a>
|
2022-08-11 17:28:02 +02:00
|
|
|
<div style={{ display: "flex", paddingTop: 4, justifyContent: "right" }}>
|
|
|
|
<a href={Pages.qr}>
|
|
|
|
<SvgIcon
|
|
|
|
title={i18n.str`QR Reader`}
|
|
|
|
dangerouslySetInnerHTML={{ __html: qrIcon }}
|
|
|
|
color="white"
|
|
|
|
/>
|
|
|
|
</a>
|
|
|
|
<a href={Pages.settings}>
|
|
|
|
<SvgIcon
|
|
|
|
title={i18n.str`Settings`}
|
|
|
|
dangerouslySetInnerHTML={{ __html: settingsIcon }}
|
|
|
|
color="white"
|
|
|
|
/>
|
|
|
|
</a>
|
|
|
|
</div>
|
2022-02-16 19:15:47 +01:00
|
|
|
</NavigationHeader>
|
2016-10-10 00:37:08 +02:00
|
|
|
);
|
2016-01-24 02:29:13 +01:00
|
|
|
}
|
|
|
|
|
2022-02-16 19:15:47 +01:00
|
|
|
export function WalletNavBar({ path = "" }: { path?: string }): VNode {
|
2022-03-14 16:15:41 +01:00
|
|
|
const { i18n } = useTranslationContext();
|
2021-11-15 15:18:58 +01:00
|
|
|
return (
|
2022-02-16 19:15:47 +01:00
|
|
|
<NavigationHeaderHolder>
|
|
|
|
<NavigationHeader>
|
2022-06-02 17:20:36 +02:00
|
|
|
<a
|
|
|
|
href={Pages.balance}
|
|
|
|
class={path.startsWith("/balance") ? "active" : ""}
|
|
|
|
>
|
2022-02-23 19:44:14 +01:00
|
|
|
<i18n.Translate>Balance</i18n.Translate>
|
2022-02-23 19:18:37 +01:00
|
|
|
</a>
|
2022-06-02 17:20:36 +02:00
|
|
|
<a
|
|
|
|
href={Pages.backup}
|
|
|
|
class={path.startsWith("/backup") ? "active" : ""}
|
|
|
|
>
|
2022-02-23 19:44:14 +01:00
|
|
|
<i18n.Translate>Backup</i18n.Translate>
|
2022-02-23 19:18:37 +01:00
|
|
|
</a>
|
2022-02-16 19:15:47 +01:00
|
|
|
|
|
|
|
<JustInDevMode>
|
2022-06-02 17:20:36 +02:00
|
|
|
<a href={Pages.dev} class={path.startsWith("/dev") ? "active" : ""}>
|
2022-02-23 19:44:14 +01:00
|
|
|
<i18n.Translate>Dev</i18n.Translate>
|
2022-02-23 19:18:37 +01:00
|
|
|
</a>
|
2022-02-16 19:15:47 +01:00
|
|
|
</JustInDevMode>
|
|
|
|
|
2022-08-11 17:28:02 +02:00
|
|
|
<div
|
|
|
|
style={{ display: "flex", paddingTop: 4, justifyContent: "right" }}
|
2022-02-16 19:15:47 +01:00
|
|
|
>
|
2022-08-11 17:28:02 +02:00
|
|
|
<a href={Pages.qr}>
|
|
|
|
<SvgIcon
|
|
|
|
title={i18n.str`QR Reader`}
|
|
|
|
dangerouslySetInnerHTML={{ __html: qrIcon }}
|
|
|
|
color="white"
|
|
|
|
/>
|
|
|
|
</a>
|
|
|
|
<a href={Pages.settings}>
|
|
|
|
<SvgIcon
|
|
|
|
title={i18n.str`Settings`}
|
|
|
|
dangerouslySetInnerHTML={{ __html: settingsIcon }}
|
|
|
|
color="white"
|
|
|
|
/>
|
|
|
|
</a>
|
|
|
|
</div>
|
2022-02-16 19:15:47 +01:00
|
|
|
</NavigationHeader>
|
|
|
|
</NavigationHeaderHolder>
|
2021-11-15 15:18:58 +01:00
|
|
|
);
|
2021-07-16 17:00:39 +02:00
|
|
|
}
|