Skip to content

front: pass ?preview=all through API calls#21

Merged
simonmorley merged 1 commit into
mainfrom
gate-tia-preview
Apr 24, 2026
Merged

front: pass ?preview=all through API calls#21
simonmorley merged 1 commit into
mainfrom
gate-tia-preview

Conversation

@simonmorley
Copy link
Copy Markdown
Member

Frontend side of TIA drip-feed gating. Reads ?preview=all from the current URL and forwards it on outbound API requests.

Implementation

New previewParam() helper in src/api/client.ts:

  • Reads window.location.search live (per request — SPA navigation flips visibility immediately)
  • Returns 'all' iff the URL has ?preview=all, else null
  • SSR-safe (typeof window check)

fetchEvents, fetchNetworks, fetchStats now include the param when present.

Depends on

slasher-infra/18 + slasher-api PR. Merge order: infra → api → front.

Test plan

  • npm run build — zero TS errors
  • Post-merge: slashr.dev shows 5 networks (no celestia), slashr.dev/?preview=all shows 6

New previewParam() helper in src/api/client.ts reads
window.location.search live per request and returns 'all' iff the
URL has ?preview=all. Not cached — SPA navigation to/from the
preview URL flips visibility immediately. SSR-safe via typeof
window check.

fetchEvents, fetchNetworks, fetchStats now include ?preview=all in
their outbound requests when the caller's URL carries it. Other
endpoints (validator profile, leaderboard, insights) are reachable
directly and don't list gated networks; leaving them unmodified
keeps the PR tight.

No new frontend state. No route changes. Users hitting the site
without the query param see exactly what they saw before (five
networks post-Celestia-gating). Internal users with ?preview=all
see all enabled networks.
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a previewParam helper to support gated networks by appending a preview query parameter to API requests in fetchEvents, fetchNetworks, and fetchStats. The review feedback highlights that this parameter should be applied to all relevant API functions for full coverage and notes that React hooks need to be updated to trigger re-fetches upon URL changes. Furthermore, using URLSearchParams is recommended for consistency and better maintainability compared to manual string concatenation.

Comment thread src/api/client.ts
Comment on lines +39 to +43
function previewParam(): string | null {
if (typeof window === 'undefined') return null;
const p = new URLSearchParams(window.location.search).get('preview');
return p === 'all' ? 'all' : null;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The previewParam helper is a good addition for handling gated content, but there are two significant issues with the current implementation:

  1. Incomplete Coverage: This parameter is only being passed in fetchEvents, fetchNetworks, and fetchStats. However, many other functions in this file (such as fetchValidator, fetchLeaderboard, fetchChainData, fetchDelegations, and fetchHealthCheck) likely also need to support this parameter to ensure that gated networks are visible and functional across all views (e.g., when viewing a specific validator's profile on a gated network).
  2. SPA Navigation & React Hooks: The PR description states that visibility flips "immediately" during SPA navigation. While the API client reads the URL live, the corresponding hooks (like useNetworks and useStats in src/hooks/) do not include the URL search parameters in their dependency arrays. Consequently, navigating to or from a ?preview=all URL within the SPA will not trigger a re-fetch, and the UI will not update until a manual refresh or a different state change occurs.

Consider applying this parameter to all relevant API calls and updating the hooks to react to URL search parameter changes.

Comment thread src/api/client.ts
Comment on lines +69 to +71
const pv = previewParam();
const suffix = pv ? `?preview=${pv}` : '';
const res = await fetch(`${BASE_URL}/v1/networks${suffix}`);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

For better maintainability and consistency with the approach used in fetchEvents, consider using URLSearchParams to construct the query string instead of manual string concatenation.

Suggested change
const pv = previewParam();
const suffix = pv ? `?preview=${pv}` : '';
const res = await fetch(`${BASE_URL}/v1/networks${suffix}`);
const qs = new URLSearchParams();
const pv = previewParam();
if (pv) qs.set('preview', pv);
const query = qs.toString();
const res = await fetch(`${BASE_URL}/v1/networks${query ? `?${query}` : ''}`);

Comment thread src/api/client.ts
Comment on lines +79 to +81
const pv = previewParam();
const suffix = pv ? `?preview=${pv}` : '';
const res = await fetch(`${BASE_URL}/v1/stats${suffix}`);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

For better maintainability and consistency with the approach used in fetchEvents, consider using URLSearchParams to construct the query string instead of manual string concatenation.

Suggested change
const pv = previewParam();
const suffix = pv ? `?preview=${pv}` : '';
const res = await fetch(`${BASE_URL}/v1/stats${suffix}`);
const qs = new URLSearchParams();
const pv = previewParam();
if (pv) qs.set('preview', pv);
const query = qs.toString();
const res = await fetch(`${BASE_URL}/v1/stats${query ? `?${query}` : ''}`);

@simonmorley simonmorley merged commit a9f88b8 into main Apr 24, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant