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
|
<script lang="ts">
import PhLockFill from "virtual:icons/ph/lock-fill";
import PhLightningFill from "virtual:icons/ph/lightning-fill";
import { copy, s, f, toFiat } from "$lib/utils";
import { fiat } from "$lib/store";
const {
align = "",
amount,
locale = undefined,
tip = undefined,
rate,
currency,
locked = false,
small = false,
}: any = $props();
const canShowFiat = $derived($fiat && rate && currency);
const toggleFiat = (e) => {
e.preventDefault();
e.stopPropagation();
$fiat = !$fiat;
};
</script>
{#if typeof amount !== "undefined"}
<div>
<h2
class="{small ? 'text-base' : '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"
>
{#if !canShowFiat}
{#if locked}
<PhLockFill width="20" class="text-yellow-300" />
{:else}
<PhLightningFill width={small ? 14 : 20} class="text-yellow-300" />
{/if}
{/if}
<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}
|