@openfort/react 1.0.13 → 1.0.14

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.
@@ -25,7 +25,11 @@ export interface ConnectionStrategy {
25
25
  getConnectRoutes(): ConnectRoute[];
26
26
  /** External wallet connectors; only when wagmi/bridge exists. Otherwise []. */
27
27
  getConnectors(): ExternalConnectorProps[];
28
- /** @param chainId - Current chain for EVM; when provided, uses this for fee sponsorship/rpc instead of config default. */
29
- initProvider(openfort: Openfort, walletConfig: OpenfortWalletConfig, chainId?: number): Promise<void>;
28
+ /**
29
+ * @param chainId - Current chain for EVM; when provided, uses this for fee sponsorship/rpc instead of config default.
30
+ * @param activeEmbeddedAddress - Active embedded account address. When undefined, EVM strategies skip
31
+ * `wallet_switchEthereumChain` to avoid sending `account: null` to /v2/accounts/switch-chain (422).
32
+ */
33
+ initProvider(openfort: Openfort, walletConfig: OpenfortWalletConfig, chainId?: number, activeEmbeddedAddress?: string): Promise<void>;
30
34
  disconnect(openfort: Openfort): Promise<void>;
31
35
  }
@@ -32,7 +32,7 @@ function createEthereumBridgeStrategy(bridge, connectors) {
32
32
  getConnectors() {
33
33
  return connectors;
34
34
  },
35
- async initProvider(openfort, walletConfig, chainIdOverride) {
35
+ async initProvider(openfort, walletConfig, chainIdOverride, activeEmbeddedAddress) {
36
36
  const chainId = chainIdOverride !== null && chainIdOverride !== void 0 ? chainIdOverride : bridge.chainId;
37
37
  const feeSponsorshipObj = chainId != null ? resolveEthereumFeeSponsorship(walletConfig, chainId) : undefined;
38
38
  const rpcUrls = bridge.config.chains.reduce((acc, ch) => {
@@ -54,20 +54,19 @@ function createEthereumBridgeStrategy(bridge, connectors) {
54
54
  });
55
55
  // Tell the provider which chain is active (EIP-1193). Keeps provider in sync with wagmi.
56
56
  // Skip if the chain hasn't changed since last init to avoid spurious 422s.
57
- // Also skip if there are no accounts yet switch-chain requires an initialized account.
58
- if (chainId != null && chainId !== lastInitChainId) {
59
- const accounts = (await provider.request({ method: 'eth_accounts' }));
60
- if (accounts.length > 0) {
61
- try {
62
- await provider.request({
63
- method: 'wallet_switchEthereumChain',
64
- params: [{ chainId: `0x${chainId.toString(16)}` }],
65
- });
66
- lastInitChainId = chainId;
67
- }
68
- catch (switchErr) {
69
- logger.warn('[@openfort/react] wallet_switchEthereumChain failed — provider may be on wrong chain', switchErr);
70
- }
57
+ // Skip if no active embedded account: openfort-js sends `account: null` to
58
+ // /v2/accounts/switch-chain 422. eth_accounts isn't a reliable proxy here —
59
+ // it returns the signer address even when the active account isn't set yet.
60
+ if (chainId != null && chainId !== lastInitChainId && activeEmbeddedAddress) {
61
+ try {
62
+ await provider.request({
63
+ method: 'wallet_switchEthereumChain',
64
+ params: [{ chainId: `0x${chainId.toString(16)}` }],
65
+ });
66
+ lastInitChainId = chainId;
67
+ }
68
+ catch (switchErr) {
69
+ logger.warn('[@openfort/react] wallet_switchEthereumChain failed — provider may be on wrong chain', switchErr);
71
70
  }
72
71
  }
73
72
  },
@@ -1 +1 @@
1
- {"version":3,"file":"EthereumBridgeStrategy.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"EthereumBridgeStrategy.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -44,7 +44,7 @@ function createEthereumEmbeddedStrategy(walletConfig) {
44
44
  getConnectors() {
45
45
  return [];
46
46
  },
47
- async initProvider(openfort, config, chainIdOverride) {
47
+ async initProvider(openfort, config, chainIdOverride, activeEmbeddedAddress) {
48
48
  var _a, _b;
49
49
  const ethereum = config === null || config === void 0 ? void 0 : config.ethereum;
50
50
  const chainId = (_a = chainIdOverride !== null && chainIdOverride !== void 0 ? chainIdOverride : ethereum === null || ethereum === void 0 ? void 0 : ethereum.chainId) !== null && _a !== void 0 ? _a : DEFAULT_DEV_CHAIN_ID;
@@ -57,20 +57,19 @@ function createEthereumEmbeddedStrategy(walletConfig) {
57
57
  // Tell the provider which chain is active (EIP-1193). Without this, the provider
58
58
  // stays on its initial chain (e.g. 80002) while fee sponsorship resolution is per-chain.
59
59
  // Skip if the chain hasn't changed since last init to avoid spurious 422s.
60
- // Also skip if there are no accounts yet switch-chain requires an initialized account.
61
- if (chainId !== lastInitChainId) {
62
- const accounts = (await provider.request({ method: 'eth_accounts' }));
63
- if (accounts.length > 0) {
64
- try {
65
- await provider.request({
66
- method: 'wallet_switchEthereumChain',
67
- params: [{ chainId: `0x${chainId.toString(16)}` }],
68
- });
69
- lastInitChainId = chainId;
70
- }
71
- catch (switchErr) {
72
- logger.warn('[@openfort/react] wallet_switchEthereumChain failed — provider may be on wrong chain', switchErr);
73
- }
60
+ // Skip if no active embedded account: openfort-js sends `account: null` to
61
+ // /v2/accounts/switch-chain 422. eth_accounts isn't a reliable proxy here —
62
+ // it returns the signer address even when the active account isn't set yet.
63
+ if (chainId !== lastInitChainId && activeEmbeddedAddress) {
64
+ try {
65
+ await provider.request({
66
+ method: 'wallet_switchEthereumChain',
67
+ params: [{ chainId: `0x${chainId.toString(16)}` }],
68
+ });
69
+ lastInitChainId = chainId;
70
+ }
71
+ catch (switchErr) {
72
+ logger.warn('[@openfort/react] wallet_switchEthereumChain failed — provider may be on wrong chain', switchErr);
74
73
  }
75
74
  }
76
75
  },
@@ -1 +1 @@
1
- {"version":3,"file":"EthereumEmbeddedStrategy.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"EthereumEmbeddedStrategy.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -245,13 +245,24 @@ const CoreOpenfortProvider = ({ children, onConnect, onDisconnect, openfortConfi
245
245
  }
246
246
  // Skip if we already initialized with the same parameters
247
247
  const feeSponsorshipPolicy = evmChainId != null ? (_a = resolveEthereumFeeSponsorship(walletConfig, evmChainId)) === null || _a === void 0 ? void 0 : _a.policy : undefined;
248
- const initKey = { kind: strategy.kind, chainType: strategy.chainType, evmChainId, feeSponsorshipPolicy };
248
+ // Track whether we had an active embedded address at init time. When it transitions
249
+ // from absent → present, we re-init so wallet_switchEthereumChain can finally fire
250
+ // (openfort-js needs the active account set, otherwise it sends `account: null` → 422).
251
+ const hasActiveEmbeddedAddress = !!storeActiveEmbeddedAddress;
252
+ const initKey = {
253
+ kind: strategy.kind,
254
+ chainType: strategy.chainType,
255
+ evmChainId,
256
+ feeSponsorshipPolicy,
257
+ hasActiveEmbeddedAddress,
258
+ };
249
259
  const prev = lastInitRef.current;
250
260
  if (prev &&
251
261
  prev.kind === initKey.kind &&
252
262
  prev.chainType === initKey.chainType &&
253
263
  prev.evmChainId === initKey.evmChainId &&
254
- prev.feeSponsorshipPolicy === initKey.feeSponsorshipPolicy) {
264
+ prev.feeSponsorshipPolicy === initKey.feeSponsorshipPolicy &&
265
+ prev.hasActiveEmbeddedAddress === initKey.hasActiveEmbeddedAddress) {
255
266
  return;
256
267
  }
257
268
  // Prevent concurrent initProvider calls
@@ -261,7 +272,7 @@ const CoreOpenfortProvider = ({ children, onConnect, onDisconnect, openfortConfi
261
272
  initInProgressRef.current = true;
262
273
  let cancelled = false;
263
274
  strategy
264
- .initProvider(openfort, walletConfig, evmChainId)
275
+ .initProvider(openfort, walletConfig, evmChainId, storeActiveEmbeddedAddress !== null && storeActiveEmbeddedAddress !== void 0 ? storeActiveEmbeddedAddress : undefined)
265
276
  .then(() => {
266
277
  if (cancelled)
267
278
  return;
@@ -283,7 +294,7 @@ const CoreOpenfortProvider = ({ children, onConnect, onDisconnect, openfortConfi
283
294
  // re-fire initProvider → repeated /v2/accounts/switch-chain 422s.
284
295
  cancelled = true;
285
296
  };
286
- }, [openfort, walletConfig, strategy, evmChainId, storeEmbeddedState]);
297
+ }, [openfort, walletConfig, strategy, evmChainId, storeEmbeddedState, storeActiveEmbeddedAddress]);
287
298
  // On refresh, embeddedState reaches READY before the user is loaded, so
288
299
  // fetchEmbeddedAccounts (called inside initProvider) returns empty. Re-fetch
289
300
  // once the user becomes available while still in READY state.
@@ -1 +1 @@
1
- {"version":3,"file":"CoreOpenfortProvider.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"CoreOpenfortProvider.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1 +1 @@
1
- export declare const OPENFORT_VERSION = "1.0.13";
1
+ export declare const OPENFORT_VERSION = "1.0.14";
package/build/version.js CHANGED
@@ -1,4 +1,4 @@
1
- const OPENFORT_VERSION = '1.0.13';
1
+ const OPENFORT_VERSION = '1.0.14';
2
2
 
3
3
  export { OPENFORT_VERSION };
4
4
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openfort/react",
3
- "version": "1.0.13",
3
+ "version": "1.0.14",
4
4
  "author": "Openfort (https://www.openfort.io)",
5
5
  "license": "BSD-2-Clause license",
6
6
  "description": "The easiest way to integrate Openfort to your project.",