@explorins/pers-sdk-react-native 2.2.0-alpha.4 → 2.2.0-alpha.7
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/hooks/index.js +1 -1
- package/dist/hooks/useRedemptions.d.ts +1 -1
- package/dist/hooks/useTransactionSigner.d.ts +5 -4
- package/dist/hooks/useTransactionSigner.d.ts.map +1 -1
- package/dist/hooks/useTransactionSigner.js +18 -8
- package/dist/hooks/useTransactions.d.ts +1 -1
- package/dist/index.js +40 -29
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/hooks/useTransactionSigner.ts +28 -12
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@explorins/pers-sdk-react-native",
|
|
3
|
-
"version": "2.2.0-alpha.
|
|
3
|
+
"version": "2.2.0-alpha.7",
|
|
4
4
|
"description": "React Native SDK for PERS Platform - Tourism Loyalty System with Blockchain Transaction Signing and WebAuthn Authentication",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"author": "eXplorins",
|
|
38
38
|
"license": "MIT",
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@explorins/pers-sdk": "^2.1.
|
|
41
|
-
"@explorins/pers-signer": "^1.0.
|
|
40
|
+
"@explorins/pers-sdk": "^2.1.33-alpha.0",
|
|
41
|
+
"@explorins/pers-signer": "^1.0.34",
|
|
42
42
|
"buffer": "^6.0.3",
|
|
43
43
|
"ethers": "^6.15.0"
|
|
44
44
|
},
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { useCallback, useState, useRef, useEffect } from 'react';
|
|
2
2
|
// import { usePersSDK } from '../providers/PersSDKProvider';
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
// TYPE-ONLY imports from /types entry - NO native module deps, safe at any time
|
|
5
|
+
import type { PersSignerConfig, StatusCallback, StatusUpdateData } from '@explorins/pers-signer/types';
|
|
6
|
+
import type { SigningStatus as SigningStatusType } from '@explorins/pers-signer/types';
|
|
7
|
+
// Runtime const import - also from /types (no native deps)
|
|
8
|
+
import { SigningStatus as SigningStatusConst } from '@explorins/pers-signer/types';
|
|
4
9
|
|
|
5
10
|
// Import actual SDK types from the React Native-specific export
|
|
6
11
|
type PersSignerSDK = import('@explorins/pers-signer/react-native').PersSignerSDK;
|
|
@@ -8,21 +13,29 @@ type SubmissionResult = import('@explorins/pers-signer/react-native').Submission
|
|
|
8
13
|
type AuthenticatedUser = import('@explorins/pers-signer/react-native').AuthenticatedUser;
|
|
9
14
|
type TransactionSigningResult = import('@explorins/pers-signer/react-native').TransactionSigningResult;
|
|
10
15
|
|
|
11
|
-
// Re-export
|
|
12
|
-
export { SigningStatus };
|
|
16
|
+
// Re-export the type for external consumers
|
|
17
|
+
export type { SigningStatusType as SigningStatus };
|
|
13
18
|
export type { StatusUpdateData };
|
|
14
19
|
|
|
15
20
|
/**
|
|
16
21
|
* Simple status callback function type for React Native consumers
|
|
17
22
|
* (Simplified from the signer SDK's object-based StatusCallback interface)
|
|
18
23
|
*/
|
|
19
|
-
export type OnStatusUpdateFn = (status:
|
|
24
|
+
export type OnStatusUpdateFn = (status: SigningStatusType, message: string, data?: StatusUpdateData) => void;
|
|
20
25
|
|
|
21
26
|
|
|
22
|
-
// Lazy-loaded signer SDK
|
|
27
|
+
// Lazy-loaded signer SDK - initialized on first use to avoid native module timing issues
|
|
23
28
|
let _createPersSignerSDK: ((config: PersSignerConfig) => Promise<PersSignerSDK>) | null = null;
|
|
24
29
|
let _signerInitAttempted = false;
|
|
25
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Get the SigningStatus const object
|
|
33
|
+
* Now directly imported from /types (no native deps, always available)
|
|
34
|
+
*/
|
|
35
|
+
function getSigningStatus(): typeof SigningStatusType {
|
|
36
|
+
return SigningStatusConst;
|
|
37
|
+
}
|
|
38
|
+
|
|
26
39
|
/**
|
|
27
40
|
* Lazily load the PERS Signer SDK.
|
|
28
41
|
*
|
|
@@ -41,7 +54,8 @@ function getSignerSDKFactory(): ((config: PersSignerConfig) => Promise<PersSigne
|
|
|
41
54
|
|
|
42
55
|
// Check for customer pre-initialized global (for native module timing issues)
|
|
43
56
|
if (typeof global !== 'undefined' && (global as any).__PersSigner?.createPersSignerSDK) {
|
|
44
|
-
|
|
57
|
+
const globalModule = (global as any).__PersSigner;
|
|
58
|
+
_createPersSignerSDK = globalModule.createPersSignerSDK;
|
|
45
59
|
return _createPersSignerSDK;
|
|
46
60
|
}
|
|
47
61
|
|
|
@@ -79,7 +93,7 @@ export interface TransactionSignerHook {
|
|
|
79
93
|
signPersTransaction: (jwt: string, onStatusUpdate?: OnStatusUpdateFn) => Promise<TransactionSigningResult>;
|
|
80
94
|
isSignerInitialized: boolean;
|
|
81
95
|
isSignerAvailable: boolean;
|
|
82
|
-
currentStatus:
|
|
96
|
+
currentStatus: SigningStatusType | null;
|
|
83
97
|
statusMessage: string | null;
|
|
84
98
|
}
|
|
85
99
|
|
|
@@ -266,7 +280,7 @@ const DEFAULT_ETHERS_PROVIDER = "https://sepolia.infura.io/v3/2781b4b5242343d5b0
|
|
|
266
280
|
export const useTransactionSigner = (): TransactionSignerHook => {
|
|
267
281
|
// const { isInitialized, isAuthenticated, user } = usePersSDK();
|
|
268
282
|
const [isSignerInitialized, setIsSignerInitialized] = useState(false);
|
|
269
|
-
const [currentStatus, setCurrentStatus] = useState<
|
|
283
|
+
const [currentStatus, setCurrentStatus] = useState<SigningStatusType | null>(null);
|
|
270
284
|
const [statusMessage, setStatusMessage] = useState<string | null>(null);
|
|
271
285
|
const signerSDKRef = useRef<PersSignerSDK | null>(null);
|
|
272
286
|
|
|
@@ -398,7 +412,7 @@ export const useTransactionSigner = (): TransactionSignerHook => {
|
|
|
398
412
|
|
|
399
413
|
// Create status callback wrapper that updates both hook state and calls user callback
|
|
400
414
|
const statusCallback: StatusCallback = {
|
|
401
|
-
onStatusUpdate: (status:
|
|
415
|
+
onStatusUpdate: (status: SigningStatusType, message: string, data?: StatusUpdateData) => {
|
|
402
416
|
setCurrentStatus(status);
|
|
403
417
|
setStatusMessage(message);
|
|
404
418
|
onStatusUpdate?.(status, message, data);
|
|
@@ -413,7 +427,8 @@ export const useTransactionSigner = (): TransactionSignerHook => {
|
|
|
413
427
|
|
|
414
428
|
} catch (error) {
|
|
415
429
|
console.error('[useTransactionSigner] JWT transaction signing failed:', error);
|
|
416
|
-
|
|
430
|
+
const SigningStatusEnum = getSigningStatus();
|
|
431
|
+
if (SigningStatusEnum) setCurrentStatus(SigningStatusEnum.ERROR);
|
|
417
432
|
setStatusMessage(error instanceof Error ? error.message : 'Transaction failed');
|
|
418
433
|
throw error; // Re-throw to maintain error handling upstream
|
|
419
434
|
}
|
|
@@ -459,7 +474,7 @@ export const useTransactionSigner = (): TransactionSignerHook => {
|
|
|
459
474
|
|
|
460
475
|
// Create status callback wrapper
|
|
461
476
|
const statusCallback: StatusCallback = {
|
|
462
|
-
onStatusUpdate: (status:
|
|
477
|
+
onStatusUpdate: (status: SigningStatusType, message: string, data?: StatusUpdateData) => {
|
|
463
478
|
setCurrentStatus(status);
|
|
464
479
|
setStatusMessage(message);
|
|
465
480
|
onStatusUpdate?.(status, message, data);
|
|
@@ -472,7 +487,8 @@ export const useTransactionSigner = (): TransactionSignerHook => {
|
|
|
472
487
|
return signingResult;
|
|
473
488
|
} catch (error) {
|
|
474
489
|
console.error('[useTransactionSigner] Sign-only transaction failed:', error);
|
|
475
|
-
|
|
490
|
+
const SigningStatusEnum = getSigningStatus();
|
|
491
|
+
if (SigningStatusEnum) setCurrentStatus(SigningStatusEnum.ERROR);
|
|
476
492
|
setStatusMessage(error instanceof Error ? error.message : 'Signing failed');
|
|
477
493
|
throw error;
|
|
478
494
|
}
|