-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
135 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 76 additions & 1 deletion
77
src/routes/[network]/(account)/account/balances/+page.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,79 @@ | ||
<script lang="ts"> | ||
import { getContext, onMount } from 'svelte'; | ||
import type { UnicoveContext } from '$lib/state/client.svelte'; | ||
import Stack from '$lib/components/layout/stack.svelte'; | ||
import Button from '$lib/components/button/button.svelte'; | ||
import TokenTable from '../components/tokens.svelte'; | ||
import { TokenBalance } from '@wharfkit/session'; | ||
import Switcher from '$lib/components/layout/switcher.svelte'; | ||
import Card from '$lib/components/layout/box/card.svelte'; | ||
import { Asset } from '@wharfkit/antelope'; | ||
import type { TokenMeta } from '@wharfkit/common'; | ||
const { data } = $props(); | ||
const context = getContext<UnicoveContext>('state'); | ||
let totalTokenValue: Asset | undefined = $state(); | ||
let totalUsdValue: Asset | undefined = $state(); | ||
let systemTokenMeta: TokenMeta | undefined = $state(); | ||
let tokenBalances: TokenBalance[] = $state([]); | ||
$effect(() => { | ||
totalTokenValue = context.account?.balance?.total || undefined; | ||
totalUsdValue = context.account?.value?.total || undefined; | ||
if (context.account?.balances) { | ||
tokenBalances = context.account.balances; | ||
} else { | ||
tokenBalances = []; | ||
} | ||
let systemTokenBlanace: TokenBalance | undefined = undefined; | ||
if (totalTokenValue) { | ||
systemTokenBlanace = tokenBalances.find((item) => | ||
item.asset.symbol.equals(totalTokenValue!.symbol) | ||
); | ||
} | ||
systemTokenMeta = systemTokenBlanace?.metadata; | ||
}); | ||
const network = $derived(String(data.network)); | ||
</script> | ||
|
||
<div>Blances</div> | ||
<Stack> | ||
<Switcher threshold="40rem" class="items-start justify-center"> | ||
<Card> | ||
<div class="flex items-center gap-5"> | ||
<div class="flex h-14 w-14 items-center justify-center rounded-full bg-[#303338]"> | ||
{#if systemTokenMeta} | ||
<img class="h-6 w-6" src={systemTokenMeta.logo} alt="LOGO" /> | ||
{/if} | ||
</div> | ||
<Stack> | ||
<p>Total {totalTokenValue?.symbol.name} Balance</p> | ||
<h3>{totalTokenValue?.value}</h3> | ||
</Stack> | ||
</div> | ||
</Card> | ||
|
||
<Card> | ||
<div class="flex items-center gap-5"> | ||
<div class="flex h-14 w-14 items-center justify-center rounded-full bg-[#303338]">$</div> | ||
<Stack> | ||
<p>Total {totalUsdValue?.symbol.name} Balance</p> | ||
<h3>{totalUsdValue?.value}</h3> | ||
</Stack> | ||
</div> | ||
</Card> | ||
</Switcher> | ||
<TokenTable {tokenBalances}> | ||
{#snippet transferIntent(data: TokenBalance)} | ||
<div class="flex flex-col"> | ||
<Button class="text-blue-400" variant="pill" href="/{network}/send?quantity={data.asset}" | ||
>Send</Button | ||
> | ||
</div> | ||
{/snippet} | ||
</TokenTable> | ||
</Stack> |
43 changes: 43 additions & 0 deletions
43
src/routes/[network]/(account)/account/components/tokens.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<script lang="ts"> | ||
import type { TokenBalance } from '@wharfkit/common'; | ||
import type { Snippet } from 'svelte'; | ||
interface Props { | ||
transferIntent?: Snippet<[TokenBalance]>; | ||
tokenBalances: TokenBalance[]; | ||
} | ||
const { transferIntent, tokenBalances }: Props = $props(); | ||
</script> | ||
|
||
<div class="flex flex-col text-base font-medium"> | ||
<div class="flex items-center justify-end gap-4 p-2"> | ||
<div class="flex flex-1">Token</div> | ||
<div class="flex flex-1 justify-end">Amount</div> | ||
<div class="flex flex-1 justify-end"></div> | ||
</div> | ||
<div> | ||
{#snippet row(name: string, balance: TokenBalance, transferable: boolean = false)} | ||
<div class="flex items-center justify-end gap-4 p-2 border-b border-white/20 last:border-0 odd:bg-black/10"> | ||
<div class="flex flex-1 gap-2"> | ||
<div class="flex h-5 w-5 items-center justify-center rounded-full bg-black"> | ||
{#if balance.metadata?.logo} | ||
<img class="h-4 w-4" src={balance.metadata?.logo} alt="LOGO" /> | ||
{/if} | ||
</div> | ||
<span>{name}</span> | ||
</div> | ||
<div class="flex flex-1 justify-end"> | ||
{balance.asset.value} | ||
</div> | ||
<div class="flex flex-1 justify-end"> | ||
{#if transferable && transferIntent} | ||
{@render transferIntent(balance)} | ||
{/if} | ||
</div> | ||
</div> | ||
{/snippet} | ||
|
||
{#each tokenBalances as item} | ||
{@render row(item.asset.symbol.name, item, true)} | ||
{/each} | ||
</div> | ||
</div> |