add redirects
This commit is contained in:
@@ -3,10 +3,13 @@ import { useNavigate } from 'react-router-dom'
|
||||
import { useQueryClient } from '@tanstack/react-query'
|
||||
import {
|
||||
useJumperTokens, useWalletBalance, useWalletAddresses, useFetchJumperQuote, useExecuteBridge,
|
||||
useRelayQuote,
|
||||
type Chain, type JumperToken, type WalletBalanceData, type JumperQuote, type JumperQuotePayload,
|
||||
type RelayQuotePayload,
|
||||
} from '@features/wallet'
|
||||
import { Notification, PrimaryButton } from '@shared/ui'
|
||||
import { ROUTES } from '@shared/config/routes'
|
||||
import { useDebounce } from '@shared/lib/hooks/useDebounce'
|
||||
import { toBaseUnits, fromBaseUnits } from '@shared/lib/utils/baseUnits'
|
||||
import { truncateDecimals } from '@shared/lib/utils/truncateDecimals'
|
||||
import {
|
||||
@@ -32,6 +35,15 @@ const NET_BY_CHAIN_ID: Record<string, string> = Object.fromEntries(
|
||||
Object.entries(CHAIN_ID_BY_NET).map(([net, id]) => [id, net])
|
||||
)
|
||||
|
||||
// Relay использует собственные chain id (отличаются от Jumper, напр. для SOL)
|
||||
const RELAY_CHAIN_ID: Record<string, number> = {
|
||||
ETH: 1,
|
||||
BSC: 56,
|
||||
SOL: 792703809,
|
||||
TRX: 728126428,
|
||||
BTC: 8253038,
|
||||
}
|
||||
|
||||
function mapJumperToken(t: JumperToken): Token {
|
||||
const meta = TOKEN_META[t.symbol]
|
||||
return {
|
||||
@@ -115,10 +127,43 @@ export function BridgeForm() {
|
||||
}
|
||||
: null
|
||||
|
||||
const displayToAmount = quote
|
||||
// Реактивная оценка суммы назначения через /api/relay/quote (как в SwapForm)
|
||||
const debouncedAmount = useDebounce(fromAmount, 500)
|
||||
const parsedDebounced = parseFloat(debouncedAmount)
|
||||
const relayOriginChainId = RELAY_CHAIN_ID[fromNetwork]
|
||||
const relayDestChainId = RELAY_CHAIN_ID[toNetwork]
|
||||
|
||||
const relayQuotePayload: RelayQuotePayload | null =
|
||||
fromJumper && toJumper && fromAddress && toAddress &&
|
||||
relayOriginChainId && relayDestChainId && parsedDebounced > 0
|
||||
? {
|
||||
user: fromAddress,
|
||||
recipient: toAddress,
|
||||
originChainId: relayOriginChainId,
|
||||
destinationChainId: relayDestChainId,
|
||||
originCurrency: fromJumper.address,
|
||||
destinationCurrency: toJumper.address,
|
||||
amount: toBaseUnits(debouncedAmount, fromToken.decimals),
|
||||
tradeType: 'EXACT_INPUT',
|
||||
}
|
||||
: null
|
||||
|
||||
const { data: relayQuote } = useRelayQuote(relayQuotePayload)
|
||||
|
||||
const displayToAmount = relayQuote
|
||||
? relayQuote.details.currencyOut.amountFormatted
|
||||
: quote
|
||||
? truncateDecimals(fromBaseUnits(quote.estimate.toAmount, quote.action.toToken.decimals), 8)
|
||||
: '0'
|
||||
|
||||
function handleFromNetworkChange(net: string) {
|
||||
setFromNetwork(net)
|
||||
// сеть назначения не может совпадать с исходной — переключаем на первую доступную
|
||||
if (net === toNetwork) {
|
||||
setToNetwork(NETWORKS.find(n => n !== net) ?? toNetwork)
|
||||
}
|
||||
}
|
||||
|
||||
function handleConfirm() {
|
||||
if (!quotePayload) return
|
||||
setErrorMessage(null)
|
||||
@@ -165,8 +210,8 @@ export function BridgeForm() {
|
||||
<NetworkSelect
|
||||
label="ИЗ"
|
||||
value={fromNetwork}
|
||||
onChange={setFromNetwork}
|
||||
options={NETWORKS.filter(n => n !== toNetwork)}
|
||||
onChange={handleFromNetworkChange}
|
||||
options={NETWORKS}
|
||||
/>
|
||||
<SwapCard
|
||||
mode="from"
|
||||
@@ -195,7 +240,7 @@ export function BridgeForm() {
|
||||
hideNetworkSelect
|
||||
/>
|
||||
|
||||
<PrimaryButton label="Подтвердить бридж" onClick={handleConfirm} disabled={!quotePayload || isPending} />
|
||||
<PrimaryButton label={isPending ? 'Загрузка...' : 'Подтвердить бридж'} onClick={handleConfirm} disabled={!quotePayload || isPending} />
|
||||
|
||||
{quote && (
|
||||
<BridgeConfirmModal
|
||||
|
||||
@@ -153,7 +153,11 @@ export function SwapForm() {
|
||||
|
||||
<SwapInfoPanel gasFee={gasFee} />
|
||||
|
||||
<PrimaryButton onClick={handleSwap} disabled={isButtonDisabled} />
|
||||
<PrimaryButton
|
||||
label={isSwapping || isFetchingTrxQuote ? 'Загрузка...' : undefined}
|
||||
onClick={handleSwap}
|
||||
disabled={isButtonDisabled}
|
||||
/>
|
||||
|
||||
{modalData && (
|
||||
<SwapConfirmModal
|
||||
|
||||
Reference in New Issue
Block a user