@aptos-labs/wallet-adapter-react 8.0.0-xchaininit2.0 → 8.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/WalletProvider.d.ts +1 -0
- package/dist/WalletProvider.d.ts.map +1 -1
- package/dist/components/WalletItem.d.ts.map +1 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +67 -27
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +68 -25
- package/dist/index.mjs.map +1 -1
- package/dist/useWallet.d.ts +1 -0
- package/dist/useWallet.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/WalletProvider.tsx +52 -17
- package/src/components/WalletItem.tsx +10 -5
- package/src/index.tsx +0 -2
- package/src/useWallet.tsx +1 -0
package/src/WalletProvider.tsx
CHANGED
|
@@ -26,6 +26,7 @@ import { WalletContext } from "./useWallet";
|
|
|
26
26
|
export interface AptosWalletProviderProps {
|
|
27
27
|
children: ReactNode;
|
|
28
28
|
optInWallets?: ReadonlyArray<AvailableWallets>;
|
|
29
|
+
hideWallets?: ReadonlyArray<AvailableWallets>;
|
|
29
30
|
autoConnect?:
|
|
30
31
|
| boolean
|
|
31
32
|
| ((core: WalletCore, adapter: AdapterWallet) => Promise<boolean>);
|
|
@@ -49,6 +50,7 @@ const initialState: {
|
|
|
49
50
|
export const AptosWalletAdapterProvider: FC<AptosWalletProviderProps> = ({
|
|
50
51
|
children,
|
|
51
52
|
optInWallets,
|
|
53
|
+
hideWallets,
|
|
52
54
|
autoConnect = false,
|
|
53
55
|
dappConfig,
|
|
54
56
|
disableTelemetry = false,
|
|
@@ -63,6 +65,9 @@ export const AptosWalletAdapterProvider: FC<AptosWalletProviderProps> = ({
|
|
|
63
65
|
const [walletCore, setWalletCore] = useState<WalletCore>();
|
|
64
66
|
|
|
65
67
|
const [wallets, setWallets] = useState<ReadonlyArray<AdapterWallet>>([]);
|
|
68
|
+
const [hiddenWallets, setHiddenWallets] = useState<
|
|
69
|
+
ReadonlyArray<AdapterWallet>
|
|
70
|
+
>([]);
|
|
66
71
|
const [notDetectedWallets, setNotDetectedWallets] = useState<
|
|
67
72
|
ReadonlyArray<AdapterNotDetectedWallet>
|
|
68
73
|
>([]);
|
|
@@ -74,7 +79,8 @@ export const AptosWalletAdapterProvider: FC<AptosWalletProviderProps> = ({
|
|
|
74
79
|
const walletCore = new WalletCore(
|
|
75
80
|
optInWallets,
|
|
76
81
|
dappConfig,
|
|
77
|
-
disableTelemetry
|
|
82
|
+
disableTelemetry,
|
|
83
|
+
hideWallets ? hideWallets : ["Petra Web"],
|
|
78
84
|
);
|
|
79
85
|
setWalletCore(walletCore);
|
|
80
86
|
}, []);
|
|
@@ -82,6 +88,7 @@ export const AptosWalletAdapterProvider: FC<AptosWalletProviderProps> = ({
|
|
|
82
88
|
// Update initial Wallets state once WalletCore has been initialized
|
|
83
89
|
useEffect(() => {
|
|
84
90
|
setWallets(walletCore?.wallets ?? []);
|
|
91
|
+
setHiddenWallets(walletCore?.hiddenWallets ?? []);
|
|
85
92
|
setNotDetectedWallets(walletCore?.notDetectedWallets ?? []);
|
|
86
93
|
}, [walletCore]);
|
|
87
94
|
|
|
@@ -107,7 +114,7 @@ export const AptosWalletAdapterProvider: FC<AptosWalletProviderProps> = ({
|
|
|
107
114
|
|
|
108
115
|
// Make sure the wallet is installed
|
|
109
116
|
const selectedWallet = walletCore.wallets.find(
|
|
110
|
-
(e) => e.name === walletName
|
|
117
|
+
(e) => e.name === walletName,
|
|
111
118
|
) as AdapterWallet | undefined;
|
|
112
119
|
if (
|
|
113
120
|
!selectedWallet ||
|
|
@@ -146,10 +153,8 @@ export const AptosWalletAdapterProvider: FC<AptosWalletProviderProps> = ({
|
|
|
146
153
|
}, [autoConnect, wallets]);
|
|
147
154
|
|
|
148
155
|
useEffect(() => {
|
|
149
|
-
//
|
|
150
|
-
//
|
|
151
|
-
// If it's safe to call multiple times, this is fine.
|
|
152
|
-
// Usually, these setup functions are idempotent or replace previous listeners.
|
|
156
|
+
// Initialize cross-chain wallet support based on dappConfig flags.
|
|
157
|
+
// Dynamically imports the packages to avoid bundling them when not used.
|
|
153
158
|
if (!derivationInitialized.current) {
|
|
154
159
|
if (dappConfig?.crossChainWallets?.solana) {
|
|
155
160
|
import("@aptos-labs/derived-wallet-solana").then(
|
|
@@ -157,7 +162,7 @@ export const AptosWalletAdapterProvider: FC<AptosWalletProviderProps> = ({
|
|
|
157
162
|
setupAutomaticSolanaWalletDerivation({
|
|
158
163
|
defaultNetwork: dappConfig?.network,
|
|
159
164
|
});
|
|
160
|
-
}
|
|
165
|
+
},
|
|
161
166
|
);
|
|
162
167
|
}
|
|
163
168
|
if (dappConfig?.crossChainWallets?.evm) {
|
|
@@ -166,7 +171,7 @@ export const AptosWalletAdapterProvider: FC<AptosWalletProviderProps> = ({
|
|
|
166
171
|
setupAutomaticEthereumWalletDerivation({
|
|
167
172
|
defaultNetwork: dappConfig?.network,
|
|
168
173
|
});
|
|
169
|
-
}
|
|
174
|
+
},
|
|
170
175
|
);
|
|
171
176
|
}
|
|
172
177
|
derivationInitialized.current = true;
|
|
@@ -214,7 +219,7 @@ export const AptosWalletAdapterProvider: FC<AptosWalletProviderProps> = ({
|
|
|
214
219
|
};
|
|
215
220
|
|
|
216
221
|
const signAndSubmitTransaction = async (
|
|
217
|
-
transaction: InputTransactionData
|
|
222
|
+
transaction: InputTransactionData,
|
|
218
223
|
): Promise<AptosSignAndSubmitTransactionOutput> => {
|
|
219
224
|
try {
|
|
220
225
|
if (!walletCore) {
|
|
@@ -254,7 +259,7 @@ export const AptosWalletAdapterProvider: FC<AptosWalletProviderProps> = ({
|
|
|
254
259
|
};
|
|
255
260
|
|
|
256
261
|
const submitTransaction = async (
|
|
257
|
-
transaction: InputSubmitTransactionData
|
|
262
|
+
transaction: InputSubmitTransactionData,
|
|
258
263
|
): Promise<PendingTransactionResponse> => {
|
|
259
264
|
if (!walletCore) {
|
|
260
265
|
throw new Error("WalletCore is not initialized");
|
|
@@ -268,7 +273,7 @@ export const AptosWalletAdapterProvider: FC<AptosWalletProviderProps> = ({
|
|
|
268
273
|
};
|
|
269
274
|
|
|
270
275
|
const signMessage = async (
|
|
271
|
-
message: AptosSignMessageInput
|
|
276
|
+
message: AptosSignMessageInput,
|
|
272
277
|
): Promise<AptosSignMessageOutput> => {
|
|
273
278
|
if (!walletCore) {
|
|
274
279
|
throw new Error("WalletCore is not initialized");
|
|
@@ -282,7 +287,7 @@ export const AptosWalletAdapterProvider: FC<AptosWalletProviderProps> = ({
|
|
|
282
287
|
};
|
|
283
288
|
|
|
284
289
|
const signMessageAndVerify = async (
|
|
285
|
-
message: AptosSignMessageInput
|
|
290
|
+
message: AptosSignMessageInput,
|
|
286
291
|
): Promise<boolean> => {
|
|
287
292
|
if (!walletCore) {
|
|
288
293
|
throw new Error("WalletCore is not initialized");
|
|
@@ -369,7 +374,7 @@ export const AptosWalletAdapterProvider: FC<AptosWalletProviderProps> = ({
|
|
|
369
374
|
// Manage current wallet state by removing optional duplications
|
|
370
375
|
// as new wallets are coming
|
|
371
376
|
const existingWalletIndex = wallets.findIndex(
|
|
372
|
-
(wallet) => wallet.name == standardWallet.name
|
|
377
|
+
(wallet) => wallet.name == standardWallet.name,
|
|
373
378
|
);
|
|
374
379
|
if (existingWalletIndex !== -1) {
|
|
375
380
|
// If wallet exists, replace it with the new wallet
|
|
@@ -384,13 +389,34 @@ export const AptosWalletAdapterProvider: FC<AptosWalletProviderProps> = ({
|
|
|
384
389
|
}
|
|
385
390
|
};
|
|
386
391
|
|
|
392
|
+
const handleStandardWalletsHiddenAdded = (
|
|
393
|
+
standardWallet: AdapterWallet,
|
|
394
|
+
): void => {
|
|
395
|
+
// Manage hidden wallet state by removing optional duplications
|
|
396
|
+
// as new wallets are coming
|
|
397
|
+
const existingWalletIndex = hiddenWallets.findIndex(
|
|
398
|
+
(wallet) => wallet.name === standardWallet.name,
|
|
399
|
+
);
|
|
400
|
+
if (existingWalletIndex !== -1) {
|
|
401
|
+
// If wallet exists, replace it with the new wallet
|
|
402
|
+
setHiddenWallets((hiddenWallets) => [
|
|
403
|
+
...hiddenWallets.slice(0, existingWalletIndex),
|
|
404
|
+
standardWallet,
|
|
405
|
+
...hiddenWallets.slice(existingWalletIndex + 1),
|
|
406
|
+
]);
|
|
407
|
+
} else {
|
|
408
|
+
// If wallet doesn't exist, add it to the array
|
|
409
|
+
setHiddenWallets((hiddenWallets) => [...hiddenWallets, standardWallet]);
|
|
410
|
+
}
|
|
411
|
+
};
|
|
412
|
+
|
|
387
413
|
const handleStandardNotDetectedWalletsAdded = (
|
|
388
|
-
notDetectedWallet: AdapterNotDetectedWallet
|
|
414
|
+
notDetectedWallet: AdapterNotDetectedWallet,
|
|
389
415
|
): void => {
|
|
390
416
|
// Manage current wallet state by removing optional duplications
|
|
391
417
|
// as new wallets are coming
|
|
392
418
|
const existingWalletIndex = wallets.findIndex(
|
|
393
|
-
(wallet) => wallet.name == notDetectedWallet.name
|
|
419
|
+
(wallet) => wallet.name == notDetectedWallet.name,
|
|
394
420
|
);
|
|
395
421
|
if (existingWalletIndex !== -1) {
|
|
396
422
|
// If wallet exists, replace it with the new wallet
|
|
@@ -411,9 +437,13 @@ export const AptosWalletAdapterProvider: FC<AptosWalletProviderProps> = ({
|
|
|
411
437
|
walletCore?.on("networkChange", handleNetworkChange);
|
|
412
438
|
walletCore?.on("disconnect", handleDisconnect);
|
|
413
439
|
walletCore?.on("standardWalletsAdded", handleStandardWalletsAdded);
|
|
440
|
+
walletCore?.on(
|
|
441
|
+
"standardWalletsHiddenAdded",
|
|
442
|
+
handleStandardWalletsHiddenAdded,
|
|
443
|
+
);
|
|
414
444
|
walletCore?.on(
|
|
415
445
|
"standardNotDetectedWalletAdded",
|
|
416
|
-
handleStandardNotDetectedWalletsAdded
|
|
446
|
+
handleStandardNotDetectedWalletsAdded,
|
|
417
447
|
);
|
|
418
448
|
return () => {
|
|
419
449
|
walletCore?.off("connect", handleConnect);
|
|
@@ -421,9 +451,13 @@ export const AptosWalletAdapterProvider: FC<AptosWalletProviderProps> = ({
|
|
|
421
451
|
walletCore?.off("networkChange", handleNetworkChange);
|
|
422
452
|
walletCore?.off("disconnect", handleDisconnect);
|
|
423
453
|
walletCore?.off("standardWalletsAdded", handleStandardWalletsAdded);
|
|
454
|
+
walletCore?.off(
|
|
455
|
+
"standardWalletsHiddenAdded",
|
|
456
|
+
handleStandardWalletsHiddenAdded,
|
|
457
|
+
);
|
|
424
458
|
walletCore?.off(
|
|
425
459
|
"standardNotDetectedWalletAdded",
|
|
426
|
-
handleStandardNotDetectedWalletsAdded
|
|
460
|
+
handleStandardNotDetectedWalletsAdded,
|
|
427
461
|
);
|
|
428
462
|
};
|
|
429
463
|
}, [wallets, account]);
|
|
@@ -446,6 +480,7 @@ export const AptosWalletAdapterProvider: FC<AptosWalletProviderProps> = ({
|
|
|
446
480
|
wallet,
|
|
447
481
|
wallets,
|
|
448
482
|
notDetectedWallets,
|
|
483
|
+
hiddenWallets,
|
|
449
484
|
isLoading,
|
|
450
485
|
}}
|
|
451
486
|
>
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
AdapterWallet,
|
|
4
4
|
WalletReadyState,
|
|
5
5
|
isRedirectable,
|
|
6
|
+
shouldUseFallbackWallet,
|
|
6
7
|
} from "@aptos-labs/wallet-adapter-core";
|
|
7
8
|
import { Slot } from "@radix-ui/react-slot";
|
|
8
9
|
import { createContext, forwardRef, useCallback, useContext } from "react";
|
|
@@ -35,16 +36,20 @@ const Root = forwardRef<HTMLDivElement, WalletItemProps>(
|
|
|
35
36
|
({ wallet, onConnect, className, asChild, children }, ref) => {
|
|
36
37
|
const { connect } = useWallet();
|
|
37
38
|
|
|
38
|
-
const connectWallet = useCallback(() => {
|
|
39
|
-
connect(wallet.name);
|
|
40
|
-
onConnect?.();
|
|
41
|
-
}, [connect, wallet.name, onConnect]);
|
|
42
|
-
|
|
43
39
|
const isWalletReady = wallet.readyState === WalletReadyState.Installed;
|
|
44
40
|
|
|
45
41
|
const mobileSupport =
|
|
46
42
|
"deeplinkProvider" in wallet && wallet.deeplinkProvider;
|
|
47
43
|
|
|
44
|
+
const connectWallet = useCallback(() => {
|
|
45
|
+
const connectionWallet = shouldUseFallbackWallet(wallet)
|
|
46
|
+
? wallet.fallbackWallet
|
|
47
|
+
: wallet;
|
|
48
|
+
if (!connectionWallet) return;
|
|
49
|
+
connect(connectionWallet.name);
|
|
50
|
+
onConnect?.();
|
|
51
|
+
}, [wallet, connect, onConnect]);
|
|
52
|
+
|
|
48
53
|
if (!isWalletReady && isRedirectable() && !mobileSupport) return null;
|
|
49
54
|
|
|
50
55
|
const Component = asChild ? Slot : "div";
|
package/src/index.tsx
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
export * from "@aptos-labs/wallet-adapter-core";
|
|
2
|
-
export * from "@aptos-labs/derived-wallet-solana";
|
|
3
|
-
export * from "@aptos-labs/derived-wallet-ethereum";
|
|
4
2
|
export * from "./WalletProvider";
|
|
5
3
|
export * from "./components/AboutAptosConnect";
|
|
6
4
|
export * from "./components/AboutPetraWeb";
|
package/src/useWallet.tsx
CHANGED
|
@@ -47,6 +47,7 @@ export interface WalletContextState {
|
|
|
47
47
|
): Promise<PendingTransactionResponse>;
|
|
48
48
|
wallet: AdapterWallet | null;
|
|
49
49
|
wallets: ReadonlyArray<AdapterWallet>;
|
|
50
|
+
hiddenWallets: ReadonlyArray<AdapterWallet>;
|
|
50
51
|
notDetectedWallets: ReadonlyArray<AdapterNotDetectedWallet>;
|
|
51
52
|
}
|
|
52
53
|
|