Skip to content

Commit

Permalink
fix(solana): Some wallets cannot connect again
Browse files Browse the repository at this point in the history
  • Loading branch information
gin-lsl committed Jan 24, 2025
1 parent b5532ab commit a4a638a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/hip-vans-laugh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@ant-design/web3-solana': patch
---

fix(solana): Some wallets cannot connect again
14 changes: 13 additions & 1 deletion packages/solana/src/solana-provider/config-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export interface AntDesignWeb3ConfigProviderProps {
export const AntDesignWeb3ConfigProvider: React.FC<
React.PropsWithChildren<AntDesignWeb3ConfigProviderProps>
> = (props) => {
const mountRef = useRef(false);

const {
publicKey,
connected,
Expand All @@ -45,7 +47,6 @@ export const AntDesignWeb3ConfigProvider: React.FC<
} = useWallet();

const { connection } = useConnection();

const connectAsyncRef = useRef<ConnectAsync>();

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

// connect/disconnect wallet
useEffect(() => {
// 初始化时跳过,避免与 WalletProvider 的自动连接逻辑冲突
if (!mountRef.current) {
return;
}

if (wallet?.adapter?.name) {
// if wallet is not ready, need clear selected wallet
if (!hasWalletReady(wallet.adapter.readyState)) {
Expand All @@ -113,6 +119,12 @@ export const AntDesignWeb3ConfigProvider: React.FC<
}
}, [wallet?.adapter?.name, connected]);

useEffect(() => {
if (!mountRef.current) {
mountRef.current = true;
}
}, []);

const chainList = useMemo(() => {
return props.availableChains
.map((item) => {
Expand Down

0 comments on commit a4a638a

Please sign in to comment.