@dynamic-labs/multi-wallet 0.17.16 → 0.17.100-viem.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/CHANGELOG.md CHANGED
@@ -1,4 +1,6 @@
1
1
 
2
+ ### [0.17.100-viem.1](https://github.com/dynamic-labs/DynamicAuth/compare/v0.17.100-viem.0...v0.17.100-viem.1) (2023-06-28)
3
+
2
4
  ### [0.17.16](https://github.com/dynamic-labs/DynamicAuth/compare/v0.17.15...v0.17.16) (2023-06-28)
3
5
 
4
6
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/multi-wallet",
3
- "version": "0.17.16",
3
+ "version": "0.17.100-viem.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/dynamic-labs/DynamicAuth.git",
@@ -8,13 +8,12 @@
8
8
  },
9
9
  "dependencies": {
10
10
  "@dynamic-labs/sdk-api": "0.0.198",
11
- "ethers": "5.7.2",
12
11
  "tslib": "2.4.1",
13
- "@dynamic-labs/rpc-providers": "0.17.16",
14
- "@dynamic-labs/types": "0.17.16",
15
- "@dynamic-labs/utils": "0.17.16",
16
- "@dynamic-labs/wallet-book": "0.17.16",
17
- "@dynamic-labs/wallet-connector-core": "0.17.16"
12
+ "@dynamic-labs/rpc-providers": "0.17.100-viem.1",
13
+ "@dynamic-labs/types": "0.17.100-viem.1",
14
+ "@dynamic-labs/utils": "0.17.100-viem.1",
15
+ "@dynamic-labs/wallet-book": "0.17.100-viem.1",
16
+ "@dynamic-labs/wallet-connector-core": "0.17.100-viem.1"
18
17
  },
19
18
  "devDependencies": {
20
19
  "@walletconnect/types": "2.4.2"
@@ -38,5 +37,7 @@
38
37
  },
39
38
  "./package.json": "./package.json"
40
39
  },
41
- "peerDependencies": {}
40
+ "peerDependencies": {
41
+ "viem": "^1.1.0"
42
+ }
42
43
  }
package/src/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export * from './multi-wallet';
2
- export * from './types';
3
- export { generateMessageToSign } from './utils/message';
1
+ export * from './multi-wallet';
2
+ export * from './types';
3
+ export { generateMessageToSign } from './utils/message';
@@ -7,134 +7,134 @@ var walletBook = require('@dynamic-labs/wallet-book');
7
7
  var utils = require('@dynamic-labs/utils');
8
8
  var getApiProviders = require('./utils/getApiProviders.cjs');
9
9
 
10
- let wallets = [];
11
- const defaultWalletUiUtils = {
12
- disabledConfirmationOnce: () => {
13
- throw Error('disabledConfirmationOnce, not implemented');
14
- },
15
- sendTransaction: () => {
16
- throw Error('requestSendTransactionConfirmation not implemented');
17
- },
18
- signMessage: () => {
19
- throw Error('signMessage not implemented');
20
- },
21
- };
22
- const getSupportedWallets = (args) => {
23
- const { appLogoUrl = '', appName = '', chainRpcProviders, flowNetwork, isWalletConnectV2Enabled = false, networkConfigurations = { cosmos: [], evm: [], solana: [], starknet: [] }, customerApiProviders = [], skipMemo = false, walletConnectProjectId = '', walletConnectorsProp, walletUiUtils = undefined, walletConnectV1Bridge, } = args;
24
- if (!skipMemo && wallets.length > 0) {
25
- return wallets;
26
- }
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 apiProviders = getApiProviders.getApiProviders(customerApiProviders);
31
- const opts = {
32
- apiProviders,
33
- appLogoUrl,
34
- appName,
35
- chainRpcProviders,
36
- cosmosNetworks: cosmosNetworkConfigs,
37
- evmNetworks: evmNetworkConfigs,
38
- flowNetwork,
39
- isWalletConnectV2Enabled,
40
- projectId: walletConnectProjectId,
41
- solNetworks: solanaNetworkConfigs,
42
- walletConnectV1Bridge,
43
- walletUiUtils: walletUiUtils || defaultWalletUiUtils,
44
- };
45
- const allWallets = walletConnectorsProp
46
- .map((walletConnector) => walletConnector(opts))
47
- .flat()
48
- .map((wallet) => new wallet(opts).getMobileOrInstalledWallet());
49
- // Memoize the wallets
50
- const filteredWallets = filterWalletsForPlatform(allWallets);
51
- wallets = applyLinksOverrides(filteredWallets);
52
- return wallets;
53
- };
54
- const applyLinksOverrides = (wallets) => wallets.map((wallet) => {
55
- const metadata = walletBook.getWalletBookWallet(wallet.name);
56
- if (metadata.switchNetworkOnlyFromWallet !== undefined) {
57
- wallet.switchNetworkOnlyFromWallet = metadata.switchNetworkOnlyFromWallet;
58
- }
59
- return wallet;
60
- });
61
- const filterWalletsForPlatform = (wallets) => wallets.filter((wallet) => {
62
- const metadata = walletBook.getWalletBookWallet(wallet.name);
63
- if (wallet.isInstalledOnBrowser()) {
64
- return true;
65
- }
66
- else if (walletConnectorCore.isEmbeddedConnector(wallet)) {
67
- return true;
68
- }
69
- else if (metadata.showOnlyIfInstalled) {
70
- return false;
71
- }
72
- else if (!utils.isMobile()) {
73
- return true;
74
- }
75
- else {
76
- return handleMobileWalletFilter(wallet.name, metadata);
77
- }
78
- });
79
- const handleMobileWalletFilter = (walletName, metadata) => {
80
- if (!metadata.mobile)
81
- return false;
82
- /**
83
- * WalletConnect provides a "universal" and "native" deep link. They recommend using
84
- * the universal deep link over the native one due to UX differences, and our current
85
- * implementation uses only universal. This means we need to filter for wallets that
86
- * have a universal deep link available.
87
- */
88
- const hasWalletConnectLink = Boolean(metadata.mobile.universal) || Boolean(metadata.mobile.native);
89
- const isWalletConnectWallet = metadata.walletConnect !== undefined;
90
- if (utils.isIPad() || utils.isIPhone()) {
91
- const hasIOSLink = Boolean(walletBook.getWalletLinks(walletName).ios);
92
- return !isWalletConnectWallet
93
- ? hasIOSLink
94
- : hasIOSLink && hasWalletConnectLink;
95
- }
96
- else {
97
- const hasAndroidLink = Boolean(walletBook.getWalletLinks(walletName).android);
98
- return !isWalletConnectWallet
99
- ? hasAndroidLink
100
- : hasAndroidLink && hasWalletConnectLink;
101
- }
102
- };
103
- const chainStringToChains = {
104
- 'eip155:1': ['ETH', 'EVM'],
105
- 'flow:mainnet': ['FLOW'],
106
- };
107
- const getSupportedChainsForWalletConnector = (walletConnector) => {
108
- var _a;
109
- const metadata = walletBook.getWalletBookWallet(walletConnector.name);
110
- /**
111
- * chains could contain multiple eth networks eg
112
- * "eip155:1",
113
- * "eip155:10",
114
- * "eip155:56",
115
- * "eip155:100",
116
- *
117
- * so we will use a set to ensure uniqueness
118
- */
119
- const chainSet = new Set();
120
- const chainStringList = (_a = metadata.chains) !== null && _a !== void 0 ? _a : [];
121
- chainStringList.forEach((chainString) => {
122
- const chains = chainStringToChains[chainString];
123
- chains === null || chains === void 0 ? void 0 : chains.forEach((chain) => {
124
- chainSet.add(chain);
125
- });
126
- });
127
- walletConnector.supportedChains.forEach((chain) => {
128
- chainSet.add(chain);
129
- });
130
- return [...chainSet];
131
- };
132
- const getEnabledWallets = (props) => {
133
- const supportedWallets = getSupportedWallets(props.getSupportedWalletOpts);
134
- const allEnabledWallets = supportedWallets.filter((wallet) => (props.enabledChains.some((chain) => getSupportedChainsForWalletConnector(wallet).includes(chain)) &&
135
- wallet.isInstalledOnBrowser() === props.installed) ||
136
- wallet.key === 'magiclink');
137
- return allEnabledWallets;
10
+ let wallets = [];
11
+ const defaultWalletUiUtils = {
12
+ disabledConfirmationOnce: () => {
13
+ throw Error('disabledConfirmationOnce, not implemented');
14
+ },
15
+ sendTransaction: () => {
16
+ throw Error('requestSendTransactionConfirmation not implemented');
17
+ },
18
+ signMessage: () => {
19
+ throw Error('signMessage not implemented');
20
+ },
21
+ };
22
+ const getSupportedWallets = (args) => {
23
+ const { appLogoUrl = '', appName = '', chainRpcProviders, flowNetwork, isWalletConnectV2Enabled = false, networkConfigurations = { cosmos: [], evm: [], solana: [], starknet: [] }, customerApiProviders = [], skipMemo = false, walletConnectProjectId = '', walletConnectorsProp, walletUiUtils = undefined, walletConnectV1Bridge, } = args;
24
+ if (!skipMemo && wallets.length > 0) {
25
+ return wallets;
26
+ }
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 apiProviders = getApiProviders.getApiProviders(customerApiProviders);
31
+ const opts = {
32
+ apiProviders,
33
+ appLogoUrl,
34
+ appName,
35
+ chainRpcProviders,
36
+ cosmosNetworks: cosmosNetworkConfigs,
37
+ evmNetworks: evmNetworkConfigs,
38
+ flowNetwork,
39
+ isWalletConnectV2Enabled,
40
+ projectId: walletConnectProjectId,
41
+ solNetworks: solanaNetworkConfigs,
42
+ walletConnectV1Bridge,
43
+ walletUiUtils: walletUiUtils || defaultWalletUiUtils,
44
+ };
45
+ const allWallets = walletConnectorsProp
46
+ .map((walletConnector) => walletConnector(opts))
47
+ .flat()
48
+ .map((wallet) => new wallet(opts).getMobileOrInstalledWallet());
49
+ // Memoize the wallets
50
+ const filteredWallets = filterWalletsForPlatform(allWallets);
51
+ wallets = applyLinksOverrides(filteredWallets);
52
+ return wallets;
53
+ };
54
+ const applyLinksOverrides = (wallets) => wallets.map((wallet) => {
55
+ const metadata = walletBook.getWalletBookWallet(wallet.name);
56
+ if (metadata.switchNetworkOnlyFromWallet !== undefined) {
57
+ wallet.switchNetworkOnlyFromWallet = metadata.switchNetworkOnlyFromWallet;
58
+ }
59
+ return wallet;
60
+ });
61
+ const filterWalletsForPlatform = (wallets) => wallets.filter((wallet) => {
62
+ const metadata = walletBook.getWalletBookWallet(wallet.name);
63
+ if (wallet.isInstalledOnBrowser()) {
64
+ return true;
65
+ }
66
+ else if (walletConnectorCore.isEmbeddedConnector(wallet)) {
67
+ return true;
68
+ }
69
+ else if (metadata.showOnlyIfInstalled) {
70
+ return false;
71
+ }
72
+ else if (!utils.isMobile()) {
73
+ return true;
74
+ }
75
+ else {
76
+ return handleMobileWalletFilter(wallet.name, metadata);
77
+ }
78
+ });
79
+ const handleMobileWalletFilter = (walletName, metadata) => {
80
+ if (!metadata.mobile)
81
+ return false;
82
+ /**
83
+ * WalletConnect provides a "universal" and "native" deep link. They recommend using
84
+ * the universal deep link over the native one due to UX differences, and our current
85
+ * implementation uses only universal. This means we need to filter for wallets that
86
+ * have a universal deep link available.
87
+ */
88
+ const hasWalletConnectLink = Boolean(metadata.mobile.universal) || Boolean(metadata.mobile.native);
89
+ const isWalletConnectWallet = metadata.walletConnect !== undefined;
90
+ if (utils.isIPad() || utils.isIPhone()) {
91
+ const hasIOSLink = Boolean(walletBook.getWalletLinks(walletName).ios);
92
+ return !isWalletConnectWallet
93
+ ? hasIOSLink
94
+ : hasIOSLink && hasWalletConnectLink;
95
+ }
96
+ else {
97
+ const hasAndroidLink = Boolean(walletBook.getWalletLinks(walletName).android);
98
+ return !isWalletConnectWallet
99
+ ? hasAndroidLink
100
+ : hasAndroidLink && hasWalletConnectLink;
101
+ }
102
+ };
103
+ const chainStringToChains = {
104
+ 'eip155:1': ['ETH', 'EVM'],
105
+ 'flow:mainnet': ['FLOW'],
106
+ };
107
+ const getSupportedChainsForWalletConnector = (walletConnector) => {
108
+ var _a;
109
+ const metadata = walletBook.getWalletBookWallet(walletConnector.name);
110
+ /**
111
+ * chains could contain multiple eth networks eg
112
+ * "eip155:1",
113
+ * "eip155:10",
114
+ * "eip155:56",
115
+ * "eip155:100",
116
+ *
117
+ * so we will use a set to ensure uniqueness
118
+ */
119
+ const chainSet = new Set();
120
+ const chainStringList = (_a = metadata.chains) !== null && _a !== void 0 ? _a : [];
121
+ chainStringList.forEach((chainString) => {
122
+ const chains = chainStringToChains[chainString];
123
+ chains === null || chains === void 0 ? void 0 : chains.forEach((chain) => {
124
+ chainSet.add(chain);
125
+ });
126
+ });
127
+ walletConnector.supportedChains.forEach((chain) => {
128
+ chainSet.add(chain);
129
+ });
130
+ return [...chainSet];
131
+ };
132
+ const getEnabledWallets = (props) => {
133
+ const supportedWallets = getSupportedWallets(props.getSupportedWalletOpts);
134
+ const allEnabledWallets = supportedWallets.filter((wallet) => (props.enabledChains.some((chain) => getSupportedChainsForWalletConnector(wallet).includes(chain)) &&
135
+ wallet.isInstalledOnBrowser() === props.installed) ||
136
+ wallet.key === 'magiclink');
137
+ return allEnabledWallets;
138
138
  };
139
139
 
140
140
  exports.getEnabledWallets = getEnabledWallets;
@@ -1,9 +1,9 @@
1
- import { Chain, WalletConnector } from '@dynamic-labs/wallet-connector-core';
2
- import { GetSupportedWallets, GetSupportedWalletsOpts } from './types';
3
- export declare const getSupportedWallets: GetSupportedWallets;
4
- export declare const getSupportedChainsForWalletConnector: (walletConnector: WalletConnector) => Chain[];
5
- export declare const getEnabledWallets: (props: {
6
- enabledChains: Chain[];
7
- getSupportedWalletOpts: GetSupportedWalletsOpts;
8
- installed: boolean;
9
- }) => WalletConnector[];
1
+ import { Chain, WalletConnector } from '@dynamic-labs/wallet-connector-core';
2
+ import { GetSupportedWallets, GetSupportedWalletsOpts } from './types';
3
+ export declare const getSupportedWallets: GetSupportedWallets;
4
+ export declare const getSupportedChainsForWalletConnector: (walletConnector: WalletConnector) => Chain[];
5
+ export declare const getEnabledWallets: (props: {
6
+ enabledChains: Chain[];
7
+ getSupportedWalletOpts: GetSupportedWalletsOpts;
8
+ installed: boolean;
9
+ }) => WalletConnector[];
@@ -3,134 +3,134 @@ import { getWalletBookWallet, getWalletLinks } from '@dynamic-labs/wallet-book';
3
3
  import { isMobile, isIPad, isIPhone } from '@dynamic-labs/utils';
4
4
  import { getApiProviders } from './utils/getApiProviders.js';
5
5
 
6
- let wallets = [];
7
- const defaultWalletUiUtils = {
8
- disabledConfirmationOnce: () => {
9
- throw Error('disabledConfirmationOnce, not implemented');
10
- },
11
- sendTransaction: () => {
12
- throw Error('requestSendTransactionConfirmation not implemented');
13
- },
14
- signMessage: () => {
15
- throw Error('signMessage not implemented');
16
- },
17
- };
18
- const getSupportedWallets = (args) => {
19
- const { appLogoUrl = '', appName = '', chainRpcProviders, flowNetwork, isWalletConnectV2Enabled = false, networkConfigurations = { cosmos: [], evm: [], solana: [], starknet: [] }, customerApiProviders = [], skipMemo = false, walletConnectProjectId = '', walletConnectorsProp, walletUiUtils = undefined, walletConnectV1Bridge, } = args;
20
- if (!skipMemo && wallets.length > 0) {
21
- return wallets;
22
- }
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 apiProviders = getApiProviders(customerApiProviders);
27
- const opts = {
28
- apiProviders,
29
- appLogoUrl,
30
- appName,
31
- chainRpcProviders,
32
- cosmosNetworks: cosmosNetworkConfigs,
33
- evmNetworks: evmNetworkConfigs,
34
- flowNetwork,
35
- isWalletConnectV2Enabled,
36
- projectId: walletConnectProjectId,
37
- solNetworks: solanaNetworkConfigs,
38
- walletConnectV1Bridge,
39
- walletUiUtils: walletUiUtils || defaultWalletUiUtils,
40
- };
41
- const allWallets = walletConnectorsProp
42
- .map((walletConnector) => walletConnector(opts))
43
- .flat()
44
- .map((wallet) => new wallet(opts).getMobileOrInstalledWallet());
45
- // Memoize the wallets
46
- const filteredWallets = filterWalletsForPlatform(allWallets);
47
- wallets = applyLinksOverrides(filteredWallets);
48
- return wallets;
49
- };
50
- const applyLinksOverrides = (wallets) => wallets.map((wallet) => {
51
- const metadata = getWalletBookWallet(wallet.name);
52
- if (metadata.switchNetworkOnlyFromWallet !== undefined) {
53
- wallet.switchNetworkOnlyFromWallet = metadata.switchNetworkOnlyFromWallet;
54
- }
55
- return wallet;
56
- });
57
- const filterWalletsForPlatform = (wallets) => wallets.filter((wallet) => {
58
- const metadata = getWalletBookWallet(wallet.name);
59
- if (wallet.isInstalledOnBrowser()) {
60
- return true;
61
- }
62
- else if (isEmbeddedConnector(wallet)) {
63
- return true;
64
- }
65
- else if (metadata.showOnlyIfInstalled) {
66
- return false;
67
- }
68
- else if (!isMobile()) {
69
- return true;
70
- }
71
- else {
72
- return handleMobileWalletFilter(wallet.name, metadata);
73
- }
74
- });
75
- const handleMobileWalletFilter = (walletName, metadata) => {
76
- if (!metadata.mobile)
77
- return false;
78
- /**
79
- * WalletConnect provides a "universal" and "native" deep link. They recommend using
80
- * the universal deep link over the native one due to UX differences, and our current
81
- * implementation uses only universal. This means we need to filter for wallets that
82
- * have a universal deep link available.
83
- */
84
- const hasWalletConnectLink = Boolean(metadata.mobile.universal) || Boolean(metadata.mobile.native);
85
- const isWalletConnectWallet = metadata.walletConnect !== undefined;
86
- if (isIPad() || isIPhone()) {
87
- const hasIOSLink = Boolean(getWalletLinks(walletName).ios);
88
- return !isWalletConnectWallet
89
- ? hasIOSLink
90
- : hasIOSLink && hasWalletConnectLink;
91
- }
92
- else {
93
- const hasAndroidLink = Boolean(getWalletLinks(walletName).android);
94
- return !isWalletConnectWallet
95
- ? hasAndroidLink
96
- : hasAndroidLink && hasWalletConnectLink;
97
- }
98
- };
99
- const chainStringToChains = {
100
- 'eip155:1': ['ETH', 'EVM'],
101
- 'flow:mainnet': ['FLOW'],
102
- };
103
- const getSupportedChainsForWalletConnector = (walletConnector) => {
104
- var _a;
105
- const metadata = getWalletBookWallet(walletConnector.name);
106
- /**
107
- * chains could contain multiple eth networks eg
108
- * "eip155:1",
109
- * "eip155:10",
110
- * "eip155:56",
111
- * "eip155:100",
112
- *
113
- * so we will use a set to ensure uniqueness
114
- */
115
- const chainSet = new Set();
116
- const chainStringList = (_a = metadata.chains) !== null && _a !== void 0 ? _a : [];
117
- chainStringList.forEach((chainString) => {
118
- const chains = chainStringToChains[chainString];
119
- chains === null || chains === void 0 ? void 0 : chains.forEach((chain) => {
120
- chainSet.add(chain);
121
- });
122
- });
123
- walletConnector.supportedChains.forEach((chain) => {
124
- chainSet.add(chain);
125
- });
126
- return [...chainSet];
127
- };
128
- const getEnabledWallets = (props) => {
129
- const supportedWallets = getSupportedWallets(props.getSupportedWalletOpts);
130
- const allEnabledWallets = supportedWallets.filter((wallet) => (props.enabledChains.some((chain) => getSupportedChainsForWalletConnector(wallet).includes(chain)) &&
131
- wallet.isInstalledOnBrowser() === props.installed) ||
132
- wallet.key === 'magiclink');
133
- return allEnabledWallets;
6
+ let wallets = [];
7
+ const defaultWalletUiUtils = {
8
+ disabledConfirmationOnce: () => {
9
+ throw Error('disabledConfirmationOnce, not implemented');
10
+ },
11
+ sendTransaction: () => {
12
+ throw Error('requestSendTransactionConfirmation not implemented');
13
+ },
14
+ signMessage: () => {
15
+ throw Error('signMessage not implemented');
16
+ },
17
+ };
18
+ const getSupportedWallets = (args) => {
19
+ const { appLogoUrl = '', appName = '', chainRpcProviders, flowNetwork, isWalletConnectV2Enabled = false, networkConfigurations = { cosmos: [], evm: [], solana: [], starknet: [] }, customerApiProviders = [], skipMemo = false, walletConnectProjectId = '', walletConnectorsProp, walletUiUtils = undefined, walletConnectV1Bridge, } = args;
20
+ if (!skipMemo && wallets.length > 0) {
21
+ return wallets;
22
+ }
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 apiProviders = getApiProviders(customerApiProviders);
27
+ const opts = {
28
+ apiProviders,
29
+ appLogoUrl,
30
+ appName,
31
+ chainRpcProviders,
32
+ cosmosNetworks: cosmosNetworkConfigs,
33
+ evmNetworks: evmNetworkConfigs,
34
+ flowNetwork,
35
+ isWalletConnectV2Enabled,
36
+ projectId: walletConnectProjectId,
37
+ solNetworks: solanaNetworkConfigs,
38
+ walletConnectV1Bridge,
39
+ walletUiUtils: walletUiUtils || defaultWalletUiUtils,
40
+ };
41
+ const allWallets = walletConnectorsProp
42
+ .map((walletConnector) => walletConnector(opts))
43
+ .flat()
44
+ .map((wallet) => new wallet(opts).getMobileOrInstalledWallet());
45
+ // Memoize the wallets
46
+ const filteredWallets = filterWalletsForPlatform(allWallets);
47
+ wallets = applyLinksOverrides(filteredWallets);
48
+ return wallets;
49
+ };
50
+ const applyLinksOverrides = (wallets) => wallets.map((wallet) => {
51
+ const metadata = getWalletBookWallet(wallet.name);
52
+ if (metadata.switchNetworkOnlyFromWallet !== undefined) {
53
+ wallet.switchNetworkOnlyFromWallet = metadata.switchNetworkOnlyFromWallet;
54
+ }
55
+ return wallet;
56
+ });
57
+ const filterWalletsForPlatform = (wallets) => wallets.filter((wallet) => {
58
+ const metadata = getWalletBookWallet(wallet.name);
59
+ if (wallet.isInstalledOnBrowser()) {
60
+ return true;
61
+ }
62
+ else if (isEmbeddedConnector(wallet)) {
63
+ return true;
64
+ }
65
+ else if (metadata.showOnlyIfInstalled) {
66
+ return false;
67
+ }
68
+ else if (!isMobile()) {
69
+ return true;
70
+ }
71
+ else {
72
+ return handleMobileWalletFilter(wallet.name, metadata);
73
+ }
74
+ });
75
+ const handleMobileWalletFilter = (walletName, metadata) => {
76
+ if (!metadata.mobile)
77
+ return false;
78
+ /**
79
+ * WalletConnect provides a "universal" and "native" deep link. They recommend using
80
+ * the universal deep link over the native one due to UX differences, and our current
81
+ * implementation uses only universal. This means we need to filter for wallets that
82
+ * have a universal deep link available.
83
+ */
84
+ const hasWalletConnectLink = Boolean(metadata.mobile.universal) || Boolean(metadata.mobile.native);
85
+ const isWalletConnectWallet = metadata.walletConnect !== undefined;
86
+ if (isIPad() || isIPhone()) {
87
+ const hasIOSLink = Boolean(getWalletLinks(walletName).ios);
88
+ return !isWalletConnectWallet
89
+ ? hasIOSLink
90
+ : hasIOSLink && hasWalletConnectLink;
91
+ }
92
+ else {
93
+ const hasAndroidLink = Boolean(getWalletLinks(walletName).android);
94
+ return !isWalletConnectWallet
95
+ ? hasAndroidLink
96
+ : hasAndroidLink && hasWalletConnectLink;
97
+ }
98
+ };
99
+ const chainStringToChains = {
100
+ 'eip155:1': ['ETH', 'EVM'],
101
+ 'flow:mainnet': ['FLOW'],
102
+ };
103
+ const getSupportedChainsForWalletConnector = (walletConnector) => {
104
+ var _a;
105
+ const metadata = getWalletBookWallet(walletConnector.name);
106
+ /**
107
+ * chains could contain multiple eth networks eg
108
+ * "eip155:1",
109
+ * "eip155:10",
110
+ * "eip155:56",
111
+ * "eip155:100",
112
+ *
113
+ * so we will use a set to ensure uniqueness
114
+ */
115
+ const chainSet = new Set();
116
+ const chainStringList = (_a = metadata.chains) !== null && _a !== void 0 ? _a : [];
117
+ chainStringList.forEach((chainString) => {
118
+ const chains = chainStringToChains[chainString];
119
+ chains === null || chains === void 0 ? void 0 : chains.forEach((chain) => {
120
+ chainSet.add(chain);
121
+ });
122
+ });
123
+ walletConnector.supportedChains.forEach((chain) => {
124
+ chainSet.add(chain);
125
+ });
126
+ return [...chainSet];
127
+ };
128
+ const getEnabledWallets = (props) => {
129
+ const supportedWallets = getSupportedWallets(props.getSupportedWalletOpts);
130
+ const allEnabledWallets = supportedWallets.filter((wallet) => (props.enabledChains.some((chain) => getSupportedChainsForWalletConnector(wallet).includes(chain)) &&
131
+ wallet.isInstalledOnBrowser() === props.installed) ||
132
+ wallet.key === 'magiclink');
133
+ return allEnabledWallets;
134
134
  };
135
135
 
136
136
  export { getEnabledWallets, getSupportedChainsForWalletConnector, getSupportedWallets };
package/src/types.d.ts CHANGED
@@ -1,29 +1,29 @@
1
- import type { Provider } from '@dynamic-labs/sdk-api';
2
- import { WalletConnector, Chain, WalletConnectorsMethod } from '@dynamic-labs/wallet-connector-core';
3
- import { NetworkConfigurationMap, WalletUiUtils } from '@dynamic-labs/types';
4
- import { ChainRpcProviders } from '@dynamic-labs/rpc-providers';
5
- export type GetSupportedWalletsOpts = {
6
- appLogoUrl?: string;
7
- appName?: string;
8
- chainRpcProviders: typeof ChainRpcProviders;
9
- customerApiProviders?: Provider[];
10
- flowNetwork?: 'mainnet' | 'testnet';
11
- isWalletConnectV2Enabled?: boolean;
12
- networkConfigurations?: NetworkConfigurationMap;
13
- skipMemo?: boolean;
14
- walletConnectV1Bridge?: string;
15
- walletConnectProjectId?: string;
16
- walletConnectorsProp: WalletConnectorsMethod[];
17
- walletUiUtils?: WalletUiUtils;
18
- };
19
- export type GetSupportedWallets = (opts: GetSupportedWalletsOpts) => WalletConnector[];
20
- export type ChainInfo = {
21
- blockchainName: string;
22
- displayName: string;
23
- name: string;
24
- symbol: Chain;
25
- };
26
- export type ChainWihtIcon = {
27
- icon?: string;
28
- name: string | undefined;
29
- };
1
+ import type { Provider } from '@dynamic-labs/sdk-api';
2
+ import { WalletConnector, Chain, WalletConnectorsMethod } from '@dynamic-labs/wallet-connector-core';
3
+ import { NetworkConfigurationMap, WalletUiUtils } from '@dynamic-labs/types';
4
+ import { ChainRpcProviders } from '@dynamic-labs/rpc-providers';
5
+ export type GetSupportedWalletsOpts = {
6
+ appLogoUrl?: string;
7
+ appName?: string;
8
+ chainRpcProviders: typeof ChainRpcProviders;
9
+ customerApiProviders?: Provider[];
10
+ flowNetwork?: 'mainnet' | 'testnet';
11
+ isWalletConnectV2Enabled?: boolean;
12
+ networkConfigurations?: NetworkConfigurationMap;
13
+ skipMemo?: boolean;
14
+ walletConnectV1Bridge?: string;
15
+ walletConnectProjectId?: string;
16
+ walletConnectorsProp: WalletConnectorsMethod[];
17
+ walletUiUtils?: WalletUiUtils;
18
+ };
19
+ export type GetSupportedWallets = (opts: GetSupportedWalletsOpts) => WalletConnector[];
20
+ export type ChainInfo = {
21
+ blockchainName: string;
22
+ displayName: string;
23
+ name: string;
24
+ symbol: Chain;
25
+ };
26
+ export type ChainWihtIcon = {
27
+ icon?: string;
28
+ name: string | undefined;
29
+ };
@@ -4,12 +4,12 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var sdkApi = require('@dynamic-labs/sdk-api');
6
6
 
7
- const getApiProviders = (providers) => Object.values(sdkApi.ProviderEnum).reduce((acc, provider) => {
8
- const foundProvider = providers.find((providerSetting) => providerSetting.provider === provider);
9
- if (foundProvider) {
10
- acc[provider] = foundProvider;
11
- }
12
- return acc;
7
+ const getApiProviders = (providers) => Object.values(sdkApi.ProviderEnum).reduce((acc, provider) => {
8
+ const foundProvider = providers.find((providerSetting) => providerSetting.provider === provider);
9
+ if (foundProvider) {
10
+ acc[provider] = foundProvider;
11
+ }
12
+ return acc;
13
13
  }, {});
14
14
 
15
15
  exports.getApiProviders = getApiProviders;
@@ -1,17 +1,17 @@
1
- import { Provider, ProviderEnum } from '@dynamic-labs/sdk-api';
2
- export declare const getApiProviders: (providers: Provider[]) => {
3
- emailOnly?: Provider | undefined;
4
- magicLink?: Provider | undefined;
5
- apple?: Provider | undefined;
6
- bitbucket?: Provider | undefined;
7
- discord?: Provider | undefined;
8
- facebook?: Provider | undefined;
9
- github?: Provider | undefined;
10
- gitlab?: Provider | undefined;
11
- google?: Provider | undefined;
12
- instagram?: Provider | undefined;
13
- linkedin?: Provider | undefined;
14
- microsoft?: Provider | undefined;
15
- twitch?: Provider | undefined;
16
- twitter?: Provider | undefined;
17
- };
1
+ import { Provider, ProviderEnum } from '@dynamic-labs/sdk-api';
2
+ export declare const getApiProviders: (providers: Provider[]) => {
3
+ emailOnly?: Provider | undefined;
4
+ magicLink?: Provider | undefined;
5
+ apple?: Provider | undefined;
6
+ bitbucket?: Provider | undefined;
7
+ discord?: Provider | undefined;
8
+ facebook?: Provider | undefined;
9
+ github?: Provider | undefined;
10
+ gitlab?: Provider | undefined;
11
+ google?: Provider | undefined;
12
+ instagram?: Provider | undefined;
13
+ linkedin?: Provider | undefined;
14
+ microsoft?: Provider | undefined;
15
+ twitch?: Provider | undefined;
16
+ twitter?: Provider | undefined;
17
+ };
@@ -1,11 +1,11 @@
1
1
  import { ProviderEnum } from '@dynamic-labs/sdk-api';
2
2
 
3
- const getApiProviders = (providers) => Object.values(ProviderEnum).reduce((acc, provider) => {
4
- const foundProvider = providers.find((providerSetting) => providerSetting.provider === provider);
5
- if (foundProvider) {
6
- acc[provider] = foundProvider;
7
- }
8
- return acc;
3
+ const getApiProviders = (providers) => Object.values(ProviderEnum).reduce((acc, provider) => {
4
+ const foundProvider = providers.find((providerSetting) => providerSetting.provider === provider);
5
+ if (foundProvider) {
6
+ acc[provider] = foundProvider;
7
+ }
8
+ return acc;
9
9
  }, {});
10
10
 
11
11
  export { getApiProviders };
@@ -2,54 +2,54 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var utils = require('ethers/lib/utils');
5
+ var viem = require('viem');
6
6
  var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
7
7
 
8
- const generateMessageToSign = ({ blockchain, domain, chainId, nonce, uri, publicKey, issuedAt = new Date().toISOString(), statement, requestId, resources, }) => {
9
- var _a, _b;
10
- if (blockchain === 'STARK') {
11
- return nonce;
12
- }
13
- const blockchainName = (_b = (_a = walletConnectorCore.getChainInfo(blockchain)) === null || _a === void 0 ? void 0 : _a.blockchainName) !== null && _b !== void 0 ? _b : 'Ethereum';
14
- // This format follows the sign-in with ethereum (SIWE) standard,
15
- // but we are using it also for non-ethereum wallets for now (eg. Solana)
16
- // for more context on format and fields, please see:
17
- // https://docs.login.xyz/general-information/siwe-overview/eip-4361
18
- const header = `${domain} wants you to sign in with your ${blockchainName} account:`;
19
- // This is only required for Ethereum-based wallets
20
- const messageAddress = getEip55Address(publicKey, chainId);
21
- const prefix = [header, messageAddress].join('\n');
22
- const prefixWithStatement = `${[prefix, statement].join('\n\n')}\n`;
23
- const suffixFields = [];
24
- suffixFields.push(`URI: ${uri}`);
25
- suffixFields.push('Version: 1');
26
- if (chainId) {
27
- suffixFields.push(`Chain ID: ${chainId}`);
28
- }
29
- suffixFields.push(`Nonce: ${nonce}`);
30
- suffixFields.push(`Issued At: ${issuedAt}`);
31
- if (requestId) {
32
- suffixFields.push(`Request ID: ${requestId}`);
33
- }
34
- if (resources === null || resources === void 0 ? void 0 : resources.length) {
35
- suffixFields.push(`Resources:${resources.map((resource) => '\n- ' + resource).join()}`);
36
- }
37
- const suffix = suffixFields.join('\n');
38
- return [prefixWithStatement, suffix].join('\n');
39
- };
40
- // The SIWE parser library used to validate signed messages for EVM/Ethereum
41
- // checks that an address is in EIP55 format, so make sure we do that here.
42
- // see: https://eips.ethereum.org/EIPS/eip-55
43
- const getEip55Address = (publicKey, chainId) => {
44
- try {
45
- if (chainId) {
46
- return utils.getAddress(publicKey);
47
- }
48
- }
49
- catch (err) {
50
- walletConnectorCore.logger.debug(`Error getting checksum, returning default ${publicKey}`);
51
- }
52
- return publicKey;
8
+ const generateMessageToSign = ({ blockchain, domain, chainId, nonce, uri, publicKey, issuedAt = new Date().toISOString(), statement, requestId, resources, }) => {
9
+ var _a, _b;
10
+ if (blockchain === 'STARK') {
11
+ return nonce;
12
+ }
13
+ const blockchainName = (_b = (_a = walletConnectorCore.getChainInfo(blockchain)) === null || _a === void 0 ? void 0 : _a.blockchainName) !== null && _b !== void 0 ? _b : 'Ethereum';
14
+ // This format follows the sign-in with ethereum (SIWE) standard,
15
+ // but we are using it also for non-ethereum wallets for now (eg. Solana)
16
+ // for more context on format and fields, please see:
17
+ // https://docs.login.xyz/general-information/siwe-overview/eip-4361
18
+ const header = `${domain} wants you to sign in with your ${blockchainName} account:`;
19
+ // This is only required for Ethereum-based wallets
20
+ const messageAddress = getEip55Address(publicKey, chainId);
21
+ const prefix = [header, messageAddress].join('\n');
22
+ const prefixWithStatement = `${[prefix, statement].join('\n\n')}\n`;
23
+ const suffixFields = [];
24
+ suffixFields.push(`URI: ${uri}`);
25
+ suffixFields.push('Version: 1');
26
+ if (chainId) {
27
+ suffixFields.push(`Chain ID: ${chainId}`);
28
+ }
29
+ suffixFields.push(`Nonce: ${nonce}`);
30
+ suffixFields.push(`Issued At: ${issuedAt}`);
31
+ if (requestId) {
32
+ suffixFields.push(`Request ID: ${requestId}`);
33
+ }
34
+ if (resources === null || resources === void 0 ? void 0 : resources.length) {
35
+ suffixFields.push(`Resources:${resources.map((resource) => '\n- ' + resource).join()}`);
36
+ }
37
+ const suffix = suffixFields.join('\n');
38
+ return [prefixWithStatement, suffix].join('\n');
39
+ };
40
+ // The SIWE parser library used to validate signed messages for EVM/Ethereum
41
+ // checks that an address is in EIP55 format, so make sure we do that here.
42
+ // see: https://eips.ethereum.org/EIPS/eip-55
43
+ const getEip55Address = (publicKey, chainId) => {
44
+ try {
45
+ if (chainId) {
46
+ return viem.getAddress(publicKey);
47
+ }
48
+ }
49
+ catch (err) {
50
+ walletConnectorCore.logger.debug(`Error getting checksum, returning default ${publicKey}`);
51
+ }
52
+ return publicKey;
53
53
  };
54
54
 
55
55
  exports.generateMessageToSign = generateMessageToSign;
@@ -1,15 +1,15 @@
1
- import { Chain } from '@dynamic-labs/wallet-connector-core';
2
- export interface MessageParameters {
3
- blockchain: Chain;
4
- chainId?: number | string;
5
- domain: string;
6
- issuedAt?: string;
7
- nonce: string;
8
- publicKey: string;
9
- requestId?: string;
10
- resources?: string[];
11
- statement?: string;
12
- uri: string;
13
- }
14
- export declare const generateMessageToSign: ({ blockchain, domain, chainId, nonce, uri, publicKey, issuedAt, statement, requestId, resources, }: MessageParameters) => string;
15
- export declare const getEip55Address: (publicKey: string, chainId?: number | string) => string;
1
+ import { Chain } from '@dynamic-labs/wallet-connector-core';
2
+ export interface MessageParameters {
3
+ blockchain: Chain;
4
+ chainId?: number | string;
5
+ domain: string;
6
+ issuedAt?: string;
7
+ nonce: string;
8
+ publicKey: string;
9
+ requestId?: string;
10
+ resources?: string[];
11
+ statement?: string;
12
+ uri: string;
13
+ }
14
+ export declare const generateMessageToSign: ({ blockchain, domain, chainId, nonce, uri, publicKey, issuedAt, statement, requestId, resources, }: MessageParameters) => string;
15
+ export declare const getEip55Address: (publicKey: string, chainId?: number | string) => string;
@@ -1,51 +1,51 @@
1
- import { getAddress } from 'ethers/lib/utils.js';
1
+ import { getAddress } from 'viem';
2
2
  import { getChainInfo, logger } from '@dynamic-labs/wallet-connector-core';
3
3
 
4
- const generateMessageToSign = ({ blockchain, domain, chainId, nonce, uri, publicKey, issuedAt = new Date().toISOString(), statement, requestId, resources, }) => {
5
- var _a, _b;
6
- if (blockchain === 'STARK') {
7
- return nonce;
8
- }
9
- const blockchainName = (_b = (_a = getChainInfo(blockchain)) === null || _a === void 0 ? void 0 : _a.blockchainName) !== null && _b !== void 0 ? _b : 'Ethereum';
10
- // This format follows the sign-in with ethereum (SIWE) standard,
11
- // but we are using it also for non-ethereum wallets for now (eg. Solana)
12
- // for more context on format and fields, please see:
13
- // https://docs.login.xyz/general-information/siwe-overview/eip-4361
14
- const header = `${domain} wants you to sign in with your ${blockchainName} account:`;
15
- // This is only required for Ethereum-based wallets
16
- const messageAddress = getEip55Address(publicKey, chainId);
17
- const prefix = [header, messageAddress].join('\n');
18
- const prefixWithStatement = `${[prefix, statement].join('\n\n')}\n`;
19
- const suffixFields = [];
20
- suffixFields.push(`URI: ${uri}`);
21
- suffixFields.push('Version: 1');
22
- if (chainId) {
23
- suffixFields.push(`Chain ID: ${chainId}`);
24
- }
25
- suffixFields.push(`Nonce: ${nonce}`);
26
- suffixFields.push(`Issued At: ${issuedAt}`);
27
- if (requestId) {
28
- suffixFields.push(`Request ID: ${requestId}`);
29
- }
30
- if (resources === null || resources === void 0 ? void 0 : resources.length) {
31
- suffixFields.push(`Resources:${resources.map((resource) => '\n- ' + resource).join()}`);
32
- }
33
- const suffix = suffixFields.join('\n');
34
- return [prefixWithStatement, suffix].join('\n');
35
- };
36
- // The SIWE parser library used to validate signed messages for EVM/Ethereum
37
- // checks that an address is in EIP55 format, so make sure we do that here.
38
- // see: https://eips.ethereum.org/EIPS/eip-55
39
- const getEip55Address = (publicKey, chainId) => {
40
- try {
41
- if (chainId) {
42
- return getAddress(publicKey);
43
- }
44
- }
45
- catch (err) {
46
- logger.debug(`Error getting checksum, returning default ${publicKey}`);
47
- }
48
- return publicKey;
4
+ const generateMessageToSign = ({ blockchain, domain, chainId, nonce, uri, publicKey, issuedAt = new Date().toISOString(), statement, requestId, resources, }) => {
5
+ var _a, _b;
6
+ if (blockchain === 'STARK') {
7
+ return nonce;
8
+ }
9
+ const blockchainName = (_b = (_a = getChainInfo(blockchain)) === null || _a === void 0 ? void 0 : _a.blockchainName) !== null && _b !== void 0 ? _b : 'Ethereum';
10
+ // This format follows the sign-in with ethereum (SIWE) standard,
11
+ // but we are using it also for non-ethereum wallets for now (eg. Solana)
12
+ // for more context on format and fields, please see:
13
+ // https://docs.login.xyz/general-information/siwe-overview/eip-4361
14
+ const header = `${domain} wants you to sign in with your ${blockchainName} account:`;
15
+ // This is only required for Ethereum-based wallets
16
+ const messageAddress = getEip55Address(publicKey, chainId);
17
+ const prefix = [header, messageAddress].join('\n');
18
+ const prefixWithStatement = `${[prefix, statement].join('\n\n')}\n`;
19
+ const suffixFields = [];
20
+ suffixFields.push(`URI: ${uri}`);
21
+ suffixFields.push('Version: 1');
22
+ if (chainId) {
23
+ suffixFields.push(`Chain ID: ${chainId}`);
24
+ }
25
+ suffixFields.push(`Nonce: ${nonce}`);
26
+ suffixFields.push(`Issued At: ${issuedAt}`);
27
+ if (requestId) {
28
+ suffixFields.push(`Request ID: ${requestId}`);
29
+ }
30
+ if (resources === null || resources === void 0 ? void 0 : resources.length) {
31
+ suffixFields.push(`Resources:${resources.map((resource) => '\n- ' + resource).join()}`);
32
+ }
33
+ const suffix = suffixFields.join('\n');
34
+ return [prefixWithStatement, suffix].join('\n');
35
+ };
36
+ // The SIWE parser library used to validate signed messages for EVM/Ethereum
37
+ // checks that an address is in EIP55 format, so make sure we do that here.
38
+ // see: https://eips.ethereum.org/EIPS/eip-55
39
+ const getEip55Address = (publicKey, chainId) => {
40
+ try {
41
+ if (chainId) {
42
+ return getAddress(publicKey);
43
+ }
44
+ }
45
+ catch (err) {
46
+ logger.debug(`Error getting checksum, returning default ${publicKey}`);
47
+ }
48
+ return publicKey;
49
49
  };
50
50
 
51
51
  export { generateMessageToSign, getEip55Address };