@openfort/react-native 1.0.9 → 1.1.0

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,39 +5,6 @@ import { getEmbeddedStateName, logger } from '../lib/logger';
5
5
  import { EmbeddedWalletWebView, NativePasskeyHandler, WebViewUtils } from '../native';
6
6
  import { createOpenfortClient, setDefaultClient } from './client';
7
7
  import { OpenfortContext } from './context';
8
- /**
9
- * Starts polling the embedded wallet state and invokes the callback when transitions occur.
10
- *
11
- * @param client - The Openfort client to query for embedded wallet state.
12
- * @param onChange - Callback invoked whenever the state changes.
13
- * @param intervalMs - Polling interval in milliseconds. Defaults to 1000ms.
14
- * @returns A function that stops polling when called.
15
- */
16
- function startEmbeddedStatePolling(client, onChange, intervalMs = 1000) {
17
- let lastState = null;
18
- let stopped = false;
19
- const check = async () => {
20
- if (stopped)
21
- return;
22
- try {
23
- const state = await client.embeddedWallet.getEmbeddedState();
24
- if (state !== lastState) {
25
- lastState = state;
26
- onChange(state);
27
- }
28
- }
29
- catch (error) {
30
- logger.error('Error checking embedded state with Openfort', error);
31
- }
32
- };
33
- const intervalId = setInterval(check, intervalMs);
34
- // Run once immediately so we don't wait for the first interval tick
35
- void check();
36
- return () => {
37
- stopped = true;
38
- clearInterval(intervalId);
39
- };
40
- }
41
8
  /**
42
9
  * Root provider component that initializes the Openfort SDK and makes it available throughout your app.
43
10
  *
@@ -139,15 +106,19 @@ export const OpenfortProvider = ({ children, publishableKey, supportedChains, wa
139
106
  }, [publishableKey, walletConfig, overrides, thirdPartyAuth, passkeyHandler]);
140
107
  // Embedded state
141
108
  const [embeddedState, setEmbeddedState] = useState(EmbeddedState.NONE);
142
- // Start polling embedded state: only update and log when state changes
109
+ // Watch embedded state: event-driven with polling fallback via core SDK
143
110
  useEffect(() => {
144
111
  if (!client)
145
112
  return;
146
- const stop = startEmbeddedStatePolling(client, (state) => {
147
- setEmbeddedState(state);
148
- logger.info('Current state of the embedded wallet:', getEmbeddedStateName(state));
149
- }, 1000);
150
- return stop;
113
+ return client.embeddedWallet.watchEmbeddedState({
114
+ onChange: (state) => {
115
+ setEmbeddedState(state);
116
+ logger.info('Current state of the embedded wallet:', getEmbeddedStateName(state));
117
+ },
118
+ onError: (error) => {
119
+ logger.error('Error watching embedded state', error);
120
+ },
121
+ });
151
122
  }, [client]);
152
123
  // Core state
153
124
  const [user, setUser] = useState(null);
@@ -119,7 +119,10 @@ export function useEmbeddedEthereumWallet(options = {}) {
119
119
  const accounts = await client.embeddedWallet.list({
120
120
  limit: 100,
121
121
  chainType: ChainTypeEnum.EVM,
122
- accountType: walletConfig?.accountType === AccountTypeEnum.EOA ? undefined : AccountTypeEnum.SMART_ACCOUNT,
122
+ accountType: walletConfig?.accountType === AccountTypeEnum.EOA ||
123
+ walletConfig?.accountType === AccountTypeEnum.DELEGATED_ACCOUNT
124
+ ? undefined
125
+ : walletConfig?.accountType || AccountTypeEnum.SMART_ACCOUNT,
123
126
  });
124
127
  // Filter for Ethereum accounts only
125
128
  setEmbeddedAccounts(accounts);
@@ -160,20 +163,20 @@ export function useEmbeddedEthereumWallet(options = {}) {
160
163
  }, [client]);
161
164
  // Get Ethereum provider
162
165
  const getEthereumProvider = useCallback(async () => {
163
- const resolvePolicy = () => {
164
- const ethereumProviderPolicyId = walletConfig?.ethereumProviderPolicyId;
165
- if (!ethereumProviderPolicyId)
166
+ const resolveFeeSponsorship = () => {
167
+ const feeSponsorshipId = walletConfig?.feeSponsorshipId;
168
+ if (!feeSponsorshipId)
166
169
  return undefined;
167
- if (typeof ethereumProviderPolicyId === 'string') {
168
- return ethereumProviderPolicyId;
170
+ if (typeof feeSponsorshipId === 'string') {
171
+ return feeSponsorshipId;
169
172
  }
170
173
  if (!options.chainId)
171
174
  return undefined;
172
- const policy = ethereumProviderPolicyId[options.chainId];
173
- if (!policy) {
175
+ const feeSponsorship = feeSponsorshipId[options.chainId];
176
+ if (!feeSponsorship) {
174
177
  return undefined;
175
178
  }
176
- return policy;
179
+ return feeSponsorship;
177
180
  };
178
181
  // Build chains map from supportedChains (chainId -> rpcUrl)
179
182
  const resolveChains = () => {
@@ -190,7 +193,7 @@ export function useEmbeddedEthereumWallet(options = {}) {
190
193
  };
191
194
  return await client.embeddedWallet.getEthereumProvider({
192
195
  announceProvider: false,
193
- policy: resolvePolicy(),
196
+ feeSponsorship: resolveFeeSponsorship(),
194
197
  chains: resolveChains(),
195
198
  });
196
199
  }, [client.embeddedWallet, walletConfig, options.chainId, supportedChains]);
@@ -287,7 +290,7 @@ export function useEmbeddedEthereumWallet(options = {}) {
287
290
  }
288
291
  // Build recovery params
289
292
  const recoveryParams = await buildRecoveryParams({ ...createOptions, userId: user?.id }, walletConfig);
290
- const accountType = createOptions?.accountType || walletConfig?.accountType || AccountTypeEnum.SMART_ACCOUNT;
293
+ const accountType = createOptions?.accountType || walletConfig?.accountType || AccountTypeEnum.EOA;
291
294
  // Create embedded wallet
292
295
  const embeddedAccount = await client.embeddedWallet.create({
293
296
  chainId: accountType === AccountTypeEnum.EOA ? undefined : chainId,
@@ -1,11 +1,11 @@
1
1
  import { type AccountTypeEnum, type SDKOverrides, type ThirdPartyAuthConfiguration } from '@openfort/openfort-js';
2
2
  import React from 'react';
3
- type PolicyConfig = string | Record<number, string>;
3
+ type FeeSponsorshipConfig = string | Record<number, string>;
4
4
  export type CommonEmbeddedWalletConfiguration = {
5
5
  /** Publishable key for the Shield API. */
6
6
  shieldPublishableKey: string;
7
- /** Policy ID (pol_...) for the embedded signer. */
8
- ethereumProviderPolicyId?: PolicyConfig;
7
+ /** Fee sponsorship ID for the embedded signer. */
8
+ feeSponsorshipId?: FeeSponsorshipConfig;
9
9
  accountType?: AccountTypeEnum;
10
10
  debug?: boolean;
11
11
  /** Recovery method for the embedded wallet: 'automatic', 'password', or 'passkey' */
@@ -178,7 +178,7 @@ export type CreateEthereumWalletOptions = {
178
178
  /** OTP code for Shield verification when using automatic recovery */
179
179
  otpCode?: string;
180
180
  accountType?: AccountTypeEnum;
181
- policyId?: string;
181
+ feeSponsorshipId?: string;
182
182
  /** Recovery method to use: 'automatic', 'password', or 'passkey' */
183
183
  recoveryMethod?: 'automatic' | 'password' | 'passkey';
184
184
  /** Passkey ID for passkey recovery (required when recoveryMethod is 'passkey' for recovery) */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@openfort/react-native",
3
3
  "main": "dist/index.js",
4
- "version": "1.0.9",
4
+ "version": "1.1.0",
5
5
  "license": "MIT",
6
6
  "description": "React Native SDK for Openfort platform integration",
7
7
  "repository": {
@@ -24,7 +24,7 @@
24
24
  }
25
25
  },
26
26
  "dependencies": {
27
- "@openfort/openfort-js": "^1.1.7",
27
+ "@openfort/openfort-js": "^1.3.0",
28
28
  "react-native-passkeys": "0.4.0"
29
29
  },
30
30
  "peerDependencies": {
@@ -57,7 +57,7 @@
57
57
  "react-native-webview": "^13.15.0",
58
58
  "size-limit": "^11.2.0",
59
59
  "typedoc": "^0.28.14",
60
- "typescript": "^5.9.3"
60
+ "typescript": "5.9.3"
61
61
  },
62
62
  "knip": {
63
63
  "entry": [