Skip to content

Commit a4a638a

Browse files
committed
fix(solana): Some wallets cannot connect again
1 parent b5532ab commit a4a638a

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

.changeset/hip-vans-laugh.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@ant-design/web3-solana': patch
3+
---
4+
5+
fix(solana): Some wallets cannot connect again

packages/solana/src/solana-provider/config-provider.tsx

+13-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ export interface AntDesignWeb3ConfigProviderProps {
3434
export const AntDesignWeb3ConfigProvider: React.FC<
3535
React.PropsWithChildren<AntDesignWeb3ConfigProviderProps>
3636
> = (props) => {
37+
const mountRef = useRef(false);
38+
3739
const {
3840
publicKey,
3941
connected,
@@ -45,7 +47,6 @@ export const AntDesignWeb3ConfigProvider: React.FC<
4547
} = useWallet();
4648

4749
const { connection } = useConnection();
48-
4950
const connectAsyncRef = useRef<ConnectAsync>();
5051

5152
const [balanceData, setBalanceData] = useState<bigint>();
@@ -98,6 +99,11 @@ export const AntDesignWeb3ConfigProvider: React.FC<
9899

99100
// connect/disconnect wallet
100101
useEffect(() => {
102+
// 初始化时跳过,避免与 WalletProvider 的自动连接逻辑冲突
103+
if (!mountRef.current) {
104+
return;
105+
}
106+
101107
if (wallet?.adapter?.name) {
102108
// if wallet is not ready, need clear selected wallet
103109
if (!hasWalletReady(wallet.adapter.readyState)) {
@@ -113,6 +119,12 @@ export const AntDesignWeb3ConfigProvider: React.FC<
113119
}
114120
}, [wallet?.adapter?.name, connected]);
115121

122+
useEffect(() => {
123+
if (!mountRef.current) {
124+
mountRef.current = true;
125+
}
126+
}, []);
127+
116128
const chainList = useMemo(() => {
117129
return props.availableChains
118130
.map((item) => {

0 commit comments

Comments
 (0)