init: 初始化 AssetX 项目仓库
包含 webapp(Next.js 用户端)、webapp-back(Go 后端)、 antdesign(管理后台)、landingpage(营销落地页)、 数据库 SQL 和配置文件。
This commit is contained in:
35
webapp/hooks/useWalletStatus.ts
Normal file
35
webapp/hooks/useWalletStatus.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
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,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user