@web3auth/no-modal 10.8.0 → 10.8.2

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.
@@ -145,7 +145,7 @@ const getWalletServicesAnalyticsProperties = walletServicesConfig => {
145
145
  ws_default_portfolio: walletServicesConfig === null || walletServicesConfig === void 0 || (_walletServicesConfig1 = walletServicesConfig.whiteLabel) === null || _walletServicesConfig1 === void 0 ? void 0 : _walletServicesConfig1.defaultPortfolio
146
146
  };
147
147
  };
148
- const sdkVersion = "10.8.0";
148
+ const sdkVersion = "10.8.2";
149
149
  const getErrorAnalyticsProperties = error => {
150
150
  try {
151
151
  const code = error instanceof index.Web3AuthError ? error.code : error === null || error === void 0 ? void 0 : error.code;
@@ -147,12 +147,37 @@ class CoinbaseConnector extends baseEvmConnector.BaseEvmConnector {
147
147
  }
148
148
  async switchChain(params, init = false) {
149
149
  super.checkSwitchChainRequirements(params, init);
150
- await this.coinbaseProvider.request({
151
- method: "wallet_switchEthereumChain",
152
- params: [{
153
- chainId: params.chainId
154
- }]
155
- });
150
+ try {
151
+ await this.coinbaseProvider.request({
152
+ method: "wallet_switchEthereumChain",
153
+ params: [{
154
+ chainId: params.chainId
155
+ }]
156
+ });
157
+ } catch (switchError) {
158
+ // 4902 indicates that the client does not recognize the Harmony One network
159
+ if (switchError.code === 4902) {
160
+ const chainConfig = this.coreOptions.chains.find(x => x.chainId === params.chainId);
161
+ if (!chainConfig) throw index$1.WalletLoginError.connectionError("Chain config is not available");
162
+ await this.coinbaseProvider.request({
163
+ method: "wallet_addEthereumChain",
164
+ params: [{
165
+ chainId: chainConfig.chainId,
166
+ rpcUrls: [chainConfig.rpcTarget],
167
+ chainName: chainConfig.displayName,
168
+ nativeCurrency: {
169
+ name: chainConfig.tickerName,
170
+ symbol: chainConfig.ticker,
171
+ decimals: chainConfig.decimals || 18
172
+ },
173
+ blockExplorerUrls: [chainConfig.blockExplorerUrl],
174
+ iconUrls: [chainConfig.logo]
175
+ }]
176
+ });
177
+ return;
178
+ }
179
+ throw switchError;
180
+ }
156
181
  }
157
182
  async enableMFA() {
158
183
  throw new Error("Method Not implemented");
@@ -215,7 +215,7 @@ class MetaMaskConnector extends baseEvmConnector.BaseEvmConnector {
215
215
  } catch (error) {
216
216
  // If the error code is 4902, the network needs to be added
217
217
  if ((error === null || error === void 0 ? void 0 : error.code) === 4902) {
218
- const chainConfig = this.coreOptions.chains.find(x => x.chainId === params.chainId && [baseControllers.CHAIN_NAMESPACES.EIP155, baseControllers.CHAIN_NAMESPACES.SOLANA].includes(x.chainNamespace));
218
+ const chainConfig = this.coreOptions.chains.find(x => x.chainId === params.chainId && [baseControllers.CHAIN_NAMESPACES.EIP155].includes(x.chainNamespace));
219
219
  await this.addChain(chainConfig);
220
220
  await requestSwitchChain();
221
221
  } else {
@@ -597,9 +597,9 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
597
597
  const isExternalWalletEnabled = Boolean(projectConfig.externalWalletAuth);
598
598
  const isMipdEnabled = isExternalWalletEnabled && ((_this$coreOptions$mul = this.coreOptions.multiInjectedProviderDiscovery) !== null && _this$coreOptions$mul !== void 0 ? _this$coreOptions$mul : true);
599
599
  const chainNamespaces = new Set(this.coreOptions.chains.map(chain => chain.chainNamespace));
600
- // it's safe to add it here as if there is a MetaMask injected provider, this won't override it
601
- // only set headless to true if modal SDK is used, otherwise just use the modal from native Metamask SDK
602
- if (utils.isBrowser() && chainNamespaces.has(baseControllers.CHAIN_NAMESPACES.EIP155) && !chainNamespaces.has(baseControllers.CHAIN_NAMESPACES.SOLANA)) {
600
+ // prioritize using MM connector over injected connector for EVM chains
601
+ if (utils.isBrowser() && chainNamespaces.has(baseControllers.CHAIN_NAMESPACES.EIP155)) {
602
+ // only set headless to true if modal SDK is used, otherwise just use the modal from native Metamask SDK
603
603
  connectorFns.push(metamaskConnector.metaMaskConnector(modalMode ? {
604
604
  headless: true
605
605
  } : undefined));
@@ -635,13 +635,6 @@ class Web3AuthNoModal extends auth.SafeEventEmitter {
635
635
  connectorFns.push(...evmMipd.getProviders().map(injectedEvmConnector));
636
636
  }
637
637
  }
638
- // it's safe to add it here as if there is a MetaMask injected provider, this won't override it
639
- // only set headless to true if modal SDK is used, otherwise just use the modal from native Metamask SDK
640
- if (utils.isBrowser() && (chainNamespaces.has(baseControllers.CHAIN_NAMESPACES.SOLANA) || chainNamespaces.has(baseControllers.CHAIN_NAMESPACES.EIP155))) {
641
- connectorFns.push(metamaskConnector.metaMaskConnector(modalMode ? {
642
- headless: true
643
- } : undefined));
644
- }
645
638
  // add WalletConnectV2 connector if external wallets are enabled
646
639
  if (utils.isBrowser() && isExternalWalletEnabled && (chainNamespaces.has(baseControllers.CHAIN_NAMESPACES.SOLANA) || chainNamespaces.has(baseControllers.CHAIN_NAMESPACES.EIP155))) {
647
640
  const {
@@ -145,7 +145,7 @@ const getWalletServicesAnalyticsProperties = walletServicesConfig => {
145
145
  ws_default_portfolio: walletServicesConfig === null || walletServicesConfig === void 0 || (_walletServicesConfig1 = walletServicesConfig.whiteLabel) === null || _walletServicesConfig1 === void 0 ? void 0 : _walletServicesConfig1.defaultPortfolio
146
146
  };
147
147
  };
148
- const sdkVersion = "10.8.0";
148
+ const sdkVersion = "10.8.2";
149
149
  const getErrorAnalyticsProperties = error => {
150
150
  try {
151
151
  const code = error instanceof Web3AuthError ? error.code : error === null || error === void 0 ? void 0 : error.code;
@@ -137,12 +137,37 @@ class CoinbaseConnector extends BaseEvmConnector {
137
137
  }
138
138
  async switchChain(params, init = false) {
139
139
  super.checkSwitchChainRequirements(params, init);
140
- await this.coinbaseProvider.request({
141
- method: "wallet_switchEthereumChain",
142
- params: [{
143
- chainId: params.chainId
144
- }]
145
- });
140
+ try {
141
+ await this.coinbaseProvider.request({
142
+ method: "wallet_switchEthereumChain",
143
+ params: [{
144
+ chainId: params.chainId
145
+ }]
146
+ });
147
+ } catch (switchError) {
148
+ // 4902 indicates that the client does not recognize the Harmony One network
149
+ if (switchError.code === 4902) {
150
+ const chainConfig = this.coreOptions.chains.find(x => x.chainId === params.chainId);
151
+ if (!chainConfig) throw WalletLoginError.connectionError("Chain config is not available");
152
+ await this.coinbaseProvider.request({
153
+ method: "wallet_addEthereumChain",
154
+ params: [{
155
+ chainId: chainConfig.chainId,
156
+ rpcUrls: [chainConfig.rpcTarget],
157
+ chainName: chainConfig.displayName,
158
+ nativeCurrency: {
159
+ name: chainConfig.tickerName,
160
+ symbol: chainConfig.ticker,
161
+ decimals: chainConfig.decimals || 18
162
+ },
163
+ blockExplorerUrls: [chainConfig.blockExplorerUrl],
164
+ iconUrls: [chainConfig.logo]
165
+ }]
166
+ });
167
+ return;
168
+ }
169
+ throw switchError;
170
+ }
146
171
  }
147
172
  async enableMFA() {
148
173
  throw new Error("Method Not implemented");
@@ -215,7 +215,7 @@ class MetaMaskConnector extends BaseEvmConnector {
215
215
  } catch (error) {
216
216
  // If the error code is 4902, the network needs to be added
217
217
  if ((error === null || error === void 0 ? void 0 : error.code) === 4902) {
218
- const chainConfig = this.coreOptions.chains.find(x => x.chainId === params.chainId && [CHAIN_NAMESPACES.EIP155, CHAIN_NAMESPACES.SOLANA].includes(x.chainNamespace));
218
+ const chainConfig = this.coreOptions.chains.find(x => x.chainId === params.chainId && [CHAIN_NAMESPACES.EIP155].includes(x.chainNamespace));
219
219
  await this.addChain(chainConfig);
220
220
  await requestSwitchChain();
221
221
  } else {
@@ -11,9 +11,9 @@ import { Analytics, ANALYTICS_INTEGRATION_TYPE, ANALYTICS_SDK_TYPE, ANALYTICS_EV
11
11
  import { sdkVersion, fetchProjectConfig, withAbort, getErrorAnalyticsProperties, getCaipChainId, isHexStrict, getHostname, getWhitelabelAnalyticsProperties, getAaAnalyticsProperties, getWalletServicesAnalyticsProperties, isBrowser } from './base/utils.js';
12
12
  import { CommonJRPCProvider } from './providers/base-provider/CommonJRPCProvider.js';
13
13
  import { authConnector } from './connectors/auth-connector/authConnector.js';
14
- import { metaMaskConnector } from './connectors/metamask-connector/metamaskConnector.js';
15
14
  import { walletServicesPlugin } from './plugins/wallet-services-plugin/plugin.js';
16
15
  import { storageAvailable } from './base/connector/utils.js';
16
+ import { metaMaskConnector } from './connectors/metamask-connector/metamaskConnector.js';
17
17
  import { CONNECTOR_STATUS, CONNECTOR_EVENTS } from './base/connector/constants.js';
18
18
  import { WalletInitializationError, WalletLoginError } from './base/errors/index.js';
19
19
  import { log } from './base/loglevel.js';
@@ -609,9 +609,9 @@ class Web3AuthNoModal extends SafeEventEmitter {
609
609
  const isMipdEnabled = isExternalWalletEnabled && ((_this$coreOptions$mul = this.coreOptions.multiInjectedProviderDiscovery) !== null && _this$coreOptions$mul !== void 0 ? _this$coreOptions$mul : true);
610
610
  const chainNamespaces = new Set(this.coreOptions.chains.map(chain => chain.chainNamespace));
611
611
 
612
- // it's safe to add it here as if there is a MetaMask injected provider, this won't override it
613
- // only set headless to true if modal SDK is used, otherwise just use the modal from native Metamask SDK
614
- if (isBrowser() && chainNamespaces.has(CHAIN_NAMESPACES.EIP155) && !chainNamespaces.has(CHAIN_NAMESPACES.SOLANA)) {
612
+ // prioritize using MM connector over injected connector for EVM chains
613
+ if (isBrowser() && chainNamespaces.has(CHAIN_NAMESPACES.EIP155)) {
614
+ // only set headless to true if modal SDK is used, otherwise just use the modal from native Metamask SDK
615
615
  connectorFns.push(metaMaskConnector(modalMode ? {
616
616
  headless: true
617
617
  } : undefined));
@@ -648,14 +648,6 @@ class Web3AuthNoModal extends SafeEventEmitter {
648
648
  }
649
649
  }
650
650
 
651
- // it's safe to add it here as if there is a MetaMask injected provider, this won't override it
652
- // only set headless to true if modal SDK is used, otherwise just use the modal from native Metamask SDK
653
- if (isBrowser() && (chainNamespaces.has(CHAIN_NAMESPACES.SOLANA) || chainNamespaces.has(CHAIN_NAMESPACES.EIP155))) {
654
- connectorFns.push(metaMaskConnector(modalMode ? {
655
- headless: true
656
- } : undefined));
657
- }
658
-
659
651
  // add WalletConnectV2 connector if external wallets are enabled
660
652
  if (isBrowser() && isExternalWalletEnabled && (chainNamespaces.has(CHAIN_NAMESPACES.SOLANA) || chainNamespaces.has(CHAIN_NAMESPACES.EIP155))) {
661
653
  const {