add redirects
This commit is contained in:
@@ -3,10 +3,13 @@ import { useNavigate } from 'react-router-dom'
|
|||||||
import { useQueryClient } from '@tanstack/react-query'
|
import { useQueryClient } from '@tanstack/react-query'
|
||||||
import {
|
import {
|
||||||
useJumperTokens, useWalletBalance, useWalletAddresses, useFetchJumperQuote, useExecuteBridge,
|
useJumperTokens, useWalletBalance, useWalletAddresses, useFetchJumperQuote, useExecuteBridge,
|
||||||
|
useRelayQuote,
|
||||||
type Chain, type JumperToken, type WalletBalanceData, type JumperQuote, type JumperQuotePayload,
|
type Chain, type JumperToken, type WalletBalanceData, type JumperQuote, type JumperQuotePayload,
|
||||||
|
type RelayQuotePayload,
|
||||||
} from '@features/wallet'
|
} from '@features/wallet'
|
||||||
import { Notification, PrimaryButton } from '@shared/ui'
|
import { Notification, PrimaryButton } from '@shared/ui'
|
||||||
import { ROUTES } from '@shared/config/routes'
|
import { ROUTES } from '@shared/config/routes'
|
||||||
|
import { useDebounce } from '@shared/lib/hooks/useDebounce'
|
||||||
import { toBaseUnits, fromBaseUnits } from '@shared/lib/utils/baseUnits'
|
import { toBaseUnits, fromBaseUnits } from '@shared/lib/utils/baseUnits'
|
||||||
import { truncateDecimals } from '@shared/lib/utils/truncateDecimals'
|
import { truncateDecimals } from '@shared/lib/utils/truncateDecimals'
|
||||||
import {
|
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])
|
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 {
|
function mapJumperToken(t: JumperToken): Token {
|
||||||
const meta = TOKEN_META[t.symbol]
|
const meta = TOKEN_META[t.symbol]
|
||||||
return {
|
return {
|
||||||
@@ -115,10 +127,43 @@ export function BridgeForm() {
|
|||||||
}
|
}
|
||||||
: null
|
: 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)
|
? truncateDecimals(fromBaseUnits(quote.estimate.toAmount, quote.action.toToken.decimals), 8)
|
||||||
: '0'
|
: '0'
|
||||||
|
|
||||||
|
function handleFromNetworkChange(net: string) {
|
||||||
|
setFromNetwork(net)
|
||||||
|
// сеть назначения не может совпадать с исходной — переключаем на первую доступную
|
||||||
|
if (net === toNetwork) {
|
||||||
|
setToNetwork(NETWORKS.find(n => n !== net) ?? toNetwork)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function handleConfirm() {
|
function handleConfirm() {
|
||||||
if (!quotePayload) return
|
if (!quotePayload) return
|
||||||
setErrorMessage(null)
|
setErrorMessage(null)
|
||||||
@@ -165,8 +210,8 @@ export function BridgeForm() {
|
|||||||
<NetworkSelect
|
<NetworkSelect
|
||||||
label="ИЗ"
|
label="ИЗ"
|
||||||
value={fromNetwork}
|
value={fromNetwork}
|
||||||
onChange={setFromNetwork}
|
onChange={handleFromNetworkChange}
|
||||||
options={NETWORKS.filter(n => n !== toNetwork)}
|
options={NETWORKS}
|
||||||
/>
|
/>
|
||||||
<SwapCard
|
<SwapCard
|
||||||
mode="from"
|
mode="from"
|
||||||
@@ -195,7 +240,7 @@ export function BridgeForm() {
|
|||||||
hideNetworkSelect
|
hideNetworkSelect
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<PrimaryButton label="Подтвердить бридж" onClick={handleConfirm} disabled={!quotePayload || isPending} />
|
<PrimaryButton label={isPending ? 'Загрузка...' : 'Подтвердить бридж'} onClick={handleConfirm} disabled={!quotePayload || isPending} />
|
||||||
|
|
||||||
{quote && (
|
{quote && (
|
||||||
<BridgeConfirmModal
|
<BridgeConfirmModal
|
||||||
|
|||||||
@@ -153,7 +153,11 @@ export function SwapForm() {
|
|||||||
|
|
||||||
<SwapInfoPanel gasFee={gasFee} />
|
<SwapInfoPanel gasFee={gasFee} />
|
||||||
|
|
||||||
<PrimaryButton onClick={handleSwap} disabled={isButtonDisabled} />
|
<PrimaryButton
|
||||||
|
label={isSwapping || isFetchingTrxQuote ? 'Загрузка...' : undefined}
|
||||||
|
onClick={handleSwap}
|
||||||
|
disabled={isButtonDisabled}
|
||||||
|
/>
|
||||||
|
|
||||||
{modalData && (
|
{modalData && (
|
||||||
<SwapConfirmModal
|
<SwapConfirmModal
|
||||||
|
|||||||
Reference in New Issue
Block a user