From cdbd9318cf319dfad164a8f172aee50bae49cdc9 Mon Sep 17 00:00:00 2001 From: rassadin11 Date: Thu, 14 May 2026 22:39:06 +0300 Subject: [PATCH] 14.05.2026 rip --- src/features/wallet/api/walletApi.ts | 9 +++++ src/features/wallet/index.ts | 2 +- src/features/wallet/model/useWalletData.ts | 15 ++++++++- src/pages/seed-phrase/ui/SeedPhrasePage.tsx | 8 +++-- src/pages/wallet/ui/WalletPage.module.css | 14 ++++++++ src/pages/wallet/ui/WalletPage.tsx | 28 ++++++++++++++-- src/widgets/swap-form/ui/SwapForm.tsx | 37 ++++++++------------- 7 files changed, 81 insertions(+), 32 deletions(-) diff --git a/src/features/wallet/api/walletApi.ts b/src/features/wallet/api/walletApi.ts index ceed614..58034e8 100644 --- a/src/features/wallet/api/walletApi.ts +++ b/src/features/wallet/api/walletApi.ts @@ -192,3 +192,12 @@ export async function getTokensList(): Promise { export async function getRelayQuote(payload: RelayQuotePayload): Promise { return walletPost('/api/relay/quote', payload) } + +export async function createWallet(): Promise { + await walletPost('/wallet/create', {}) +} + +export async function revealMnemonic(): Promise { + const res = await walletPost<{ success: boolean; data: { mnemonic: string } }>('/wallets/mnemonic/reveal', {}) + return res.data.mnemonic +} diff --git a/src/features/wallet/index.ts b/src/features/wallet/index.ts index d9837c6..75640f1 100644 --- a/src/features/wallet/index.ts +++ b/src/features/wallet/index.ts @@ -1,3 +1,3 @@ -export { useAllWalletBalances, usePrices, useSendWallet, useWalletAddresses, useWalletBalance, usePortfolio, useTokensList, useRelayQuote } from './model/useWalletData' +export { useAllWalletBalances, usePrices, useSendWallet, useWalletAddresses, useWalletBalance, usePortfolio, useTokensList, useRelayQuote, useCreateWallet, useRevealMnemonic } from './model/useWalletData' export type { Chain, FormattedAmount, WalletBalanceData, PriceEntry, SendWalletPayload, SendWalletResponse, WalletAddress, PortfolioData, PortfolioChain, PortfolioNative, PortfolioToken, TokenInfo, RelayQuotePayload, RelayQuoteResponse } from './api/walletApi' export { CHAINS } from './api/walletApi' diff --git a/src/features/wallet/model/useWalletData.ts b/src/features/wallet/model/useWalletData.ts index f2e2270..518b16a 100644 --- a/src/features/wallet/model/useWalletData.ts +++ b/src/features/wallet/model/useWalletData.ts @@ -1,5 +1,5 @@ import { useQuery, useQueries, useMutation } from '@tanstack/react-query' -import { getWalletBalance, getPrices, sendWallet, getWalletAddresses, getPortfolio, getTokensList, getRelayQuote, CHAINS, type Chain, type SendWalletPayload, type RelayQuotePayload } from '../api/walletApi' +import { getWalletBalance, getPrices, sendWallet, getWalletAddresses, getPortfolio, getTokensList, getRelayQuote, createWallet, revealMnemonic, CHAINS, type Chain, type SendWalletPayload, type RelayQuotePayload } from '../api/walletApi' export function useWalletBalance(chain: Chain) { return useQuery({ @@ -58,6 +58,19 @@ export function useTokensList() { }) } +export function useCreateWallet() { + return useMutation({ mutationFn: createWallet }) +} + +export function useRevealMnemonic() { + return useQuery({ + queryKey: ['wallet', 'mnemonic'], + queryFn: revealMnemonic, + staleTime: Infinity, + retry: false, + }) +} + export function useRelayQuote(payload: RelayQuotePayload | null) { return useQuery({ queryKey: ['relay', 'quote', diff --git a/src/pages/seed-phrase/ui/SeedPhrasePage.tsx b/src/pages/seed-phrase/ui/SeedPhrasePage.tsx index 8faf0ee..351b52e 100644 --- a/src/pages/seed-phrase/ui/SeedPhrasePage.tsx +++ b/src/pages/seed-phrase/ui/SeedPhrasePage.tsx @@ -1,16 +1,18 @@ import { WalletHeader } from '@widgets/wallet-header' import { SeedPhraseWidget } from '@widgets/seed-phrase' +import { useRevealMnemonic } from '@features/wallet' import styles from './SeedPhrasePage.module.css' -const MOCK_WORDS = ['egg', 'phone', 'long', 'vibe', 'potato', 'soup', 'skirt', 'black', 'phase', 'word', 'num', 'cucumber'] - export function SeedPhrasePage() { + const { data: mnemonic, isLoading } = useRevealMnemonic() + const words = mnemonic ? mnemonic.split(' ') : [] + return (
- + {!isLoading && }
) diff --git a/src/pages/wallet/ui/WalletPage.module.css b/src/pages/wallet/ui/WalletPage.module.css index 6c009a1..300ed4e 100644 --- a/src/pages/wallet/ui/WalletPage.module.css +++ b/src/pages/wallet/ui/WalletPage.module.css @@ -35,6 +35,20 @@ font-size: 14px; } +.noWallet { + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + gap: 24px; + min-height: 300px; + color: var(--text-primary); + font-size: 16px; + text-align: center; + position: relative; + z-index: 1; +} + @media (max-width: 992px) { .glow { width: auto; diff --git a/src/pages/wallet/ui/WalletPage.tsx b/src/pages/wallet/ui/WalletPage.tsx index 2e93e30..0d2994d 100644 --- a/src/pages/wallet/ui/WalletPage.tsx +++ b/src/pages/wallet/ui/WalletPage.tsx @@ -1,13 +1,20 @@ -import { Navigate } from 'react-router-dom' +import { Navigate, useNavigate } from 'react-router-dom' import { useMe } from '@features/auth' import { ROUTES } from '@shared/config/routes' +import { usePortfolio, useCreateWallet } from '@features/wallet' import { BalanceCard } from '@widgets/balance-card' import { TokenTable } from '@widgets/token-table' import { WalletHeader } from '@widgets/wallet-header' +import { Button } from '@shared/ui' import styles from './WalletPage.module.css' export function WalletPage() { const { data, isLoading, isError } = useMe() + const { error: portfolioError } = usePortfolio() + const { mutate: createWallet, isPending } = useCreateWallet() + const navigate = useNavigate() + + const noWallet = (portfolioError as any)?.error?.includes('No wallets') if (isLoading) return null if (isError) return
Произошла ошибка. Попробуйте обновить страницу.
@@ -18,8 +25,23 @@ export function WalletPage() {
- - + {noWallet ? ( +
+

У вас пока нет кошелька. Создайте его, чтобы начать.

+ +
+ ) : ( + <> + + + + )}
) diff --git a/src/widgets/swap-form/ui/SwapForm.tsx b/src/widgets/swap-form/ui/SwapForm.tsx index a9f4600..35d28c0 100644 --- a/src/widgets/swap-form/ui/SwapForm.tsx +++ b/src/widgets/swap-form/ui/SwapForm.tsx @@ -3,13 +3,11 @@ import { PrimaryButton } from '@shared/ui' import { useWalletBalance, useWalletAddresses, useTokensList, useRelayQuote, type Chain } from '@features/wallet' import { useDebounce } from '@shared/lib/hooks/useDebounce' import { TOKENS_LIST, buildTokensFromBalance, useSwapForm } from '../model/useSwapForm' -import { RateRow } from './RateRow' import { SwapCard } from './SwapCard' import { SwapDirectionButton } from './SwapDirectionButton' import { SwapInfoPanel } from './SwapInfoPanel' import styles from './SwapForm.module.css' -const RATE = 82.2578 const CHAIN_ID: Record = { ETH: 1, BSC: 56, SOL: 792703809 } const NATIVE_ADDR: Record = { @@ -24,8 +22,7 @@ export function SwapForm() { const { fromAmount, fromUsd, fromToken, toToken, - isRefreshing, - setFromAmount, setPercent, swapTokens, refreshRate, + setFromAmount, setPercent, swapTokens, setFromToken, setToToken, } = useSwapForm() @@ -47,27 +44,27 @@ export function SwapForm() { const chainId = CHAIN_ID[fromNetwork] const walletAddress = addresses?.find(a => a.chain === fromNetwork)?.address const fromContract = tokensList?.find(t => t.chain === fromNetwork && t.symbol === fromToken.symbol)?.contract ?? nativeAddr(fromNetwork) - const toContract = tokensList?.find(t => t.chain === fromNetwork && t.symbol === toToken.symbol)?.contract ?? nativeAddr(fromNetwork) + const toContract = tokensList?.find(t => t.chain === fromNetwork && t.symbol === toToken.symbol)?.contract ?? nativeAddr(fromNetwork) const parsedAmount = parseFloat(debouncedAmount) const quotePayload = chainId && walletAddress && parsedAmount > 0 ? { - user: walletAddress, - recipient: walletAddress, - originChainId: chainId, - destinationChainId: chainId, - originCurrency: fromContract, - destinationCurrency: toContract, - amount: Math.round(parsedAmount * Math.pow(10, fromToken.decimals)).toString(), - tradeType: 'EXACT_INPUT' as const, - } + user: walletAddress, + recipient: walletAddress, + originChainId: chainId, + destinationChainId: chainId, + originCurrency: fromContract, + destinationCurrency: toContract, + amount: Math.round(parsedAmount * Math.pow(10, fromToken.decimals)).toString(), + tradeType: 'EXACT_INPUT' as const, + } : null const { data: quoteData } = useRelayQuote(quotePayload) const displayToAmount = quoteData?.details.currencyOut.amountFormatted ?? '0' - const displayToUsd = quoteData?.details.currencyOut.amountUsd - const gasFee = quoteData?.fees.gas.amountUsd + const displayToUsd = quoteData?.details.currencyOut.amountUsd + const gasFee = quoteData?.fees.gas.amountUsd return (
@@ -95,14 +92,6 @@ export function SwapForm() { onTokenChange={setToToken} /> - -