* Fetch Grove config from API and store in cache
(accountId: string)
| 217 | * Fetch Grove config from API and store in cache |
| 218 | */ |
| 219 | async function fetchAndStoreGroveConfig(accountId: string): Promise<void> { |
| 220 | try { |
| 221 | const result = await getGroveNoticeConfig() |
| 222 | if (!result.success) { |
| 223 | return |
| 224 | } |
| 225 | const groveEnabled = result.data.grove_enabled |
| 226 | const cachedEntry = getGlobalConfig().groveConfigCache?.[accountId] |
| 227 | if ( |
| 228 | cachedEntry?.grove_enabled === groveEnabled && |
| 229 | Date.now() - cachedEntry.timestamp <= GROVE_CACHE_EXPIRATION_MS |
| 230 | ) { |
| 231 | return |
| 232 | } |
| 233 | saveGlobalConfig(current => ({ |
| 234 | ...current, |
| 235 | groveConfigCache: { |
| 236 | ...current.groveConfigCache, |
| 237 | [accountId]: { |
| 238 | grove_enabled: groveEnabled, |
| 239 | timestamp: Date.now(), |
| 240 | }, |
| 241 | }, |
| 242 | })) |
| 243 | } catch (err) { |
| 244 | logForDebugging(`Grove: Failed to fetch and store config: ${err}`) |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | /** |
| 249 | * Get Grove Statsig configuration from the API. |
no test coverage detected