diff --git a/app/hooks/useSmartWalletTransfer.ts b/app/hooks/useSmartWalletTransfer.ts index 8e3ffb92..92a4857d 100644 --- a/app/hooks/useSmartWalletTransfer.ts +++ b/app/hooks/useSmartWalletTransfer.ts @@ -77,6 +77,7 @@ export function useSmartWalletTransfer({ const [txHash, setTxHash] = useState(null); const [transferAmount, setTransferAmount] = useState(""); const [transferToken, setTransferToken] = useState(""); + const [txNetworkName, setTxNetworkName] = useState(""); // Helper to get the embedded wallet address (with address) for tx history const getEmbeddedWalletAddress = (): `0x${string}` | undefined => { @@ -107,6 +108,7 @@ export function useSmartWalletTransfer({ setIsSuccess(false); setError(""); setTxHash(null); + setTxNetworkName(""); setTransferAmount(""); setTransferToken(""); @@ -128,6 +130,7 @@ export function useSmartWalletTransfer({ if (!hash) throw new Error("No transaction hash returned"); const txhash = hash as unknown as string; setTxHash(txhash); + setTxNetworkName(selectedNetwork.chain.name); setTransferAmount(amount.toString()); setTransferToken(token); setIsSuccess(true); @@ -246,6 +249,7 @@ export function useSmartWalletTransfer({ if (!hash) throw new Error("No transaction hash returned"); setTxHash(hash); + setTxNetworkName(selectedNetwork.chain.name); setTransferAmount(amount.toString()); setTransferToken(token); @@ -359,9 +363,9 @@ export function useSmartWalletTransfer({ ); const getTxExplorerLink = useCallback((): string | undefined => { - if (!txHash) return undefined; - return getExplorerLink(selectedNetwork.chain.name, txHash) || undefined; - }, [txHash, selectedNetwork]); + if (!txHash || !txNetworkName) return undefined; + return getExplorerLink(txNetworkName, txHash) || undefined; + }, [txHash, txNetworkName]); return { isLoading, diff --git a/app/utils.ts b/app/utils.ts index 66622620..6268cc36 100644 --- a/app/utils.ts +++ b/app/utils.ts @@ -591,17 +591,14 @@ export function calculateCorrectedTotalBalance( export async function fetchBalanceForNetwork( network: { chain: any }, walletAddress: string, -): Promise<{ total: number; balances: Record }> { +): Promise<{ total: number; balances: Record; balancesInWei: Record }> { const { createPublicClient, http } = await import("viem"); - const { bsc } = await import("viem/chains"); + + const rpcUrl = getRpcUrl(network.chain.name); const publicClient = createPublicClient({ chain: network.chain, - transport: http( - network.chain.id === bsc.id - ? "https://bsc-dataseed.bnbchain.org/" - : undefined, - ), + transport: http(rpcUrl), }); return fetchWalletBalance(publicClient, walletAddress);