14.05.2026 rip
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
import { PrimaryButton } from '@shared/ui'
|
||||
import { useWalletBalance, type Chain } from '@features/wallet'
|
||||
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'
|
||||
@@ -10,6 +11,15 @@ import styles from './SwapForm.module.css'
|
||||
|
||||
const RATE = 82.2578
|
||||
|
||||
const CHAIN_ID: Record<string, number> = { ETH: 1, BSC: 56, SOL: 792703809 }
|
||||
const NATIVE_ADDR: Record<string, string> = {
|
||||
SOL: '11111111111111111111111111111111',
|
||||
DEFAULT: '0x0000000000000000000000000000000000000000',
|
||||
}
|
||||
function nativeAddr(chain: string) {
|
||||
return NATIVE_ADDR[chain] ?? NATIVE_ADDR.DEFAULT
|
||||
}
|
||||
|
||||
export function SwapForm() {
|
||||
const {
|
||||
fromAmount, toAmount, fromUsd, toUsd,
|
||||
@@ -30,6 +40,34 @@ export function SwapForm() {
|
||||
setToToken(t => tokenOptions.find(o => o.symbol === t.symbol) ?? (tokenOptions[1] ?? tokenOptions[0]))
|
||||
}, [walletData, fromNetwork])
|
||||
|
||||
const debouncedAmount = useDebounce(fromAmount, 500)
|
||||
const { data: addresses } = useWalletAddresses()
|
||||
const { data: tokensList } = useTokensList()
|
||||
|
||||
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 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,
|
||||
}
|
||||
: null
|
||||
|
||||
const { data: quoteData } = useRelayQuote(quotePayload)
|
||||
|
||||
const displayToAmount = quoteData?.details.currencyOut.amountFormatted ?? toAmount
|
||||
const displayToUsd = quoteData?.details.currencyOut.amountUsd ?? toUsd
|
||||
|
||||
return (
|
||||
<div className={styles.form}>
|
||||
<SwapCard
|
||||
@@ -51,8 +89,8 @@ export function SwapForm() {
|
||||
mode="to"
|
||||
token={toToken}
|
||||
tokenOptions={tokenOptions}
|
||||
amount={toAmount}
|
||||
usd={toUsd}
|
||||
amount={displayToAmount}
|
||||
usd={displayToUsd}
|
||||
slippage="−0.16%"
|
||||
onTokenChange={setToToken}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user