fix: use SDK SolistingStateCurrency type in priceStr
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
import type { SolistingStateCurrency } from '@solisting/sdk'
|
||||||
|
|
||||||
export function abbrev(pk: string | null | undefined): string {
|
export function abbrev(pk: string | null | undefined): string {
|
||||||
if (!pk) return '—'
|
if (!pk) return '—'
|
||||||
return `${pk.slice(0, 4)}…${pk.slice(-4)}`
|
return `${pk.slice(0, 4)}…${pk.slice(-4)}`
|
||||||
@@ -25,10 +27,14 @@ export function exact(ts: number): string {
|
|||||||
return new Date(ts * 1000).toUTCString()
|
return new Date(ts * 1000).toUTCString()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CurrencyWithSymbol =
|
||||||
|
| { __kind: 'Sol' }
|
||||||
|
| (Extract<SolistingStateCurrency, { __kind: 'Spl' }> & { symbol?: string })
|
||||||
|
|
||||||
export function priceStr(
|
export function priceStr(
|
||||||
currency: { __kind: 'Sol' } | { __kind: 'Spl'; decimals: number; symbol?: string },
|
currency: CurrencyWithSymbol,
|
||||||
price: bigint | number,
|
price: bigint | number,
|
||||||
): string {
|
): string {
|
||||||
if (currency.__kind === 'Sol') return fmtSol(price)
|
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')
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user