Files
assetx/webapp/hooks/useWalletStatus.ts

36 lines
759 B
TypeScript
Raw Normal View History

import { useAccount, useChainId } from 'wagmi'
import { useEffect, useState } from 'react'
/**
* Hook
*
*/
export function useWalletStatus() {
const { address, isConnected, isConnecting } = useAccount()
const chainId = useChainId()
const [mounted, setMounted] = useState(false)
useEffect(() => {
setMounted(true)
}, [])
// 在 SSR 期间或未 mounted 时返回安全的默认值
if (!mounted) {
return {
address: undefined,
isConnected: false,
isConnecting: false,
chainId: undefined,
mounted: false,
}
}
return {
address,
isConnected,
isConnecting,
chainId,
mounted: true,
}
}