feat: render hourly investment states
This commit was merged in pull request #51.
This commit is contained in:
@@ -19,12 +19,14 @@ function auth() {
|
||||
}
|
||||
|
||||
describe("read-only screen synchronization", () => {
|
||||
it("retries the resource with GET and never starts a sync POST", async () => {
|
||||
it("retries the resource with GET without requesting source observation", async () => {
|
||||
auth();
|
||||
let gets = 0;
|
||||
const syncModes: (null | string)[] = [];
|
||||
server.use(
|
||||
http.get("*/api/v1/brokerage-accounts", () => {
|
||||
http.get("*/api/v1/brokerage-accounts", ({ request }) => {
|
||||
gets += 1;
|
||||
syncModes.push(new URL(request.url).searchParams.get("sync"));
|
||||
|
||||
return gets === 1
|
||||
? HttpResponse.json({ code: "TBANK_UNAVAILABLE" }, { status: 503 })
|
||||
@@ -49,6 +51,7 @@ describe("read-only screen synchronization", () => {
|
||||
await waitFor(() => expect(result.current.accounts.data).toEqual([]));
|
||||
|
||||
expect(gets).toBe(2);
|
||||
expect(syncModes).toEqual([null, null]);
|
||||
});
|
||||
|
||||
it("refreshes the currently open resources together", async () => {
|
||||
|
||||
@@ -8,7 +8,6 @@ type ScreenResource = {
|
||||
isError: boolean;
|
||||
isFetching: boolean;
|
||||
meta?: InvestmentResourceMeta;
|
||||
observe: () => Promise<unknown>;
|
||||
queryKey: QueryKey;
|
||||
refetch: () => Promise<unknown>;
|
||||
};
|
||||
@@ -42,14 +41,12 @@ function useScreenSync(_scope: ScreenScope, resources: ScreenResource[]) {
|
||||
await Promise.allSettled(resources.map(resource => resource.refetch()));
|
||||
};
|
||||
|
||||
// Retry failed HTTP reads without asking the source to import again.
|
||||
// Retry only the HTTP read; source attempts are reported in resource metadata.
|
||||
const retry = async () => {
|
||||
const failed = resources.filter(
|
||||
resource => resource.isError,
|
||||
);
|
||||
const failed = resources.filter(resource => resource.isError);
|
||||
|
||||
if (failed.length > 0)
|
||||
await Promise.allSettled(failed.map(resource => resource.observe()));
|
||||
await Promise.allSettled(failed.map(resource => resource.refetch()));
|
||||
else await refresh();
|
||||
};
|
||||
|
||||
@@ -57,7 +54,9 @@ function useScreenSync(_scope: ScreenScope, resources: ScreenResource[]) {
|
||||
refresh,
|
||||
refreshing: isRefreshing,
|
||||
retry,
|
||||
sourceError: resources.some(({ meta }) => meta?.sync.state === "failed"),
|
||||
sourceError: resources.some(
|
||||
({ meta }) => meta?.lastAttempt.state === "failed",
|
||||
),
|
||||
transportError: resources.some(resource => resource.isError),
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user