Skip to content

Commit 414d4b0

Browse files
feat: Added the ability to enable experimental features via a URL parameter. (#42)
* feat: Added the ability to enable experimental (Arbitrum Sepolia) features via a URL parameter. * refactor: add isExperimental value on chain object for better readability * refactor: replace SUPPORTED_CHAIN_IDS with a local variable for improved clarity in UnsupportedChain component
1 parent 070a2a1 commit 414d4b0

File tree

7 files changed

+70
-13
lines changed

7 files changed

+70
-13
lines changed

package-lock.json

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"tailwind-merge": "^3.2.0",
5454
"tailwindcss": "^4.1.3",
5555
"tw-animate-css": "^1.2.5",
56+
"use-local-storage-state": "^19.5.0",
5657
"viem": "^2.28.0",
5758
"wagmi": "^2.15.0",
5859
"zustand": "^5.0.3"

src/components/UnsupportedChain.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
import { SUPPORTED_CHAINS } from '@/config';
21
import { AlertOctagon } from 'lucide-react';
32
import { useAccount } from 'wagmi';
3+
import { getSupportedChains } from '@/utils/chain.utils';
44
import { Alert, AlertDescription, AlertTitle } from './ui/alert';
55

6-
const SUPPORTED_CHAIN_IDS = SUPPORTED_CHAINS.map((chain) => chain.id);
7-
86
export function UnsupportedChain() {
97
const { isConnected, chainId } = useAccount();
8+
const supportedChainIds = getSupportedChains().map((chain) => chain.id);
109
const isChainSupported =
11-
chainId !== undefined && SUPPORTED_CHAIN_IDS.includes(chainId);
10+
chainId !== undefined && supportedChainIds.includes(chainId);
1211

1312
if (!isConnected || isChainSupported) {
1413
return null;

src/components/navbar/ChainSelector.tsx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
import { SUPPORTED_CHAINS } from '@/config.ts';
1+
import { LOCAL_STORAGE_PREFIX } from '@/config.ts';
2+
import { useSearch } from '@tanstack/react-router';
3+
import { useEffect } from 'react';
4+
import useLocalStorageState from 'use-local-storage-state';
25
import { useChainSwitch } from '@/hooks/useChainSwitch.ts';
36
import useUserStore from '@/stores/useUser.store.ts';
7+
import { getSupportedChains } from '@/utils/chain.utils.ts';
48
import {
59
Select,
610
SelectContent,
@@ -12,6 +16,19 @@ import {
1216
export function ChainSelector({ className }: { className?: string }) {
1317
const { chainId } = useUserStore();
1418
const { requestChainChange } = useChainSwitch();
19+
const search = useSearch({ strict: false });
20+
const [, setExperimental] = useLocalStorageState<boolean>(
21+
`${LOCAL_STORAGE_PREFIX}_experimental`,
22+
{ defaultValue: false }
23+
);
24+
25+
useEffect(() => {
26+
if (search?.feature === 'experimental') {
27+
setExperimental(true);
28+
}
29+
}, [search?.feature, setExperimental]);
30+
31+
const filteredChains = getSupportedChains();
1532

1633
const handleChainChange = async (value: string) => {
1734
requestChainChange(Number(value));
@@ -27,7 +44,7 @@ export function ChainSelector({ className }: { className?: string }) {
2744
<SelectValue placeholder="Select Chain" />
2845
</SelectTrigger>
2946
<SelectContent className={className}>
30-
{SUPPORTED_CHAINS.map((chain) => (
47+
{filteredChains.map((chain) => (
3148
<SelectItem
3249
key={chain.id}
3350
value={chain.id.toString()}

src/config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import arbitrumSepoliaIcon from './assets/chain-icons/arbitrum-sepolia.svg';
22
import iexecLogo from './assets/iexec-logo.svg';
33
import { bellecour, arbitrumSepolia } from './utils/wagmiNetworks';
44

5+
export const LOCAL_STORAGE_PREFIX = 'Explorer';
6+
57
export const PREVIEW_TABLE_LENGTH = 5;
68
export const DETAIL_TABLE_LENGTH = 8;
79
export const TABLE_LENGTH = 16;
@@ -37,5 +39,6 @@ export const SUPPORTED_CHAINS = [
3739
'https://thegraph.arbitrum-sepolia-testnet.iex.ec/api/subgraphs/id/2GCj8gzLCihsiEDq8cYvC5nUgK6VfwZ6hm3Wj8A3kcxz',
3840
wagmiNetwork: arbitrumSepolia,
3941
tokenSymbol: 'RLC',
42+
isExperimental: true,
4043
},
4144
];

src/routes/$chainSlug/_layout/index.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { SUPPORTED_CHAINS } from '@/config';
21
import { createFileRoute, useSearch } from '@tanstack/react-router';
32
import { AppsPreviewTable } from '@/modules/apps/AppsPreviewTable';
43
import { DatasetsPreviewTable } from '@/modules/datasets/DatasetsPreviewTable';
@@ -7,6 +6,7 @@ import { SearcherBar } from '@/modules/search/SearcherBar';
76
import { TasksPreviewTable } from '@/modules/tasks/TasksPreviewTable';
87
import { WorkerpoolsPreviewTable } from '@/modules/workerpools/WorkerpoolsPreviewTable';
98
import useUserStore from '@/stores/useUser.store';
9+
import { getSupportedChains } from '@/utils/chain.utils';
1010

1111
export const Route = createFileRoute('/$chainSlug/_layout/')({
1212
component: Index,
@@ -18,7 +18,9 @@ function Index() {
1818

1919
const initialSearch = search?.search;
2020

21-
const currentChain = SUPPORTED_CHAINS.find((chain) => chain.id === chainId);
21+
const currentChain = getSupportedChains().find(
22+
(chain) => chain.id === chainId
23+
);
2224

2325
return (
2426
<div className="flex flex-col gap-10 pt-10 sm:mt-6 sm:gap-20 md:mt-10">

src/utils/chain.utils.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
1-
import { SUPPORTED_CHAINS } from '@/config';
1+
import { SUPPORTED_CHAINS, LOCAL_STORAGE_PREFIX } from '@/config';
2+
3+
function isExperimentalEnabled(): boolean {
4+
if (typeof window === 'undefined') return false;
5+
try {
6+
return (
7+
localStorage.getItem(`${LOCAL_STORAGE_PREFIX}_experimental`) === 'true'
8+
);
9+
} catch {
10+
return false;
11+
}
12+
}
13+
14+
export function getSupportedChains() {
15+
const experimental = isExperimentalEnabled();
16+
return SUPPORTED_CHAINS.filter(
17+
(chain) => !chain.isExperimental || experimental
18+
);
19+
}
220

321
export function getSubgraphUrl(chainId: number) {
4-
const subgraphUrl = SUPPORTED_CHAINS.find(
22+
const subgraphUrl = getSupportedChains().find(
523
(chain) => chain.id === chainId
624
)?.subgraphUrl;
725
if (!subgraphUrl) {
@@ -11,11 +29,11 @@ export function getSubgraphUrl(chainId: number) {
1129
}
1230

1331
export function getChainFromSlug(slug: string | undefined) {
14-
return SUPPORTED_CHAINS.find((c) => c.slug === slug);
32+
return getSupportedChains().find((c) => c.slug === slug);
1533
}
1634

1735
export function getChainFromId(id: number | undefined) {
18-
return SUPPORTED_CHAINS.find((c) => c.id === id);
36+
return getSupportedChains().find((c) => c.id === id);
1937
}
2038

2139
export function getBlockExplorerUrl(chainId: number) {
@@ -28,4 +46,4 @@ export function getBlockExplorerUrl(chainId: number) {
2846
*/
2947
export const INITIAL_CHAIN =
3048
getChainFromSlug(new URL(window.location.href).pathname.split('/')[1]) ||
31-
SUPPORTED_CHAINS[0];
49+
getSupportedChains()[0];

0 commit comments

Comments
 (0)