@web3auth/no-modal 10.5.3 → 10.5.6

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.5.3";
148
+ const sdkVersion = "10.5.6";
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;
@@ -32,6 +32,7 @@ require('@toruslabs/bs58');
32
32
  var JrpcClient = require('../../providers/solana-provider/rpc/JrpcClient.js');
33
33
  var solanaRpcMiddlewares = require('../../providers/solana-provider/rpc/solanaRpcMiddlewares.js');
34
34
  require('@web3auth/ws-embed');
35
+ var utils$1 = require('./utils.js');
35
36
  var walletConnectV2Utils = require('./walletConnectV2Utils.js');
36
37
 
37
38
  var _WalletConnectV2Provider;
@@ -217,14 +218,14 @@ class WalletConnectV2Provider extends baseProvider.BaseProvider {
217
218
  if (event.name === "chainChanged") {
218
219
  if (!data) return;
219
220
  const connectedChainId = data;
220
- const connectedHexChainId = `0x${connectedChainId.toString(16)}`;
221
+ const formattedChainId = utils$1.formatChainId(connectedChainId);
221
222
  // Check if chainId changed and trigger event
222
223
  const {
223
224
  currentChain
224
225
  } = this;
225
- if (connectedHexChainId && currentChain.chainId !== connectedHexChainId) {
226
+ if (formattedChainId && currentChain.chainId !== formattedChainId) {
226
227
  // Handle rpcUrl update
227
- await this.setupEngine(connector, connectedHexChainId);
228
+ await this.setupEngine(connector, formattedChainId);
228
229
  }
229
230
  }
230
231
  });
@@ -0,0 +1,14 @@
1
+ 'use strict';
2
+
3
+ require('@babel/runtime/helpers/objectSpread2');
4
+
5
+ const formatChainId = chainId => {
6
+ if (typeof chainId === "number") {
7
+ return `0x${chainId.toString(16)}`;
8
+ } else if (typeof chainId === "string") {
9
+ return chainId.startsWith("0x") ? chainId : `0x${parseInt(chainId, 10).toString(16)}`;
10
+ }
11
+ throw new Error(`Invalid chainId: ${chainId}`);
12
+ };
13
+
14
+ exports.formatChainId = formatChainId;
@@ -124,6 +124,20 @@ function WagmiProvider(_ref) {
124
124
  web3Auth,
125
125
  isInitialized
126
126
  } = useWeb3Auth.useWeb3Auth();
127
+ const getTransport = chain => {
128
+ const {
129
+ wsTarget,
130
+ rpcTarget,
131
+ fallbackWsTargets = [],
132
+ fallbackRpcTargets = []
133
+ } = chain;
134
+ const transports = [];
135
+ if (wsTarget) transports.push(wagmi.webSocket(wsTarget));
136
+ if (fallbackWsTargets.length > 0) transports.push(...fallbackWsTargets.map(target => wagmi.webSocket(target)));
137
+ if (rpcTarget) transports.push(wagmi.http(rpcTarget));
138
+ if (fallbackRpcTargets.length > 0) transports.push(...fallbackRpcTargets.map(target => wagmi.http(target)));
139
+ return wagmi.fallback(transports);
140
+ };
127
141
  const finalConfig = react.useMemo(() => {
128
142
  var _web3Auth$coreOptions;
129
143
  web3Auth === null || web3Auth === void 0 || web3Auth.setAnalyticsProperties({
@@ -174,7 +188,7 @@ function WagmiProvider(_ref) {
174
188
  } else {
175
189
  wagmiChains.push(wagmiChain);
176
190
  }
177
- finalConfig.transports[wagmiChain.id] = chain.wsTarget ? wagmi.webSocket(chain.wsTarget) : wagmi.http(chain.rpcTarget);
191
+ finalConfig.transports[wagmiChain.id] = getTransport(chain);
178
192
  });
179
193
  finalConfig.chains = [wagmiChains[0], ...wagmiChains.slice(1)];
180
194
  }
@@ -8,4 +8,7 @@ export declare const CONNECTOR_NAMESPACES: {
8
8
  };
9
9
  export type ConnectorNamespaceType = (typeof CONNECTOR_NAMESPACES)[keyof typeof CONNECTOR_NAMESPACES];
10
10
  export { CHAIN_NAMESPACES, type ChainNamespaceType };
11
- export type CustomChainConfig = ProviderConfig;
11
+ export type CustomChainConfig = ProviderConfig & {
12
+ fallbackRpcTargets?: string[];
13
+ fallbackWsTargets?: string[];
14
+ };
@@ -1,3 +1,4 @@
1
1
  import type { EngineTypes } from "@walletconnect/types";
2
2
  import type { ChainNamespaceType } from "../../base";
3
3
  export declare const isChainIdSupported: (chainNamespace: ChainNamespaceType, chainID: number, loginSettings: EngineTypes.ConnectParams | undefined) => boolean;
4
+ export declare const formatChainId: (chainId: number | string) => string;
@@ -150,6 +150,20 @@ const WagmiProvider = vue.defineComponent({
150
150
  } = useWeb3Auth.useWeb3Auth();
151
151
  const finalConfig = vue.shallowRef(constants.defaultWagmiConfig);
152
152
  const configKey = vue.ref(auth.randomId());
153
+ const getTransport = chain => {
154
+ const {
155
+ wsTarget,
156
+ rpcTarget,
157
+ fallbackWsTargets = [],
158
+ fallbackRpcTargets = []
159
+ } = chain;
160
+ const transports = [];
161
+ if (wsTarget) transports.push(viem.webSocket(wsTarget));
162
+ if (fallbackWsTargets.length > 0) transports.push(...fallbackWsTargets.map(target => viem.webSocket(target)));
163
+ if (rpcTarget) transports.push(viem.http(rpcTarget));
164
+ if (fallbackRpcTargets.length > 0) transports.push(...fallbackRpcTargets.map(target => viem.http(target)));
165
+ return viem.fallback(transports);
166
+ };
153
167
  const defineWagmiConfig = () => {
154
168
  var _web3Auth$value;
155
169
  const configParams = _objectSpread(_objectSpread({
@@ -196,7 +210,7 @@ const WagmiProvider = vue.defineComponent({
196
210
  } else {
197
211
  wagmiChains.push(wagmiChain);
198
212
  }
199
- configParams.transports[wagmiChain.id] = chain.wsTarget ? viem.webSocket(chain.wsTarget) : viem.http(chain.rpcTarget);
213
+ configParams.transports[wagmiChain.id] = getTransport(chain);
200
214
  });
201
215
  configParams.chains = [wagmiChains[0], ...wagmiChains.slice(1)];
202
216
  }
@@ -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.5.3";
148
+ const sdkVersion = "10.5.6";
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;
@@ -2,6 +2,7 @@ import _objectSpread from '@babel/runtime/helpers/objectSpread2';
2
2
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
3
3
  import { getAccountsFromNamespaces, parseAccountId } from '@walletconnect/utils';
4
4
  import { providerErrors, JRPCEngine, providerFromEngine } from '@web3auth/auth';
5
+ import { formatChainId } from './utils.js';
5
6
  import { switchChain, getAccounts, getEthProviderHandlers, getSolProviderHandlers } from './walletConnectV2Utils.js';
6
7
  import { createEthMiddleware, createEthChainSwitchMiddleware } from '../../providers/ethereum-provider/rpc/ethRpcMiddlewares.js';
7
8
  import { createEthJsonRpcClient } from '../../providers/ethereum-provider/rpc/jrpcClient.js';
@@ -196,15 +197,14 @@ class WalletConnectV2Provider extends BaseProvider {
196
197
  if (event.name === "chainChanged") {
197
198
  if (!data) return;
198
199
  const connectedChainId = data;
199
- const connectedHexChainId = `0x${connectedChainId.toString(16)}`;
200
-
200
+ const formattedChainId = formatChainId(connectedChainId);
201
201
  // Check if chainId changed and trigger event
202
202
  const {
203
203
  currentChain
204
204
  } = this;
205
- if (connectedHexChainId && currentChain.chainId !== connectedHexChainId) {
205
+ if (formattedChainId && currentChain.chainId !== formattedChainId) {
206
206
  // Handle rpcUrl update
207
- await this.setupEngine(connector, connectedHexChainId);
207
+ await this.setupEngine(connector, formattedChainId);
208
208
  }
209
209
  }
210
210
  });
@@ -0,0 +1,12 @@
1
+ import '@babel/runtime/helpers/objectSpread2';
2
+
3
+ const formatChainId = chainId => {
4
+ if (typeof chainId === "number") {
5
+ return `0x${chainId.toString(16)}`;
6
+ } else if (typeof chainId === "string") {
7
+ return chainId.startsWith("0x") ? chainId : `0x${parseInt(chainId, 10).toString(16)}`;
8
+ }
9
+ throw new Error(`Invalid chainId: ${chainId}`);
10
+ };
11
+
12
+ export { formatChainId };
@@ -2,7 +2,7 @@ import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProper
2
2
  import _objectSpread from '@babel/runtime/helpers/objectSpread2';
3
3
  import { useMemo, createElement, useEffect, Fragment } from 'react';
4
4
  import { defineChain } from 'viem';
5
- import { webSocket, http, createConfig, WagmiProvider as WagmiProvider$1, useConfig, useReconnect, useAccountEffect } from 'wagmi';
5
+ import { createConfig, WagmiProvider as WagmiProvider$1, webSocket, http, fallback, useConfig, useReconnect, useAccountEffect } from 'wagmi';
6
6
  import { injected } from 'wagmi/connectors';
7
7
  import { defaultWagmiConfig } from './constants.js';
8
8
  import { useWeb3Auth } from '../hooks/useWeb3Auth.js';
@@ -113,6 +113,20 @@ function WagmiProvider(_ref) {
113
113
  web3Auth,
114
114
  isInitialized
115
115
  } = useWeb3Auth();
116
+ const getTransport = chain => {
117
+ const {
118
+ wsTarget,
119
+ rpcTarget,
120
+ fallbackWsTargets = [],
121
+ fallbackRpcTargets = []
122
+ } = chain;
123
+ const transports = [];
124
+ if (wsTarget) transports.push(webSocket(wsTarget));
125
+ if (fallbackWsTargets.length > 0) transports.push(...fallbackWsTargets.map(target => webSocket(target)));
126
+ if (rpcTarget) transports.push(http(rpcTarget));
127
+ if (fallbackRpcTargets.length > 0) transports.push(...fallbackRpcTargets.map(target => http(target)));
128
+ return fallback(transports);
129
+ };
116
130
  const finalConfig = useMemo(() => {
117
131
  var _web3Auth$coreOptions;
118
132
  web3Auth === null || web3Auth === void 0 || web3Auth.setAnalyticsProperties({
@@ -163,7 +177,7 @@ function WagmiProvider(_ref) {
163
177
  } else {
164
178
  wagmiChains.push(wagmiChain);
165
179
  }
166
- finalConfig.transports[wagmiChain.id] = chain.wsTarget ? webSocket(chain.wsTarget) : http(chain.rpcTarget);
180
+ finalConfig.transports[wagmiChain.id] = getTransport(chain);
167
181
  });
168
182
  finalConfig.chains = [wagmiChains[0], ...wagmiChains.slice(1)];
169
183
  }
@@ -3,7 +3,7 @@ import { hydrate } from '@wagmi/core';
3
3
  import { configKey, createConfig, useConfig, useReconnect, useAccountEffect } from '@wagmi/vue';
4
4
  import { injected } from '@wagmi/vue/connectors';
5
5
  import { randomId } from '@web3auth/auth';
6
- import { defineChain, webSocket, http } from 'viem';
6
+ import { defineChain, webSocket, http, fallback } from 'viem';
7
7
  import { defineComponent, h, shallowRef, ref, watch, provide } from 'vue';
8
8
  import { log } from '../../base/loglevel.js';
9
9
  import { defaultWagmiConfig } from './constants.js';
@@ -142,6 +142,20 @@ const WagmiProvider = defineComponent({
142
142
  } = useWeb3Auth();
143
143
  const finalConfig = shallowRef(defaultWagmiConfig);
144
144
  const configKey = ref(randomId());
145
+ const getTransport = chain => {
146
+ const {
147
+ wsTarget,
148
+ rpcTarget,
149
+ fallbackWsTargets = [],
150
+ fallbackRpcTargets = []
151
+ } = chain;
152
+ const transports = [];
153
+ if (wsTarget) transports.push(webSocket(wsTarget));
154
+ if (fallbackWsTargets.length > 0) transports.push(...fallbackWsTargets.map(target => webSocket(target)));
155
+ if (rpcTarget) transports.push(http(rpcTarget));
156
+ if (fallbackRpcTargets.length > 0) transports.push(...fallbackRpcTargets.map(target => http(target)));
157
+ return fallback(transports);
158
+ };
145
159
  const defineWagmiConfig = () => {
146
160
  var _web3Auth$value;
147
161
  const configParams = _objectSpread(_objectSpread({
@@ -188,7 +202,7 @@ const WagmiProvider = defineComponent({
188
202
  } else {
189
203
  wagmiChains.push(wagmiChain);
190
204
  }
191
- configParams.transports[wagmiChain.id] = chain.wsTarget ? webSocket(chain.wsTarget) : http(chain.rpcTarget);
205
+ configParams.transports[wagmiChain.id] = getTransport(chain);
192
206
  });
193
207
  configParams.chains = [wagmiChains[0], ...wagmiChains.slice(1)];
194
208
  }