@dynamic-labs/multi-wallet 4.0.0-alpha.2 → 4.0.0-alpha.20

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 (50) hide show
  1. package/CHANGELOG.md +183 -0
  2. package/package.cjs +8 -0
  3. package/package.js +4 -0
  4. package/package.json +9 -16
  5. package/src/index.cjs +12 -7
  6. package/src/index.d.ts +1 -2
  7. package/src/index.js +9 -2
  8. package/src/utils/{getApiProviders.d.ts → getApiProviders/getApiProviders.d.ts} +6 -0
  9. package/src/utils/getApiProviders/index.d.ts +1 -0
  10. package/src/utils/getEnabledProviders/getEnabledProviders.cjs +18 -0
  11. package/src/utils/getEnabledProviders/getEnabledProviders.d.ts +2 -0
  12. package/src/utils/getEnabledProviders/getEnabledProviders.js +14 -0
  13. package/src/utils/getEnabledProviders/index.d.ts +1 -0
  14. package/src/utils/getEnabledWallets/getEnabledWallets.cjs +16 -0
  15. package/src/utils/getEnabledWallets/getEnabledWallets.d.ts +6 -0
  16. package/src/utils/getEnabledWallets/getEnabledWallets.js +12 -0
  17. package/src/utils/getEnabledWallets/index.d.ts +1 -0
  18. package/src/utils/getSupportedChainsForWalletConnector/getSupportedChainsForWalletConnector.cjs +38 -0
  19. package/src/utils/getSupportedChainsForWalletConnector/getSupportedChainsForWalletConnector.d.ts +3 -0
  20. package/src/utils/getSupportedChainsForWalletConnector/getSupportedChainsForWalletConnector.js +34 -0
  21. package/src/utils/getSupportedChainsForWalletConnector/index.d.ts +1 -0
  22. package/src/utils/getSupportedWallets/applyLinksOverrides/applyLinksOverrides.cjs +16 -0
  23. package/src/utils/getSupportedWallets/applyLinksOverrides/applyLinksOverrides.d.ts +3 -0
  24. package/src/utils/getSupportedWallets/applyLinksOverrides/applyLinksOverrides.js +12 -0
  25. package/src/utils/getSupportedWallets/applyLinksOverrides/index.d.ts +1 -0
  26. package/src/utils/getSupportedWallets/const.cjs +30 -0
  27. package/src/utils/getSupportedWallets/const.d.ts +3 -0
  28. package/src/utils/getSupportedWallets/const.js +26 -0
  29. package/src/utils/getSupportedWallets/filterWalletsForPlatform/filterWalletsForPlatform.cjs +30 -0
  30. package/src/utils/getSupportedWallets/filterWalletsForPlatform/filterWalletsForPlatform.d.ts +3 -0
  31. package/src/utils/getSupportedWallets/filterWalletsForPlatform/filterWalletsForPlatform.js +26 -0
  32. package/src/utils/getSupportedWallets/filterWalletsForPlatform/index.d.ts +1 -0
  33. package/src/utils/getSupportedWallets/getSupportedWallets.cjs +103 -0
  34. package/src/utils/getSupportedWallets/getSupportedWallets.d.ts +2 -0
  35. package/src/utils/getSupportedWallets/getSupportedWallets.js +99 -0
  36. package/src/utils/getSupportedWallets/handleMobileWalletFilter/handleMobileWalletFilter.cjs +34 -0
  37. package/src/utils/getSupportedWallets/handleMobileWalletFilter/handleMobileWalletFilter.d.ts +2 -0
  38. package/src/utils/getSupportedWallets/handleMobileWalletFilter/handleMobileWalletFilter.js +30 -0
  39. package/src/utils/getSupportedWallets/handleMobileWalletFilter/index.d.ts +1 -0
  40. package/src/utils/getSupportedWallets/index.d.ts +1 -0
  41. package/src/utils/index.d.ts +5 -0
  42. package/src/utils/message/index.d.ts +1 -0
  43. package/src/multi-wallet.cjs +0 -178
  44. package/src/multi-wallet.d.ts +0 -11
  45. package/src/multi-wallet.js +0 -171
  46. /package/src/utils/{getApiProviders.cjs → getApiProviders/getApiProviders.cjs} +0 -0
  47. /package/src/utils/{getApiProviders.js → getApiProviders/getApiProviders.js} +0 -0
  48. /package/src/utils/{message.cjs → message/message.cjs} +0 -0
  49. /package/src/utils/{message.d.ts → message/message.d.ts} +0 -0
  50. /package/src/utils/{message.js → message/message.js} +0 -0
@@ -0,0 +1,26 @@
1
+ 'use client'
2
+ import { isEmbeddedConnector } from '@dynamic-labs/wallet-connector-core';
3
+ import { isMobile } from '@dynamic-labs/utils';
4
+ import { getWalletBookWallet } from '@dynamic-labs/wallet-book';
5
+ import { handleMobileWalletFilter } from '../handleMobileWalletFilter/handleMobileWalletFilter.js';
6
+
7
+ const filterWalletsForPlatform = (walletBook, wallets) => wallets.filter((wallet) => {
8
+ const metadata = getWalletBookWallet(walletBook, wallet.key, wallet.walletFallback);
9
+ if (wallet.isInstalledOnBrowser()) {
10
+ return true;
11
+ }
12
+ else if (isEmbeddedConnector(wallet)) {
13
+ return true;
14
+ }
15
+ else if (metadata.showOnlyIfInstalled) {
16
+ return false;
17
+ }
18
+ else if (!isMobile()) {
19
+ return true;
20
+ }
21
+ else {
22
+ return handleMobileWalletFilter(walletBook, wallet.key, metadata);
23
+ }
24
+ });
25
+
26
+ export { filterWalletsForPlatform };
@@ -0,0 +1 @@
1
+ export * from './filterWalletsForPlatform';
@@ -0,0 +1,103 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
7
+ var getApiProviders = require('../getApiProviders/getApiProviders.cjs');
8
+ var getEnabledProviders = require('../getEnabledProviders/getEnabledProviders.cjs');
9
+ var filterWalletsForPlatform = require('./filterWalletsForPlatform/filterWalletsForPlatform.cjs');
10
+ var applyLinksOverrides = require('./applyLinksOverrides/applyLinksOverrides.cjs');
11
+ var _const = require('./const.cjs');
12
+
13
+ const getSupportedWallets = (args) => {
14
+ var _a;
15
+ const { appLogoUrl = '', appName = '', coinbaseWalletPreference, chainRpcProviders, deepLinkPreference, flowNetwork, mobileExperience = 'in-app-browser', networkConfigurations = {
16
+ cosmos: [],
17
+ eclipse: [],
18
+ evm: [],
19
+ solana: [],
20
+ starknet: [],
21
+ }, settings, skipMemo = false, walletConnectProjectId = '', walletConnectorsProp, walletUiUtils = undefined, walletBook, walletConnectPreferredChains, } = args;
22
+ let walletConnectors = [];
23
+ if (!skipMemo && walletConnectors.length > 0) {
24
+ return walletConnectors;
25
+ }
26
+ const eclipseNetworkConfigs = (networkConfigurations === null || networkConfigurations === void 0 ? void 0 : networkConfigurations.eclipse) || [];
27
+ const evmNetworkConfigs = (networkConfigurations === null || networkConfigurations === void 0 ? void 0 : networkConfigurations.evm) || [];
28
+ const solanaNetworkConfigs = (networkConfigurations === null || networkConfigurations === void 0 ? void 0 : networkConfigurations.solana) || [];
29
+ const cosmosNetworkConfigs = (networkConfigurations === null || networkConfigurations === void 0 ? void 0 : networkConfigurations.cosmos) || [];
30
+ const starknetNetworkConfigs = (networkConfigurations === null || networkConfigurations === void 0 ? void 0 : networkConfigurations.starknet) || [];
31
+ const apiProviders = getApiProviders.getApiProviders(getEnabledProviders.getEnabledProviders(settings.providers));
32
+ const disabledConnectors = (_a = settings.sdk.disabledWalletConnectors) !== null && _a !== void 0 ? _a : [];
33
+ const opts = {
34
+ apiProviders,
35
+ appLogoUrl,
36
+ appName,
37
+ chainRpcProviders,
38
+ coinbaseWalletPreference,
39
+ cosmosNetworks: cosmosNetworkConfigs,
40
+ deepLinkPreference,
41
+ eclipseNetworks: eclipseNetworkConfigs,
42
+ evmNetworks: evmNetworkConfigs,
43
+ flowNetwork,
44
+ mobileExperience,
45
+ projectId: walletConnectProjectId,
46
+ settings,
47
+ solNetworks: solanaNetworkConfigs,
48
+ starknetNetworks: starknetNetworkConfigs,
49
+ walletBook,
50
+ walletConnectPreferredChains,
51
+ walletConnectorEventsEmitter: walletConnectorCore.walletConnectorEvents,
52
+ walletUiUtils: walletUiUtils || _const.defaultWalletUiUtils,
53
+ };
54
+ const allWalletConnectors = walletConnectorsProp
55
+ .map((getWalletConnectorConstructors) => getWalletConnectorConstructors(opts))
56
+ .flat()
57
+ .map((walletConnectorConstructor) => {
58
+ try {
59
+ // This may contain third party code so we must be ready for anything
60
+ return new walletConnectorConstructor(opts);
61
+ }
62
+ catch (error) {
63
+ walletConnectorCore.logger.error(`Failed to construct wallet ${walletConnectorConstructor.name}`, error);
64
+ return undefined;
65
+ }
66
+ })
67
+ // filter out undefined and disabled connectors
68
+ .filter((walletConnector) => {
69
+ var _a;
70
+ return walletConnector &&
71
+ (!((_a = walletConnector.metadata) === null || _a === void 0 ? void 0 : _a.id) ||
72
+ !disabledConnectors.includes(walletConnector.metadata.id));
73
+ })
74
+ // initialize the wallet connector if it's not a WalletConnect connector
75
+ // or just the generic 'walletconnect' connector, not other WC connectors
76
+ .map((walletConnector) => {
77
+ if (!(walletConnector === null || walletConnector === void 0 ? void 0 : walletConnector.isWalletConnect) ||
78
+ walletConnector.key === 'walletconnect') {
79
+ walletConnector === null || walletConnector === void 0 ? void 0 : walletConnector.init();
80
+ }
81
+ return walletConnector;
82
+ })
83
+ // applies custom filter defined in the wallet connector
84
+ .filter((walletConnector) => walletConnector === null || walletConnector === void 0 ? void 0 : walletConnector.filter())
85
+ .map((walletConnector) => walletConnector.getMobileOrInstalledWallet());
86
+ // Filter out duplicated wallets (WC vs. non-WC)
87
+ const nonDuplicatedWalletConnectors = allWalletConnectors.filter((walletConnector) => {
88
+ if (!walletConnector.isWalletConnect)
89
+ return true;
90
+ // if current wallet is WalletConnect, check if there is another wallet with the same key that is
91
+ // not WalletConnect
92
+ // if there is, return false(filter out WC wallet)
93
+ // if there is no other wallet with the same key that is not WalletConnect, return true (keep WC wallet)
94
+ return !allWalletConnectors.some((wc) => wc.key === walletConnector.key &&
95
+ !wc.isWalletConnect &&
96
+ wc.isInstalledOnBrowser());
97
+ });
98
+ const filteredWalletConnectors = filterWalletsForPlatform.filterWalletsForPlatform(walletBook, nonDuplicatedWalletConnectors);
99
+ walletConnectors = applyLinksOverrides.applyLinksOverrides(walletBook, filteredWalletConnectors);
100
+ return walletConnectors;
101
+ };
102
+
103
+ exports.getSupportedWallets = getSupportedWallets;
@@ -0,0 +1,2 @@
1
+ import { GetSupportedWallets } from '../../types';
2
+ export declare const getSupportedWallets: GetSupportedWallets;
@@ -0,0 +1,99 @@
1
+ 'use client'
2
+ import { logger, walletConnectorEvents } from '@dynamic-labs/wallet-connector-core';
3
+ import { getApiProviders } from '../getApiProviders/getApiProviders.js';
4
+ import { getEnabledProviders } from '../getEnabledProviders/getEnabledProviders.js';
5
+ import { filterWalletsForPlatform } from './filterWalletsForPlatform/filterWalletsForPlatform.js';
6
+ import { applyLinksOverrides } from './applyLinksOverrides/applyLinksOverrides.js';
7
+ import { defaultWalletUiUtils } from './const.js';
8
+
9
+ const getSupportedWallets = (args) => {
10
+ var _a;
11
+ const { appLogoUrl = '', appName = '', coinbaseWalletPreference, chainRpcProviders, deepLinkPreference, flowNetwork, mobileExperience = 'in-app-browser', networkConfigurations = {
12
+ cosmos: [],
13
+ eclipse: [],
14
+ evm: [],
15
+ solana: [],
16
+ starknet: [],
17
+ }, settings, skipMemo = false, walletConnectProjectId = '', walletConnectorsProp, walletUiUtils = undefined, walletBook, walletConnectPreferredChains, } = args;
18
+ let walletConnectors = [];
19
+ if (!skipMemo && walletConnectors.length > 0) {
20
+ return walletConnectors;
21
+ }
22
+ const eclipseNetworkConfigs = (networkConfigurations === null || networkConfigurations === void 0 ? void 0 : networkConfigurations.eclipse) || [];
23
+ const evmNetworkConfigs = (networkConfigurations === null || networkConfigurations === void 0 ? void 0 : networkConfigurations.evm) || [];
24
+ const solanaNetworkConfigs = (networkConfigurations === null || networkConfigurations === void 0 ? void 0 : networkConfigurations.solana) || [];
25
+ const cosmosNetworkConfigs = (networkConfigurations === null || networkConfigurations === void 0 ? void 0 : networkConfigurations.cosmos) || [];
26
+ const starknetNetworkConfigs = (networkConfigurations === null || networkConfigurations === void 0 ? void 0 : networkConfigurations.starknet) || [];
27
+ const apiProviders = getApiProviders(getEnabledProviders(settings.providers));
28
+ const disabledConnectors = (_a = settings.sdk.disabledWalletConnectors) !== null && _a !== void 0 ? _a : [];
29
+ const opts = {
30
+ apiProviders,
31
+ appLogoUrl,
32
+ appName,
33
+ chainRpcProviders,
34
+ coinbaseWalletPreference,
35
+ cosmosNetworks: cosmosNetworkConfigs,
36
+ deepLinkPreference,
37
+ eclipseNetworks: eclipseNetworkConfigs,
38
+ evmNetworks: evmNetworkConfigs,
39
+ flowNetwork,
40
+ mobileExperience,
41
+ projectId: walletConnectProjectId,
42
+ settings,
43
+ solNetworks: solanaNetworkConfigs,
44
+ starknetNetworks: starknetNetworkConfigs,
45
+ walletBook,
46
+ walletConnectPreferredChains,
47
+ walletConnectorEventsEmitter: walletConnectorEvents,
48
+ walletUiUtils: walletUiUtils || defaultWalletUiUtils,
49
+ };
50
+ const allWalletConnectors = walletConnectorsProp
51
+ .map((getWalletConnectorConstructors) => getWalletConnectorConstructors(opts))
52
+ .flat()
53
+ .map((walletConnectorConstructor) => {
54
+ try {
55
+ // This may contain third party code so we must be ready for anything
56
+ return new walletConnectorConstructor(opts);
57
+ }
58
+ catch (error) {
59
+ logger.error(`Failed to construct wallet ${walletConnectorConstructor.name}`, error);
60
+ return undefined;
61
+ }
62
+ })
63
+ // filter out undefined and disabled connectors
64
+ .filter((walletConnector) => {
65
+ var _a;
66
+ return walletConnector &&
67
+ (!((_a = walletConnector.metadata) === null || _a === void 0 ? void 0 : _a.id) ||
68
+ !disabledConnectors.includes(walletConnector.metadata.id));
69
+ })
70
+ // initialize the wallet connector if it's not a WalletConnect connector
71
+ // or just the generic 'walletconnect' connector, not other WC connectors
72
+ .map((walletConnector) => {
73
+ if (!(walletConnector === null || walletConnector === void 0 ? void 0 : walletConnector.isWalletConnect) ||
74
+ walletConnector.key === 'walletconnect') {
75
+ walletConnector === null || walletConnector === void 0 ? void 0 : walletConnector.init();
76
+ }
77
+ return walletConnector;
78
+ })
79
+ // applies custom filter defined in the wallet connector
80
+ .filter((walletConnector) => walletConnector === null || walletConnector === void 0 ? void 0 : walletConnector.filter())
81
+ .map((walletConnector) => walletConnector.getMobileOrInstalledWallet());
82
+ // Filter out duplicated wallets (WC vs. non-WC)
83
+ const nonDuplicatedWalletConnectors = allWalletConnectors.filter((walletConnector) => {
84
+ if (!walletConnector.isWalletConnect)
85
+ return true;
86
+ // if current wallet is WalletConnect, check if there is another wallet with the same key that is
87
+ // not WalletConnect
88
+ // if there is, return false(filter out WC wallet)
89
+ // if there is no other wallet with the same key that is not WalletConnect, return true (keep WC wallet)
90
+ return !allWalletConnectors.some((wc) => wc.key === walletConnector.key &&
91
+ !wc.isWalletConnect &&
92
+ wc.isInstalledOnBrowser());
93
+ });
94
+ const filteredWalletConnectors = filterWalletsForPlatform(walletBook, nonDuplicatedWalletConnectors);
95
+ walletConnectors = applyLinksOverrides(walletBook, filteredWalletConnectors);
96
+ return walletConnectors;
97
+ };
98
+
99
+ export { getSupportedWallets };
@@ -0,0 +1,34 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var utils = require('@dynamic-labs/utils');
7
+ var walletBook = require('@dynamic-labs/wallet-book');
8
+
9
+ const handleMobileWalletFilter = (walletBook$1, walletKey, metadata) => {
10
+ if (!metadata.mobile)
11
+ return false;
12
+ /**
13
+ * WalletConnect provides a "universal" and "native" deep link. They recommend using
14
+ * the universal deep link over the native one due to UX differences, and our current
15
+ * implementation uses only universal. This means we need to filter for wallets that
16
+ * have a universal deep link available.
17
+ */
18
+ const hasWalletConnectLink = Boolean(metadata.mobile.universal) || Boolean(metadata.mobile.native);
19
+ const isWalletConnectWallet = metadata.walletConnect !== undefined;
20
+ if (utils.isIPad() || utils.isIPhone()) {
21
+ const hasIOSLink = Boolean(walletBook.getWalletLinks(walletBook$1, walletKey).ios);
22
+ return !isWalletConnectWallet
23
+ ? hasIOSLink
24
+ : hasIOSLink && hasWalletConnectLink;
25
+ }
26
+ else {
27
+ const hasAndroidLink = Boolean(walletBook.getWalletLinks(walletBook$1, walletKey).android);
28
+ return !isWalletConnectWallet
29
+ ? hasAndroidLink
30
+ : hasAndroidLink && hasWalletConnectLink;
31
+ }
32
+ };
33
+
34
+ exports.handleMobileWalletFilter = handleMobileWalletFilter;
@@ -0,0 +1,2 @@
1
+ import { WalletBookSchema, WalletSchema } from '@dynamic-labs/wallet-book';
2
+ export declare const handleMobileWalletFilter: (walletBook: WalletBookSchema, walletKey: string, metadata: WalletSchema) => boolean;
@@ -0,0 +1,30 @@
1
+ 'use client'
2
+ import { isIPad, isIPhone } from '@dynamic-labs/utils';
3
+ import { getWalletLinks } from '@dynamic-labs/wallet-book';
4
+
5
+ const handleMobileWalletFilter = (walletBook, walletKey, metadata) => {
6
+ if (!metadata.mobile)
7
+ return false;
8
+ /**
9
+ * WalletConnect provides a "universal" and "native" deep link. They recommend using
10
+ * the universal deep link over the native one due to UX differences, and our current
11
+ * implementation uses only universal. This means we need to filter for wallets that
12
+ * have a universal deep link available.
13
+ */
14
+ const hasWalletConnectLink = Boolean(metadata.mobile.universal) || Boolean(metadata.mobile.native);
15
+ const isWalletConnectWallet = metadata.walletConnect !== undefined;
16
+ if (isIPad() || isIPhone()) {
17
+ const hasIOSLink = Boolean(getWalletLinks(walletBook, walletKey).ios);
18
+ return !isWalletConnectWallet
19
+ ? hasIOSLink
20
+ : hasIOSLink && hasWalletConnectLink;
21
+ }
22
+ else {
23
+ const hasAndroidLink = Boolean(getWalletLinks(walletBook, walletKey).android);
24
+ return !isWalletConnectWallet
25
+ ? hasAndroidLink
26
+ : hasAndroidLink && hasWalletConnectLink;
27
+ }
28
+ };
29
+
30
+ export { handleMobileWalletFilter };
@@ -0,0 +1 @@
1
+ export * from './handleMobileWalletFilter';
@@ -0,0 +1 @@
1
+ export * from './getSupportedWallets';
@@ -0,0 +1,5 @@
1
+ export { generateMessageToSign } from './message';
2
+ export { getEnabledProviders } from './getEnabledProviders';
3
+ export { getEnabledWallets } from './getEnabledWallets';
4
+ export { getSupportedWallets } from './getSupportedWallets';
5
+ export { getSupportedChainsForWalletConnector } from './getSupportedChainsForWalletConnector';
@@ -0,0 +1 @@
1
+ export * from './message';
@@ -1,178 +0,0 @@
1
- 'use client'
2
- 'use strict';
3
-
4
- Object.defineProperty(exports, '__esModule', { value: true });
5
-
6
- var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
7
- var walletBook = require('@dynamic-labs/wallet-book');
8
- var utils = require('@dynamic-labs/utils');
9
- var sdkApiCore = require('@dynamic-labs/sdk-api-core');
10
- var getApiProviders = require('./utils/getApiProviders.cjs');
11
-
12
- let wallets = [];
13
- const defaultWalletUiUtils = {
14
- createPassword: () => {
15
- throw Error('createPassword not implemented');
16
- },
17
- disabledConfirmationOnce: () => {
18
- throw Error('disabledConfirmationOnce, not implemented');
19
- },
20
- enterPassword: () => {
21
- throw Error('enterPassword not implemented');
22
- },
23
- sendTransaction: () => {
24
- throw Error('requestSendTransactionConfirmation not implemented');
25
- },
26
- signMessage: () => {
27
- throw Error('signMessage not implemented');
28
- },
29
- syncWallet: () => {
30
- throw Error('syncWallet not implemented');
31
- },
32
- };
33
- const getSupportedWallets = (args) => {
34
- const { appLogoUrl = '', appName = '', coinbaseWalletPreference, chainRpcProviders, deepLinkPreference, flowNetwork, mobileExperience = 'in-app-browser', networkConfigurations = { cosmos: [], evm: [], solana: [], starknet: [] }, settings, skipMemo = false, walletConnectProjectId = '', walletConnectorsProp, walletUiUtils = undefined, walletBook, walletConnectPreferredChains, } = args;
35
- if (!skipMemo && wallets.length > 0) {
36
- return wallets;
37
- }
38
- const evmNetworkConfigs = (networkConfigurations === null || networkConfigurations === void 0 ? void 0 : networkConfigurations.evm) || [];
39
- const solanaNetworkConfigs = (networkConfigurations === null || networkConfigurations === void 0 ? void 0 : networkConfigurations.solana) || [];
40
- const cosmosNetworkConfigs = (networkConfigurations === null || networkConfigurations === void 0 ? void 0 : networkConfigurations.cosmos) || [];
41
- const starknetNetworkConfigs = (networkConfigurations === null || networkConfigurations === void 0 ? void 0 : networkConfigurations.starknet) || [];
42
- const apiProviders = getApiProviders.getApiProviders(getEnabledProviders(settings.providers));
43
- const opts = {
44
- apiProviders,
45
- appLogoUrl,
46
- appName,
47
- chainRpcProviders,
48
- coinbaseWalletPreference,
49
- cosmosNetworks: cosmosNetworkConfigs,
50
- deepLinkPreference,
51
- evmNetworks: evmNetworkConfigs,
52
- flowNetwork,
53
- mobileExperience,
54
- projectId: walletConnectProjectId,
55
- settings,
56
- solNetworks: solanaNetworkConfigs,
57
- starknetNetworks: starknetNetworkConfigs,
58
- walletBook,
59
- walletConnectPreferredChains,
60
- walletUiUtils: walletUiUtils || defaultWalletUiUtils,
61
- };
62
- const allWallets = walletConnectorsProp
63
- .map((walletConnector) => walletConnector(opts))
64
- .flat()
65
- .map((wallet) => {
66
- try {
67
- // This may contain third party code so we must be ready for anything
68
- return new wallet(opts);
69
- }
70
- catch (error) {
71
- walletConnectorCore.logger.error(`Failed to construct wallet ${wallet.name}`, error);
72
- return undefined;
73
- }
74
- })
75
- .filter((wallet) => wallet === null || wallet === void 0 ? void 0 : wallet.filter())
76
- .map((wallet) => wallet.getMobileOrInstalledWallet());
77
- // Memoize the wallets
78
- const filteredWallets = filterWalletsForPlatform(walletBook, allWallets);
79
- wallets = applyLinksOverrides(walletBook, filteredWallets);
80
- return wallets;
81
- };
82
- const applyLinksOverrides = (walletBook$1, wallets) => wallets.map((wallet) => {
83
- const metadata = walletBook.getWalletBookWallet(walletBook$1, wallet.key, wallet.walletFallback);
84
- if (metadata.switchNetworkOnlyFromWallet !== undefined) {
85
- wallet.switchNetworkOnlyFromWallet = metadata.switchNetworkOnlyFromWallet;
86
- }
87
- return wallet;
88
- });
89
- const filterWalletsForPlatform = (walletBook$1, wallets) => wallets.filter((wallet) => {
90
- const metadata = walletBook.getWalletBookWallet(walletBook$1, wallet.key, wallet.walletFallback);
91
- if (wallet.isInstalledOnBrowser()) {
92
- return true;
93
- }
94
- else if (walletConnectorCore.isEmbeddedConnector(wallet)) {
95
- return true;
96
- }
97
- else if (metadata.showOnlyIfInstalled) {
98
- return false;
99
- }
100
- else if (!utils.isMobile()) {
101
- return true;
102
- }
103
- else {
104
- return handleMobileWalletFilter(walletBook$1, wallet.key, metadata);
105
- }
106
- });
107
- const handleMobileWalletFilter = (walletBook$1, walletKey, metadata) => {
108
- if (!metadata.mobile)
109
- return false;
110
- /**
111
- * WalletConnect provides a "universal" and "native" deep link. They recommend using
112
- * the universal deep link over the native one due to UX differences, and our current
113
- * implementation uses only universal. This means we need to filter for wallets that
114
- * have a universal deep link available.
115
- */
116
- const hasWalletConnectLink = Boolean(metadata.mobile.universal) || Boolean(metadata.mobile.native);
117
- const isWalletConnectWallet = metadata.walletConnect !== undefined;
118
- if (utils.isIPad() || utils.isIPhone()) {
119
- const hasIOSLink = Boolean(walletBook.getWalletLinks(walletBook$1, walletKey).ios);
120
- return !isWalletConnectWallet
121
- ? hasIOSLink
122
- : hasIOSLink && hasWalletConnectLink;
123
- }
124
- else {
125
- const hasAndroidLink = Boolean(walletBook.getWalletLinks(walletBook$1, walletKey).android);
126
- return !isWalletConnectWallet
127
- ? hasAndroidLink
128
- : hasAndroidLink && hasWalletConnectLink;
129
- }
130
- };
131
- const chainStringToChains = {
132
- 'eip155:1': ['ETH', 'EVM'],
133
- 'flow:mainnet': ['FLOW'],
134
- };
135
- const getSupportedChainsForWalletConnector = (walletBook$1, walletConnector) => {
136
- var _a;
137
- const metadata = walletBook.getWalletBookWallet(walletBook$1, walletConnector.key, walletConnector.walletFallback);
138
- /**
139
- * chains could contain multiple eth networks eg
140
- * "eip155:1",
141
- * "eip155:10",
142
- * "eip155:56",
143
- * "eip155:100",
144
- *
145
- * so we will use a set to ensure uniqueness
146
- */
147
- const chainSet = new Set();
148
- const chainStringList = (_a = metadata.chains) !== null && _a !== void 0 ? _a : [];
149
- chainStringList.forEach((chainString) => {
150
- const chains = chainStringToChains[chainString];
151
- chains === null || chains === void 0 ? void 0 : chains.forEach((chain) => {
152
- chainSet.add(chain);
153
- });
154
- });
155
- walletConnector.supportedChains.forEach((chain) => {
156
- chainSet.add(chain);
157
- });
158
- return [...chainSet];
159
- };
160
- const getEnabledWallets = (props) => {
161
- const supportedWallets = getSupportedWallets(props.getSupportedWalletOpts);
162
- const allEnabledWallets = supportedWallets.filter((wallet) => props.enabledChains.some((chain) => getSupportedChainsForWalletConnector(props.getSupportedWalletOpts.walletBook, wallet).includes(chain)) || wallet.key === 'magiclink');
163
- return allEnabledWallets;
164
- };
165
- // get list of providers enabled in the sense that we should have wallet connectors for them
166
- // note: magic and turnkey are considered enabled when a provider exists (for magic, a providerProjectId exists)
167
- const getEnabledProviders = (providers) => {
168
- var _a;
169
- return (_a = providers === null || providers === void 0 ? void 0 : providers.filter((provider) => Boolean(provider.enabledAt) ||
170
- (provider.provider === sdkApiCore.ProviderEnum.MagicLink &&
171
- Boolean(provider.providerProjectId)) ||
172
- provider.provider === sdkApiCore.ProviderEnum.Turnkey)) !== null && _a !== void 0 ? _a : [];
173
- };
174
-
175
- exports.getEnabledProviders = getEnabledProviders;
176
- exports.getEnabledWallets = getEnabledWallets;
177
- exports.getSupportedChainsForWalletConnector = getSupportedChainsForWalletConnector;
178
- exports.getSupportedWallets = getSupportedWallets;
@@ -1,11 +0,0 @@
1
- import { Chain, InternalWalletConnector } from '@dynamic-labs/wallet-connector-core';
2
- import { WalletBookSchema } from '@dynamic-labs/wallet-book';
3
- import { Provider } from '@dynamic-labs/sdk-api-core';
4
- import { GetSupportedWallets, GetSupportedWalletsOpts } from './types';
5
- export declare const getSupportedWallets: GetSupportedWallets;
6
- export declare const getSupportedChainsForWalletConnector: (walletBook: WalletBookSchema, walletConnector: InternalWalletConnector) => Chain[];
7
- export declare const getEnabledWallets: (props: {
8
- enabledChains: Chain[];
9
- getSupportedWalletOpts: GetSupportedWalletsOpts;
10
- }) => InternalWalletConnector[];
11
- export declare const getEnabledProviders: (providers: Provider[] | undefined) => Provider[];