From 73c722cfb589fd7b805cfffa8302b927139c7a50 Mon Sep 17 00:00:00 2001 From: secretmemelocker Date: Sun, 18 Jan 2026 09:59:15 -0600 Subject: [PATCH 1/4] Fix explorer linking --- src/components/shared/account-actions-popover.tsx | 7 ++++--- src/components/shared/account-identity.tsx | 8 ++++---- src/features/market-detail/market-view.tsx | 12 +++++++++--- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/components/shared/account-actions-popover.tsx b/src/components/shared/account-actions-popover.tsx index 3e7fe38c..4a9c1af0 100644 --- a/src/components/shared/account-actions-popover.tsx +++ b/src/components/shared/account-actions-popover.tsx @@ -11,7 +11,8 @@ import type { Address } from 'viem'; type AccountActionsPopoverProps = { address: Address; - children: ReactNode; + children?: ReactNode; + chainId?: number; }; /** @@ -20,7 +21,7 @@ type AccountActionsPopoverProps = { * - View account (positions page) * - View on Etherscan */ -export function AccountActionsPopover({ address, children }: AccountActionsPopoverProps) { +export function AccountActionsPopover({ address, chainId, children }: AccountActionsPopoverProps) { const toast = useStyledToast(); const handleCopy = useCallback(async () => { @@ -37,7 +38,7 @@ export function AccountActionsPopover({ address, children }: AccountActionsPopov }, [address]); const handleViewExplorer = useCallback(() => { - const explorerUrl = getExplorerURL(address, SupportedNetworks.Mainnet); + const explorerUrl = getExplorerURL(address, (chainId ?? SupportedNetworks.Mainnet) as SupportedNetworks); window.open(explorerUrl, '_blank', 'noopener,noreferrer'); }, [address]); diff --git a/src/components/shared/account-identity.tsx b/src/components/shared/account-identity.tsx index 24085549..e20fdac9 100644 --- a/src/components/shared/account-identity.tsx +++ b/src/components/shared/account-identity.tsx @@ -49,7 +49,7 @@ export function AccountIdentity({ showActions = true, className, }: AccountIdentityProps) { - const { address: connectedAddress, isConnected } = useConnection(); + const { address: connectedAddress, isConnected, chainId } = useConnection(); const [mounted, setMounted] = useState(false); const toast = useStyledToast(); const { vaultName, shortAddress } = useAddressLabel(address); @@ -152,7 +152,7 @@ export function AccountIdentity({ ); if (showActions) { - return {badgeElement}; + return {badgeElement}; } return badgeElement; @@ -228,7 +228,7 @@ export function AccountIdentity({ ); if (showActions) { - return {compactElement}; + return {compactElement}; } return compactElement; @@ -327,7 +327,7 @@ export function AccountIdentity({ ); if (showActions) { - return {fullElement}; + return {fullElement}; } return fullElement; diff --git a/src/features/market-detail/market-view.tsx b/src/features/market-detail/market-view.tsx index 8e6964e1..76c27405 100644 --- a/src/features/market-detail/market-view.tsx +++ b/src/features/market-detail/market-view.tsx @@ -2,10 +2,10 @@ 'use client'; -import { useState, useCallback, useMemo } from 'react'; +import { useState, useCallback, useMemo, useEffect } from 'react'; import { useParams } from 'next/navigation'; import { parseUnits, formatUnits, type Address, encodeFunctionData } from 'viem'; -import { useConnection, useSwitchChain } from 'wagmi'; +import { useAccount, useConnection, useSwitchChain } from 'wagmi'; import morphoAbi from '@/abis/morpho'; import { BorrowModal } from '@/modals/borrow/borrow-modal'; import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'; @@ -77,6 +77,7 @@ function MarketContent() { }); const { address } = useConnection(); + const { chain } = useAccount(); const { position: userPosition, refetch: refetchUserPosition } = useUserPosition(address, network, marketId as string); @@ -100,6 +101,12 @@ function MarketContent() { const { mutateAsync: switchChainAsync } = useSwitchChain(); + useEffect(() => { + if (market?.morphoBlue.chain.id && chain?.id !== market.morphoBlue.chain.id) { + void switchChainAsync({ chainId: market.morphoBlue.chain.id }); + } + }, [market?.morphoBlue.chain.id, chain?.id, switchChainAsync]); + // Transaction hook for accruing interest const { sendTransaction } = useTransactionWithToast({ toastId: 'accrue-interest', @@ -266,7 +273,6 @@ function MarketContent() { }; const handleAccrueInterest = async () => { - await switchChainAsync({ chainId: market.morphoBlue.chain.id }); const morphoAddress = market.morphoBlue.address as Address; sendTransaction({ From ea24efa763bd0ace9ce355a14d193271d139fec6 Mon Sep 17 00:00:00 2001 From: secretmemelocker Date: Sun, 18 Jan 2026 10:21:19 -0600 Subject: [PATCH 2/4] Do not switch chain aggressively on market-view. --- src/components/layout/header/AccountDropdown.tsx | 2 ++ src/components/shared/account-identity.tsx | 6 ++++-- src/components/shared/allocator-card.tsx | 4 ++++ src/components/ui/badge.tsx | 2 +- src/components/ui/tooltip.tsx | 2 +- src/features/admin/components/transaction-table-body.tsx | 1 + .../components/vault-detail/settings/AgentListItem.tsx | 5 ++++- .../components/vault-detail/settings/AgentsTab.tsx | 5 +++++ src/features/market-detail/components/borrowers-table.tsx | 1 + src/features/market-detail/components/borrows-table.tsx | 1 + .../market-detail/components/liquidations-table.tsx | 1 + src/features/market-detail/components/suppliers-table.tsx | 1 + src/features/market-detail/components/supplies-table.tsx | 1 + src/features/market-detail/market-view.tsx | 7 +------ src/features/positions/positions-view.tsx | 4 ++++ src/features/rewards/rewards-view.tsx | 1 + 16 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/components/layout/header/AccountDropdown.tsx b/src/components/layout/header/AccountDropdown.tsx index 14a1e73e..4decda63 100644 --- a/src/components/layout/header/AccountDropdown.tsx +++ b/src/components/layout/header/AccountDropdown.tsx @@ -11,6 +11,7 @@ import { AccountIdentity } from '@/components/shared/account-identity'; import { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem } from '@/components/ui/dropdown-menu'; import { useStyledToast } from '@/hooks/useStyledToast'; import { getExplorerURL } from '@/utils/external'; +import { SupportedNetworks } from '@/utils/networks'; export function AccountDropdown() { const { address, chainId } = useConnection(); @@ -61,6 +62,7 @@ export function AccountDropdown() { /> diff --git a/src/components/shared/account-identity.tsx b/src/components/shared/account-identity.tsx index e20fdac9..92343081 100644 --- a/src/components/shared/account-identity.tsx +++ b/src/components/shared/account-identity.tsx @@ -19,6 +19,7 @@ import type { Address } from 'viem'; type AccountIdentityProps = { address: Address; + chainId: number; variant?: 'badge' | 'compact' | 'full'; linkTo?: 'explorer' | 'profile' | 'none'; copyable?: boolean; @@ -41,6 +42,7 @@ type AccountIdentityProps = { */ export function AccountIdentity({ address, + chainId, variant = 'badge', linkTo = 'none', copyable = false, @@ -49,7 +51,7 @@ export function AccountIdentity({ showActions = true, className, }: AccountIdentityProps) { - const { address: connectedAddress, isConnected, chainId } = useConnection(); + const { address: connectedAddress, isConnected} = useConnection(); const [mounted, setMounted] = useState(false); const toast = useStyledToast(); const { vaultName, shortAddress } = useAddressLabel(address); @@ -72,7 +74,7 @@ export function AccountIdentity({ if (linkTo === 'none') return null; if (linkTo === 'explorer') { - return getExplorerURL(address as `0x${string}`, SupportedNetworks.Mainnet); + return getExplorerURL(address as `0x${string}`, chainId ?? SupportedNetworks.Mainnet); } if (linkTo === 'profile') { return `/positions/${address}`; diff --git a/src/components/shared/allocator-card.tsx b/src/components/shared/allocator-card.tsx index e41add68..8cbc91f2 100644 --- a/src/components/shared/allocator-card.tsx +++ b/src/components/shared/allocator-card.tsx @@ -1,5 +1,7 @@ import type { Address } from 'viem'; import { AccountIdentity } from './account-identity'; +import { useConnection } from 'wagmi'; +import { SupportedNetworks } from '@/utils/networks'; type AllocatorCardProps = { name: string; @@ -18,6 +20,7 @@ export function AllocatorCard({ onSelect, disabled = false, }: AllocatorCardProps): JSX.Element { + const { chainId } = useConnection(); return (