14.05.2026 rip
This commit is contained in:
@@ -96,7 +96,12 @@ async function walletGet<T>(path: string, allowRetry: boolean = true): Promise<T
|
||||
return data as T
|
||||
}
|
||||
|
||||
async function walletPost<T>(path: string, body: unknown, allowRetry: boolean = true): Promise<T> {
|
||||
async function walletPost<T>(
|
||||
path: string,
|
||||
body: unknown,
|
||||
allowRetry: boolean = true,
|
||||
extraHeaders: Record<string, string> = {}
|
||||
): Promise<T> {
|
||||
const csrf = await getCsrfToken()
|
||||
const bearer = tokenStore.get()
|
||||
|
||||
@@ -107,6 +112,7 @@ async function walletPost<T>(path: string, body: unknown, allowRetry: boolean =
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRF-Token': csrf,
|
||||
...(bearer ? { Authorization: `Bearer ${bearer}` } : {}),
|
||||
...extraHeaders,
|
||||
},
|
||||
body: JSON.stringify(body),
|
||||
})
|
||||
@@ -114,7 +120,7 @@ async function walletPost<T>(path: string, body: unknown, allowRetry: boolean =
|
||||
if (res.status === 401 && allowRetry) {
|
||||
try {
|
||||
await refreshAccessToken()
|
||||
return walletPost<T>(path, body, false)
|
||||
return walletPost<T>(path, body, false, extraHeaders)
|
||||
} catch {
|
||||
tokenStore.clear()
|
||||
throw new Error('Unauthorized')
|
||||
@@ -225,8 +231,8 @@ export interface RelaySwapResponse {
|
||||
operation: string
|
||||
sender: string
|
||||
recipient: string
|
||||
currencyIn: { amount: string; amountFormatted: string; amountUsd: string; currency: unknown }
|
||||
currencyOut: { amount: string; amountFormatted: string; amountUsd: string; currency: unknown }
|
||||
currencyIn: { amount: string; amountFormatted: string; amountUsd: string; currency: { symbol: string } }
|
||||
currencyOut: { amount: string; amountFormatted: string; amountUsd: string; currency: { symbol: string } }
|
||||
totalImpact: { usd: string; percent: string }
|
||||
rate: string
|
||||
timeEstimate: number
|
||||
@@ -237,6 +243,18 @@ export async function executeRelaySwap(payload: RelayQuotePayload): Promise<Rela
|
||||
return walletPost<RelaySwapResponse>('/api/relay/execute/swap', payload)
|
||||
}
|
||||
|
||||
export async function signRawEvmTx(
|
||||
chain: 'ETH' | 'BSC',
|
||||
txData: RelaySwapStep['items'][0]['data']
|
||||
): Promise<unknown> {
|
||||
const key = `relay-${chain.toLowerCase()}-${Date.now()}`
|
||||
return walletPost(`/api/wallets/${chain}/sign-raw-evm-tx`, txData, true, { 'Idempotency-Key': key })
|
||||
}
|
||||
|
||||
export async function signSolTx(txData: unknown): Promise<unknown> {
|
||||
return walletPost('/api/wallets/SOL/sign-and-broadcast-tx', txData)
|
||||
}
|
||||
|
||||
export async function createWallet(): Promise<void> {
|
||||
await walletPost<unknown>('/api/wallets/create', {})
|
||||
}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
export { useAllWalletBalances, usePrices, useSendWallet, useWalletAddresses, useWalletBalance, usePortfolio, useTokensList, useRelayQuote, useExecuteRelaySwap, useCreateWallet, useRevealMnemonic } from './model/useWalletData'
|
||||
export { useAllWalletBalances, usePrices, useSendWallet, useWalletAddresses, useWalletBalance, usePortfolio, useTokensList, useRelayQuote, useExecuteRelaySwap, useSignSwap, useCreateWallet, useRevealMnemonic } from './model/useWalletData'
|
||||
export type { Chain, FormattedAmount, WalletBalanceData, PriceEntry, SendWalletPayload, SendWalletResponse, WalletAddress, PortfolioData, PortfolioChain, PortfolioNative, PortfolioToken, TokenInfo, RelayQuotePayload, RelayQuoteResponse, RelaySwapResponse, RelaySwapStep } 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, createWallet, revealMnemonic, CHAINS, type Chain, type SendWalletPayload, type RelayQuotePayload } from '../api/walletApi'
|
||||
import { getWalletBalance, getPrices, sendWallet, getWalletAddresses, getPortfolio, getTokensList, getRelayQuote, executeRelaySwap, signRawEvmTx, signSolTx, createWallet, revealMnemonic, CHAINS, type Chain, type SendWalletPayload, type RelayQuotePayload, type RelaySwapStep } from '../api/walletApi'
|
||||
|
||||
export function useWalletBalance(chain: Chain) {
|
||||
return useQuery({
|
||||
@@ -88,3 +88,12 @@ export function useExecuteRelaySwap() {
|
||||
mutationFn: (payload: RelayQuotePayload) => executeRelaySwap(payload),
|
||||
})
|
||||
}
|
||||
|
||||
export function useSignSwap() {
|
||||
return useMutation({
|
||||
mutationFn: ({ chain, txData }: { chain: Chain; txData: unknown }) => {
|
||||
if (chain === 'SOL') return signSolTx(txData)
|
||||
return signRawEvmTx(chain as 'ETH' | 'BSC', txData as RelaySwapStep['items'][0]['data'])
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user