14.05.2026 rip
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { getCsrfToken } from '@shared/api/csrf'
|
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'
|
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']
|
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 csrf = await getCsrfToken()
|
||||||
|
const bearer = tokenStore.get()
|
||||||
|
|
||||||
const res = await fetch(`${WALLET_API_URL}${path}`, {
|
const res = await fetch(`${WALLET_API_URL}${path}`, {
|
||||||
credentials: 'include',
|
credentials: 'include',
|
||||||
headers: {
|
headers: {
|
||||||
'X-CSRF-Token': csrf,
|
'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()
|
const data = await res.json()
|
||||||
if (!res.ok) throw data
|
if (!res.ok) throw data
|
||||||
return data as T
|
return data as T
|
||||||
|
|||||||
Reference in New Issue
Block a user