f
This commit is contained in:
File diff suppressed because one or more lines are too long
2
dist/index.html
vendored
2
dist/index.html
vendored
@@ -5,7 +5,7 @@
|
||||
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>ЭКСА — Ваш мост в мир цифровых активов</title>
|
||||
<script type="module" crossorigin src="/assets/index-lpDOSqEV.js"></script>
|
||||
<script type="module" crossorigin src="/assets/index-C426d72k.js"></script>
|
||||
<link rel="stylesheet" crossorigin href="/assets/index-CnYQBevk.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
@@ -41,30 +41,20 @@ export interface WalletAddress {
|
||||
derivationPath: string
|
||||
}
|
||||
|
||||
export interface PortfolioToken {
|
||||
symbol: string
|
||||
amountFormatted: string
|
||||
usd: number
|
||||
}
|
||||
|
||||
export interface PortfolioNative {
|
||||
amount: string
|
||||
amountFormatted: string
|
||||
usd: number
|
||||
}
|
||||
|
||||
export interface PortfolioChain {
|
||||
chain: Chain
|
||||
address: string
|
||||
stale: boolean
|
||||
native: PortfolioNative
|
||||
tokens: PortfolioToken[]
|
||||
native: FormattedAmount
|
||||
tokens: Record<string, FormattedAmount>
|
||||
totalUsd: number
|
||||
stale: boolean
|
||||
lastUpdated: number
|
||||
}
|
||||
|
||||
export interface PortfolioData {
|
||||
totalUsd: number
|
||||
asOfMs: number
|
||||
chains: Record<Chain, PortfolioChain>
|
||||
hasErrors: boolean
|
||||
perChain: Record<Chain, PortfolioChain>
|
||||
}
|
||||
|
||||
export const CHAINS: Chain[] = ['ETH', 'BSC', 'BTC', 'TRX', 'SOL']
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
export { useAllWalletBalances, usePrices, useSendWallet, useWalletAddresses, useWalletBalance, usePortfolio, useTokensList, useRelayQuote, useExecuteRelaySwap, useSignSwap, useTrxSwapQuote, useFetchTrxQuote, useExecuteTrxSwap, useJumperTokens, useJumperQuote, useFetchJumperQuote, useExecuteBridge, useCreateWallet, useRevealMnemonic } from './model/useWalletData'
|
||||
export type { Chain, FormattedAmount, WalletBalanceData, PriceEntry, SendWalletPayload, SendWalletResponse, WalletAddress, PortfolioData, PortfolioChain, PortfolioNative, PortfolioToken, TokenInfo, RelayQuotePayload, RelayQuoteResponse, RelaySwapResponse, RelaySwapStep, TrxSwapQuotePayload, TrxSwapQuoteData, JumperToken, JumperTokensMap, JumperQuote, JumperQuotePayload, JumperQuoteToken, JumperFeeCost, BridgeExecutePayload, BridgeExecuteResult } from './api/walletApi'
|
||||
export type { Chain, FormattedAmount, WalletBalanceData, PriceEntry, SendWalletPayload, SendWalletResponse, WalletAddress, PortfolioData, PortfolioChain, TokenInfo, RelayQuotePayload, RelayQuoteResponse, RelaySwapResponse, RelaySwapStep, TrxSwapQuotePayload, TrxSwapQuoteData, JumperToken, JumperTokensMap, JumperQuote, JumperQuotePayload, JumperQuoteToken, JumperFeeCost, BridgeExecutePayload, BridgeExecuteResult } from './api/walletApi'
|
||||
export { CHAINS } from './api/walletApi'
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useWalletBalance, usePortfolio, CHAINS } from '@features/wallet'
|
||||
import type { Chain } from '@features/wallet'
|
||||
import type { Chain, FormattedAmount } from '@features/wallet'
|
||||
import { getCoinIcon } from '@shared/assets/coins'
|
||||
import { truncateDecimals } from '@shared/lib/utils/truncateDecimals'
|
||||
import { TOKENS, type Token } from './tokens'
|
||||
@@ -39,29 +39,29 @@ function lookupStatic(ticker: string): Token | undefined {
|
||||
return TOKENS.find((t) => t.ticker === ticker)
|
||||
}
|
||||
|
||||
export function useChainTokenRows(chain: Chain) {
|
||||
const { data, isLoading } = useWalletBalance(chain)
|
||||
|
||||
if (!data) return { rows: [] as Token[], isLoading }
|
||||
|
||||
const nativeTicker = NATIVE_TICKER[chain]
|
||||
const nativeStatic = lookupStatic(nativeTicker)
|
||||
|
||||
const nativeRow: Token = {
|
||||
ticker: nativeTicker,
|
||||
function nativeRowFor(chain: Chain, native: FormattedAmount): Token {
|
||||
const ticker = NATIVE_TICKER[chain]
|
||||
const staticToken = lookupStatic(ticker)
|
||||
return {
|
||||
id: `${chain}-${ticker}`,
|
||||
chain,
|
||||
ticker,
|
||||
name: NATIVE_NAME[chain],
|
||||
logo: getCoinIcon(nativeTicker) ?? nativeStatic?.logo,
|
||||
color: nativeStatic?.color ?? DEFAULT_TOKEN_COLOR,
|
||||
price: formatPrice(data.native.usdPrice),
|
||||
logo: getCoinIcon(ticker) ?? staticToken?.logo,
|
||||
color: staticToken?.color ?? DEFAULT_TOKEN_COLOR,
|
||||
price: formatPrice(native.usdPrice),
|
||||
change: 0,
|
||||
bal: truncateDecimals(data.native.formatted),
|
||||
usd: formatUsd(data.native.usdValue),
|
||||
bal: truncateDecimals(native.formatted),
|
||||
usd: formatUsd(native.usdValue),
|
||||
fav: false,
|
||||
}
|
||||
}
|
||||
|
||||
const tokenRows: Token[] = Object.entries(data.tokens ?? {}).map(([symbol, amount]) => {
|
||||
function tokenRowFor(chain: Chain, symbol: string, amount: FormattedAmount): Token {
|
||||
const staticToken = lookupStatic(symbol)
|
||||
return {
|
||||
id: `${chain}-${symbol}`,
|
||||
chain,
|
||||
ticker: symbol,
|
||||
name: staticToken?.name ?? symbol,
|
||||
logo: getCoinIcon(symbol) ?? staticToken?.logo,
|
||||
@@ -72,69 +72,47 @@ export function useChainTokenRows(chain: Chain) {
|
||||
usd: formatUsd(amount.usdValue),
|
||||
fav: false,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function hasBalance(amount: FormattedAmount): boolean {
|
||||
return parseFloat(amount.formatted) > 0
|
||||
}
|
||||
|
||||
export function useChainTokenRows(chain: Chain) {
|
||||
const { data, isLoading } = useWalletBalance(chain)
|
||||
|
||||
if (!data) return { rows: [] as Token[], isLoading }
|
||||
|
||||
const nativeRow = nativeRowFor(chain, data.native)
|
||||
const tokenRows = Object.entries(data.tokens ?? {}).map(([symbol, amount]) =>
|
||||
tokenRowFor(chain, symbol, amount),
|
||||
)
|
||||
|
||||
return { rows: [nativeRow, ...tokenRows], isLoading }
|
||||
}
|
||||
|
||||
function hasBalance(amountFormatted: string): boolean {
|
||||
return parseFloat(amountFormatted) > 0
|
||||
}
|
||||
|
||||
function unitPrice(usd: number, amountFormatted: string): number | null {
|
||||
const amount = parseFloat(amountFormatted)
|
||||
return amount > 0 && usd > 0 ? usd / amount : null
|
||||
}
|
||||
|
||||
export function useAllWalletTokenRows() {
|
||||
const { data, isLoading } = usePortfolio()
|
||||
|
||||
if (!data) return { rows: [] as Token[], isLoading }
|
||||
|
||||
const rows: Token[] = []
|
||||
const entries: { row: Token; value: number }[] = []
|
||||
|
||||
for (const chain of CHAINS) {
|
||||
const chainData = data.chains?.[chain]
|
||||
const chainData = data.perChain?.[chain]
|
||||
if (!chainData) continue
|
||||
|
||||
const nativeTicker = NATIVE_TICKER[chain]
|
||||
if (chainData.native && hasBalance(chainData.native.amountFormatted)) {
|
||||
const nativeStatic = lookupStatic(nativeTicker)
|
||||
rows.push({
|
||||
id: `${chain}-${nativeTicker}`,
|
||||
chain,
|
||||
ticker: nativeTicker,
|
||||
name: NATIVE_NAME[chain],
|
||||
logo: getCoinIcon(nativeTicker) ?? nativeStatic?.logo,
|
||||
color: nativeStatic?.color ?? DEFAULT_TOKEN_COLOR,
|
||||
price: formatPrice(unitPrice(chainData.native.usd, chainData.native.amountFormatted)),
|
||||
change: 0,
|
||||
bal: truncateDecimals(chainData.native.amountFormatted),
|
||||
usd: formatUsd(chainData.native.usd),
|
||||
fav: false,
|
||||
})
|
||||
if (chainData.native && hasBalance(chainData.native)) {
|
||||
entries.push({ row: nativeRowFor(chain, chainData.native), value: chainData.native.usdValue })
|
||||
}
|
||||
|
||||
for (const token of chainData.tokens ?? []) {
|
||||
if (!hasBalance(token.amountFormatted)) continue
|
||||
const staticToken = lookupStatic(token.symbol)
|
||||
rows.push({
|
||||
id: `${chain}-${token.symbol}`,
|
||||
chain,
|
||||
ticker: token.symbol,
|
||||
name: staticToken?.name ?? token.symbol,
|
||||
logo: getCoinIcon(token.symbol) ?? staticToken?.logo,
|
||||
color: staticToken?.color ?? DEFAULT_TOKEN_COLOR,
|
||||
price: formatPrice(unitPrice(token.usd, token.amountFormatted)),
|
||||
change: 0,
|
||||
bal: truncateDecimals(token.amountFormatted),
|
||||
usd: formatUsd(token.usd),
|
||||
fav: false,
|
||||
})
|
||||
for (const [symbol, amount] of Object.entries(chainData.tokens ?? {})) {
|
||||
if (!hasBalance(amount)) continue
|
||||
entries.push({ row: tokenRowFor(chain, symbol, amount), value: amount.usdValue })
|
||||
}
|
||||
}
|
||||
|
||||
rows.sort((a, b) => (parseFloat(b.usd.replace(/[$,—]/g, '')) || 0) - (parseFloat(a.usd.replace(/[$,—]/g, '')) || 0))
|
||||
entries.sort((a, b) => b.value - a.value)
|
||||
|
||||
return { rows, isLoading }
|
||||
return { rows: entries.map((e) => e.row), isLoading }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user