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] 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; }