* Fetch Grove config from API and store in cache
(accountId: string)
| 198 | * Fetch Grove config from API and store in cache |
| 199 | */ |
| 200 | async function fetchAndStoreGroveConfig(accountId: string): Promise<void> { |
| 201 | try { |
| 202 | const result = await getGroveNoticeConfig() |
| 203 | if (!result.success) { |
| 204 | return |
| 205 | } |
| 206 | const groveEnabled = result.data.grove_enabled |
| 207 | const cachedEntry = getGlobalConfig().groveConfigCache?.[accountId] |
| 208 | if ( |
| 209 | cachedEntry?.grove_enabled === groveEnabled && |
| 210 | Date.now() - cachedEntry.timestamp <= GROVE_CACHE_EXPIRATION_MS |
| 211 | ) { |
| 212 | return |
| 213 | } |
| 214 | saveGlobalConfig(current => ({ |
| 215 | ...current, |
| 216 | groveConfigCache: { |
| 217 | ...current.groveConfigCache, |
| 218 | [accountId]: { |
| 219 | grove_enabled: groveEnabled, |
| 220 | timestamp: Date.now(), |
| 221 | }, |
| 222 | }, |
| 223 | })) |
| 224 | } catch (err) { |
| 225 | logForDebugging(`Grove: Failed to fetch and store config: ${err}`) |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | /** |
| 230 | * Get Grove Statsig configuration from the API. |
no test coverage detected