From 9c15b814098795f7c6631e40ae8b2701d997b84b Mon Sep 17 00:00:00 2001 From: h Date: Sun, 18 Oct 2026 17:02:12 +0000 Subject: [PATCH] fix(subscriptions): a payment made around a past due date counts as paid, runway refetches on focus A bill paid a day before its due date showed as overdue in the runway because past due dates were never matched against payments; now any payment within a third of the cycle around the date settles it. The runway's bills and payments refetch when the tab gets focus, so entries the bot made meanwhile show up. --- src/lib/subscriptions/queries.ts | 2 ++ src/lib/subscriptions/runway.ts | 6 +----- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/lib/subscriptions/queries.ts b/src/lib/subscriptions/queries.ts index 1c32aa9..8d03776 100644 --- a/src/lib/subscriptions/queries.ts +++ b/src/lib/subscriptions/queries.ts @@ -28,10 +28,12 @@ export const runwayQueries = { bills: (start: string, end: string) => ({ queryFn: () => all("/v1/bills", { end, start }), queryKey: ["subscriptions", "runway", start, end], + refetchOnWindowFocus: true, }), paid: () => ({ queryFn: async () => toPayments(await search("has_any_bill:true")), queryKey: ["subscriptions", "payments"], + refetchOnWindowFocus: true, }), unlinked: (day: string) => { const after = addDays(day, -UNLINKED_DAYS); diff --git a/src/lib/subscriptions/runway.ts b/src/lib/subscriptions/runway.ts index f9417da..57cf4f6 100644 --- a/src/lib/subscriptions/runway.ts +++ b/src/lib/subscriptions/runway.ts @@ -208,11 +208,7 @@ function occurrences(bill: Bill, day: string) { return (bill.pay_dates ?? []) .map((raw) => raw.slice(0, 10)) .filter((date) => !end || date <= end) - .filter( - (date) => - date < day || - !paid.some((p) => p <= date && daysBetween(p, date) < early) - ) + .filter((date) => !paid.some((p) => Math.abs(daysBetween(p, date)) < early)) .map((date) => ({ date: date < day ? day : date, overdue: date < day })); }