@openfort/react-native 1.0.10 → 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.
package/dist/core/provider.js
CHANGED
|
@@ -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
|
-
//
|
|
109
|
+
// Watch embedded state: event-driven with polling fallback via core SDK
|
|
143
110
|
useEffect(() => {
|
|
144
111
|
if (!client)
|
|
145
112
|
return;
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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);
|
|
@@ -163,20 +163,20 @@ export function useEmbeddedEthereumWallet(options = {}) {
|
|
|
163
163
|
}, [client]);
|
|
164
164
|
// Get Ethereum provider
|
|
165
165
|
const getEthereumProvider = useCallback(async () => {
|
|
166
|
-
const
|
|
167
|
-
const
|
|
168
|
-
if (!
|
|
166
|
+
const resolveFeeSponsorship = () => {
|
|
167
|
+
const feeSponsorshipId = walletConfig?.feeSponsorshipId;
|
|
168
|
+
if (!feeSponsorshipId)
|
|
169
169
|
return undefined;
|
|
170
|
-
if (typeof
|
|
171
|
-
return
|
|
170
|
+
if (typeof feeSponsorshipId === 'string') {
|
|
171
|
+
return feeSponsorshipId;
|
|
172
172
|
}
|
|
173
173
|
if (!options.chainId)
|
|
174
174
|
return undefined;
|
|
175
|
-
const
|
|
176
|
-
if (!
|
|
175
|
+
const feeSponsorship = feeSponsorshipId[options.chainId];
|
|
176
|
+
if (!feeSponsorship) {
|
|
177
177
|
return undefined;
|
|
178
178
|
}
|
|
179
|
-
return
|
|
179
|
+
return feeSponsorship;
|
|
180
180
|
};
|
|
181
181
|
// Build chains map from supportedChains (chainId -> rpcUrl)
|
|
182
182
|
const resolveChains = () => {
|
|
@@ -193,7 +193,7 @@ export function useEmbeddedEthereumWallet(options = {}) {
|
|
|
193
193
|
};
|
|
194
194
|
return await client.embeddedWallet.getEthereumProvider({
|
|
195
195
|
announceProvider: false,
|
|
196
|
-
|
|
196
|
+
feeSponsorship: resolveFeeSponsorship(),
|
|
197
197
|
chains: resolveChains(),
|
|
198
198
|
});
|
|
199
199
|
}, [client.embeddedWallet, walletConfig, options.chainId, supportedChains]);
|
|
@@ -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
|
|
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
|
-
/**
|
|
8
|
-
|
|
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
|
-
|
|
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
|
|
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.
|
|
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": "
|
|
60
|
+
"typescript": "5.9.3"
|
|
61
61
|
},
|
|
62
62
|
"knip": {
|
|
63
63
|
"entry": [
|