|
1 | 1 | <script lang="ts">
|
2 |
| -import { cn } from "$lib/utils/index.js" |
3 |
| -import { transfer } from "$lib/components/Transfer/transfer.svelte.js" |
4 |
| -import { TokenRawAmount, type Chain, type Token } from "@unionlabs/sdk/schema" |
5 |
| -import { Option } from "effect" |
6 |
| -import Skeleton from "$lib/components/ui/Skeleton.svelte" |
7 |
| -import { chains } from "$lib/stores/chains.svelte.ts" |
8 |
| -import SharpArrowLeft from "$lib/components/icons/SharpArrowLeft.svelte" |
9 |
| -import TokenComponent from "$lib/components/model/TokenComponent.svelte" |
| 2 | + import { cn } from "$lib/utils/index.js"; |
| 3 | + import { transfer } from "$lib/components/Transfer/transfer.svelte.js"; |
| 4 | + import { |
| 5 | + TokenRawAmount, |
| 6 | + type Chain, |
| 7 | + type Token, |
| 8 | + } from "@unionlabs/sdk/schema"; |
| 9 | + import { Option } from "effect"; |
| 10 | + import Skeleton from "$lib/components/ui/Skeleton.svelte"; |
| 11 | + import { chains } from "$lib/stores/chains.svelte.ts"; |
| 12 | + import SharpArrowLeft from "$lib/components/icons/SharpArrowLeft.svelte"; |
| 13 | + import TokenComponent from "$lib/components/model/TokenComponent.svelte"; |
10 | 14 |
|
11 |
| -type Props = { |
12 |
| - token: Token |
13 |
| - chain: Chain |
14 |
| - selectAsset: (token: Token) => void |
15 |
| -} |
| 15 | + type Props = { |
| 16 | + token: Token; |
| 17 | + chain: Chain; |
| 18 | + selectAsset: (token: Token) => void; |
| 19 | + }; |
16 | 20 |
|
17 |
| -let { token, chain, selectAsset }: Props = $props() |
| 21 | + let { token, chain, selectAsset }: Props = $props(); |
18 | 22 |
|
19 |
| -let isSelected = $derived(transfer.raw.asset === token.denom) |
| 23 | + let isSelected = $derived(transfer.raw.asset === token.denom); |
20 | 24 |
|
21 |
| -let tokenBalance = $derived.by(() => { |
22 |
| - if (Option.isNone(transfer.sortedBalances)) return Option.none() |
23 |
| - const found = transfer.sortedBalances.value.find(t => t.token.denom === token.denom) |
24 |
| - return found ? Option.some(found) : Option.none() |
25 |
| -}) |
| 25 | + let tokenBalance = $derived.by(() => { |
| 26 | + if (Option.isNone(transfer.sortedBalances)) return Option.none(); |
| 27 | + const found = transfer.sortedBalances.value.find( |
| 28 | + (t) => t.token.denom === token.denom, |
| 29 | + ); |
| 30 | + return found ? Option.some(found) : Option.none(); |
| 31 | + }); |
26 | 32 |
|
27 |
| -let isLoading = $derived(Option.isSome(transfer.sortedBalances) && Option.isNone(tokenBalance)) |
| 33 | + let isLoading = $derived( |
| 34 | + Option.isSome(transfer.sortedBalances) && Option.isNone(tokenBalance), |
| 35 | + ); |
28 | 36 |
|
29 |
| -export const toDisplayName = ( |
30 |
| - chain_id: string | undefined | null, |
31 |
| - chains: ReadonlyArray<Chain> |
32 |
| -): string => chains.find(c => c.chain_id === chain_id)?.display_name ?? chain_id ?? "unknown chain" |
| 37 | + export const toDisplayName = ( |
| 38 | + chain_id: string | undefined | null, |
| 39 | + chains: ReadonlyArray<Chain>, |
| 40 | + ): string => |
| 41 | + chains.find((c) => c.chain_id === chain_id)?.display_name ?? |
| 42 | + chain_id ?? |
| 43 | + "unknown chain"; |
33 | 44 | </script>
|
34 | 45 |
|
35 | 46 | <button
|
36 |
| - class={cn( |
37 |
| - "flex flex-col items-start w-full overflow-x-scroll px-4 py-3 text-left bg-zinc-900 hover:bg-zinc-800 transition-colors cursor-pointer rounded", |
38 |
| - isSelected ? "bg-zinc-700 text-white" : "text-zinc-300" |
39 |
| - )} |
40 |
| - onclick={() => { |
41 |
| - console.log(token) |
42 |
| - selectAsset(token) |
43 |
| - }} |
| 47 | + class={cn( |
| 48 | + "flex flex-col items-start w-full overflow-x-auto px-4 py-3 text-left bg-zinc-900 hover:bg-zinc-800 transition-colors cursor-pointer rounded", |
| 49 | + isSelected ? "bg-zinc-700 text-white" : "text-zinc-300", |
| 50 | + )} |
| 51 | + onclick={() => { |
| 52 | + console.log(token); |
| 53 | + selectAsset(token); |
| 54 | + }} |
44 | 55 | >
|
45 |
| - <div class="flex items-center gap-1 overflow-x-scroll text-sm text-zinc-200"> |
46 |
| - <div class="mr-1"> |
47 |
| - {#if isLoading} |
48 |
| - <Skeleton class="h-3 w-16"/> |
49 |
| - {:else if Option.isSome(tokenBalance) && Option.isSome(tokenBalance.value.error)} |
50 |
| - <span class="text-red-400">Error</span> |
51 |
| - {:else if Option.isSome(tokenBalance)} |
52 |
| - {#if Option.isSome(tokenBalance.value.balance)} |
53 |
| - <TokenComponent {chain} denom={token.denom} amount={tokenBalance.value.balance.value} /> |
54 |
| - {:else} |
55 |
| - <TokenComponent {chain} denom={token.denom} amount={TokenRawAmount.make(0n)} /> |
56 |
| - {/if} |
| 56 | + <div class="flex items-center gap-1 overflow-x-auto text-sm text-zinc-200"> |
| 57 | + <div class="mr-1"> |
| 58 | + {#if isLoading} |
| 59 | + <Skeleton class="h-3 w-16" /> |
| 60 | + {:else if Option.isSome(tokenBalance) && Option.isSome(tokenBalance.value.error)} |
| 61 | + <span class="text-red-400">Error</span> |
| 62 | + {:else if Option.isSome(tokenBalance)} |
| 63 | + {#if Option.isSome(tokenBalance.value.balance)} |
| 64 | + <TokenComponent |
| 65 | + {chain} |
| 66 | + denom={token.denom} |
| 67 | + amount={tokenBalance.value.balance.value} |
| 68 | + /> |
| 69 | + {:else} |
| 70 | + <TokenComponent |
| 71 | + {chain} |
| 72 | + denom={token.denom} |
| 73 | + amount={TokenRawAmount.make(0n)} |
| 74 | + /> |
57 | 75 | {/if}
|
58 |
| - </div> |
| 76 | + {/if} |
59 | 77 | </div>
|
| 78 | + </div> |
60 | 79 | </button>
|
0 commit comments