Skip to content

Commit 2d70c17

Browse files
committed
feat: add custom wallet handler
1 parent 2170996 commit 2d70c17

File tree

4 files changed

+40
-12
lines changed

4 files changed

+40
-12
lines changed

packages/common/src/types.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export interface NFTMetadata {
102102
}
103103

104104
export interface ConnectOptions {
105-
connectType?: 'extension' | 'qrCode';
105+
connectType?: 'extension' | 'qrCode' | 'custom';
106106
}
107107

108108
export interface UniversalWeb3ProviderInterface {
@@ -137,6 +137,7 @@ export interface Wallet extends WalletMetadata {
137137
_standardWallet?: any;
138138
hasWalletReady?: () => Promise<boolean>;
139139
hasExtensionInstalled?: () => Promise<boolean>;
140+
hasCustomHandler?: () => boolean;
140141
getQrCode?: () => Promise<{ uri: string }>;
141142
customQrCodePanel?: boolean;
142143
}

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

+10-4
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ export const AntDesignWeb3ConfigProvider: React.FC<
4949
const { connection } = useConnection();
5050
const connectAsyncRef = useRef<ConnectAsync>();
5151

52+
console.log('wallets:', wallets);
53+
5254
const [balanceData, setBalanceData] = useState<bigint>();
5355
const [account, setAccount] = useState<Account>();
5456
const [currentWalletName, setCurrentWalletName] = useState(() => wallet?.adapter?.name ?? null);
@@ -188,11 +190,14 @@ export const AntDesignWeb3ConfigProvider: React.FC<
188190
remark: adapter.name,
189191
_standardWallet: adapter,
190192

191-
hasExtensionInstalled: async () => {
192-
return true;
193-
},
193+
hasCustomHandler: () => {},
194+
195+
// hasExtensionInstalled: async () => {
196+
// return true;
197+
// },
194198
hasWalletReady: async () => {
195-
return hasWalletReady(adapter.readyState);
199+
// return hasWalletReady(adapter.readyState);
200+
return true;
196201
},
197202
};
198203
}
@@ -245,6 +250,7 @@ export const AntDesignWeb3ConfigProvider: React.FC<
245250
selectWallet(currentWalletName);
246251
}}
247252
connect={async (_wallet, options) => {
253+
console.log('connect_wallet:', _wallet, options);
248254
let resolve: any;
249255
let reject: any;
250256

packages/web3/src/connect-modal/components/ModalPanel.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,13 @@ const ModalPanel: React.FC<ModalPanelProps> = (props) => {
6565
async (wallet?: Wallet, connectOptions?: ConnectOptions) => {
6666
setSelectedWallet(wallet);
6767
if (wallet && connectOptions) {
68+
console.log('wallet:', wallet, connectOptions);
6869
if (connectOptions.connectType === 'qrCode' && !wallet.customQrCodePanel) {
6970
updatePanelRoute('qrCode', true);
7071
} else if (connectOptions.connectType === 'extension') {
7172
updatePanelRoute('link', true);
73+
} else if (connectOptions.connectType === 'custom') {
74+
updatePanelRoute('link', true);
7275
} else {
7376
setPanelRoute('init');
7477
}
@@ -77,6 +80,7 @@ const ModalPanel: React.FC<ModalPanelProps> = (props) => {
7780
},
7881
[onWalletSelected],
7982
);
83+
8084
const panelRouteBack = React.useCallback(() => {
8185
routeStack.current.pop();
8286
const route = routeStack.current[routeStack.current.length - 1];

packages/web3/src/connect-modal/components/WalletList.tsx

+24-7
Original file line numberDiff line numberDiff line change
@@ -61,24 +61,41 @@ const WalletList: ForwardRefRenderFunction<ConnectModalActionType, WalletListPro
6161
};
6262

6363
const selectWallet = async (wallet: Wallet) => {
64+
console.log('selectWallet:', wallet);
6465
const hasWalletReady = await wallet.hasWalletReady?.();
6566
if (hasWalletReady) {
6667
// wallet is ready, call ConnectModal's onWalletSelected
6768
const hasExtensionInstalled = await wallet?.hasExtensionInstalled?.();
68-
if (hasExtensionInstalled) {
69+
70+
// first check if the wallet has custom handler
71+
if (wallet.hasCustomHandler) {
72+
wallet.hasCustomHandler();
73+
updateSelectedWallet(wallet, {
74+
connectType: 'custom',
75+
});
76+
}
77+
78+
// use extension to connect
79+
else if (hasExtensionInstalled) {
6980
updateSelectedWallet(wallet, {
7081
connectType: 'extension',
7182
});
72-
} else if (mobile()) {
73-
// open in universal link
83+
}
84+
85+
// open in universal link
86+
else if (mobile()) {
7487
openInUniversalLink(wallet);
75-
} else if (wallet.getQrCode) {
76-
// Extension not installed and can use qr code to connect
88+
}
89+
90+
// Extension not installed and can use qr code to connect
91+
else if (wallet.getQrCode) {
7792
updateSelectedWallet(wallet, {
7893
connectType: 'qrCode',
7994
});
80-
} else {
81-
// use the default connect
95+
}
96+
97+
// use the default connect
98+
else {
8299
updateSelectedWallet(wallet, {});
83100
}
84101
return;

0 commit comments

Comments
 (0)