From 30ee8d372d95e800163f604cd595e0e5055aeedb Mon Sep 17 00:00:00 2001 From: Bl0ck <36800583+Bl0ck154@users.noreply.github.com> Date: Mon, 7 Sep 2026 11:05:08 +0300 Subject: [PATCH 1/2] fix: preserve cached usage when deleting accounts --- src/hooks/useAccounts.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/hooks/useAccounts.ts b/src/hooks/useAccounts.ts index 94064a8f..07e71253 100644 --- a/src/hooks/useAccounts.ts +++ b/src/hooks/useAccounts.ts @@ -246,8 +246,19 @@ export function useAccounts() { const deleteAccount = useCallback( async (accountId: string) => { try { + const deletedAccount = accountsRef.current.find((account) => account.id === accountId); await invokeBackend("delete_account", { accountId }); - await loadAccounts(); + + if (deletedAccount && !deletedAccount.is_active) { + // Deleting an inactive account does not change any other account. Keep + // their already-fetched usage in place instead of rebuilding the list. + setAccounts((prev) => prev.filter((account) => account.id !== accountId)); + return; + } + + // Removing the active account can make another account active on the + // backend. Re-read account metadata, but never discard cached usage. + await loadAccounts(true); } catch (err) { throw err; } From 7e666f8bfca8ac5f2ea0f65edd45a400347e9c34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=9C=E7=81=AF?= Date: Wed, 30 Sep 2026 18:37:55 +0800 Subject: [PATCH 2/2] fix: reconcile account metadata after deletion --- src/hooks/useAccounts.ts | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/hooks/useAccounts.ts b/src/hooks/useAccounts.ts index 80f8734a..23b6c615 100644 --- a/src/hooks/useAccounts.ts +++ b/src/hooks/useAccounts.ts @@ -292,18 +292,9 @@ export function useAccounts() { const deleteAccount = useCallback( async (accountId: string) => { try { - const deletedAccount = accountsRef.current.find((account) => account.id === accountId); await invokeBackend("delete_account", { accountId }); - - if (deletedAccount && !deletedAccount.is_active) { - // Deleting an inactive account does not change any other account. Keep - // their already-fetched usage in place instead of rebuilding the list. - setAccounts((prev) => prev.filter((account) => account.id !== accountId)); - return; - } - - // Removing the active account can make another account active on the - // backend. Re-read account metadata, but never discard cached usage. + // Account activation can change while deletion is in flight. Re-read + // backend metadata without discarding the latest cached usage. await loadAccounts(true); } catch (err) { throw err;