aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/Amount.svelte
blob: 1f2b1f29d87a3a4a7c2a0f74de1bcfb5d6b8be45 (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
<script lang="ts">
  import { copy, s, f, toFiat } from "$lib/utils";
  import { fiat } from "$lib/store";
  const {
    align = "",
    amount,
    locale = undefined,
    tip = undefined,
    rate,
    currency,
    locked = false,
  }: any = $props();

  const icon = $derived(locked ? "ph:lock-fill" : "ph:lightning-fill");
  const canShowFiat = $derived($fiat && rate && currency);

  const toggleFiat = (e) => {
    e.preventDefault();
    e.stopPropagation();
    $fiat = !$fiat;
  };
</script>

{#if typeof amount !== "undefined"}
  <div>
    <h2
      class="text-2xl md:text-3xl font-semibold flex items-end"
      class:justify-center={align !== "left"}
    >
      <button
        type="button"
        class="flex items-center"
        onclick={toggleFiat}
        aria-label="Toggle currency display"
      >
        <iconify-icon noobserver {icon} class="text-yellow-300" class:hidden={canShowFiat}></iconify-icon>
        <span class:hidden={!canShowFiat}>{f(toFiat(amount, rate), currency, locale)}</span>
        <span class:hidden={canShowFiat}>{s(amount, locale)}</span>
      </button>

      {#if tip}
        <div class="flex items-center text-lg ml-2">
          <div>+</div>
          <div class="font-semibold">
            <span class:hidden={!canShowFiat}>{f(toFiat(tip, rate), currency, locale)}</span>
            <span class:hidden={canShowFiat}>{s(tip, locale)}</span>
          </div>
        </div>
      {/if}
    </h2>
  </div>
{/if}