2022-06-06 17:06:25 +02:00
|
|
|
/*
|
|
|
|
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 <http://www.gnu.org/licenses/>
|
|
|
|
*/
|
2022-03-14 19:20:32 +01:00
|
|
|
import { classifyTalerUri, TalerUriType } from "@gnu-taler/taler-util";
|
2021-11-30 21:29:33 +01:00
|
|
|
import { Fragment, h, VNode } from "preact";
|
|
|
|
import { useState } from "preact/hooks";
|
2023-01-04 19:44:28 +01:00
|
|
|
import { platform } from "../platform/foreground.js";
|
2022-06-01 20:47:47 +02:00
|
|
|
import { InputWithLabel } from "../components/styled/index.js";
|
2022-03-29 04:41:07 +02:00
|
|
|
import { useTranslationContext } from "../context/translation.js";
|
2022-06-01 20:47:47 +02:00
|
|
|
import { Button } from "../mui/Button.js";
|
2021-11-30 21:29:33 +01:00
|
|
|
|
|
|
|
export interface Props {
|
2022-06-01 20:47:47 +02:00
|
|
|
onCancel: () => Promise<void>;
|
2021-11-30 21:29:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export function AddNewActionView({ onCancel }: Props): VNode {
|
|
|
|
const [url, setUrl] = useState("");
|
|
|
|
const uriType = classifyTalerUri(url);
|
2022-03-14 19:20:32 +01:00
|
|
|
const { i18n } = useTranslationContext();
|
2021-11-30 21:29:33 +01:00
|
|
|
|
2022-06-01 20:47:47 +02:00
|
|
|
async function redirectToWallet(): Promise<void> {
|
2022-03-25 20:57:27 +01:00
|
|
|
platform.openWalletURIFromPopup(url);
|
2022-03-23 14:50:12 +01:00
|
|
|
}
|
|
|
|
|
2021-11-30 21:29:33 +01:00
|
|
|
return (
|
|
|
|
<Fragment>
|
|
|
|
<section>
|
|
|
|
<InputWithLabel
|
|
|
|
invalid={url !== "" && uriType === TalerUriType.Unknown}
|
|
|
|
>
|
|
|
|
<label>GNU Taler URI</label>
|
|
|
|
<div>
|
|
|
|
<input
|
|
|
|
style={{ width: "100%" }}
|
|
|
|
type="text"
|
|
|
|
value={url}
|
|
|
|
placeholder="taler://pay/...."
|
|
|
|
onInput={(e) => setUrl(e.currentTarget.value)}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</InputWithLabel>
|
|
|
|
</section>
|
|
|
|
<footer>
|
2022-06-01 20:47:47 +02:00
|
|
|
<Button variant="contained" color="secondary" onClick={onCancel}>
|
2022-03-17 16:39:16 +01:00
|
|
|
<i18n.Translate>Cancel</i18n.Translate>
|
2022-02-23 19:18:37 +01:00
|
|
|
</Button>
|
2021-11-30 21:29:33 +01:00
|
|
|
{uriType !== TalerUriType.Unknown && (
|
2022-06-01 20:47:47 +02:00
|
|
|
<Button
|
|
|
|
variant="contained"
|
|
|
|
color="success"
|
|
|
|
onClick={redirectToWallet}
|
|
|
|
>
|
2022-03-14 19:20:32 +01:00
|
|
|
{(() => {
|
|
|
|
switch (uriType) {
|
|
|
|
case TalerUriType.TalerPay:
|
|
|
|
return <i18n.Translate>Open pay page</i18n.Translate>;
|
|
|
|
case TalerUriType.TalerRefund:
|
|
|
|
return <i18n.Translate>Open refund page</i18n.Translate>;
|
|
|
|
case TalerUriType.TalerTip:
|
|
|
|
return <i18n.Translate>Open tip page</i18n.Translate>;
|
|
|
|
case TalerUriType.TalerWithdraw:
|
|
|
|
return <i18n.Translate>Open withdraw page</i18n.Translate>;
|
|
|
|
}
|
|
|
|
return <Fragment />;
|
|
|
|
})()}
|
2022-06-01 20:47:47 +02:00
|
|
|
</Button>
|
2021-11-30 21:29:33 +01:00
|
|
|
)}
|
|
|
|
</footer>
|
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
}
|