14.05.2026 rip
This commit is contained in:
@@ -24,6 +24,17 @@ export interface PriceEntry {
|
||||
usd: number
|
||||
}
|
||||
|
||||
export interface SendWalletPayload {
|
||||
to: string
|
||||
amount: string
|
||||
token?: string
|
||||
feeTier?: 'slow' | 'normal' | 'fast'
|
||||
}
|
||||
|
||||
export interface SendWalletResponse {
|
||||
data: { txid: string; chain: Chain }
|
||||
}
|
||||
|
||||
export const CHAINS: Chain[] = ['ETH', 'BSC', 'BTC', 'TRX', 'SOL']
|
||||
|
||||
async function walletGet<T>(path: string, allowRetry: boolean = true): Promise<T> {
|
||||
@@ -53,6 +64,36 @@ 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> {
|
||||
const csrf = await getCsrfToken()
|
||||
const bearer = tokenStore.get()
|
||||
|
||||
const res = await fetch(`${WALLET_API_URL}${path}`, {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRF-Token': csrf,
|
||||
...(bearer ? { Authorization: `Bearer ${bearer}` } : {}),
|
||||
},
|
||||
body: JSON.stringify(body),
|
||||
})
|
||||
|
||||
if (res.status === 401 && allowRetry) {
|
||||
try {
|
||||
await refreshAccessToken()
|
||||
return walletPost<T>(path, body, false)
|
||||
} catch {
|
||||
tokenStore.clear()
|
||||
throw new Error('Unauthorized')
|
||||
}
|
||||
}
|
||||
|
||||
const data = await res.json()
|
||||
if (!res.ok) throw data
|
||||
return data as T
|
||||
}
|
||||
|
||||
export async function getWalletBalance(chain: Chain): Promise<WalletBalanceData> {
|
||||
const res = await walletGet<{ success: boolean; data: WalletBalanceData }>(`/api/wallets/${chain}/balance`)
|
||||
return res.data
|
||||
@@ -64,3 +105,7 @@ export async function getPrices(symbols: string[]): Promise<Record<string, Price
|
||||
)
|
||||
return res.data
|
||||
}
|
||||
|
||||
export async function sendWallet(chain: Chain, payload: SendWalletPayload): Promise<SendWalletResponse> {
|
||||
return walletPost<SendWalletResponse>(`/api/wallets/${chain}/send`, payload)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user