fix: improve mock data handling in IndeehubApiService
- Updated the getZapStats method to merge mock zap data when the API returns empty results or in development mode. - Introduced a new environment variable, VITE_HIDE_MOCK_ZAPS, to control the visibility of mock zaps in production. These changes ensure that the zap UI remains functional during development and improves the handling of scenarios with no available zap data.
This commit is contained in:
@@ -206,7 +206,8 @@ class IndeehubApiService {
|
||||
|
||||
/**
|
||||
* Get zap stats for film cards (count, amount, recent zapper pubkeys) by project id.
|
||||
* In dev, merges mock zap data for the first few projects so the UI is visible without real zaps.
|
||||
* In dev, or when API returns empty (e.g. no zaps in DB yet), merges mock data so the zap UI is visible.
|
||||
* Set VITE_HIDE_MOCK_ZAPS=true to never show mock zaps in production.
|
||||
*/
|
||||
async getZapStats(projectIds: string[]): Promise<Record<string, { zapCount: number; zapAmountSats: number; recentZapperPubkeys: string[] }>> {
|
||||
if (projectIds.length === 0) return {}
|
||||
@@ -221,7 +222,9 @@ class IndeehubApiService {
|
||||
} catch {
|
||||
data = {}
|
||||
}
|
||||
if (import.meta.env.DEV) {
|
||||
const hideMock = import.meta.env.VITE_HIDE_MOCK_ZAPS === 'true'
|
||||
const shouldMock = !hideMock && (import.meta.env.DEV || Object.keys(data).length === 0)
|
||||
if (shouldMock) {
|
||||
Object.assign(data, this.getMockZapStats(projectIds))
|
||||
}
|
||||
return data
|
||||
|
||||
Reference in New Issue
Block a user