@@ -8,7 +8,13 @@ import { Card } from '@/components/ui/Card';
88import { Button } from '@/components/ui/Button' ;
99import { EmptyState } from '@/components/ui/EmptyState' ;
1010import { triggerHeaderRefresh } from '@/hooks/useHeaderRefresh' ;
11- import { useNotificationStore , useQuotaStore , useThemeStore } from '@/stores' ;
11+ import {
12+ captureQuotaCacheGeneration ,
13+ commitIfQuotaCacheCurrent ,
14+ useNotificationStore ,
15+ useQuotaStore ,
16+ useThemeStore ,
17+ } from '@/stores' ;
1218import type { AuthFileItem , ResolvedTheme } from '@/types' ;
1319import { getStatusFromError } from '@/utils/quota' ;
1420import { QuotaCard } from './QuotaCard' ;
@@ -201,6 +207,7 @@ export function QuotaSection<TState extends QuotaStatusState, TData>({
201207 async ( file : AuthFileItem ) => {
202208 if ( disabled || file . disabled ) return ;
203209 if ( quota [ file . name ] ?. status === 'loading' ) return ;
210+ const cacheGeneration = captureQuotaCacheGeneration ( ) ;
204211
205212 setQuota ( ( prev ) => ( {
206213 ...prev ,
@@ -209,22 +216,26 @@ export function QuotaSection<TState extends QuotaStatusState, TData>({
209216
210217 try {
211218 const data = await config . fetchQuota ( file , t ) ;
212- setQuota ( ( prev ) => ( {
213- ...prev ,
214- [ file . name ] : config . buildSuccessState ( data ) ,
215- } ) ) ;
216- showNotification ( t ( 'auth_files.quota_refresh_success' , { name : file . name } ) , 'success' ) ;
219+ commitIfQuotaCacheCurrent ( cacheGeneration , ( ) => {
220+ setQuota ( ( prev ) => ( {
221+ ...prev ,
222+ [ file . name ] : config . buildSuccessState ( data ) ,
223+ } ) ) ;
224+ showNotification ( t ( 'auth_files.quota_refresh_success' , { name : file . name } ) , 'success' ) ;
225+ } ) ;
217226 } catch ( err : unknown ) {
218227 const message = err instanceof Error ? err . message : t ( 'common.unknown_error' ) ;
219228 const status = getStatusFromError ( err ) ;
220- setQuota ( ( prev ) => ( {
221- ...prev ,
222- [ file . name ] : config . buildErrorState ( message , status ) ,
223- } ) ) ;
224- showNotification (
225- t ( 'auth_files.quota_refresh_failed' , { name : file . name , message } ) ,
226- 'error'
227- ) ;
229+ commitIfQuotaCacheCurrent ( cacheGeneration , ( ) => {
230+ setQuota ( ( prev ) => ( {
231+ ...prev ,
232+ [ file . name ] : config . buildErrorState ( message , status ) ,
233+ } ) ) ;
234+ showNotification (
235+ t ( 'auth_files.quota_refresh_failed' , { name : file . name , message } ) ,
236+ 'error'
237+ ) ;
238+ } ) ;
228239 }
229240 } ,
230241 [ config , disabled , quota , setQuota , showNotification , t ]
@@ -244,17 +255,25 @@ export function QuotaSection<TState extends QuotaStatusState, TData>({
244255 confirmText : t ( 'codex_quota.reset_confirm_button' ) ,
245256 variant : 'primary' ,
246257 onConfirm : async ( ) => {
258+ const cacheGeneration = captureQuotaCacheGeneration ( ) ;
247259 setResettingQuotaName ( file . name ) ;
248260 try {
249261 const data = await resetQuota ( file , t ) ;
250- setQuota ( ( prev ) => ( {
251- ...prev ,
252- [ file . name ] : config . buildSuccessState ( data ) ,
253- } ) ) ;
254- showNotification ( t ( 'codex_quota.reset_success' , { name : file . name } ) , 'success' ) ;
262+ commitIfQuotaCacheCurrent ( cacheGeneration , ( ) => {
263+ setQuota ( ( prev ) => ( {
264+ ...prev ,
265+ [ file . name ] : config . buildSuccessState ( data ) ,
266+ } ) ) ;
267+ showNotification ( t ( 'codex_quota.reset_success' , { name : file . name } ) , 'success' ) ;
268+ } ) ;
255269 } catch ( err : unknown ) {
256270 const message = err instanceof Error ? err . message : t ( 'common.unknown_error' ) ;
257- showNotification ( t ( 'codex_quota.reset_failed' , { name : file . name , message } ) , 'error' ) ;
271+ commitIfQuotaCacheCurrent ( cacheGeneration , ( ) => {
272+ showNotification (
273+ t ( 'codex_quota.reset_failed' , { name : file . name , message } ) ,
274+ 'error'
275+ ) ;
276+ } ) ;
258277 } finally {
259278 setResettingQuotaName ( ( current ) => ( current === file . name ? null : current ) ) ;
260279 }
0 commit comments