Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {
XIcon,
} from "lucide-react";
import Link from "next/link";
import { useMemo, useState } from "react";
import { defineChain, type ThirdwebClient } from "thirdweb";
import { useState } from "react";
import type { ThirdwebClient } from "thirdweb";
import { useWalletBalance } from "thirdweb/react";
import {
DEFAULT_ACCOUNT_FACTORY_V0_7,
Expand Down Expand Up @@ -48,6 +48,7 @@ import {
TableRow,
} from "@/components/ui/table";
import { ToolTipLabel } from "@/components/ui/tooltip";
import { useV5DashboardChain } from "@/hooks/chains/v5-adapter";
import { WalletProductIcon } from "@/icons/WalletProductIcon";
import { cn } from "@/lib/utils";
import CreateServerWallet from "../components/create-server-wallet.client";
Expand Down Expand Up @@ -277,10 +278,7 @@ function ServerWalletTableRow(props: {
const { wallet, project, teamSlug, client, chainId, showSmartAccount } =
props;

const chain = useMemo(() => {
// eslint-disable-next-line no-restricted-syntax
return defineChain(chainId);
}, [chainId]);
const chain = useV5DashboardChain(chainId);
Copy link
Contributor

Choose a reason for hiding this comment

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

Potential behavior change with useV5DashboardChain

The switch from defineChain(chainId) to useV5DashboardChain(chainId) may introduce different handling for invalid/unsupported chain IDs:

  • defineChain() would attempt to create a chain object even for unknown chains
  • useV5DashboardChain() might return null or undefined for unsupported chains

This could cause runtime errors in components that expect a valid chain object. Consider:

  1. Adding validation to handle potential null/undefined chain values
  2. Ensuring useV5DashboardChain has equivalent fallback behavior to defineChain
  3. Adding tests for edge cases with unsupported chain IDs

This is particularly important for the wallet balance functionality which depends on a valid chain object.

Suggested change
const chain = useV5DashboardChain(chainId);
const chain = useV5DashboardChain(chainId) ?? defineChain(chainId);

Spotted by Diamond

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.


const smartAccountAddressQuery = useQuery({
queryFn: async () => {
Expand Down Expand Up @@ -458,10 +456,10 @@ function WalletBalanceCell(props: {
chainId: number;
client: ThirdwebClient;
}) {
const chain = useV5DashboardChain(props.chainId);
const balance = useWalletBalance({
address: props.address,
// eslint-disable-next-line no-restricted-syntax
chain: defineChain(props.chainId),
chain: chain,
client: props.client,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import { useQuery } from "@tanstack/react-query";
import { useMemo } from "react";
import type { ThirdwebClient } from "thirdweb";
import { defineChain } from "thirdweb/chains";
import { getContract, resolveAbiFromContractApi } from "thirdweb/contract";
import { useGetV5DashboardChain } from "@/hooks/chains/v5-adapter";
import { parseAddresses } from "../utils/webhookPayloadUtils";
import type {
AbiData,
Expand All @@ -29,6 +29,7 @@ export function useAbiMultiFetch({
) => EventSignature[] | FunctionSignature[];
type: "event" | "transaction";
}) {
const getChain = useGetV5DashboardChain();
const pairs = useMemo(() => {
const result: { chainId: string; address: string }[] = [];
const seen = new Set<string>();
Expand All @@ -54,8 +55,7 @@ export function useAbiMultiFetch({
return Promise.all(
pairs.map(async ({ chainId, address }) => {
try {
// eslint-disable-next-line no-restricted-syntax
const chainObj = defineChain(Number(chainId));
const chainObj = getChain(Number(chainId));
const contract = getContract({
address,
chain: chainObj,
Expand Down
Loading