Skip to content

Commit

Permalink
adapt full variant for asset component
Browse files Browse the repository at this point in the history
  • Loading branch information
ttwishing committed Oct 31, 2024
1 parent 038d6bf commit 8899986
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/lib/components/elements/asset.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
interface AssetProps extends HTMLAttributes<HTMLSpanElement> {
value?: Asset;
variant?: 'value' | 'quantity' | 'full';
variant?: 'value' | 'full';
fallback?: string;
}
Expand All @@ -17,14 +17,18 @@
fallback = '0',
...props
}: AssetProps = $props();
function formatAssetValue(value?: Asset) {
return Number(value?.value || fallback).toLocaleString(languageTag(), {
minimumFractionDigits: value?.symbol.precision
});
}
</script>

<span class={className} {...props}>
{#if variant === 'full'}
{value ? `${value.quantity} ${value.symbol.name}` : fallback}
{value ? `${formatAssetValue(value)} ${value.symbol.name}` : fallback}
{:else}
{Number(value?.value || fallback).toLocaleString(languageTag(), {
minimumFractionDigits: value?.symbol.precision
})}
{formatAssetValue(value)}
{/if}
</span>

0 comments on commit 8899986

Please sign in to comment.