/
ikratkiy
/
Hyperliquid
Обзор
Документация
Войти
/
ikratkiy
/
Hyperliquid
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
src/shared/utils/format.ts
34 строки
1 KB
ikratkiy
fix: harden wallet and hyperevm async state
09 июн 2026, 09:23
09 июн 2026, 09:23
e278893
Код
Авторство
О чём код?
import { formatEther } from "viem"; export function shortenAddress(address: string, chars = 6) { return address.length > chars * 2 + 2 ? `${address.slice(0, chars + 2)}...${address.slice(-chars)}` : address; } export function stringifyJson(value: unknown) { return JSON.stringify(value, (_key, inner) => (typeof inner === "bigint" ? inner.toString() : inner), 2); } export function formatNumber(value: string | number | null | undefined, maxDecimals = 8) { if (value === null || value === undefined || value === "") return "—"; const numeric = Number(value); if (!Number.isFinite(numeric)) return String(value); return new Intl.NumberFormat("ru-RU", { maximumFractionDigits: maxDecimals }).format(numeric); } export function formatTimestamp(value: number | null | undefined) { return value ? new Intl.DateTimeFormat("ru-RU", { dateStyle: "short", timeStyle: "medium" }).format(value) : "—"; } export function formatHypeBalance(balance: bigint) { const displayDecimals = 6; const minimumDisplayedWei = 10n ** BigInt(18 - displayDecimals); if (balance > 0n && balance < minimumDisplayedWei) { return "<0.000001 HYPE"; } const [whole, fractional = ""] = formatEther(balance).split("."); const trimmedFractional = fractional.slice(0, displayDecimals).replace(/0+$/, ""); return `${trimmedFractional ? `${whole}.${trimmedFractional}` : whole} HYPE`; }