Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
f3de12d
Stop surfacing broken card task and RBR after 90 days while keeping t…
wildan-m May 22, 2026
99591aa
Merge remote-tracking branch 'upstream/main' into wildan/91451-broken…
wildan-m Jun 13, 2026
9df0102
Add unit tests for the broken-connection 90-day grace period
wildan-m Jun 13, 2026
4551c82
Merge remote-tracking branch 'upstream/main' into wildan/91451-broken…
wildan-m Jun 14, 2026
34bbf11
Merge remote-tracking branch 'upstream/main' into HEAD
wildan-m Jun 16, 2026
4966465
Merge remote-tracking branch 'upstream/main' into HEAD
wildan-m Jun 24, 2026
c074a83
Merge remote-tracking branch 'upstream/main' into HEAD
wildan-m Jun 25, 2026
3d10c4d
Merge remote-tracking branch 'upstream/main' into HEAD
wildan-m Jun 25, 2026
1d3ba67
Merge remote-tracking branch 'upstream/main' into HEAD
wildan-m Jun 25, 2026
78b7495
Merge remote-tracking branch 'upstream/main' into HEAD
wildan-m Jun 25, 2026
bc3bc01
Merge remote-tracking branch 'upstream/main' into HEAD
wildan-m Jun 25, 2026
35f445c
Merge remote-tracking branch 'upstream/main' into HEAD
wildan-m Jun 25, 2026
85431d7
fix: re-derive card feed errors at day rollover for 90-day broken-con…
wildan-m Jun 25, 2026
d535e91
Merge remote-tracking branch 'upstream/main' into HEAD
wildan-m Jun 27, 2026
9609644
Merge remote-tracking branch 'upstream/main' into HEAD
wildan-m Jun 28, 2026
6f25cba
Merge remote-tracking branch 'upstream/main' into HEAD
wildan-m Jul 1, 2026
1969d61
fix: parse lastScrape with explicit DB format for cross-engine safety
wildan-m Jul 1, 2026
00765f5
test: use full DB datetime format in grace-period fixtures
wildan-m Jul 1, 2026
8f31c5b
Merge remote-tracking branch 'upstream/main' into HEAD
wildan-m Jul 6, 2026
9f0029e
Merge remote-tracking branch 'upstream/main' into HEAD
wildan-m Jul 6, 2026
e2295b6
Merge remote-tracking branch 'upstream/main' into HEAD
wildan-m Jul 8, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/CONST/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4569,6 +4569,9 @@ const CONST = {
},
COMPANY_CARDS: {
BROKEN_CONNECTION_IGNORED_STATUSES: brokenConnectionScrapeStatuses,
// After a card connection has been broken and unresolved for this many days, stop actively
// prompting the user: the time-sensitive home task and the RBR are removed (the error itself is kept).
BROKEN_CONNECTION_DISMISS_AFTER_DAYS: 90,
WORKSPACE_FEEDS_LOAD_ERROR: 'workspaceFeedsLoadError',
FEED_LOAD_ERROR: 'feedLoadError',
STEP: {
Expand Down
28 changes: 27 additions & 1 deletion src/libs/CardUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import type IconAsset from '@src/types/utils/IconAsset';
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import type {TupleToUnion, ValueOf} from 'type-fest';

import {format, fromUnixTime, isBefore} from 'date-fns';
import {format, fromUnixTime, isBefore, parse} from 'date-fns';
import groupBy from 'lodash/groupBy';
import lodashSortBy from 'lodash/sortBy';

Expand Down Expand Up @@ -1259,6 +1259,31 @@ function isCardConnectionBroken(card: Card): boolean {
return !!card.lastScrapeResult && !CONST.COMPANY_CARDS.BROKEN_CONNECTION_IGNORED_STATUSES.includes(card.lastScrapeResult);
}

/**
* Check whether a broken card connection has been unresolved long enough that we should stop
* actively prompting the user (remove the time-sensitive task and the RBR). The error itself is
* kept, so this is only used to gate the proactive surfacing, not the underlying broken state.
*
* `lastScrape` is the last successful update timestamp (a separate `lastImportAttempt` tracks
* attempts), so for a broken connection its age equals how long the connection has been failing.
*
* @param card the card to check
* @returns true if the connection is broken and has been unresolved for at least the grace period
*/
function isBrokenConnectionPastDismissThreshold(card: Card): boolean {
if (!isCardConnectionBroken(card) || !card.lastScrape) {
return false;
}
// `card.lastScrape` uses the Expensify DB datetime format (e.g. "2024-11-27 11:00:53"). Parse it explicitly with the
// matching format instead of relying on `new Date()`, whose handling of this non-ISO string is not portable across JS
// engines — an invalid parse would make the difference NaN, so the comparison would always be false and never dismiss.
const lastScrapeDate = parse(card.lastScrape, 'yyyy-MM-dd HH:mm:ss', new Date());
if (Number.isNaN(lastScrapeDate.getTime())) {
return false;
}
return DateUtils.getDifferenceInDaysFromNow(lastScrapeDate) >= CONST.COMPANY_CARDS.BROKEN_CONNECTION_DISMISS_AFTER_DAYS;
}

/**
* Checks if an Expensify Card was issued for a given workspace.
*/
Expand Down Expand Up @@ -1939,6 +1964,7 @@ export {
getCSVFeedType,
getFeedType,
isCardConnectionBroken,
isBrokenConnectionPastDismissThreshold,
isSmartLimitEnabled,
lastFourNumbersFromCardName,
isMatchingCard,
Expand Down
14 changes: 10 additions & 4 deletions src/libs/actions/OnyxDerived/configs/cardFeedErrors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {getCombinedCardFeedsFromAllFeeds, getWorkspaceCardFeedsStatus} from '@libs/CardFeedUtils';
import {filterInactiveCards, getCardFeedWithDomainID, isCardConnectionBroken, isPersonalCard} from '@libs/CardUtils';
import {filterInactiveCards, getCardFeedWithDomainID, isBrokenConnectionPastDismissThreshold, isCardConnectionBroken, isPersonalCard} from '@libs/CardUtils';

import createOnyxDerivedValueConfig from '@userActions/OnyxDerived/createOnyxDerivedValueConfig';

Expand Down Expand Up @@ -32,7 +32,9 @@ function getShouldShowRBR(state: Partial<CardFeedErrorState>): boolean {

export default createOnyxDerivedValueConfig({
key: ONYXKEYS.DERIVED.CARD_FEED_ERRORS,
dependencies: [ONYXKEYS.CARD_LIST, ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST, ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER],
// CURRENT_DATE (day-granularity) is a trigger-only dependency: it makes this value recompute when the day rolls over so the
// 90-day broken-connection grace period (isBrokenConnectionPastDismissThreshold) is re-evaluated even if no card/feed data changes.
dependencies: [ONYXKEYS.CARD_LIST, ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST, ONYXKEYS.COLLECTION.SHARED_NVP_PRIVATE_DOMAIN_MEMBER, ONYXKEYS.CURRENT_DATE],

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Recompute the grace period on native day changes

This CURRENT_DATE dependency only advances where setCurrentDate is actually called; I checked the wiring and it is started from the web platform setup, while src/setup/platformSetup/index.native.ts is a no-op. On iOS/Android, if a broken card crosses the 90-day boundary while the app remains open and no card/feed data changes, the derived value never recomputes, so the Home task and RBR can persist until a restart or unrelated data update.

Useful? React with 👍 / 👎.

compute: ([globalCardList, allWorkspaceCards, cardFeeds]) => {
const feedKeysWithCards = buildFeedKeysWithAssignedCards(allWorkspaceCards);
const combinedCompanyCardFeeds = getCombinedCardFeedsFromAllFeeds(cardFeeds, undefined, feedKeysWithCards);
Expand Down Expand Up @@ -64,7 +66,9 @@ export default createOnyxDerivedValueConfig({
: {}),
} as Record<string, CardErrors>;

const isFeedConnectionBroken = isCardConnectionBroken(card);
// Stop surfacing the broken connection (task + RBR) once it has been unresolved past the
// grace period; the underlying error on the card is kept so the user can still fix it.
const isFeedConnectionBroken = isCardConnectionBroken(card) && !isBrokenConnectionPastDismissThreshold(card);
// Track personal cards with broken feed connection
if (isFeedConnectionBroken) {
personalCardsWithBrokenConnection[card.cardID] = card;
Expand Down Expand Up @@ -119,7 +123,9 @@ export default createOnyxDerivedValueConfig({
: {}),
} as Record<string, CardErrors>;

const isFeedConnectionBroken = isCardConnectionBroken(card);
// Stop surfacing the broken connection (task + RBR) once it has been unresolved past the
// grace period; the underlying error on the card is kept so the user can still fix it.
const isFeedConnectionBroken = isCardConnectionBroken(card) && !isBrokenConnectionPastDismissThreshold(card);
Comment thread
wildan-m marked this conversation as resolved.
Resolved

const newFeedState: Omit<CardFeedErrorState, 'shouldShowRBR'> = {
isFeedConnectionBroken: isFeedConnectionBroken || previousFeedErrors.isFeedConnectionBroken,
Expand Down
Loading
Loading