aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/InvoiceData.svelte
blob: 105eb4711ffe1c762ca921b2cc0fdc4990b6e2b9 (plain) (blame)
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
<script lang="ts">
  import Amount from "$comp/Amount.svelte";

  import { btc, copy, f, sat, sats, types } from "$lib/utils";
  import { fiat } from "$lib/store";
  let {
    showQr,
    link,
    txt,
    invoice,
    amount,
    amountFiat,
    currency,
    locale,
    tip,
    rate,
    align = "",
    t,
  }: any = $props();

  let loaded = $state(false);
  let expanded = $state(false);
  let { memo } = $derived(invoice);
  let load = () => (loaded = true);
</script>

{#if showQr}
  <div class="max-w-[360px] mx-auto min-h-[360px]">
    <a href={link}>
      <img
        src={`/qr/${encodeURIComponent(invoice.text)}/raw`}
        class="z-10 border-4 border-white opacity-0 transition-opacity duration-300"
        class:opacity-100={loaded}
        onload={load}
        alt={txt}
      />
    </a>
  </div>
{/if}

{#if invoice.type === types.liquid}
  <div class="flex justify-center p-4 shadow items-center gap-2">
    <iconify-icon noobserver icon="ph:warning-bold" width="48" class="text-warning"></iconify-icon>
    <div>
      <div class="my-auto text-xl text-center text-secondary">
        {t("payments.onlyLbtc")}
        <span class="text-teal-500 font-bold">L-BTC</span>
        &mdash; {t("payments.dontDeposit")}
      </div>
    </div>
  </div>
{/if}

  <button
    data-testid="invoice-text"
    onclick={() => { copy(txt); expanded = !expanded; }}
    aria-label="Copy invoice"
    class="w-full text-center text-secondary text-xl flex gap-1 items-center justify-center cursor-pointer hover:opacity-70"
  >
    <span class:truncate={!expanded} class="break-all">{txt}</span>
    <iconify-icon noobserver icon="ph:copy-bold" width="32" class="shrink-0"></iconify-icon>
  </button>

{#each invoice.items as i}
  {@const itemTotal = i.price * i.quantity}
  <div class="grid grid-cols-12 text-xl">
    <div class="col-span-1 my-auto">{i.quantity}</div>
    <div class="mr-auto grow col-span-7 my-auto">{i.name}</div>
    {#if $fiat}
      <div class="col-span-4 font-semibold text-right my-auto">{f(itemTotal, currency)}</div>
    {:else}
      <div class="col-span-4 font-semibold text-right my-auto">{sat(btc(itemTotal, rate))}</div>
    {/if}
  </div>
{/each}

{#if amount > 0}
  <Amount {amount} {currency} {rate} {locale} {tip} />
{/if}

{#if memo}
  <div class="text-xl text-center">{memo}</div>
{/if}