( settingsResult: ApiResult<AccountSettings>, configResult: ApiResult<GroveConfig>, showIfAlreadyViewed: boolean, )
| 282 | * Returns false if either API call failed (after retry) - we hide the dialog on API failure. |
| 283 | */ |
| 284 | export function calculateShouldShowGrove( |
| 285 | settingsResult: ApiResult<AccountSettings>, |
| 286 | configResult: ApiResult<GroveConfig>, |
| 287 | showIfAlreadyViewed: boolean, |
| 288 | ): boolean { |
| 289 | // Hide dialog on API failure (after retry) |
| 290 | if (!settingsResult.success || !configResult.success) { |
| 291 | return false |
| 292 | } |
| 293 | |
| 294 | const settings = settingsResult.data |
| 295 | const config = configResult.data |
| 296 | |
| 297 | const hasChosen = settings.grove_enabled !== null |
| 298 | if (hasChosen) { |
| 299 | return false |
| 300 | } |
| 301 | if (showIfAlreadyViewed) { |
| 302 | return true |
| 303 | } |
| 304 | if (!config.notice_is_grace_period) { |
| 305 | return true |
| 306 | } |
| 307 | // Check if we need to remind the user to accept the terms and choose |
| 308 | // whether to help improve Claude. |
| 309 | const reminderFrequency = config.notice_reminder_frequency |
| 310 | if (reminderFrequency !== null && settings.grove_notice_viewed_at) { |
| 311 | const daysSinceViewed = Math.floor( |
| 312 | (Date.now() - new Date(settings.grove_notice_viewed_at).getTime()) / |
| 313 | (1000 * 60 * 60 * 24), |
| 314 | ) |
| 315 | return daysSinceViewed >= reminderFrequency |
| 316 | } else { |
| 317 | // Show if never viewed before |
| 318 | const viewedAt = settings.grove_notice_viewed_at |
| 319 | return viewedAt === null || viewedAt === undefined |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | export async function checkGroveForNonInteractive(): Promise<void> { |
| 324 | const [settingsResult, configResult] = await Promise.all([ |
no outgoing calls
no test coverage detected