@aptos-labs/wallet-adapter-core 8.0.0-xchaininit.0 → 8.0.0

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.
Files changed (41) hide show
  1. package/dist/WalletCore.d.ts +17 -1
  2. package/dist/WalletCore.d.ts.map +1 -1
  3. package/dist/constants.d.ts +8 -0
  4. package/dist/constants.d.ts.map +1 -1
  5. package/dist/index.d.mts +42 -17
  6. package/dist/index.js +111 -10
  7. package/dist/index.js.map +1 -1
  8. package/dist/index.mjs +93 -12
  9. package/dist/index.mjs.map +1 -1
  10. package/dist/sdkWallets.d.ts.map +1 -1
  11. package/dist/utils/types.d.ts +1 -1
  12. package/dist/utils/types.d.ts.map +1 -1
  13. package/dist/utils/walletSelector.d.ts +29 -4
  14. package/dist/utils/walletSelector.d.ts.map +1 -1
  15. package/dist/version.d.ts +1 -1
  16. package/dist/version.d.ts.map +1 -1
  17. package/package.json +4 -4
  18. package/src/WalletCore.ts +83 -36
  19. package/src/constants.ts +11 -0
  20. package/src/sdkWallets.ts +6 -0
  21. package/src/utils/types.ts +1 -0
  22. package/src/utils/walletSelector.ts +116 -19
  23. package/src/version.ts +1 -1
  24. package/dist/CrossChainCore.d.ts +0 -28
  25. package/dist/CrossChainCore.d.ts.map +0 -1
  26. package/dist/WalletCoreNew.d.ts +0 -194
  27. package/dist/WalletCoreNew.d.ts.map +0 -1
  28. package/dist/index.cjs +0 -2376
  29. package/dist/index.cjs.map +0 -1
  30. package/dist/utils/aptosConnect.d.ts +0 -18
  31. package/dist/utils/aptosConnect.d.ts.map +0 -1
  32. package/dist/utils/crossChain/chains/mainnet/index.d.ts +0 -45
  33. package/dist/utils/crossChain/chains/mainnet/index.d.ts.map +0 -1
  34. package/dist/utils/crossChain/chains/testnet/index.d.ts +0 -50
  35. package/dist/utils/crossChain/chains/testnet/index.d.ts.map +0 -1
  36. package/dist/utils/crossChain/tokens/mainnet.d.ts +0 -15
  37. package/dist/utils/crossChain/tokens/mainnet.d.ts.map +0 -1
  38. package/dist/utils/crossChain/tokens/testnet.d.ts +0 -11
  39. package/dist/utils/crossChain/tokens/testnet.d.ts.map +0 -1
  40. package/dist/utils/logger.d.ts +0 -6
  41. package/dist/utils/logger.d.ts.map +0 -1
package/src/WalletCore.ts CHANGED
@@ -100,6 +100,8 @@ import {
100
100
  export type AdapterWallet = AptosWallet & {
101
101
  readyState?: WalletReadyState;
102
102
  isAptosNativeWallet?: boolean;
103
+ /** A fallback wallet to use when this wallet is not installed */
104
+ fallbackWallet?: AdapterWallet;
103
105
  };
104
106
 
105
107
  // An adapter not detected wallet types is a wallet that is compatible with the wallet standard but not detected
@@ -149,6 +151,7 @@ export declare interface WalletCoreEvents {
149
151
  connect(account: AccountInfo | null): void;
150
152
  disconnect(): void;
151
153
  standardWalletsAdded(wallets: AdapterWallet): void;
154
+ standardWalletsHiddenAdded(wallets: AdapterWallet): void;
152
155
  standardNotDetectedWalletAdded(wallets: AdapterNotDetectedWallet): void;
153
156
  networkChange(network: NetworkInfo | null): void;
154
157
  accountChange(account: AccountInfo | null): void;
@@ -172,6 +175,9 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
172
175
  // Local array that holds all the wallets that are AIP-62 standard compatible but are not installed on the user machine
173
176
  private _standard_not_detected_wallets: AdapterNotDetectedWallet[] = [];
174
177
 
178
+ // Local array that holds all the wallets that are AIP-62 standard compatible but are hidden from normal display and that are installed on the user machine
179
+ private _standard_wallets_hidden: AdapterWallet[] = [];
180
+
175
181
  // Local private variable to hold the network that is currently connected
176
182
  private _network: NetworkInfo | null = null;
177
183
 
@@ -190,6 +196,9 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
190
196
  // Private array that holds all the Wallets a dapp decided to opt-in to
191
197
  private _optInWallets: ReadonlyArray<AvailableWallets> = [];
192
198
 
199
+ // Private array that holds all the Wallets a dapp decided to hide from normal display
200
+ private _hideWallets: ReadonlyArray<AvailableWallets> = [];
201
+
193
202
  // Local flag to disable the adapter telemetry tool
194
203
  private _disableTelemetry: boolean = false;
195
204
 
@@ -199,10 +208,12 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
199
208
  constructor(
200
209
  optInWallets?: ReadonlyArray<AvailableWallets>,
201
210
  dappConfig?: DappConfig,
202
- disableTelemetry?: boolean
211
+ disableTelemetry?: boolean,
212
+ hideWallets: ReadonlyArray<AvailableWallets> = ["Petra Web"],
203
213
  ) {
204
214
  super();
205
215
  this._optInWallets = optInWallets || [];
216
+ this._hideWallets = hideWallets;
206
217
  this._dappConfig = dappConfig;
207
218
  this._disableTelemetry = disableTelemetry ?? false;
208
219
  this._sdkWallets = getSDKWallets(this._dappConfig);
@@ -246,7 +257,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
246
257
  * @param extensionwWallets
247
258
  */
248
259
  private setExtensionAIP62Wallets(
249
- extensionwWallets: readonly AptosWallet[]
260
+ extensionwWallets: readonly AptosWallet[],
250
261
  ): void {
251
262
  extensionwWallets.map((wallet: AdapterWallet) => {
252
263
  if (this.excludeWallet(wallet)) {
@@ -263,22 +274,27 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
263
274
  if (isValid) {
264
275
  // check if we already have this wallet as a not detected wallet
265
276
  const index = this._standard_not_detected_wallets.findIndex(
266
- (notDetctedWallet) => notDetctedWallet.name == wallet.name
277
+ (notDetctedWallet) => notDetctedWallet.name == wallet.name,
267
278
  );
268
279
  // if we do, remove it from the not detected wallets array as it is now become detected
269
280
  if (index !== -1) {
270
281
  this._standard_not_detected_wallets.splice(index, 1);
271
282
  }
272
283
 
273
- // ✅ Check if wallet already exists in _standard_wallets
274
- const alreadyExists = this._standard_wallets.some(
275
- (w) => w.name === wallet.name
276
- );
284
+ // ✅ Check if wallet already exists in _standard_wallets or _standard_wallets_hidden
285
+ const alreadyExists =
286
+ this._standard_wallets.some((w) => w.name === wallet.name) ||
287
+ this._standard_wallets_hidden.some((w) => w.name === wallet.name);
277
288
  if (!alreadyExists) {
278
289
  wallet.readyState = WalletReadyState.Installed;
279
290
  wallet.isAptosNativeWallet = this.isAptosNativeWallet(wallet);
280
- this._standard_wallets.push(wallet);
281
- this.emit("standardWalletsAdded", wallet);
291
+ if (!this.hideWallet(wallet)) {
292
+ this._standard_wallets.push(wallet);
293
+ this.emit("standardWalletsAdded", wallet);
294
+ } else {
295
+ this._standard_wallets_hidden.push(wallet);
296
+ this.emit("standardWalletsHiddenAdded", wallet);
297
+ }
282
298
  }
283
299
  }
284
300
  });
@@ -297,7 +313,11 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
297
313
  if (isValid) {
298
314
  wallet.readyState = WalletReadyState.Installed;
299
315
  wallet.isAptosNativeWallet = this.isAptosNativeWallet(wallet);
300
- this._standard_wallets.push(wallet);
316
+ if (!this.hideWallet(wallet)) {
317
+ this._standard_wallets.push(wallet);
318
+ } else {
319
+ this._standard_wallets_hidden.push(wallet);
320
+ }
301
321
  }
302
322
  });
303
323
  }
@@ -322,9 +342,13 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
322
342
  // Loop over the registry map
323
343
  walletRegistry.map((supportedWallet: AptosStandardSupportedWallet) => {
324
344
  // Check if we already have this wallet as a detected AIP-62 wallet standard
325
- const existingStandardWallet = this._standard_wallets.find(
326
- (wallet) => wallet.name == supportedWallet.name
327
- );
345
+ const existingStandardWallet =
346
+ this._standard_wallets.find(
347
+ (wallet) => wallet.name === supportedWallet.name,
348
+ ) ||
349
+ this._standard_wallets_hidden.find(
350
+ (wallet) => wallet.name === supportedWallet.name,
351
+ );
328
352
  // If it is detected, it means the user has the wallet installed, so dont add it to the wallets array
329
353
  if (existingStandardWallet) {
330
354
  return;
@@ -364,6 +388,19 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
364
388
  return false;
365
389
  }
366
390
 
391
+ /**
392
+ * A function that hides an AIP-62 compatible wallet from normal display.
393
+ *
394
+ * @param wallet AdapterWallet | AdapterNotDetectedWallet
395
+ * @returns boolean
396
+ */
397
+ hideWallet(wallet: AdapterWallet | AdapterNotDetectedWallet): boolean {
398
+ return (
399
+ this._hideWallets.length > 0 &&
400
+ this._hideWallets.includes(wallet.name as AvailableWallets)
401
+ );
402
+ }
403
+
367
404
  private recordEvent(eventName: string, additionalInfo?: object): void {
368
405
  this.ga4?.gtag("event", `wallet_adapter_${eventName}`, {
369
406
  wallet: this._wallet?.name,
@@ -381,7 +418,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
381
418
  * @param wallet A wallet
382
419
  */
383
420
  private ensureWalletExists(
384
- wallet: AdapterWallet | null
421
+ wallet: AdapterWallet | null,
385
422
  ): asserts wallet is AdapterWallet {
386
423
  if (!wallet) {
387
424
  throw new WalletNotConnectedError().name;
@@ -396,7 +433,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
396
433
  * @param account An account
397
434
  */
398
435
  private ensureAccountExists(
399
- account: AccountInfo | null
436
+ account: AccountInfo | null,
400
437
  ): asserts account is AccountInfo {
401
438
  if (!account) {
402
439
  throw new WalletAccountError("Account is not set").name;
@@ -490,6 +527,13 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
490
527
  return this._standard_wallets;
491
528
  }
492
529
 
530
+ /**
531
+ * Getter to fetch all hidden wallets
532
+ */
533
+ get hiddenWallets(): ReadonlyArray<AdapterWallet> {
534
+ return this._standard_wallets_hidden;
535
+ }
536
+
493
537
  get notDetectedWallets(): ReadonlyArray<AdapterNotDetectedWallet> {
494
538
  return this._standard_not_detected_wallets;
495
539
  }
@@ -547,7 +591,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
547
591
  // Check if we are in a redirectable view (i.e on mobile AND not in an in-app browser)
548
592
  if (isRedirectable()) {
549
593
  const selectedWallet = this._standard_not_detected_wallets.find(
550
- (wallet: AdapterNotDetectedWallet) => wallet.name === walletName
594
+ (wallet: AdapterNotDetectedWallet) => wallet.name === walletName,
551
595
  );
552
596
 
553
597
  if (selectedWallet) {
@@ -576,10 +620,13 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
576
620
  }
577
621
 
578
622
  // Checks the wallet exists in the detected wallets array
579
- const allDetectedWallets = this._standard_wallets;
623
+ const allDetectedWallets = [
624
+ ...this._standard_wallets,
625
+ ...this._standard_wallets_hidden,
626
+ ];
580
627
 
581
628
  const selectedWallet = allDetectedWallets.find(
582
- (wallet: AdapterWallet) => wallet.name === walletName
629
+ (wallet: AdapterWallet) => wallet.name === walletName,
583
630
  );
584
631
 
585
632
  if (!selectedWallet) return;
@@ -589,7 +636,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
589
636
  // if the selected wallet is already connected, we don't need to connect again
590
637
  if (this._wallet?.name === walletName)
591
638
  throw new WalletConnectionError(
592
- `${walletName} wallet is already connected`
639
+ `${walletName} wallet is already connected`,
593
640
  ).message;
594
641
  }
595
642
 
@@ -622,7 +669,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
622
669
 
623
670
  const allDetectedWallets = this._standard_wallets;
624
671
  const selectedWallet = allDetectedWallets.find(
625
- (wallet: AdapterWallet) => wallet.name === walletName
672
+ (wallet: AdapterWallet) => wallet.name === walletName,
626
673
  );
627
674
 
628
675
  if (!selectedWallet) {
@@ -631,14 +678,14 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
631
678
 
632
679
  if (!selectedWallet.features["aptos:signIn"]) {
633
680
  throw new WalletNotSupportedMethod(
634
- `aptos:signIn is not supported by ${walletName}`
681
+ `aptos:signIn is not supported by ${walletName}`,
635
682
  ).message;
636
683
  }
637
684
 
638
685
  return await this.connectWallet(selectedWallet, async () => {
639
686
  if (!selectedWallet.features["aptos:signIn"]) {
640
687
  throw new WalletNotSupportedMethod(
641
- `aptos:signIn is not supported by ${selectedWallet.name}`
688
+ `aptos:signIn is not supported by ${selectedWallet.name}`,
642
689
  ).message;
643
690
  }
644
691
 
@@ -664,7 +711,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
664
711
  */
665
712
  private async connectWallet<T>(
666
713
  selectedWallet: AdapterWallet,
667
- onConnect: () => Promise<{ account: AccountInfo; output: T }>
714
+ onConnect: () => Promise<{ account: AccountInfo; output: T }>,
668
715
  ): Promise<T> {
669
716
  try {
670
717
  this._connecting = true;
@@ -715,7 +762,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
715
762
  * @returns AptosSignAndSubmitTransactionOutput
716
763
  */
717
764
  async signAndSubmitTransaction(
718
- transactionInput: InputTransactionData
765
+ transactionInput: InputTransactionData,
719
766
  ): Promise<AptosSignAndSubmitTransactionOutput> {
720
767
  try {
721
768
  if ("function" in transactionInput.data) {
@@ -766,7 +813,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
766
813
  });
767
814
 
768
815
  type AptosSignAndSubmitTransactionV1Method = (
769
- transaction: AnyRawTransaction
816
+ transaction: AnyRawTransaction,
770
817
  ) => Promise<UserResponse<AptosSignAndSubmitTransactionOutput>>;
771
818
 
772
819
  const signAndSubmitTransactionMethod = this._wallet.features[
@@ -775,7 +822,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
775
822
  .signAndSubmitTransaction as unknown as AptosSignAndSubmitTransactionV1Method;
776
823
 
777
824
  const response = (await signAndSubmitTransactionMethod(
778
- transaction
825
+ transaction,
779
826
  )) as UserResponse<AptosSignAndSubmitTransactionOutput>;
780
827
 
781
828
  if (response.status === UserResponseStatus.REJECTED) {
@@ -871,7 +918,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
871
918
  "aptos:signTransaction"
872
919
  ].signTransaction(
873
920
  transactionOrPayload,
874
- asFeePayer
921
+ asFeePayer,
875
922
  )) as UserResponse<AccountAuthenticator>;
876
923
  if (response.status === UserResponseStatus.REJECTED) {
877
924
  throw new WalletConnectionError("User has rejected the request")
@@ -907,7 +954,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
907
954
  AptosSignTransactionMethodV1_1;
908
955
 
909
956
  const response = (await walletSignTransactionMethod(
910
- signTransactionV1_1StandardInput
957
+ signTransactionV1_1StandardInput,
911
958
  )) as UserResponse<AptosSignTransactionOutputV1_1>;
912
959
  if (response.status === UserResponseStatus.REJECTED) {
913
960
  throw new WalletConnectionError("User has rejected the request")
@@ -933,7 +980,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
933
980
  "aptos:signTransaction"
934
981
  ].signTransaction(
935
982
  transaction,
936
- asFeePayer
983
+ asFeePayer,
937
984
  )) as UserResponse<AccountAuthenticator>;
938
985
  if (response.status === UserResponseStatus.REJECTED) {
939
986
  throw new WalletConnectionError("User has rejected the request")
@@ -960,7 +1007,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
960
1007
  * @throws WalletSignMessageError
961
1008
  */
962
1009
  async signMessage(
963
- message: AptosSignMessageInput
1010
+ message: AptosSignMessageInput,
964
1011
  ): Promise<AptosSignMessageOutput> {
965
1012
  try {
966
1013
  this.ensureWalletExists(this._wallet);
@@ -986,7 +1033,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
986
1033
  * @returns PendingTransactionResponse
987
1034
  */
988
1035
  async submitTransaction(
989
- transaction: InputSubmitTransactionData
1036
+ transaction: InputSubmitTransactionData,
990
1037
  ): Promise<PendingTransactionResponse> {
991
1038
  // The standard does not support submitTransaction, so we use the adapter to submit the transaction
992
1039
  try {
@@ -1032,7 +1079,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
1032
1079
  await this.setAnsName();
1033
1080
  this.recordEvent("account_change");
1034
1081
  this.emit("accountChange", this._account);
1035
- }
1082
+ },
1036
1083
  );
1037
1084
  } catch (error: any) {
1038
1085
  const errMsg = generalizedErrorMessage(error);
@@ -1053,7 +1100,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
1053
1100
  this.setNetwork(data);
1054
1101
  await this.setAnsName();
1055
1102
  this.emit("networkChange", this._network);
1056
- }
1103
+ },
1057
1104
  );
1058
1105
  } catch (error: any) {
1059
1106
  const errMsg = generalizedErrorMessage(error);
@@ -1087,7 +1134,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
1087
1134
  if (this._wallet.features["aptos:changeNetwork"]) {
1088
1135
  const response =
1089
1136
  await this._wallet.features["aptos:changeNetwork"].changeNetwork(
1090
- networkInfo
1137
+ networkInfo,
1091
1138
  );
1092
1139
  if (response.status === UserResponseStatus.REJECTED) {
1093
1140
  throw new WalletConnectionError("User has rejected the request")
@@ -1097,7 +1144,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
1097
1144
  }
1098
1145
 
1099
1146
  throw new WalletChangeNetworkError(
1100
- `${this._wallet.name} does not support changing network request`
1147
+ `${this._wallet.name} does not support changing network request`,
1101
1148
  ).message;
1102
1149
  } catch (error: any) {
1103
1150
  const errMsg = generalizedErrorMessage(error);
@@ -1127,7 +1174,7 @@ export class WalletCore extends EventEmitter<WalletCoreEvents> {
1127
1174
 
1128
1175
  const aptosConfig = getAptosConfig(this._network, this._dappConfig);
1129
1176
  const signingMessage = new TextEncoder().encode(
1130
- response.args.fullMessage
1177
+ response.args.fullMessage,
1131
1178
  );
1132
1179
  if ("verifySignatureAsync" in (this._account.publicKey as Object)) {
1133
1180
  return await this._account.publicKey.verifySignatureAsync({
package/src/constants.ts CHANGED
@@ -29,6 +29,17 @@ export const APTOS_CONNECT_BASE_URL = "https://aptosconnect.app";
29
29
  /** The base URL for all Petra Web wallets. */
30
30
  export const PETRA_WEB_BASE_URL = "https://web.petra.app";
31
31
 
32
+ /** The name of the generic wallet for Petra Web. */
33
+ export const PETRA_WEB_GENERIC_WALLET_NAME = "Petra Web";
34
+
35
+ /** The name of the Petra wallet. */
36
+ export const PETRA_WALLET_NAME = "Petra";
37
+
38
+ /** The default connection fallbacks for wallets that are not installed. */
39
+ export const DEFAULT_WALLET_CONNECTION_FALLBACKS = {
40
+ [PETRA_WALLET_NAME]: PETRA_WEB_GENERIC_WALLET_NAME,
41
+ };
42
+
32
43
  /**
33
44
  * The URL to the Aptos Connect account page if the user is signed in to Aptos Connect.
34
45
  *
package/src/sdkWallets.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  AptosConnectAppleWallet,
3
+ AptosConnectGenericWallet,
3
4
  AptosConnectGoogleWallet,
4
5
  } from "@aptos-connect/wallet-adapter-plugin";
5
6
  import { DappConfig, AdapterWallet } from "./WalletCore";
@@ -20,6 +21,11 @@ export function getSDKWallets(dappConfig?: DappConfig) {
20
21
  dappId: dappConfig?.aptosConnectDappId,
21
22
  ...dappConfig?.aptosConnect,
22
23
  }),
24
+ new AptosConnectGenericWallet({
25
+ network: dappConfig?.network,
26
+ dappId: dappConfig?.aptosConnectDappId,
27
+ ...dappConfig?.aptosConnect,
28
+ }),
23
29
  );
24
30
  }
25
31
 
@@ -30,6 +30,7 @@ export interface AptosStandardSupportedWallet {
30
30
  export type AvailableWallets =
31
31
  | "Continue with Apple"
32
32
  | "Continue with Google"
33
+ | "Petra Web"
33
34
  | "OKX Wallet"
34
35
  | "Petra"
35
36
  | "Nightly"
@@ -1,8 +1,9 @@
1
- import { WalletInfo } from "./types";
1
+ import { AvailableWallets, WalletInfo } from "./types";
2
2
  import { AdapterNotDetectedWallet, AdapterWallet } from "../WalletCore";
3
3
  import {
4
4
  APTOS_CONNECT_BASE_URL,
5
5
  PETRA_WEB_BASE_URL,
6
+ PETRA_WEB_GENERIC_WALLET_NAME,
6
7
  WalletReadyState,
7
8
  } from "../constants";
8
9
  import { isRedirectable } from "./helpers";
@@ -15,15 +16,18 @@ import { isRedirectable } from "./helpers";
15
16
  export function partitionWallets(
16
17
  wallets: ReadonlyArray<AdapterWallet | AdapterNotDetectedWallet>,
17
18
  partitionFunction: (
18
- wallet: AdapterWallet | AdapterNotDetectedWallet,
19
- ) => boolean = isInstalledOrLoadable,
19
+ wallet: AdapterWallet | AdapterNotDetectedWallet
20
+ ) => boolean = isInstalledOrLoadable
20
21
  ) {
21
22
  const defaultWallets: Array<AdapterWallet> = [];
22
23
  const moreWallets: Array<AdapterNotDetectedWallet> = [];
23
24
 
24
25
  for (const wallet of wallets) {
25
- if (partitionFunction(wallet)) defaultWallets.push(wallet as AdapterWallet);
26
- else moreWallets.push(wallet as AdapterNotDetectedWallet);
26
+ if (partitionFunction(wallet)) {
27
+ defaultWallets.push(wallet as AdapterWallet);
28
+ } else {
29
+ moreWallets.push(wallet as AdapterNotDetectedWallet);
30
+ }
27
31
  }
28
32
 
29
33
  return { defaultWallets, moreWallets };
@@ -31,8 +35,8 @@ export function partitionWallets(
31
35
 
32
36
  /** Returns true if the wallet is installed or loadable. */
33
37
  export function isInstalledOrLoadable(
34
- wallet: AdapterWallet | AdapterNotDetectedWallet,
35
- ) {
38
+ wallet: AdapterWallet | AdapterNotDetectedWallet
39
+ ): wallet is AdapterWallet {
36
40
  return wallet.readyState === WalletReadyState.Installed;
37
41
  }
38
42
 
@@ -41,7 +45,7 @@ export function isInstalledOrLoadable(
41
45
  * This can be used to decide whether to show a "Connect" button or "Install" link in the UI.
42
46
  */
43
47
  export function isInstallRequired(
44
- wallet: AdapterWallet | AdapterNotDetectedWallet,
48
+ wallet: AdapterWallet | AdapterNotDetectedWallet
45
49
  ) {
46
50
  const isWalletReady = isInstalledOrLoadable(wallet);
47
51
  const isMobile = !isWalletReady && isRedirectable();
@@ -49,6 +53,16 @@ export function isInstallRequired(
49
53
  return !isMobile && !isWalletReady;
50
54
  }
51
55
 
56
+ export function shouldUseFallbackWallet(
57
+ wallet: AdapterWallet | AdapterNotDetectedWallet
58
+ ): boolean {
59
+ return (
60
+ !!wallet.fallbackWallet &&
61
+ isInstallRequired(wallet) &&
62
+ isInstalledOrLoadable(wallet.fallbackWallet)
63
+ );
64
+ }
65
+
52
66
  /** Truncates the provided wallet address at the middle with an ellipsis. */
53
67
  export function truncateAddress(address: string | undefined) {
54
68
  if (!address) return;
@@ -64,15 +78,28 @@ export function isAptosConnectWallet(wallet: WalletInfo | AdapterWallet) {
64
78
  return isPetraWebWallet(wallet);
65
79
  }
66
80
 
67
- /** Returns `true` if the provided wallet is a Petra Web wallet. */
68
- export function isPetraWebWallet(wallet: WalletInfo | AdapterWallet) {
81
+ /** Returns `true` if the provided wallet is a Petra Web wallet. This will automatically exclude the generic wallet. */
82
+ export function isPetraWebWallet(
83
+ wallet: WalletInfo | AdapterWallet,
84
+ ignoreGenericWallet: boolean = true
85
+ ) {
69
86
  if (!wallet.url) return false;
87
+ if (ignoreGenericWallet && isPetraWebGenericWallet(wallet)) {
88
+ return false;
89
+ }
70
90
  return (
71
91
  wallet.url.startsWith(APTOS_CONNECT_BASE_URL) ||
72
92
  wallet.url.startsWith(PETRA_WEB_BASE_URL)
73
93
  );
74
94
  }
75
95
 
96
+ /** Returns true if the wallet is a generic wallet. */
97
+ export function isPetraWebGenericWallet(
98
+ wallet: AdapterWallet | AdapterNotDetectedWallet | WalletInfo
99
+ ) {
100
+ return wallet.name === PETRA_WEB_GENERIC_WALLET_NAME;
101
+ }
102
+
76
103
  /**
77
104
  * Partitions the `wallets` array so that Aptos Connect wallets are grouped separately from the rest.
78
105
  * Petra Web is a web wallet that uses social login to create accounts on the blockchain.
@@ -80,13 +107,16 @@ export function isPetraWebWallet(wallet: WalletInfo | AdapterWallet) {
80
107
  * @deprecated Use {@link getPetraWebWallets} instead.
81
108
  */
82
109
  export function getAptosConnectWallets(
83
- wallets: ReadonlyArray<AdapterWallet | AdapterNotDetectedWallet>,
110
+ wallets: ReadonlyArray<AdapterWallet | AdapterNotDetectedWallet>
84
111
  ) {
85
112
  const { defaultWallets, moreWallets } = partitionWallets(
86
113
  wallets,
87
- isAptosConnectWallet,
114
+ isAptosConnectWallet
88
115
  );
89
- return { aptosConnectWallets: defaultWallets, otherWallets: moreWallets };
116
+ return {
117
+ aptosConnectWallets: defaultWallets,
118
+ otherWallets: moreWallets,
119
+ };
90
120
  }
91
121
 
92
122
  /**
@@ -94,13 +124,16 @@ export function getAptosConnectWallets(
94
124
  * Petra Web is a web wallet that uses social login to create accounts on the blockchain.
95
125
  */
96
126
  export function getPetraWebWallets(
97
- wallets: ReadonlyArray<AdapterWallet | AdapterNotDetectedWallet>,
127
+ wallets: ReadonlyArray<AdapterWallet | AdapterNotDetectedWallet>
98
128
  ) {
99
129
  const { defaultWallets, moreWallets } = partitionWallets(
100
130
  wallets,
101
- isPetraWebWallet,
131
+ isPetraWebWallet
102
132
  );
103
- return { petraWebWallets: defaultWallets, otherWallets: moreWallets };
133
+ return {
134
+ petraWebWallets: defaultWallets,
135
+ otherWallets: moreWallets,
136
+ };
104
137
  }
105
138
 
106
139
  export interface WalletSortingOptions {
@@ -115,13 +148,31 @@ export interface WalletSortingOptions {
115
148
  /** An optional function for sorting wallets that are currently installed or loadable. */
116
149
  sortAvailableWallets?: (
117
150
  a: AdapterWallet | AdapterNotDetectedWallet,
118
- b: AdapterWallet | AdapterNotDetectedWallet,
151
+ b: AdapterWallet | AdapterNotDetectedWallet
119
152
  ) => number;
120
153
  /** An optional function for sorting wallets that are NOT currently installed or loadable. */
121
154
  sortInstallableWallets?: (
122
155
  a: AdapterWallet | AdapterNotDetectedWallet,
123
- b: AdapterWallet | AdapterNotDetectedWallet,
156
+ b: AdapterWallet | AdapterNotDetectedWallet
124
157
  ) => number;
158
+ /**
159
+ * A map of wallet names to fallback wallet names.
160
+ * If a wallet is not installed and has a fallback wallet that IS installed,
161
+ * the fallback wallet will be attached to the not-installed wallet and it will
162
+ * be moved to the available wallets list.
163
+ *
164
+ * @example
165
+ * ```ts
166
+ * // Override the default fallbacks
167
+ * fallbacks: { connections: { "Petra": "Petra Web", "OtherWallet": "OtherFallback" } }
168
+ * ```
169
+ */
170
+ fallbacks?: {
171
+ /** A map of wallet names to fallback wallet names. */
172
+ connections: Record<string | AvailableWallets, string | AvailableWallets>;
173
+ /** An optional array of wallets that are available but not intended for display. These wallets will only be shown if there is logic to explicitly show them (e.g. `fallbacks`) */
174
+ additionalFallbackWallets?: ReadonlyArray<AdapterWallet>;
175
+ };
125
176
  }
126
177
 
127
178
  /**
@@ -134,6 +185,8 @@ export interface WalletSortingOptions {
134
185
  *
135
186
  * `availableWallets` - Wallets that are currently installed or loadable by the client.
136
187
  *
188
+ * `availableWalletsWithFallbacks` - Wallets that are currently uninstalled that have a fallback wallet.
189
+ *
137
190
  * `installableWallets` - Wallets that are NOT current installed or loadable and
138
191
  * require the client to install a browser extension first.
139
192
  *
@@ -141,12 +194,54 @@ export interface WalletSortingOptions {
141
194
  */
142
195
  export function groupAndSortWallets(
143
196
  wallets: ReadonlyArray<AdapterWallet | AdapterNotDetectedWallet>,
144
- options?: WalletSortingOptions,
197
+ options?: WalletSortingOptions
145
198
  ) {
199
+ const {
200
+ fallbacks: {
201
+ connections: fallbackConnections,
202
+ additionalFallbackWallets,
203
+ } = {},
204
+ } = options ?? {};
146
205
  const { aptosConnectWallets } = getAptosConnectWallets(wallets);
147
206
  const { otherWallets, petraWebWallets } = getPetraWebWallets(wallets);
148
207
  const { defaultWallets, moreWallets } = partitionWallets(otherWallets);
149
208
 
209
+ // Attach fallback wallets to not-installed wallets and move them to available wallets if the fallback is installed
210
+ // TODO: Deprecate this and combine this with `availableWallets` in the next major version.
211
+ const availableWalletsWithFallbacks: Array<
212
+ AdapterWallet | AdapterNotDetectedWallet
213
+ > = [];
214
+
215
+ if (fallbackConnections && Object.keys(fallbackConnections).length > 0) {
216
+ for (let i = moreWallets.length - 1; i >= 0; i--) {
217
+ const wallet = moreWallets[i];
218
+ const fallbackName = fallbackConnections[wallet.name];
219
+
220
+ if (fallbackName) {
221
+ const fallbackWallet = [
222
+ ...wallets,
223
+ ...(additionalFallbackWallets ?? []),
224
+ ].find((w) => w.name === fallbackName && isInstalledOrLoadable(w)) as
225
+ | AdapterWallet
226
+ | undefined;
227
+
228
+ // If we found an installed fallback, attach it and move to available wallets
229
+ if (fallbackWallet) {
230
+ const walletWithFallback: AdapterNotDetectedWallet = {
231
+ ...wallet,
232
+ fallbackWallet,
233
+ };
234
+
235
+ // Remove from installable wallets
236
+ moreWallets.splice(i, 1);
237
+
238
+ // Add to the list to be added to available wallets
239
+ availableWalletsWithFallbacks.push(walletWithFallback);
240
+ }
241
+ }
242
+ }
243
+ }
244
+
150
245
  if (options?.sortAptosConnectWallets) {
151
246
  aptosConnectWallets.sort(options.sortAptosConnectWallets);
152
247
  }
@@ -167,6 +262,8 @@ export function groupAndSortWallets(
167
262
  petraWebWallets,
168
263
  /** Wallets that are currently installed or loadable. */
169
264
  availableWallets: defaultWallets,
265
+ /** Wallets that are currently uninstalled that have a fallback wallet. */
266
+ availableWalletsWithFallbacks,
170
267
  /** Wallets that are NOT currently installed or loadable. */
171
268
  installableWallets: moreWallets,
172
269
  };
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const WALLET_ADAPTER_CORE_VERSION = "7.10.2";
1
+ export const WALLET_ADAPTER_CORE_VERSION = "8.0.0";
@@ -1,28 +0,0 @@
1
- import { SolanaWallet } from "@xlabs-libs/wallet-aggregator-solana";
2
- import { Eip6963Wallet } from "@xlabs-libs/wallet-aggregator-evm";
3
- import { routes } from "@wormhole-foundation/sdk";
4
- import { Wallet as WalletAggregator } from "@xlabs-libs/wallet-aggregator-core";
5
- import { Network } from "@aptos-labs/ts-sdk";
6
- export { SolanaWallet, Eip6963Wallet, WalletAggregator };
7
- export interface CrossChainDappConfig {
8
- network: Network;
9
- aptosGasStationKeys?: Partial<Record<Network, string>>;
10
- disableTelemetry?: boolean;
11
- }
12
- export declare class CrossChainCore {
13
- private _solana_wallets;
14
- private _ethereum_wallets;
15
- private _dappConfig;
16
- private _cctpProviders;
17
- private _originChainSelected;
18
- private _connectedWallet;
19
- constructor(args: {
20
- dappConfig: CrossChainDappConfig;
21
- });
22
- private fetchSolanaWallets;
23
- private fetchEthereumWallets;
24
- get solanaWallets(): ReadonlyArray<SolanaWallet>;
25
- get ethereumWallets(): ReadonlyArray<Eip6963Wallet>;
26
- getWormholeCctpRoute(): Promise<routes.Route<"Mainnet" | "Testnet", routes.Options, routes.ValidatedTransferParams<routes.Options>, routes.Receipt<import("@wormhole-foundation/sdk/dist/cjs").AttestationReceipt<keyof import("@wormhole-foundation/sdk/dist/cjs").WormholeRegistry.ProtocolToInterfaceMapping<"Mainnet" | "Testnet" | "Devnet", "Ethereum" | "Solana" | "Aptos" | "Avalanche" | "Sepolia" | "Btc" | "Algorand" | "Sui" | "Near" | "Terra" | "Bsc" | "Polygon" | "Oasis" | "Aurora" | "Fantom" | "Karura" | "Acala" | "Klaytn" | "Celo" | "Moonbeam" | "Neon" | "Terra2" | "Injective" | "Osmosis" | "Arbitrum" | "Optimism" | "Gnosis" | "Pythnet" | "Xpla" | "Base" | "Sei" | "Rootstock" | "Scroll" | "Mantle" | "Blast" | "Xlayer" | "Linea" | "Berachain" | "Seievm" | "Snaxchain" | "Unichain" | "Worldchain" | "Ink" | "HyperEVM" | "Monad" | "Wormchain" | "Cosmoshub" | "Evmos" | "Kujira" | "Neutron" | "Celestia" | "Stargaze" | "Seda" | "Dymension" | "Provenance" | "Noble" | "ArbitrumSepolia" | "BaseSepolia" | "OptimismSepolia" | "Holesky" | "PolygonSepolia">>>>>;
27
- }
28
- //# sourceMappingURL=CrossChainCore.d.ts.map