@openfort/react 1.0.10 → 1.0.12

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.
@@ -5,6 +5,7 @@ import { routes } from '../components/Openfort/types.js';
5
5
  import { useOpenfort } from '../components/Openfort/useOpenfort.js';
6
6
  import { embeddedWalletId } from '../constants/openfort.js';
7
7
  import { ConnectionStrategyProvider, useConnectionStrategy } from '../core/ConnectionStrategyContext.js';
8
+ import { resolveEthereumFeeSponsorship } from '../core/strategyUtils.js';
8
9
  import { OpenfortEthereumBridgeContext } from '../ethereum/OpenfortEthereumBridgeContext.js';
9
10
  import { useConnectLifecycle } from '../hooks/useConnectLifecycle.js';
10
11
  import { showInitBanner } from '../utils/banner.js';
@@ -91,13 +92,14 @@ const CoreOpenfortProvider = ({ children, onConnect, onDisconnect, openfortConfi
91
92
  return newClient;
92
93
  }, []);
93
94
  const store = useMemo(() => {
95
+ var _a;
94
96
  return createOpenfortStore(chainType, openfort, () => {
95
97
  var _a;
96
98
  return ({
97
99
  hasBridge: !!bridgeRef.current,
98
100
  address: (_a = bridgeRef.current) === null || _a === void 0 ? void 0 : _a.account.address,
99
101
  });
100
- });
102
+ }, (_a = walletConfig === null || walletConfig === void 0 ? void 0 : walletConfig.connectOnLogin) !== null && _a !== void 0 ? _a : true);
101
103
  }, []);
102
104
  // Sync chainType from UI context into the store — useLayoutEffect so the store
103
105
  // is updated before the next paint, preventing a one-render-cycle race where
@@ -229,6 +231,7 @@ const CoreOpenfortProvider = ({ children, onConnect, onDisconnect, openfortConfi
229
231
  const initInProgressRef = useRef(false);
230
232
  // Init provider; only fetch accounts when READY (prevents list() before auth is stored)
231
233
  useEffect(() => {
234
+ var _a;
232
235
  if (!openfort || !walletConfig || !strategy)
233
236
  return;
234
237
  // EVM: only run at READY — auto-recover handles EMBEDDED_SIGNER_NOT_CONFIGURED → READY.
@@ -241,12 +244,14 @@ const CoreOpenfortProvider = ({ children, onConnect, onDisconnect, openfortConfi
241
244
  }
242
245
  }
243
246
  // Skip if we already initialized with the same parameters
244
- const initKey = { kind: strategy.kind, chainType: strategy.chainType, evmChainId };
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 };
245
249
  const prev = lastInitRef.current;
246
250
  if (prev &&
247
251
  prev.kind === initKey.kind &&
248
252
  prev.chainType === initKey.chainType &&
249
- prev.evmChainId === initKey.evmChainId) {
253
+ prev.evmChainId === initKey.evmChainId &&
254
+ prev.feeSponsorshipPolicy === initKey.feeSponsorshipPolicy) {
250
255
  return;
251
256
  }
252
257
  // Prevent concurrent initProvider calls
@@ -1 +1 @@
1
- {"version":3,"file":"CoreOpenfortProvider.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"CoreOpenfortProvider.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -43,4 +43,4 @@ export type OpenfortStore = OpenfortStoreState & OpenfortStoreActions;
43
43
  export declare function createOpenfortStore(initialChainType: ChainTypeEnum, client: Openfort, getBridgeInfo?: () => {
44
44
  hasBridge: boolean;
45
45
  address: string | undefined;
46
- }): StoreApi<OpenfortStore>;
46
+ }, connectOnLogin?: boolean): StoreApi<OpenfortStore>;
@@ -1,7 +1,7 @@
1
1
  import { EmbeddedState } from '@openfort/openfort-js';
2
2
  import { createStore } from 'zustand/vanilla';
3
3
 
4
- function computeIsLoading(embeddedState, user, hasBridge, bridgeAddress) {
4
+ function computeIsLoading(embeddedState, user, hasBridge, bridgeAddress, embeddedAccounts, activeEmbeddedAddress, connectOnLogin) {
5
5
  switch (embeddedState) {
6
6
  case EmbeddedState.NONE:
7
7
  case EmbeddedState.CREATING_ACCOUNT:
@@ -15,6 +15,11 @@ function computeIsLoading(embeddedState, user, hasBridge, bridgeAddress) {
15
15
  return true;
16
16
  if (hasBridge && !bridgeAddress)
17
17
  return true;
18
+ // Embedded accounts exist but active address not yet synced.
19
+ // Only when connectOnLogin is true — when false, address is intentionally
20
+ // not auto-set and the user must pick a wallet via the UI.
21
+ if (connectOnLogin && (embeddedAccounts === null || embeddedAccounts === void 0 ? void 0 : embeddedAccounts.length) && !activeEmbeddedAddress)
22
+ return true;
18
23
  return false;
19
24
  default:
20
25
  return true;
@@ -24,7 +29,7 @@ function computeNeedsRecovery(embeddedState, embeddedAccounts) {
24
29
  var _a;
25
30
  return embeddedState === EmbeddedState.EMBEDDED_SIGNER_NOT_CONFIGURED && ((_a = embeddedAccounts === null || embeddedAccounts === void 0 ? void 0 : embeddedAccounts.length) !== null && _a !== void 0 ? _a : 0) > 0;
26
31
  }
27
- function createOpenfortStore(initialChainType, client, getBridgeInfo) {
32
+ function createOpenfortStore(initialChainType, client, getBridgeInfo, connectOnLogin = true) {
28
33
  const store = createStore((set) => ({
29
34
  user: null,
30
35
  linkedAccounts: [],
@@ -68,7 +73,7 @@ function createOpenfortStore(initialChainType, client, getBridgeInfo) {
68
73
  var _a;
69
74
  const state = store.getState();
70
75
  const info = (_a = getBridgeInfo === null || getBridgeInfo === void 0 ? void 0 : getBridgeInfo()) !== null && _a !== void 0 ? _a : { hasBridge: false, address: undefined };
71
- const loading = computeIsLoading(state.embeddedState, state.user, info.hasBridge, info.address);
76
+ const loading = computeIsLoading(state.embeddedState, state.user, info.hasBridge, info.address, state.embeddedAccounts, state.activeEmbeddedAddress, connectOnLogin);
72
77
  if (loading !== state.isLoading) {
73
78
  set({ isLoading: loading });
74
79
  }
@@ -86,9 +91,10 @@ function createOpenfortStore(initialChainType, client, getBridgeInfo) {
86
91
  const embeddedStateChanged = state.embeddedState !== prev.embeddedState;
87
92
  const userChanged = state.user !== prev.user;
88
93
  const embeddedAccountsChanged = state.embeddedAccounts !== prev.embeddedAccounts;
89
- if (embeddedStateChanged || userChanged) {
94
+ const activeAddressChanged = state.activeEmbeddedAddress !== prev.activeEmbeddedAddress;
95
+ if (embeddedStateChanged || userChanged || embeddedAccountsChanged || activeAddressChanged) {
90
96
  const info = (_a = getBridgeInfo === null || getBridgeInfo === void 0 ? void 0 : getBridgeInfo()) !== null && _a !== void 0 ? _a : { hasBridge: false, address: undefined };
91
- const isLoading = computeIsLoading(state.embeddedState, state.user, info.hasBridge, info.address);
97
+ const isLoading = computeIsLoading(state.embeddedState, state.user, info.hasBridge, info.address, state.embeddedAccounts, state.activeEmbeddedAddress, connectOnLogin);
92
98
  if (isLoading !== state.isLoading) {
93
99
  store.setState({ isLoading });
94
100
  }
@@ -1 +1 @@
1
- {"version":3,"file":"store.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"store.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1 +1 @@
1
- export declare const OPENFORT_VERSION = "1.0.10";
1
+ export declare const OPENFORT_VERSION = "1.0.12";
package/build/version.js CHANGED
@@ -1,4 +1,4 @@
1
- const OPENFORT_VERSION = '1.0.10';
1
+ const OPENFORT_VERSION = '1.0.12';
2
2
 
3
3
  export { OPENFORT_VERSION };
4
4
  //# sourceMappingURL=version.js.map
@@ -19,6 +19,7 @@ function useEmbeddedWalletWagmiSync() {
19
19
  const provider = status === 'connected' ? wallet.provider : null;
20
20
  // Track whether an external wallet was explicitly connected — don't override it
21
21
  const externalConnectorActiveRef = useRef(false);
22
+ const connectFailedRef = useRef(false);
22
23
  useEffect(() => {
23
24
  if (activeConnector && activeConnector.id !== embeddedWalletId) {
24
25
  externalConnectorActiveRef.current = true;
@@ -27,6 +28,10 @@ function useEmbeddedWalletWagmiSync() {
27
28
  externalConnectorActiveRef.current = false;
28
29
  }
29
30
  }, [activeConnector]);
31
+ // Reset failure flag when provider changes (new session = fresh attempt)
32
+ useEffect(() => {
33
+ connectFailedRef.current = false;
34
+ }, [provider]);
30
35
  // Keep the module-level provider slot in sync — clear on disconnect
31
36
  useEffect(() => {
32
37
  if (status === 'connected' && provider) {
@@ -45,6 +50,9 @@ function useEmbeddedWalletWagmiSync() {
45
50
  return;
46
51
  if ((activeConnector === null || activeConnector === void 0 ? void 0 : activeConnector.id) === embeddedWalletId)
47
52
  return;
53
+ // Already failed for this provider — don't retry
54
+ if (connectFailedRef.current)
55
+ return;
48
56
  // An external wallet is actively connected — don't override it
49
57
  if (externalConnectorActiveRef.current) {
50
58
  logger.log('[EmbeddedWalletWagmiSync] Skipping auto-connect — external wallet is active', {
@@ -56,7 +64,10 @@ function useEmbeddedWalletWagmiSync() {
56
64
  if (!embeddedConnector)
57
65
  return;
58
66
  logger.log('[EmbeddedWalletWagmiSync] Auto-connecting embedded wallet to wagmi');
59
- connectAsync({ connector: embeddedConnector }).catch(() => { });
67
+ connectAsync({ connector: embeddedConnector }).catch((error) => {
68
+ connectFailedRef.current = true;
69
+ logger.error('[EmbeddedWalletWagmiSync] Failed to connect embedded wallet to wagmi', error);
70
+ });
60
71
  }, [status, provider, wagmiStatus, activeConnector, connectors, connectAsync]);
61
72
  // Disconnect embedded connector from wagmi when the embedded wallet logs out
62
73
  useEffect(() => {
@@ -1 +1 @@
1
- {"version":3,"file":"useEmbeddedWalletWagmiSync.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"useEmbeddedWalletWagmiSync.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openfort/react",
3
- "version": "1.0.10",
3
+ "version": "1.0.12",
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.",