fix: use SDK SolistingStateCurrency type in priceStr

This commit is contained in:
thesn10
2026-06-24 23:22:36 +02:00
parent 2529a0b0ca
commit 2f11bf2d62

View File

@@ -1,3 +1,5 @@
import type { SolistingStateCurrency } from '@solisting/sdk'
export function abbrev(pk: string | null | undefined): string {
if (!pk) return '—'
return `${pk.slice(0, 4)}${pk.slice(-4)}`
@@ -25,10 +27,14 @@ export function exact(ts: number): string {
return new Date(ts * 1000).toUTCString()
}
type CurrencyWithSymbol =
| { __kind: 'Sol' }
| (Extract<SolistingStateCurrency, { __kind: 'Spl' }> & { symbol?: string })
export function priceStr(
currency: { __kind: 'Sol' } | { __kind: 'Spl'; decimals: number; symbol?: string },
currency: CurrencyWithSymbol,
price: bigint | number,
): string {
if (currency.__kind === 'Sol') return fmtSol(price)
return fmtTok(price, currency.decimals, (currency as { symbol?: string }).symbol ?? 'SPL')
return fmtTok(price, currency.decimals, currency.symbol ?? 'SPL')
}