11import { useThirdwebAuthConfig } from "../../contexts/thirdweb-auth" ;
2- import { useBalance } from "../../hooks/async/wallet" ;
32import { LoginConfig , useAuth } from "../../hooks/auth" ;
43import { useMetamask } from "../../hooks/connectors/useMetamask" ;
5- import { useAddress } from "../../hooks/useAddress" ;
6- import { useChainId } from "../../hooks/useChainId" ;
7- import { useConnect } from "../../hooks/useConnect" ;
8- import { useDisconnect } from "../../hooks/useDisconnect" ;
9- import { useNetwork } from "../../hooks/useNetwork" ;
4+ import { useConnect } from "../../hooks/wagmi-required/useConnect" ;
5+ import { useDisconnect } from "../../hooks/wagmi-required/useDisconnect" ;
6+ import { useNetwork } from "../../hooks/wagmi-required/useNetwork" ;
7+ import { useAddress , useBalance , useChainId } from "../../hooks/wallet" ;
108import { Portal } from "../../lib/portal" ;
119import { shortenIfAddress } from "../../utils/addresses" ;
1210import { useClipboard } from "../hooks/useCopyClipboard" ;
13- import { useIsMounted } from "../hooks/useIsMounted" ;
1411import { Box } from "../shared/Box" ;
1512import { Button } from "../shared/Button" ;
1613import { Icon } from "../shared/Icon" ;
@@ -30,8 +27,8 @@ import { FiXCircle } from "@react-icons/all-files/fi/FiXCircle";
3027import { ChainId , LoginOptions , SUPPORTED_CHAIN_ID } from "@thirdweb-dev/sdk" ;
3128import * as menu from "@zag-js/menu" ;
3229import { normalizeProps , useMachine } from "@zag-js/react" ;
33- import React , { useId , useMemo } from "react" ;
34- import { Connector } from "wagmi" ;
30+ import React , { useId } from "react" ;
31+ import type { Connector } from "wagmi" ;
3532
3633const SUPPORTED_CONNECTORS = [
3734 "injected" ,
@@ -65,6 +62,7 @@ interface ConnectWalletProps extends ThemeProviderProps {
6562 loginConfig ?: LoginConfig ;
6663 loginOptional ?: boolean ;
6764 } ;
65+ className ?: string ;
6866}
6967
7068let connecting = false ;
@@ -124,15 +122,12 @@ const chainIdToCurrencyMap: Record<
124122 */
125123export const ConnectWallet : React . FC < ConnectWalletProps > = ( {
126124 auth,
125+ className,
127126 ...themeProps
128127} ) => {
129128 const id = useId ( ) ;
130- const isMounted = useIsMounted ( ) ;
131- const address = useAddress ( ) ;
132129
133- const mountedAddress = useMemo ( ( ) => {
134- return isMounted ? address : null ;
135- } , [ address , isMounted ] ) ;
130+ const walletAddress = useAddress ( ) ;
136131
137132 const [ state , send ] = useMachine (
138133 menu . machine ( {
@@ -165,24 +160,26 @@ export const ConnectWallet: React.FC<ConnectWalletProps> = ({
165160
166161 const balanceQuery = useBalance ( ) ;
167162
168- const { onCopy, hasCopied } = useClipboard ( mountedAddress || "" ) ;
163+ const { onCopy, hasCopied } = useClipboard ( walletAddress || "" ) ;
169164
170165 const authConfig = useThirdwebAuthConfig ( ) ;
171166 const { user, isLoading, login, logout } = useAuth ( auth ?. loginConfig ) ;
172167
173168 const requiresSignIn = auth ?. loginOptional
174169 ? false
175- : ! ! authConfig ?. authUrl && ! ! mountedAddress && ! user ?. address ;
170+ : ! ! authConfig ?. authUrl && ! ! walletAddress && ! user ?. address ;
176171
177172 return (
178173 < ThemeProvider { ...themeProps } >
179174 < div
180175 style = { {
181176 position : "relative" ,
177+ width : "100%" ,
182178 } }
183179 >
184180 < Button
185- style = { { height : "50px" , minWidth : "200px" } }
181+ className = { className }
182+ style = { { height : "50px" , minWidth : "200px" , width : "100%" } }
186183 onClick = { async ( e ) => {
187184 if ( requiresSignIn ) {
188185 e . preventDefault ( ) ;
@@ -204,7 +201,7 @@ export const ConnectWallet: React.FC<ConnectWalletProps> = ({
204201 ) : (
205202 < FiLock />
206203 )
207- ) : mountedAddress && chainId && chainId in chainIdToCurrencyMap ? (
204+ ) : walletAddress && chainId && chainId in chainIdToCurrencyMap ? (
208205 < Icon
209206 boxSize = "1.5em"
210207 name = { chainIdToCurrencyMap [ chainId as SUPPORTED_CHAIN_ID ] }
@@ -225,7 +222,7 @@ export const ConnectWallet: React.FC<ConnectWalletProps> = ({
225222 )
226223 }
227224 >
228- { mountedAddress ? (
225+ { walletAddress ? (
229226 requiresSignIn ? (
230227 < span style = { { whiteSpace : "nowrap" } } > Sign in</ span >
231228 ) : (
@@ -249,7 +246,7 @@ export const ConnectWallet: React.FC<ConnectWalletProps> = ({
249246 ) }
250247 </ span >
251248 < span style = { { fontSize : "0.9em" } } >
252- { shortenIfAddress ( mountedAddress ) }
249+ { shortenIfAddress ( walletAddress ) }
253250 </ span >
254251 </ span >
255252 )
@@ -267,7 +264,7 @@ export const ConnectWallet: React.FC<ConnectWalletProps> = ({
267264 } }
268265 >
269266 < Menu { ...api . contentProps } >
270- { ! api . isOpen ? null : mountedAddress ? (
267+ { ! api . isOpen ? null : walletAddress ? (
271268 < >
272269 { authConfig ?. authUrl && ! user ?. address && ! requiresSignIn ? (
273270 < MenuItem
@@ -396,10 +393,13 @@ export const ConnectWallet: React.FC<ConnectWalletProps> = ({
396393 } ) }
397394 onClick = { async ( ) => {
398395 if ( ! connecting ) {
399- connecting = true ;
400- await connectWithMetamask ( ) ;
401- connecting = false ;
402- api . close ( ) ;
396+ try {
397+ connecting = true ;
398+ await connectWithMetamask ( ) ;
399+ api . close ( ) ;
400+ } finally {
401+ connecting = false ;
402+ }
403403 }
404404 } }
405405 leftElement = { < Icon boxSize = "1.5em" name = "metamask" /> }
@@ -421,10 +421,13 @@ export const ConnectWallet: React.FC<ConnectWalletProps> = ({
421421 } ) }
422422 onClick = { async ( ) => {
423423 if ( ! connecting ) {
424- connecting = true ;
425- await connect ( c ) ;
426- connecting = false ;
427- api . close ( ) ;
424+ try {
425+ connecting = true ;
426+ await connect ( c ) ;
427+ api . close ( ) ;
428+ } finally {
429+ connecting = false ;
430+ }
428431 }
429432 } }
430433 leftElement = { getIconForConnector ( c ) }
0 commit comments