Skip to content

Commit 87ebf5e

Browse files
committed
mwa connect
1 parent 2d70c17 commit 87ebf5e

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

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

+16-5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ export interface AntDesignWeb3ConfigProviderProps {
3131
onCurrentChainChange?: (chain?: SolanaChainConfig) => void;
3232
}
3333

34+
const MWA_WALLET_NAME = 'Mobile Wallet Adapter';
35+
3436
export const AntDesignWeb3ConfigProvider: React.FC<
3537
React.PropsWithChildren<AntDesignWeb3ConfigProviderProps>
3638
> = (props) => {
@@ -99,13 +101,16 @@ export const AntDesignWeb3ConfigProvider: React.FC<
99101
getBalance();
100102
}, [connection, publicKey, props.balance]);
101103

104+
console.log('__wallet__:', wallet?.adapter.name);
105+
102106
// connect/disconnect wallet
103107
useEffect(() => {
104108
// 初始化时跳过,避免与 wallet-adapter 的自动连接逻辑冲突
105109
if (!mountRef.current) {
106110
return;
107111
}
108112

113+
console.log('wallet:', wallet?.adapter?.name, connected, wallet?.adapter);
109114
if (wallet?.adapter?.name) {
110115
// if wallet is not ready, need clear selected wallet
111116
if (!hasWalletReady(wallet.adapter.readyState)) {
@@ -177,13 +182,14 @@ export const AntDesignWeb3ConfigProvider: React.FC<
177182

178183
const providedWalletNames = providedWallets.map((w) => w.name);
179184

185+
// standard wallets
180186
const autoRegisteredWallets = wallets
181187
.filter((w) => !providedWalletNames.includes(w.adapter.name))
182188
.map<Wallet>((w) => {
183189
const adapter = w.adapter;
184190

185-
// Mobile Wallet Adapter is a special case, it's always ready
186-
if (adapter.name === 'Mobile Wallet Adapter') {
191+
// MWA is a special case, it's always ready
192+
if (adapter.name === MWA_WALLET_NAME) {
187193
return {
188194
name: adapter.name,
189195
icon: adapter.icon,
@@ -192,9 +198,9 @@ export const AntDesignWeb3ConfigProvider: React.FC<
192198

193199
hasCustomHandler: () => {},
194200

195-
// hasExtensionInstalled: async () => {
196-
// return true;
197-
// },
201+
hasExtensionInstalled: async () => {
202+
return true;
203+
},
198204
hasWalletReady: async () => {
199205
// return hasWalletReady(adapter.readyState);
200206
return true;
@@ -251,6 +257,11 @@ export const AntDesignWeb3ConfigProvider: React.FC<
251257
}}
252258
connect={async (_wallet, options) => {
253259
console.log('connect_wallet:', _wallet, options);
260+
if (_wallet?.name === MWA_WALLET_NAME) {
261+
_wallet._standardWallet?.connect();
262+
return;
263+
}
264+
254265
let resolve: any;
255266
let reject: any;
256267

0 commit comments

Comments
 (0)