14.05.2026 rip

This commit is contained in:
2026-05-14 15:50:22 +03:00
parent 0f88a68c59
commit 79f1ee371b
8 changed files with 142 additions and 7 deletions

View File

@@ -0,0 +1,36 @@
import { api } from '@shared/api/base'
export type Chain = 'ETH' | 'BSC' | 'BTC' | 'TRX' | 'SOL'
export interface FormattedAmount {
raw: string
formatted: string
decimals: number
usdPrice: number
usdValue: number
}
export interface WalletBalanceData {
chain: Chain
address: string
native: FormattedAmount
tokens: Record<string, FormattedAmount>
}
export interface PriceEntry {
usd: number
}
export const CHAINS: Chain[] = ['ETH', 'BSC', 'BTC', 'TRX', 'SOL']
export async function getWalletBalance(chain: Chain): Promise<WalletBalanceData> {
const res = await api.get<{ success: boolean; data: WalletBalanceData }>(`/api/wallets/${chain}/balance`)
return res.data
}
export async function getPrices(symbols: string[]): Promise<Record<string, PriceEntry>> {
const res = await api.get<{ success: boolean; data: Record<string, PriceEntry> }>(
`/api/prices?symbols=${symbols.join(',')}`
)
return res.data
}

View File

@@ -0,0 +1,3 @@
export { useAllWalletBalances, usePrices } from './model/useWalletData'
export type { Chain, FormattedAmount, WalletBalanceData, PriceEntry } from './api/walletApi'
export { CHAINS } from './api/walletApi'

View File

@@ -0,0 +1,20 @@
import { useQuery, useQueries } from '@tanstack/react-query'
import { getWalletBalance, getPrices, CHAINS } from '../api/walletApi'
export function useAllWalletBalances() {
return useQueries({
queries: CHAINS.map(chain => ({
queryKey: ['wallet', 'balance', chain],
queryFn: () => getWalletBalance(chain),
staleTime: 30_000,
})),
})
}
export function usePrices(symbols: string[]) {
return useQuery({
queryKey: ['wallet', 'prices', symbols.join(',')],
queryFn: () => getPrices(symbols),
staleTime: 5 * 60 * 1000,
})
}