Skip to content

Commit 2833091

Browse files
committed
feat: use chainSlug for chainId retrieval from URL in SearcherBar for better reactivity
1 parent 1ae5268 commit 2833091

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/modules/search/SearcherBar.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { execute } from '@/graphql/execute';
22
import { cn } from '@/lib/utils';
33
import { useMutation } from '@tanstack/react-query';
4-
import { useNavigate } from '@tanstack/react-router';
4+
import { useNavigate, useParams } from '@tanstack/react-router';
55
import { Search } from 'lucide-react';
66
import { useEffect, useRef, useState } from 'react';
77
import { ChainLink } from '@/components/ChainLink';
88
import { Button } from '@/components/ui/button';
99
import { Input } from '@/components/ui/input';
1010
import { getIExec, getReadonlyIExec } from '@/externals/iexecSdkClient';
1111
import useUserStore from '@/stores/useUser.store';
12-
import { getChainFromId } from '@/utils/chain.utils';
12+
import { getChainFromId, getChainFromSlug } from '@/utils/chain.utils';
1313
import { searchQuery } from './searchQuery';
1414

1515
export function SearcherBar({
@@ -19,13 +19,17 @@ export function SearcherBar({
1919
className?: string;
2020
initialSearch?: string;
2121
}) {
22-
const { isConnected, address: userAddress, chainId } = useUserStore();
22+
const { isConnected, address: userAddress } = useUserStore();
2323
const [inputValue, setInputValue] = useState('');
2424
const [shake, setShake] = useState(false);
2525
const [errorCount, setErrorCount] = useState(0);
2626
const [localError, setLocalError] = useState<Error | null>(null);
2727
const inputRef = useRef<HTMLInputElement | null>(null);
2828

29+
// Get ChainId from URL to be faster when using URL search
30+
const { chainSlug } = useParams({ from: '/$chainSlug' });
31+
const chainId = getChainFromSlug(chainSlug)?.id;
32+
2933
const navigate = useNavigate();
3034

3135
const navigateToEntity = (

0 commit comments

Comments
 (0)