Skip to content

Commit

Permalink
fix: fix runtime error when incorrect chainId is passed in search params
Browse files Browse the repository at this point in the history
  • Loading branch information
rkalis committed Dec 12, 2024
1 parent 45559b1 commit c8469ea
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions app/[locale]/address/[addressOrName]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import AllowanceDashboard from 'components/allowances/dashboard/AllowanceDashboard';
import { isNullish } from 'lib/utils';
import { getChainName } from 'lib/utils/chains';
import { getChainName, isSupportedChain } from 'lib/utils/chains';
import { shortenAddress } from 'lib/utils/formatting';
import { getAddressAndDomainName } from 'lib/utils/whois';
import type { Metadata, NextPage } from 'next';
Expand All @@ -25,7 +25,9 @@ export const generateMetadata = async ({
const { address, domainName } = await getAddressAndDomainName(addressOrName);
const addressDisplay = domainName ?? shortenAddress(address);

const chainName = getChainName(Number(searchParams.chainId || 1));
const chainIdFromSearchParams = Number(searchParams.chainId || 1);
const chainId = isSupportedChain(chainIdFromSearchParams) ? chainIdFromSearchParams : 1;
const chainName = getChainName(chainId);

const title = isNullish(searchParams.chainId)
? t('address.meta.title', { addressDisplay })
Expand Down
2 changes: 1 addition & 1 deletion lib/hooks/page-context/AddressPageContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const AddressPageContextProvider = ({ children, address, domainName, init
const queryChainId = Number.parseInt(searchParams.get('chainId') as string);
const defaultChainId = [initialChainId, queryChainId, chain?.id, 1]
.filter((chainId) => !isNullish(chainId))
.find((chainId) => isSupportedChain(chainId!)) as number;
.find((chainId) => isSupportedChain(chainId)) as number;
const [selectedChainId, selectChain] = useState<number>(defaultChainId);

// Note: We use useLayoutEffect here, because this is the only setup that works with the "spenderSearch" query param as well
Expand Down

0 comments on commit c8469ea

Please sign in to comment.