summaryrefslogtreecommitdiff
path: root/packages/demobank-ui/src/pages/BankFrame.tsx
blob: 5c43d2c3ea0ccc1b4d0a147410d1dcf09ef5213e (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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
/*
 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/>
 */

import { Amounts, Logger, PaytoUriIBAN, TranslatedString, parsePaytoUri, stringifyPaytoUri } from "@gnu-taler/taler-util";
import { notifyError, notifyException, useNotifications, useTranslationContext } from "@gnu-taler/web-util/browser";
import { ComponentChildren, Fragment, h, VNode } from "preact";
import { StateUpdater, useEffect, useErrorBoundary, useState } from "preact/hooks";
import { LangSelectorLikePy as LangSelector } from "../components/LangSelector.js";
import { useBackendContext } from "../context/backend.js";
import { useBusinessAccountDetails } from "../hooks/circuit.js";
import { bankUiSettings } from "../settings.js";
import { useSettings } from "../hooks/settings.js";
import { CopyButton, CopyIcon } from "../components/CopyButton.js";
import logo from "../assets/logo-2021.svg";
import { useAccountDetails } from "../hooks/access.js";

const GIT_HASH = typeof __GIT_HASH__ !== "undefined" ? __GIT_HASH__ : undefined;
const VERSION = typeof __VERSION__ !== "undefined" ? __VERSION__ : undefined;

const versionText = VERSION
  ? GIT_HASH
    ? `Version ${VERSION} (${GIT_HASH.substring(0, 8)})`
    : VERSION
  : "";

const logger = new Logger("BankFrame");

export function BankFrame({
  children,
  account,
}: {
  account?: string,
  children: ComponentChildren;
}): VNode {
  const { i18n } = useTranslationContext();
  const backend = useBackendContext();
  const [settings, updateSettings] = useSettings();
  const [open, setOpen] = useState(false)

  const [error, resetError] = useErrorBoundary();

  useEffect(() => {
    if (error) {
      const desc = (error instanceof Error ? error.stack : String(error)) as TranslatedString
      if (error instanceof Error) {
        notifyException(i18n.str`Internal error, please report.`, error)
      } else {
        notifyError(i18n.str`Internal error, please report.`, String(error) as TranslatedString)
      }
      resetError()
    }
  }, [error])

  const demo_sites = [];
  for (const i in bankUiSettings.demoSites)
    demo_sites.push(
      <a href={bankUiSettings.demoSites[i][1]}>
        {bankUiSettings.demoSites[i][0]}
      </a>,
    );

  return (<div class="min-h-full flex flex-col m-0" style="min-height: 100vh;">
    <div class="bg-indigo-600 pb-32">
      <nav class="">
        <div class="mx-auto max-w-7xl px-2 sm:px-4 lg:px-8">
          <div class="relative flex h-16 items-center justify-between ">
            <div class="flex items-center px-2 lg:px-0">
              <div class="flex-shrink-0 bg-white rounded-lg">
                <a href="#/">
                  <img
                    class="h-8 w-auto"
                    src={logo}
                    alt="Taler"
                    style={{ height: 35, margin: 10 }}
                  />
                </a>
              </div>
              <div class="hidden sm:block lg:ml-10 ">
                <div class="flex space-x-4">
                  {/* <!-- Current: "bg-indigo-700 text-white", Default: "text-white hover:bg-indigo-500 hover:bg-opacity-75" --> */}
                  {bankUiSettings.demoSites.map(([name, url]) => {
                    return <a href={url} class="text-white hover:bg-indigo-500 hover:bg-opacity-75 rounded-md py-2 px-3 text-sm font-medium">{name}</a>
                  })}
                </div>
              </div>
            </div>

            <div class="flex">
              <button type="button" class="relative inline-flex items-center justify-center rounded-md bg-indigo-600 p-1 text-indigo-200 hover:bg-indigo-500 hover:bg-opacity-75 hover:text-white focus:outline-none focus:ring-2 focus:ring-white focus:ring-offset-2 focus:ring-offset-indigo-600" aria-controls="mobile-menu" aria-expanded="false"
                onClick={(e) => {
                  setOpen(!open)
                }}>
                <span class="absolute -inset-0.5"></span>
                <span class="sr-only">Open main menu</span>
                <svg class="block h-10 w-10" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" aria-hidden="true">
                  <path stroke-linecap="round" stroke-linejoin="round" d="M3.75 6.75h16.5M3.75 12h16.5m-16.5 5.25h16.5" />
                </svg>
              </button>
            </div>
          </div>
        </div>

        {open &&
          <div class="relative z-10" aria-labelledby="slide-over-title" role="dialog" aria-modal="true"
            onClick={() => {
              setOpen(false)
            }}>
            <div class="fixed inset-0"></div>

            <div class="fixed inset-0 overflow-hidden">
              <div class="absolute inset-0 overflow-hidden">
                <div class="pointer-events-none fixed inset-y-0 right-0 flex max-w-full pl-10">
                  <div class="pointer-events-auto w-screen max-w-md" >
                    <div class="flex h-full flex-col overflow-y-scroll bg-white py-6 shadow-xl" onClick={(e) => {
                      //do not trigger close if clicking inside the sidebar
                      e.stopPropagation();
                    }}>
                      <div class="px-4 sm:px-6" >
                        <div class="flex items-start justify-between" >
                          <h2 class="text-base font-semibold leading-6 text-gray-900" id="slide-over-title">
                            <i18n.Translate>Preferences</i18n.Translate>
                          </h2>
                          <div class="ml-3 flex h-7 items-center">
                            <button type="button" class="relative rounded-md bg-white text-gray-400 hover:text-gray-500 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2"
                              onClick={(e) => {
                                setOpen(false)
                              }}

                            >
                              <span class="absolute -inset-2.5"></span>
                              <span class="sr-only">
                                <i18n.Translate>Close panel</i18n.Translate>
                              </span>
                              <svg class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" aria-hidden="true">
                                <path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />
                              </svg>
                            </button>
                          </div>
                        </div>
                      </div>
                      <div class="relative mt-6 flex-1 px-4 sm:px-6">
                        <nav class="flex flex-1 flex-col" aria-label="Sidebar">
                          <ul role="list" class="flex flex-1 flex-col gap-y-7">
                            <li>
                              <a href="#"
                                class="text-gray-700 hover:text-indigo-600 hover:bg-gray-100 group flex gap-x-3 rounded-md p-2 text-sm leading-6 font-semibold"
                                onClick={() => {
                                  backend.logOut();
                                  setOpen(false)
                                  updateSettings("currentWithdrawalOperationId", undefined);
                                }}
                              >
                                <svg class="h-6 w-6 shrink-0 text-indigo-600" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" aria-hidden="true">
                                  <path stroke-linecap="round" stroke-linejoin="round" d="M2.25 12l8.954-8.955c.44-.439 1.152-.439 1.591 0L21.75 12M4.5 9.75v10.125c0 .621.504 1.125 1.125 1.125H9.75v-4.875c0-.621.504-1.125 1.125-1.125h2.25c.621 0 1.125.504 1.125 1.125V21h4.125c.621 0 1.125-.504 1.125-1.125V9.75M8.25 21h8.25" />
                                </svg>
                                Log out
                                {/* <span class="ml-auto w-9 min-w-max whitespace-nowrap rounded-full bg-gray-50 px-2.5 py-0.5 text-center text-xs font-medium leading-5 text-gray-600 ring-1 ring-inset ring-gray-200" aria-hidden="true">5</span> */}
                              </a>
                            </li>
                            <li class="sm:hidden">
                              <div class="text-xs font-semibold leading-6 text-gray-400">
                                <i18n.Translate>Sites</i18n.Translate>
                              </div>
                              <ul role="list" class="-mx-2 mt-2 space-y-1">
                                {bankUiSettings.demoSites.map(([name, url]) => {
                                  return <li>
                                    <a href={url} target="_blank" rel="noopener noreferrer" class="text-gray-700 hover:text-indigo-600 hover:bg-gray-100 group flex gap-x-3 rounded-md p-2 text-sm leading-6 font-semibold">
                                      <span class="flex h-6 w-6 shrink-0 items-center justify-center rounded-lg border text-[0.625rem] font-medium bg-white text-gray-400 border-gray-200 group-hover:border-indigo-600 group-hover:text-indigo-600">&gt;</span>
                                      <span class="truncate">{name}</span>
                                    </a>
                                  </li>
                                })}
                              </ul>
                            </li>

                            <li>
                              <ul role="list" class="space-y-1">
                                <li class="mt-2">
                                  <div class="flex items-center justify-between">
                                    <span class="flex flex-grow flex-col">
                                      <span class="text-sm text-black font-medium leading-6 " id="availability-label">
                                        <i18n.Translate>Show withdrawal confirmation</i18n.Translate>
                                      </span>
                                    </span>
                                    <button type="button" data-enabled={settings.showWithdrawalSuccess} class="bg-indigo-600 data-[enabled=false]:bg-gray-200 relative inline-flex h-6 w-11 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none focus:ring-2 focus:ring-indigo-600 focus:ring-offset-2" role="switch" aria-checked="false" aria-labelledby="availability-label" aria-describedby="availability-description"

                                      onClick={() => {
                                        updateSettings("showWithdrawalSuccess", !settings.showWithdrawalSuccess);
                                      }}>
                                      <span aria-hidden="true" data-enabled={settings.showWithdrawalSuccess} class="translate-x-5 data-[enabled=false]:translate-x-0 pointer-events-none inline-block h-5 w-5 transform rounded-full bg-white shadow ring-0 transition duration-200 ease-in-out"></span>
                                    </button>
                                  </div>
                                </li>
                                <li class="mt-2">
                                  <div class="flex items-center justify-between">
                                    <span class="flex flex-grow flex-col">
                                      <span class="text-sm text-black font-medium leading-6 " id="availability-label">
                                        <i18n.Translate>Show demo description</i18n.Translate>
                                      </span>
                                    </span>
                                    <button type="button" data-enabled={settings.showDemoDescription} class="bg-indigo-600 data-[enabled=false]:bg-gray-200 relative inline-flex h-6 w-11 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none focus:ring-2 focus:ring-indigo-600 focus:ring-offset-2" role="switch" aria-checked="false" aria-labelledby="availability-label" aria-describedby="availability-description"

                                      onClick={() => {
                                        updateSettings("showDemoDescription", !settings.showDemoDescription);
                                      }}>
                                      <span aria-hidden="true" data-enabled={settings.showDemoDescription} class="translate-x-5 data-[enabled=false]:translate-x-0 pointer-events-none inline-block h-5 w-5 transform rounded-full bg-white shadow ring-0 transition duration-200 ease-in-out"></span>
                                    </button>
                                  </div>
                                </li>
                                <li class="mt-2">
                                  <div class="flex items-center justify-between">
                                    <span class="flex flex-grow flex-col">
                                      <span class="text-sm text-black font-medium leading-6 " id="availability-label">
                                        <i18n.Translate>Show install wallet first</i18n.Translate>
                                      </span>
                                    </span>
                                    <button type="button" data-enabled={settings.showInstallWallet} class="bg-indigo-600 data-[enabled=false]:bg-gray-200 relative inline-flex h-6 w-11 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none focus:ring-2 focus:ring-indigo-600 focus:ring-offset-2" role="switch" aria-checked="false" aria-labelledby="availability-label" aria-describedby="availability-description"
                                      onClick={() => {
                                        updateSettings("showInstallWallet", !settings.showInstallWallet);
                                      }}>
                                      <span aria-hidden="true" data-enabled={settings.showInstallWallet} class="translate-x-5 data-[enabled=false]:translate-x-0 pointer-events-none inline-block h-5 w-5 transform rounded-full bg-white shadow ring-0 transition duration-200 ease-in-out"></span>
                                    </button>
                                  </div>
                                </li>
                                <li class="mt-2">
                                  <div class="flex items-center justify-between">
                                    <span class="flex flex-grow flex-col">
                                      <span class="text-sm text-black font-medium leading-6 " id="availability-label">
                                        <i18n.Translate>Use fast withdrawal</i18n.Translate>
                                      </span>
                                    </span>
                                    <button type="button" data-enabled={settings.fastWithdrawal} class="bg-indigo-600 data-[enabled=false]:bg-gray-200 relative inline-flex h-6 w-11 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none focus:ring-2 focus:ring-indigo-600 focus:ring-offset-2" role="switch" aria-checked="false" aria-labelledby="availability-label" aria-describedby="availability-description"
                                      onClick={() => {
                                        updateSettings("fastWithdrawal", !settings.fastWithdrawal);
                                      }}>
                                      <span aria-hidden="true" data-enabled={settings.fastWithdrawal} class="translate-x-5 data-[enabled=false]:translate-x-0 pointer-events-none inline-block h-5 w-5 transform rounded-full bg-white shadow ring-0 transition duration-200 ease-in-out"></span>
                                    </button>
                                  </div>
                                </li>
                              </ul>
                            </li>
                          </ul>
                        </nav>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        }
      </nav >

      {account &&
        <header class="py-5 border-t border-indigo-300 border-opacity-25 bg-indigo-600 lg:border-t lg:border-indigo-400 lg:border-opacity-25">
          <div class="mx-auto max-w-7xl px-4 sm:px-6 lg:px-8">
            <div class=" flex flex-wrap items-center justify-between sm:flex-nowrap">
              <h3 class="text-2xl font-bold tracking-tight text-white"><WelcomeAccount account={account} /></h3>
              <div>
                <h3 class="text-2xl font-bold tracking-tight text-white"><AccountBalance account={account} /></h3>
              </div>
            </div>
          </div>

        </header>
      }
    </div >

    <main class="-mt-32 flex-1">
      <div class="mx-auto max-w-7xl px-4 pb-12 sm:px-6 lg:px-8">
        <div class="rounded-lg bg-white px-5 py-6 shadow sm:px-6">
          <StatusBanner />
          {children}
        </div>
      </div>
    </main>

    <Footer />
  </div >

    // <Fragment>
    //   <header
    //     class="demobar"
    //     style="display: flex; flex-direction: row; justify-content: space-between;"
    //   >
    //     <a href="#main" class="skip">{i18n.str`Skip to main content`}</a>
    //     <div style="max-width: 50em; margin-left: 2em; margin-right: 2em;">
    //       {maybeDemoContent(
    //         <p>
    //           {IS_PUBLIC_ACCOUNT_ENABLED ? (
    //             <i18n.Translate>
    //               This part of the demo shows how a bank that supports Taler
    //               directly would work. In addition to using your own bank
    //               account, you can also see the transaction history of some{" "}
    //               <a href="/public-accounts">Public Accounts</a>.
    //             </i18n.Translate>
    //           ) : (
    //             <i18n.Translate>
    //               This part of the demo shows how a bank that supports Taler
    //               directly would work.
    //             </i18n.Translate>
    //           )}
    //         </p>,
    //       )}
    //     </div>
    //   </header>
    //   <div style="display:flex; flex-direction: column;" class="navcontainer">
    //     <nav class="demolist">
    //       {maybeDemoContent(<Fragment>{demo_sites}</Fragment>)}
    //       {backend.state.status === "loggedIn" ? (
    //         <Fragment>
    //           {goToBusinessAccount && !backend.state.isUserAdministrator ? (
    //             <MaybeBusinessButton
    //               account={backend.state.username}
    //               onClick={goToBusinessAccount}
    //             />
    //           ) : undefined}

    // <LangSelector />

    //           <a
    //             href="#"
    //             class="pure-button logout-button"
    // onClick={() => {
    //   backend.logOut();
    //   updateSettings("currentWithdrawalOperationId", undefined);
    // }}
    //           >{i18n.str`Logout`}</a>
    //         </Fragment>
    //       ) : undefined}
    //     </nav>
    //   </div>
    //   <section id="main" class="content">
    //     <StatusBanner />
    //     {children}
    //   </section>
    // </Fragment>
  );
}


function StatusBanner(): VNode {
  const notifs = useNotifications()
  return <div
    class="fixed top-10 z-20 ml-4 mr-4"
  > {
      notifs.map(n => {
        switch (n.message.type) {
          case "error":
            return <div class="rounded-md bg-red-50 p-4">
              <div class="flex">
                <div class="flex-shrink-0">
                  <svg class="h-5 w-5 text-red-400" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
                    <path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zM8.28 7.22a.75.75 0 00-1.06 1.06L8.94 10l-1.72 1.72a.75.75 0 101.06 1.06L10 11.06l1.72 1.72a.75.75 0 101.06-1.06L11.06 10l1.72-1.72a.75.75 0 00-1.06-1.06L10 8.94 8.28 7.22z" clip-rule="evenodd" />
                  </svg>
                </div>
                <div class="ml-3 flex-1 md:flex md:justify-between">
                  <p class="text-sm font-medium text-red-800">{n.message.title}</p>
                </div>
                <div>
                  <p class="text-sm">
                    <button type="button" class="inline-flex font-semibold items-center rounded bg-white px-2 py-1 text-xs text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50"
                      onClick={(e) => {
                        e.preventDefault();
                        n.remove()
                      }}
                    >
                      Close
                      <svg class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
                        <path d="M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z" />
                      </svg>
                    </button>
                  </p>
                </div>
              </div>
              {n.message.description &&
                <div class="mt-2 text-sm text-red-700">
                  {n.message.description}
                </div>
              }
              {n.message.debug &&
                <div class="mt-2 text-sm text-red-700 font-mono break-all">
                    {n.message.debug}
                </div>
              }
            </div>
          case "info":
            return <div class="rounded-md bg-green-50 border-4 border-green-600 p-6">
              <div class="flex">
                <div class="flex-shrink-0">
                  <svg class="h-8 w-8 text-green-400" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
                    <path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.857-9.809a.75.75 0 00-1.214-.882l-3.483 4.79-1.88-1.88a.75.75 0 10-1.06 1.061l2.5 2.5a.75.75 0 001.137-.089l4-5.5z" clip-rule="evenodd" />
                  </svg>
                </div>
                <div class="ml-3 flex-1 md:flex md:justify-between">
                  <h3 class="text-lg font-medium text-green-800">{n.message.title}</h3>

                  <p class="mt-3 text-sm md:ml-6 md:mt-0">
                    <button type="button" class="inline-flex font-semibold items-center rounded bg-white px-2 py-1 text-md text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50"
                      onClick={(e) => {
                        e.preventDefault();
                        n.remove();
                      }}
                    >
                      Close
                      <svg class="h-8 w-8" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
                        <path d="M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z" />
                      </svg>
                    </button>
                  </p>
                </div>

              </div>
            </div>
        }
      })}
  </div>

}

function TestingTag(): VNode {
  const testingUrl = localStorage.getItem("bank-base-url");
  if (!testingUrl) return <Fragment />;
  return (
    <p class="text-xs leading-5 text-gray-300">
      Testing with {testingUrl}{" "}
      <a
        href=""
        onClick={(e) => {
          e.preventDefault();
          localStorage.removeItem("bank-base-url");
          window.location.reload();
        }}
      >
        stop testing
      </a>
    </p>
  );
}

function Footer() {
  return (
    <footer class="bottom-4 mb-4">
      <div class="mt-8 mx-8 md:order-1 md:mt-0">
        <div>
          <p class="text-xs leading-5 text-gray-400">
            You can learn more about GNU Taler on our{" "}
            <a target="_blank" rel="noreferrer noopener" class="font-semibold text-gray-500 hover:text-gray-400" href="https://taler.net">main website</a>.
          </p>
        </div>
        <div style="flex-grow:1" />
        <p class="text-xs leading-5 text-gray-400">
          Copyright &copy; 2014&mdash;2022 Taler Systems SA. {versionText}{" "}
          <TestingTag />
        </p>
      </div>
    </footer>
  );
}

function WelcomeAccount({ account }: { account: string }): VNode {
  const { i18n } = useTranslationContext();

  const result = useAccountDetails(account);
  if (!result.ok) return <div />

  const payto = parsePaytoUri(result.data.payto_uri)
  if (!payto) return <div />

  const accountNumber = !payto.isKnown ? undefined : payto.targetType === "iban" ? payto.iban : payto.targetType === "x-taler-bank" ? payto.account : undefined;
  return <i18n.Translate>
    Welcome,  {account} {accountNumber !== undefined ?
      <span>
        (<a href={result.data.payto_uri}>{accountNumber}</a> <CopyButton getContent={() => result.data.payto_uri} />)
      </span>
      : <Fragment />}!
  </i18n.Translate>

}

function AccountBalance({ account }: { account: string }): VNode {
  const result = useAccountDetails(account);
  if (!result.ok) return <div />

  return <div>
    {Amounts.currencyOf(result.data.balance.amount)}
    &nbsp;{result.data.balance.credit_debit_indicator === "debit" ? "-" : ""}
    {Amounts.stringifyValue(result.data.balance.amount)}
  </div>
}