This commit is contained in:
2026-06-01 23:39:28 +03:00
parent 0409d63874
commit 5b915bbc22
9 changed files with 417 additions and 268 deletions

View File

@@ -13,8 +13,10 @@ export interface Token {
fav: boolean
/** Stable unique key — tickers can repeat across chains (e.g. USDT on ETH/TRX/BSC). */
id?: string
/** Network this row belongs to — used to target send/receive modals. */
/** Network this row belongs to — used to target send/receive modals and grouping. */
chain?: Chain
/** Numeric USD value of the holding — used for sorting and per-network subtotals. */
usdValue?: number
}
export const TOKENS: readonly Token[] = [

View File

@@ -53,6 +53,7 @@ function nativeRowFor(chain: Chain, native: FormattedAmount): Token {
change: 0,
bal: truncateDecimals(native.formatted),
usd: formatUsd(native.usdValue),
usdValue: native.usdValue,
fav: false,
}
}
@@ -70,6 +71,7 @@ function tokenRowFor(chain: Chain, symbol: string, amount: FormattedAmount): Tok
change: 0,
bal: truncateDecimals(amount.formatted),
usd: formatUsd(amount.usdValue),
usdValue: amount.usdValue,
fav: false,
}
}
@@ -96,23 +98,28 @@ export function useAllWalletTokenRows() {
if (!data) return { rows: [] as Token[], isLoading }
const entries: { row: Token; value: number }[] = []
const rows: Token[] = []
for (const chain of CHAINS) {
const chainData = data.perChain?.[chain]
if (!chainData) continue
const chainRows: Token[] = []
if (chainData.native && hasBalance(chainData.native)) {
entries.push({ row: nativeRowFor(chain, chainData.native), value: chainData.native.usdValue })
chainRows.push(nativeRowFor(chain, chainData.native))
}
for (const [symbol, amount] of Object.entries(chainData.tokens ?? {})) {
if (!hasBalance(amount)) continue
entries.push({ row: tokenRowFor(chain, symbol, amount), value: amount.usdValue })
chainRows.push(tokenRowFor(chain, symbol, amount))
}
// Sort within the network by value; keep networks in CHAINS order so rows
// stay contiguous per chain for grouping in the table.
chainRows.sort((a, b) => (b.usdValue ?? 0) - (a.usdValue ?? 0))
rows.push(...chainRows)
}
entries.sort((a, b) => b.value - a.value)
return { rows: entries.map((e) => e.row), isLoading }
return { rows, isLoading }
}