14.05.2026 rip

This commit is contained in:
2026-05-14 15:57:32 +03:00
parent 020bf86404
commit f5562871c0

View File

@@ -1,5 +1,5 @@
import { getCsrfToken } from '@shared/api/csrf'
import { tokenStore } from '@shared/api/tokenStore'
import { tokenStore, refreshAccessToken } from '@shared/api/tokenStore'
const WALLET_API_URL = 'https://app.cryptowallet.elcsa.ru'
@@ -26,16 +26,28 @@ export interface PriceEntry {
export const CHAINS: Chain[] = ['ETH', 'BSC', 'BTC', 'TRX', 'SOL']
async function walletGet<T>(path: string): Promise<T> {
async function walletGet<T>(path: string, allowRetry: boolean = true): Promise<T> {
const csrf = await getCsrfToken()
const bearer = tokenStore.get()
const res = await fetch(`${WALLET_API_URL}${path}`, {
credentials: 'include',
headers: {
'X-CSRF-Token': csrf,
...(bearer ? { Authorization: `Bearer ${bearer}` } : {}),
},
})
if (res.status === 401 && allowRetry) {
try {
await refreshAccessToken()
return walletGet<T>(path, false)
} catch {
tokenStore.clear()
throw new Error('Unauthorized')
}
}
const data = await res.json()
if (!res.ok) throw data
return data as T