From f5562871c0f6fea5908180e88864e0a55cf70878 Mon Sep 17 00:00:00 2001 From: rassadin11 Date: Thu, 14 May 2026 15:57:32 +0300 Subject: [PATCH] 14.05.2026 rip --- src/features/wallet/api/walletApi.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/features/wallet/api/walletApi.ts b/src/features/wallet/api/walletApi.ts index 39a54d0..e62e2c3 100644 --- a/src/features/wallet/api/walletApi.ts +++ b/src/features/wallet/api/walletApi.ts @@ -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(path: string): Promise { +async function walletGet(path: string, allowRetry: boolean = true): Promise { 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(path, false) + } catch { + tokenStore.clear() + throw new Error('Unauthorized') + } + } + const data = await res.json() if (!res.ok) throw data return data as T