summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-webextension/src/wallet/ReserveCreated.tsx
blob: a72026ab88a63506d4be339c1d017fbe64e8eb5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import {
  AmountJson,
  Amounts,
  parsePaytoUri,
  PaytoUri,
} from "@gnu-taler/taler-util";
import { Fragment, h, VNode } from "preact";
import { useEffect, useState } from "preact/hooks";
import { QR } from "../components/QR";
import {
  ButtonDestructive,
  ButtonPrimary,
  WalletBox,
  WarningBox,
} from "../components/styled";
export interface Props {
  reservePub: string;
  payto: string;
  exchangeBaseUrl: string;
  amount: AmountJson;
  onBack: () => void;
}

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}>
            &nbsp; Copy &nbsp;
          </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>;
  }
  return (
    <WalletBox>
      <section>
        <h1>Bank transfer details</h1>
        <p>
          Please wire <b>{Amounts.stringify(amount)}</b> to:
        </p>
        <BankDetailsByPaytoType
          amount={Amounts.stringify(amount)}
          exchangeBaseUrl={exchangeBaseUrl}
          payto={paytoURI}
          subject={reservePub}
        />
      </section>
      <section>
        <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} />
      </section>
      <footer>
        <div />
        <ButtonDestructive onClick={onBack}>Cancel withdraw</ButtonDestructive>
      </footer>
    </WalletBox>
  );
}