14.05.2026 rip

This commit is contained in:
2026-05-14 23:23:20 +03:00
parent 26a7315ea1
commit 0d114e12c2
6 changed files with 271 additions and 8 deletions

View File

@@ -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', {})
}