14.05.2026 rip
This commit is contained in:
@@ -41,6 +41,32 @@ 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 {
|
||||
address: string
|
||||
stale: boolean
|
||||
native: PortfolioNative
|
||||
tokens: PortfolioToken[]
|
||||
totalUsd: number
|
||||
}
|
||||
|
||||
export interface PortfolioData {
|
||||
totalUsd: number
|
||||
asOfMs: number
|
||||
chains: Record<Chain, PortfolioChain>
|
||||
}
|
||||
|
||||
export const CHAINS: Chain[] = ['ETH', 'BSC', 'BTC', 'TRX', 'SOL']
|
||||
|
||||
async function walletGet<T>(path: string, allowRetry: boolean = true): Promise<T> {
|
||||
@@ -120,3 +146,8 @@ export async function getPrices(symbols: string[]): Promise<Record<string, Price
|
||||
export async function sendWallet(chain: Chain, payload: SendWalletPayload): Promise<SendWalletResponse> {
|
||||
return walletPost<SendWalletResponse>(`/api/wallets/${chain}/send`, payload)
|
||||
}
|
||||
|
||||
export async function getPortfolio(): Promise<PortfolioData> {
|
||||
const res = await walletGet<{ success: boolean; data: PortfolioData }>('/api/wallets/portfolio')
|
||||
return res.data
|
||||
}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
export { useAllWalletBalances, usePrices, useSendWallet, useWalletAddresses, useWalletBalance } from './model/useWalletData'
|
||||
export type { Chain, FormattedAmount, WalletBalanceData, PriceEntry, SendWalletPayload, SendWalletResponse, WalletAddress } from './api/walletApi'
|
||||
export { useAllWalletBalances, usePrices, useSendWallet, useWalletAddresses, useWalletBalance, usePortfolio } from './model/useWalletData'
|
||||
export type { Chain, FormattedAmount, WalletBalanceData, PriceEntry, SendWalletPayload, SendWalletResponse, WalletAddress, PortfolioData, PortfolioChain, PortfolioNative, PortfolioToken } from './api/walletApi'
|
||||
export { CHAINS } from './api/walletApi'
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { useQuery, useQueries, useMutation } from '@tanstack/react-query'
|
||||
import { getWalletBalance, getPrices, sendWallet, getWalletAddresses, CHAINS, type Chain, type SendWalletPayload } from '../api/walletApi'
|
||||
import { getWalletBalance, getPrices, sendWallet, getWalletAddresses, getPortfolio, CHAINS, type Chain, type SendWalletPayload } from '../api/walletApi'
|
||||
|
||||
export function useWalletBalance(chain: Chain) {
|
||||
return useQuery({
|
||||
@@ -41,3 +41,11 @@ export function useWalletAddresses() {
|
||||
staleTime: 10 * 60 * 1000,
|
||||
})
|
||||
}
|
||||
|
||||
export function usePortfolio() {
|
||||
return useQuery({
|
||||
queryKey: ['wallet', 'portfolio'],
|
||||
queryFn: getPortfolio,
|
||||
staleTime: 30_000,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -3,14 +3,20 @@ import topup from '@shared/assets/topup.svg'
|
||||
import swap from '@shared/assets/swap.svg'
|
||||
import { Link } from 'react-router-dom'
|
||||
import { ROUTES } from '@shared/config/routes'
|
||||
import { usePortfolio } from '@features/wallet'
|
||||
|
||||
export function BalanceCard() {
|
||||
const { data, isLoading } = usePortfolio()
|
||||
const display =
|
||||
isLoading || !data
|
||||
? '$—'
|
||||
: `$${data.totalUsd.toLocaleString('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`
|
||||
|
||||
return (
|
||||
<div className={styles.card}>
|
||||
<div className={styles.left}>
|
||||
<div className={styles.label}>Общий баланс</div>
|
||||
<div className={styles.amount}>$245.00</div>
|
||||
<div className={styles.rub}>≈ 22 340,50 ₽</div>
|
||||
<div className={styles.amount}>{display}</div>
|
||||
</div>
|
||||
<div className={styles.actions}>
|
||||
<Link to={ROUTES.CONVERTER} className={styles.btn} type="button">
|
||||
|
||||
Reference in New Issue
Block a user