Bitcoin amount
bitcoin-ui/bitcoin-amountFreeComponent
Exact satoshi and BTC value formatting.
Install it
npx shadcn@latest add https://raw.githubusercontent.com/dennisonbertram/bitcoin-ui/main/public/r/bitcoin-amount.jsonSource
1import type { ComponentProps } from "react";23import {4 formatBtc,5 formatSats,6 resolveAmountUnit,7 type AmountUnit,8 type SatoshiValue,9} from "@/lib/bitcoin";10import { componentClasses } from "@/lib/utils";1112import type { BitcoinVisualProps } from "./shared";1314export type BitcoinAmountProps = Omit<ComponentProps<"span">, "children"> &15 BitcoinVisualProps & {16 /** Amount in satoshis. bigint is recommended for exact values. */17 value: SatoshiValue;18 /**19 * Display unit. `auto` switches to BTC at 1,000,000 sats.20 * @default "auto"21 */22 unit?: AmountUnit;23 /** Includes the visible unit label. @default true */24 showUnit?: boolean;25 /** Smallest number of BTC decimal places to preserve. @default 0 */26 minimumFractionDigits?: number;27 /** Largest number of BTC decimal places to preserve. @default 8 */28 maximumFractionDigits?: number;29 };3031export function BitcoinAmount({32 value,33 unit = "auto",34 showUnit = true,35 minimumFractionDigits = 0,36 maximumFractionDigits = 8,37 unstyled,38 className,39 ...props40}: BitcoinAmountProps) {41 const resolvedUnit = resolveAmountUnit(value, unit);42 const amount =43 resolvedUnit === "btc"44 ? formatBtc(value, { minimumFractionDigits, maximumFractionDigits })45 : formatSats(value);4647 return (48 <span49 data-slot="bitcoin-amount"50 data-unit={resolvedUnit}51 data-unstyled={unstyled || undefined}52 className={componentClasses(53 unstyled,54 "inline-flex items-baseline gap-1 whitespace-nowrap font-mono text-sm font-medium tabular-nums tracking-[-0.02em]",55 className,56 )}57 {...props}58 >59 <span data-slot="bitcoin-amount-value">{amount}</span>60 {showUnit ? (61 <span62 data-slot="bitcoin-amount-unit"63 className={componentClasses(64 unstyled,65 "font-sans text-[0.72em] font-medium tracking-normal text-[var(--color-muted)]",66 )}67 >68 {resolvedUnit === "btc" ? "BTC" : "sat"}69 </span>70 ) : null}71 </span>72 );73}
What it pulls in
Other registry items
Files it writes
More from bitcoin-ui
All 23 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Address displayaddress-display | bitcoin-ui | Components | Free | no deps | |
| Bitcoin motionbitcoin-motion | bitcoin-ui | Components | Free | no deps · 2 files | |
| Bitcoin searchbitcoin-search | bitcoin-ui | Components | Free | 1 dep | |
| Block cardblock-card | bitcoin-ui | Components | Free | 1 dep | |
| Block listblock-list | bitcoin-ui | Components | Free | no deps | |
| Confirmation progressconfirmation-progress | bitcoin-ui | Components | Free | no deps | |
| Difficulty adjustmentdifficulty-adjustment | bitcoin-ui | Components | Free | no deps | |
| Fee estimatesfee-estimates | bitcoin-ui | Components | Free | 1 dep |
