From 85d6074e92379a38275d6844a294212c55730f17 Mon Sep 17 00:00:00 2001 From: MananTank Date: Tue, 9 Sep 2025 19:13:00 +0000 Subject: [PATCH] [BLD-277] Fix Server Wallets balance fetching for custom chains (#8026) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ## PR-Codex overview This PR focuses on refactoring the code to utilize a new hook, `useGetV5DashboardChain`, which replaces the previous `defineChain` function in multiple files. This change enhances the code's readability and maintainability by standardizing the method of retrieving chain information. ### Detailed summary - Replaced `defineChain` with `useGetV5DashboardChain` in `useAbiProcessing.ts`. - Updated the `chain` variable initialization in `ServerWalletTableRow` to use `useV5DashboardChain`. - Modified the `chain` parameter in `WalletBalanceCell` to utilize `useV5DashboardChain` instead of `defineChain`. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` ## Summary by CodeRabbit * **Refactor** * Unified chain handling across wallet tables and webhook ABI processing using a new dashboard adapter, improving consistency and reliability. * Streamlined balance and smart account address resolution to reduce redundant computations and potential mismatches. * Internal imports and hooks updated without changing public interfaces or user workflows. --- .../wallet-table/wallet-table-ui.client.tsx | 14 ++++++-------- .../(sidebar)/webhooks/hooks/useAbiProcessing.ts | 6 +++--- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/(sidebar)/transactions/server-wallets/wallet-table/wallet-table-ui.client.tsx b/apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/(sidebar)/transactions/server-wallets/wallet-table/wallet-table-ui.client.tsx index 59baf6adec1..c778d8ed948 100644 --- a/apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/(sidebar)/transactions/server-wallets/wallet-table/wallet-table-ui.client.tsx +++ b/apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/(sidebar)/transactions/server-wallets/wallet-table/wallet-table-ui.client.tsx @@ -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, @@ -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"; @@ -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); const smartAccountAddressQuery = useQuery({ queryFn: async () => { @@ -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, }); diff --git a/apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/(sidebar)/webhooks/hooks/useAbiProcessing.ts b/apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/(sidebar)/webhooks/hooks/useAbiProcessing.ts index b7d89931d2e..48ed9a20336 100644 --- a/apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/(sidebar)/webhooks/hooks/useAbiProcessing.ts +++ b/apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/(sidebar)/webhooks/hooks/useAbiProcessing.ts @@ -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, @@ -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(); @@ -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,