2022-07-14 20:38:02 -07:00
|
|
|
import { PublicKey } from '@solana/web3.js'
|
2023-03-28 16:57:59 -07:00
|
|
|
import { formatNumericValue, numberCompacter } from './numbers'
|
2022-07-14 20:38:02 -07:00
|
|
|
|
|
|
|
export function abbreviateAddress(address: PublicKey, size = 5) {
|
|
|
|
const base58 = address.toBase58()
|
|
|
|
return base58.slice(0, size) + '…' + base58.slice(-size)
|
|
|
|
}
|
2023-01-19 02:42:39 -08:00
|
|
|
|
|
|
|
export const formatYAxis = (value: number) => {
|
2023-01-22 19:40:59 -08:00
|
|
|
return value === 0
|
|
|
|
? '0'
|
|
|
|
: Math.abs(value) > 1
|
2023-01-19 02:42:39 -08:00
|
|
|
? numberCompacter.format(value)
|
2023-03-21 03:27:37 -07:00
|
|
|
: formatNumericValue(value, 4)
|
2023-01-19 02:42:39 -08:00
|
|
|
}
|
2023-04-28 14:36:24 -07:00
|
|
|
|
|
|
|
export const tryParse = (val: string) => {
|
|
|
|
try {
|
|
|
|
const json = JSON.parse(val)
|
|
|
|
return json
|
|
|
|
} catch (e) {
|
|
|
|
return val
|
|
|
|
}
|
|
|
|
}
|