add redirects
This commit is contained in:
@@ -195,6 +195,136 @@ export async function getTokensList(): Promise<TokenInfo[]> {
|
||||
return res.data
|
||||
}
|
||||
|
||||
export interface JumperToken {
|
||||
address: string
|
||||
chainId: number
|
||||
symbol: string
|
||||
decimals: number
|
||||
name: string
|
||||
coinKey?: string
|
||||
logoURI?: string
|
||||
priceUSD: string
|
||||
}
|
||||
|
||||
export type JumperTokensMap = Record<string, JumperToken[]>
|
||||
|
||||
export async function getJumperTokens(): Promise<JumperTokensMap> {
|
||||
const res = await walletGet<{ tokens?: JumperTokensMap; data?: { tokens: JumperTokensMap } }>(
|
||||
'/api/jumper/tokens?chains=1,56,1151111081099710,728126428,20000000000001'
|
||||
)
|
||||
return res.data?.tokens ?? res.tokens ?? {}
|
||||
}
|
||||
|
||||
export interface JumperQuotePayload {
|
||||
fromChain: string
|
||||
toChain: string
|
||||
fromToken: string
|
||||
toToken: string
|
||||
fromAmount: string
|
||||
fromAddress: string
|
||||
toAddress: string
|
||||
slippage: number
|
||||
}
|
||||
|
||||
export interface JumperQuoteToken {
|
||||
address: string
|
||||
chainId: number
|
||||
symbol: string
|
||||
decimals: number
|
||||
name: string
|
||||
logoURI?: string
|
||||
priceUSD: string
|
||||
}
|
||||
|
||||
export interface JumperFeeCost {
|
||||
name: string
|
||||
description?: string
|
||||
token: JumperQuoteToken
|
||||
amount: string
|
||||
amountUSD: string
|
||||
percentage?: string
|
||||
included?: boolean
|
||||
}
|
||||
|
||||
export interface JumperQuote {
|
||||
type: string
|
||||
id: string
|
||||
tool: string
|
||||
toolDetails: { key: string; name: string; logoURI?: string }
|
||||
action: {
|
||||
fromToken: JumperQuoteToken
|
||||
fromAmount: string
|
||||
toToken: JumperQuoteToken
|
||||
fromChainId: number
|
||||
toChainId: number
|
||||
slippage: number
|
||||
fromAddress: string
|
||||
toAddress: string
|
||||
}
|
||||
estimate: {
|
||||
tool: string
|
||||
approvalAddress?: string
|
||||
toAmountMin: string
|
||||
toAmount: string
|
||||
fromAmount: string
|
||||
feeCosts?: JumperFeeCost[]
|
||||
}
|
||||
}
|
||||
|
||||
export async function getJumperQuote(payload: JumperQuotePayload): Promise<JumperQuote> {
|
||||
const qs = new URLSearchParams({
|
||||
fromChain: payload.fromChain,
|
||||
toChain: payload.toChain,
|
||||
fromToken: payload.fromToken,
|
||||
toToken: payload.toToken,
|
||||
fromAmount: payload.fromAmount,
|
||||
fromAddress: payload.fromAddress,
|
||||
toAddress: payload.toAddress,
|
||||
slippage: String(payload.slippage),
|
||||
}).toString()
|
||||
const res = await walletGet<{ body?: JumperQuote; data?: { body?: JumperQuote } }>(
|
||||
`/api/jumper/quote-best?${qs}`
|
||||
)
|
||||
return (res.data?.body ?? res.body) as JumperQuote
|
||||
}
|
||||
|
||||
export interface BridgeExecutePayload {
|
||||
provider: string
|
||||
fromChain: number
|
||||
toChain: number
|
||||
fromToken: string
|
||||
toToken: string
|
||||
fromAmount: string
|
||||
fromAddress: string
|
||||
toAddress: string
|
||||
acceptedMinOut?: string
|
||||
}
|
||||
|
||||
export interface BridgeExecuteResult {
|
||||
provider: string
|
||||
fromChain: number
|
||||
toChain: number
|
||||
toolName: string
|
||||
feeTxid?: string
|
||||
feeAmount?: string
|
||||
bridgeTxid: string
|
||||
fromAmount: string
|
||||
toAmountMin: string
|
||||
fromAmountUSD?: string
|
||||
toAmountUSD?: string
|
||||
trackerUrl?: string
|
||||
}
|
||||
|
||||
export async function executeBridge(payload: BridgeExecutePayload): Promise<BridgeExecuteResult> {
|
||||
const res = await walletPost<{ data?: { success: boolean; data: BridgeExecuteResult } }>(
|
||||
'/api/bridge/execute',
|
||||
payload,
|
||||
true,
|
||||
{ 'Idempotency-Key': crypto.randomUUID() }
|
||||
)
|
||||
return (res.data?.data ?? res) as BridgeExecuteResult
|
||||
}
|
||||
|
||||
export async function getRelayQuote(payload: RelayQuotePayload): Promise<RelayQuoteResponse> {
|
||||
return walletPost<RelayQuoteResponse>('/api/relay/quote', payload)
|
||||
}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
export { useAllWalletBalances, usePrices, useSendWallet, useWalletAddresses, useWalletBalance, usePortfolio, useTokensList, useRelayQuote, useExecuteRelaySwap, useSignSwap, useTrxSwapQuote, useFetchTrxQuote, useExecuteTrxSwap, useCreateWallet, useRevealMnemonic } from './model/useWalletData'
|
||||
export type { Chain, FormattedAmount, WalletBalanceData, PriceEntry, SendWalletPayload, SendWalletResponse, WalletAddress, PortfolioData, PortfolioChain, PortfolioNative, PortfolioToken, TokenInfo, RelayQuotePayload, RelayQuoteResponse, RelaySwapResponse, RelaySwapStep, TrxSwapQuotePayload, TrxSwapQuoteData } from './api/walletApi'
|
||||
export { useAllWalletBalances, usePrices, useSendWallet, useWalletAddresses, useWalletBalance, usePortfolio, useTokensList, useRelayQuote, useExecuteRelaySwap, useSignSwap, useTrxSwapQuote, useFetchTrxQuote, useExecuteTrxSwap, useJumperTokens, useFetchJumperQuote, useExecuteBridge, useCreateWallet, useRevealMnemonic } from './model/useWalletData'
|
||||
export type { Chain, FormattedAmount, WalletBalanceData, PriceEntry, SendWalletPayload, SendWalletResponse, WalletAddress, PortfolioData, PortfolioChain, PortfolioNative, PortfolioToken, TokenInfo, RelayQuotePayload, RelayQuoteResponse, RelaySwapResponse, RelaySwapStep, TrxSwapQuotePayload, TrxSwapQuoteData, JumperToken, JumperTokensMap, JumperQuote, JumperQuotePayload, JumperQuoteToken, JumperFeeCost, BridgeExecutePayload, BridgeExecuteResult } 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, getPortfolio, getTokensList, getRelayQuote, executeRelaySwap, signRawEvmTx, signSolTx, getTrxSwapQuote, executeTrxSwap, createWallet, revealMnemonic, CHAINS, type Chain, type SendWalletPayload, type RelayQuotePayload, type RelaySwapStep, type TrxSwapQuotePayload } from '../api/walletApi'
|
||||
import { getWalletBalance, getPrices, sendWallet, getWalletAddresses, getPortfolio, getTokensList, getRelayQuote, executeRelaySwap, signRawEvmTx, signSolTx, getTrxSwapQuote, executeTrxSwap, getJumperTokens, getJumperQuote, executeBridge, createWallet, revealMnemonic, CHAINS, type Chain, type SendWalletPayload, type RelayQuotePayload, type RelaySwapStep, type TrxSwapQuotePayload, type JumperQuotePayload, type BridgeExecutePayload } from '../api/walletApi'
|
||||
|
||||
export function useWalletBalance(chain: Chain) {
|
||||
return useQuery({
|
||||
@@ -58,6 +58,22 @@ export function useTokensList() {
|
||||
})
|
||||
}
|
||||
|
||||
export function useJumperTokens() {
|
||||
return useQuery({
|
||||
queryKey: ['wallet', 'jumper', 'tokens'],
|
||||
queryFn: getJumperTokens,
|
||||
staleTime: 10 * 60 * 1000,
|
||||
})
|
||||
}
|
||||
|
||||
export function useFetchJumperQuote() {
|
||||
return useMutation({ mutationFn: (payload: JumperQuotePayload) => getJumperQuote(payload) })
|
||||
}
|
||||
|
||||
export function useExecuteBridge() {
|
||||
return useMutation({ mutationFn: (payload: BridgeExecutePayload) => executeBridge(payload) })
|
||||
}
|
||||
|
||||
export function useCreateWallet() {
|
||||
return useMutation({ mutationFn: createWallet })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user