@explorins/pers-sdk-react-native 1.5.17 → 1.5.18

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@explorins/pers-sdk-react-native",
3
- "version": "1.5.17",
3
+ "version": "1.5.18",
4
4
  "description": "React Native SDK for PERS Platform - Tourism Loyalty System with Manager Pattern Architecture",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,5 +1,6 @@
1
1
  import { useCallback } from 'react';
2
2
  import { usePersSDK } from '../providers/PersSDKProvider';
3
+ import { useTransactionSigner } from './useTransactionSigner';
3
4
  import type {
4
5
  TransactionRequestDTO,
5
6
  TransactionRequestResponseDTO,
@@ -45,6 +46,7 @@ import type { TransactionPaginationParams } from '@explorins/pers-sdk/transactio
45
46
  */
46
47
  export const useTransactions = () => {
47
48
  const { sdk, isInitialized, isAuthenticated } = usePersSDK();
49
+ const { signTransactionWithJWT, isSignerAvailable } = useTransactionSigner();
48
50
 
49
51
  if (!isAuthenticated && isInitialized) {
50
52
  console.warn('SDK not authenticated. Some transaction operations may fail.');
@@ -80,15 +82,45 @@ export const useTransactions = () => {
80
82
  try {
81
83
  const result = await sdk.transactions.createTransaction(request);
82
84
 
83
- // Cross-platform: Dont handle signature URLs here, leave to caller
84
-
85
85
  console.log('Transaction created successfully:', result);
86
+
87
+ // Check if transaction requires signing (contains actionable authToken)
88
+ // Type assertion needed as TransactionRequestResponseDTO type may not include all dynamic properties
89
+ const txToken = result?.actionable?.authToken;
90
+ if (txToken) {
91
+ console.log('[useTransactions] Transaction requires signing, attempting automatic signature...');
92
+
93
+ try {
94
+ if (!isSignerAvailable) {
95
+ console.warn('[useTransactions] Transaction signer not available, skipping automatic signing');
96
+ return result;
97
+ }
98
+
99
+ // Automatically sign the transaction using the authToken
100
+ const signingResult = await signTransactionWithJWT(txToken);
101
+
102
+ if (signingResult.success) {
103
+ console.log('[useTransactions] Transaction signed successfully:', signingResult.transactionHash);
104
+ // Return the original result - the transaction is now signed and will be processed
105
+ return result;
106
+ } else {
107
+ console.error('[useTransactions] Transaction signing failed:', signingResult.error);
108
+ // Don't throw error - return the original result so caller can handle signature URL manually
109
+ return result;
110
+ }
111
+ } catch (signingError) {
112
+ console.error('[useTransactions] Blockchain signing error:', signingError);
113
+ // Don't throw error - return the original result so caller can handle signature URL manually
114
+ return result;
115
+ }
116
+ }
117
+
86
118
  return result;
87
119
  } catch (error) {
88
120
  console.error('Failed to create transaction:', error);
89
121
  throw error;
90
122
  }
91
- }, [sdk, isInitialized]);
123
+ }, [sdk, isInitialized, signTransactionWithJWT, isSignerAvailable]);
92
124
 
93
125
  /**
94
126
  * Retrieves a specific transaction by its ID