fix: preserve cached data during refresh failures

This commit is contained in:
2026-08-24 00:50:39 +03:00
parent 7a3048c347
commit 6d892da9ce
12 changed files with 511 additions and 61 deletions
+21 -8
View File
@@ -14,21 +14,34 @@ export function useAccountPageViewModel() {
const account = useQueryClient()
.getQueryData<BrokerageAccount[]>(brokerageAccountsQueryKey)
?.find((item) => item.id === accountId);
if (portfolio.isError)
return {
state: "error" as const,
code: portfolioErrorCode(portfolio.error),
retry: () => portfolio.refetch(),
};
if (portfolio.isFetching || !portfolio.data)
if (!portfolio.data) {
if (portfolio.isError)
return {
state: "error" as const,
code: portfolioErrorCode(portfolio.error),
retry: () => portfolio.refetch(),
};
return { state: "loading" as const };
}
const refresh = {
refreshing: portfolio.isFetching,
refreshError: portfolio.isError,
retry: () => portfolio.refetch(),
};
if (!portfolio.data.positions.length && !portfolio.data.cashBalances.length)
return { state: "empty" as const, account, accountId, accessToken };
return {
state: "empty" as const,
account,
accountId,
accessToken,
...refresh,
};
return {
state: "loaded" as const,
account,
accountId,
accessToken,
portfolio: portfolio.data,
...refresh,
};
}