Skip to content

Commit

Permalink
Merge pull request #185 from greymass/kurt-asset-full
Browse files Browse the repository at this point in the history
adapt full variant for asset component
  • Loading branch information
aaroncox authored Oct 31, 2024
2 parents 038d6bf + 8899986 commit 1f7d953
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 1f7d953

Please sign in to comment.