2021-11-16 17:59:53 +01:00
|
|
|
import {
|
|
|
|
AmountJson,
|
|
|
|
Amounts,
|
|
|
|
parsePaytoUri,
|
|
|
|
PaytoUri,
|
|
|
|
} from "@gnu-taler/taler-util";
|
|
|
|
import { Fragment, h, VNode } from "preact";
|
|
|
|
import { useEffect, useState } from "preact/hooks";
|
2021-09-20 19:05:40 +02:00
|
|
|
import { QR } from "../components/QR";
|
2021-11-16 17:59:53 +01:00
|
|
|
import {
|
|
|
|
ButtonDestructive,
|
|
|
|
ButtonPrimary,
|
|
|
|
WalletBox,
|
|
|
|
WarningBox,
|
|
|
|
} from "../components/styled";
|
2021-09-20 19:05:40 +02:00
|
|
|
export interface Props {
|
|
|
|
reservePub: string;
|
2021-11-16 17:59:53 +01:00
|
|
|
payto: string;
|
|
|
|
exchangeBaseUrl: string;
|
|
|
|
amount: AmountJson;
|
2021-09-20 19:05:40 +02:00
|
|
|
onBack: () => void;
|
|
|
|
}
|
|
|
|
|
2021-11-16 17:59:53 +01:00
|
|
|
interface BankDetailsProps {
|
|
|
|
payto: PaytoUri;
|
|
|
|
exchangeBaseUrl: string;
|
|
|
|
subject: string;
|
|
|
|
amount: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
function Row({
|
|
|
|
name,
|
|
|
|
value,
|
|
|
|
literal,
|
|
|
|
}: {
|
|
|
|
name: string;
|
|
|
|
value: string;
|
|
|
|
literal?: boolean;
|
|
|
|
}): VNode {
|
|
|
|
const [copied, setCopied] = useState(false);
|
|
|
|
function copyText(): void {
|
|
|
|
navigator.clipboard.writeText(value);
|
|
|
|
setCopied(true);
|
|
|
|
}
|
|
|
|
useEffect(() => {
|
|
|
|
setTimeout(() => {
|
|
|
|
setCopied(false);
|
|
|
|
}, 1000);
|
|
|
|
}, [copied]);
|
|
|
|
return (
|
|
|
|
<tr>
|
|
|
|
<td>
|
|
|
|
{!copied ? (
|
|
|
|
<ButtonPrimary small onClick={copyText}>
|
|
|
|
Copy
|
|
|
|
</ButtonPrimary>
|
|
|
|
) : (
|
|
|
|
<ButtonPrimary small disabled>
|
|
|
|
Copied
|
|
|
|
</ButtonPrimary>
|
|
|
|
)}
|
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
<b>{name}</b>
|
|
|
|
</td>
|
|
|
|
{literal ? (
|
|
|
|
<td>
|
|
|
|
<pre style={{ whiteSpace: "pre-wrap", wordBreak: "break-word" }}>
|
|
|
|
{value}
|
|
|
|
</pre>
|
|
|
|
</td>
|
|
|
|
) : (
|
|
|
|
<td>{value}</td>
|
|
|
|
)}
|
|
|
|
</tr>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function BankDetailsByPaytoType({
|
|
|
|
payto,
|
|
|
|
subject,
|
|
|
|
exchangeBaseUrl,
|
|
|
|
amount,
|
|
|
|
}: BankDetailsProps): VNode {
|
|
|
|
const firstPart = !payto.isKnown ? (
|
|
|
|
<Fragment>
|
|
|
|
<Row name="Account" value={payto.targetPath} />
|
|
|
|
<Row name="Exchange" value={exchangeBaseUrl} />
|
|
|
|
</Fragment>
|
|
|
|
) : payto.targetType === "x-taler-bank" ? (
|
|
|
|
<Fragment>
|
|
|
|
<Row name="Bank host" value={payto.host} />
|
|
|
|
<Row name="Bank account" value={payto.account} />
|
|
|
|
<Row name="Exchange" value={exchangeBaseUrl} />
|
|
|
|
</Fragment>
|
|
|
|
) : payto.targetType === "iban" ? (
|
|
|
|
<Fragment>
|
|
|
|
<Row name="IBAN" value={payto.iban} />
|
|
|
|
<Row name="Exchange" value={exchangeBaseUrl} />
|
|
|
|
</Fragment>
|
|
|
|
) : undefined;
|
|
|
|
return (
|
|
|
|
<table>
|
|
|
|
{firstPart}
|
|
|
|
<Row name="Amount" value={amount} />
|
|
|
|
<Row name="Subject" value={subject} literal />
|
|
|
|
</table>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
export function ReserveCreated({
|
|
|
|
reservePub,
|
|
|
|
payto,
|
|
|
|
onBack,
|
|
|
|
exchangeBaseUrl,
|
|
|
|
amount,
|
|
|
|
}: Props): VNode {
|
|
|
|
const paytoURI = parsePaytoUri(payto);
|
|
|
|
// const url = new URL(paytoURI?.targetPath);
|
|
|
|
if (!paytoURI) {
|
|
|
|
return <div>could not parse payto uri from exchange {payto}</div>;
|
|
|
|
}
|
2021-09-20 19:05:40 +02:00
|
|
|
return (
|
|
|
|
<WalletBox>
|
|
|
|
<section>
|
2021-11-16 17:59:53 +01:00
|
|
|
<h1>Bank transfer details</h1>
|
2021-11-15 15:18:58 +01:00
|
|
|
<p>
|
2021-11-16 17:59:53 +01:00
|
|
|
Please wire <b>{Amounts.stringify(amount)}</b> to:
|
2021-11-15 15:18:58 +01:00
|
|
|
</p>
|
2021-11-16 17:59:53 +01:00
|
|
|
<BankDetailsByPaytoType
|
|
|
|
amount={Amounts.stringify(amount)}
|
|
|
|
exchangeBaseUrl={exchangeBaseUrl}
|
|
|
|
payto={paytoURI}
|
|
|
|
subject={reservePub}
|
|
|
|
/>
|
2021-09-20 19:05:40 +02:00
|
|
|
</section>
|
|
|
|
<section>
|
2021-11-16 17:59:53 +01:00
|
|
|
<p>
|
|
|
|
<WarningBox>
|
|
|
|
Make sure to use the correct subject, otherwise the money will not
|
|
|
|
arrive in this wallet.
|
|
|
|
</WarningBox>
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
Alternative, you can also scan this QR code or open{" "}
|
|
|
|
<a href={payto}>this link</a> if you have a banking app installed that
|
|
|
|
supports RFC 8905
|
|
|
|
</p>
|
|
|
|
<QR text={payto} />
|
2021-09-20 19:05:40 +02:00
|
|
|
</section>
|
|
|
|
<footer>
|
|
|
|
<div />
|
2021-11-16 17:59:53 +01:00
|
|
|
<ButtonDestructive onClick={onBack}>Cancel withdraw</ButtonDestructive>
|
2021-09-20 19:05:40 +02:00
|
|
|
</footer>
|
|
|
|
</WalletBox>
|
|
|
|
);
|
|
|
|
}
|