diff --git a/components/AddressBar.tsx b/components/AddressBar.tsx index 4f8912b..feb0fa0 100644 --- a/components/AddressBar.tsx +++ b/components/AddressBar.tsx @@ -1,19 +1,30 @@ "use client"; -import { useDisconnect } from "@starknet-react/core"; +import { useDisconnect, useNetwork } from "@starknet-react/core"; import React, { useMemo, useState } from "react"; import ClickOutsideWrapper from "./outsideClick"; import { Copy, LogOut, SquareArrowUpRight, Check } from "lucide-react"; +import { useTokenBalance } from "@/hooks/useTokenBalance"; +import { getNetworkInfo } from "@/utils/networkUtils"; function AddressBar({ address }: { address: string }) { const { disconnect } = useDisconnect(); + const { chain } = useNetwork(); const [showDisconnect, setShowDisconnect] = useState(false); const [copied, setCopied] = useState(false); + const { formattedBalance, isLoading: balanceLoading, isError: balanceError, isAccountDeployed } = useTokenBalance(); + const shortenedAddress = useMemo( () => (address ? `${address.slice(0, 6)}...${address.slice(-4)}` : ""), [address] ); + + const { isMainnet, isTestnet, networkName: currentNetworkName, explorerUrl } = useMemo( + () => getNetworkInfo(chain?.id, address), + [chain?.id, address] + ); + const handleCopy = async () => { try { await navigator.clipboard.writeText(address); @@ -27,58 +38,87 @@ function AddressBar({ address }: { address: string }) { return ( <> {showDisconnect && ( setShowDisconnect(false)} - className="absolute top-[100%] right-[1rem] pl-4 pr-4 pt-4 pb-2 rounded bg-white w-[40%] z-10 shadow-lg" + className="absolute top-[100%] right-[1rem] pl-4 pr-4 pt-4 pb-2 rounded bg-white dark:bg-dark-surface w-[40%] z-10 shadow-lg dark:shadow-dark-border/20 border border-gray-200 dark:border-dark-border transition-colors duration-300" > -
-

+

+

Wallet

-
-
+
+

Connected

+ + {/* Network section */} +
+
+ + {currentNetworkName} + +
-
+
- {shortenedAddress} +
+ {shortenedAddress} + + {balanceLoading ? "Loading balance..." : + balanceError && isAccountDeployed === false ? `Not deployed on ${currentNetworkName.toLowerCase()}` : + balanceError ? "Balance unavailable" : `${formattedBalance} ETH`} + +
-
+ + {/* Account deployment info */} + {balanceError && isAccountDeployed === false && ( +
+

+ {currentNetworkName} Deployment Required: Your account needs to be deployed on {isMainnet ? 'Starknet mainnet' : 'Sepolia testnet'}. Make your first transaction on {currentNetworkName.toLowerCase()} to deploy the account here. +

+
+ )} +
View on explorer