@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/dist/hooks/useTransactions.d.ts.map +1 -1
- package/dist/hooks/useTransactions.js +32 -2
- package/dist/index.js +216 -187
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/hooks/useTransactions.ts +35 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTransactions.d.ts","sourceRoot":"","sources":["../../src/hooks/useTransactions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useTransactions.d.ts","sourceRoot":"","sources":["../../src/hooks/useTransactions.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,qBAAqB,EACrB,6BAA6B,EAC7B,cAAc,EACf,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,iCAAiC,CAAC;AAEnF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,eAAO,MAAM,eAAe;iCA8B4B,qBAAqB,KAAG,QAAQ,6BAA6B,CAAC;wCA8DvD,MAAM,KAAG,QAAQ,cAAc,GAAG,IAAI,CAAC;uCA6BzC,MAAM,KAAW,QAAQ,cAAc,EAAE,CAAC;iCAejD,QAAQ,cAAc,EAAE,CAAC;uCAejB,2BAA2B,KAAG,QAAQ,GAAG,CAAC;iCAelD,QAAQ,IAAI,CAAC;;CAwBlE,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG,UAAU,CAAC,OAAO,eAAe,CAAC,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useCallback } from 'react';
|
|
2
2
|
import { usePersSDK } from '../providers/PersSDKProvider';
|
|
3
|
+
import { useTransactionSigner } from './useTransactionSigner';
|
|
3
4
|
/**
|
|
4
5
|
* React hook for transaction operations in the PERS SDK
|
|
5
6
|
*
|
|
@@ -38,6 +39,7 @@ import { usePersSDK } from '../providers/PersSDKProvider';
|
|
|
38
39
|
*/
|
|
39
40
|
export const useTransactions = () => {
|
|
40
41
|
const { sdk, isInitialized, isAuthenticated } = usePersSDK();
|
|
42
|
+
const { signTransactionWithJWT, isSignerAvailable } = useTransactionSigner();
|
|
41
43
|
if (!isAuthenticated && isInitialized) {
|
|
42
44
|
console.warn('SDK not authenticated. Some transaction operations may fail.');
|
|
43
45
|
}
|
|
@@ -69,15 +71,43 @@ export const useTransactions = () => {
|
|
|
69
71
|
}
|
|
70
72
|
try {
|
|
71
73
|
const result = await sdk.transactions.createTransaction(request);
|
|
72
|
-
// Cross-platform: Dont handle signature URLs here, leave to caller
|
|
73
74
|
console.log('Transaction created successfully:', result);
|
|
75
|
+
// Check if transaction requires signing (contains actionable authToken)
|
|
76
|
+
// Type assertion needed as TransactionRequestResponseDTO type may not include all dynamic properties
|
|
77
|
+
const txToken = result?.actionable?.authToken;
|
|
78
|
+
if (txToken) {
|
|
79
|
+
console.log('[useTransactions] Transaction requires signing, attempting automatic signature...');
|
|
80
|
+
try {
|
|
81
|
+
if (!isSignerAvailable) {
|
|
82
|
+
console.warn('[useTransactions] Transaction signer not available, skipping automatic signing');
|
|
83
|
+
return result;
|
|
84
|
+
}
|
|
85
|
+
// Automatically sign the transaction using the authToken
|
|
86
|
+
const signingResult = await signTransactionWithJWT(txToken);
|
|
87
|
+
if (signingResult.success) {
|
|
88
|
+
console.log('[useTransactions] Transaction signed successfully:', signingResult.transactionHash);
|
|
89
|
+
// Return the original result - the transaction is now signed and will be processed
|
|
90
|
+
return result;
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
console.error('[useTransactions] Transaction signing failed:', signingResult.error);
|
|
94
|
+
// Don't throw error - return the original result so caller can handle signature URL manually
|
|
95
|
+
return result;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
catch (signingError) {
|
|
99
|
+
console.error('[useTransactions] Blockchain signing error:', signingError);
|
|
100
|
+
// Don't throw error - return the original result so caller can handle signature URL manually
|
|
101
|
+
return result;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
74
104
|
return result;
|
|
75
105
|
}
|
|
76
106
|
catch (error) {
|
|
77
107
|
console.error('Failed to create transaction:', error);
|
|
78
108
|
throw error;
|
|
79
109
|
}
|
|
80
|
-
}, [sdk, isInitialized]);
|
|
110
|
+
}, [sdk, isInitialized, signTransactionWithJWT, isSignerAvailable]);
|
|
81
111
|
/**
|
|
82
112
|
* Retrieves a specific transaction by its ID
|
|
83
113
|
*
|
package/dist/index.js
CHANGED
|
@@ -30055,193 +30055,6 @@ const useTokens = () => {
|
|
|
30055
30055
|
};
|
|
30056
30056
|
};
|
|
30057
30057
|
|
|
30058
|
-
/**
|
|
30059
|
-
* React hook for transaction operations in the PERS SDK
|
|
30060
|
-
*
|
|
30061
|
-
* Provides comprehensive transaction management including creation, retrieval, history,
|
|
30062
|
-
* and administrative operations. Supports pagination and CSV export functionality.
|
|
30063
|
-
*
|
|
30064
|
-
* @returns Transaction hook with methods for transaction management
|
|
30065
|
-
*
|
|
30066
|
-
* @example
|
|
30067
|
-
* ```typescript
|
|
30068
|
-
* function TransactionsComponent() {
|
|
30069
|
-
* const {
|
|
30070
|
-
* createTransaction,
|
|
30071
|
-
* getUserTransactionHistory
|
|
30072
|
-
* } = useTransactions();
|
|
30073
|
-
*
|
|
30074
|
-
* const handleCreateTransaction = async (request) => {
|
|
30075
|
-
* try {
|
|
30076
|
-
* const result = await createTransaction(request);
|
|
30077
|
-
* console.log('Transaction created:', result);
|
|
30078
|
-
* // Handle signature URL if returned
|
|
30079
|
-
* } catch (error) {
|
|
30080
|
-
* console.error('Transaction failed:', error);
|
|
30081
|
-
* }
|
|
30082
|
-
* };
|
|
30083
|
-
*
|
|
30084
|
-
* return (
|
|
30085
|
-
* <div>
|
|
30086
|
-
* <button onClick={() => handleCreateTransaction(transactionRequest)}>
|
|
30087
|
-
* Create Transaction
|
|
30088
|
-
* </button>
|
|
30089
|
-
* </div>
|
|
30090
|
-
* );
|
|
30091
|
-
* }
|
|
30092
|
-
* ```
|
|
30093
|
-
*/
|
|
30094
|
-
const useTransactions = () => {
|
|
30095
|
-
const { sdk, isInitialized, isAuthenticated } = usePersSDK();
|
|
30096
|
-
if (!isAuthenticated && isInitialized) {
|
|
30097
|
-
console.warn('SDK not authenticated. Some transaction operations may fail.');
|
|
30098
|
-
}
|
|
30099
|
-
/**
|
|
30100
|
-
* Creates a new transaction in the system
|
|
30101
|
-
*
|
|
30102
|
-
* Automatically handles signature URLs by opening them in the device's browser.
|
|
30103
|
-
* The transaction may require user approval through external wallet applications.
|
|
30104
|
-
*
|
|
30105
|
-
* @param request - Transaction request data including amount, recipient, etc.
|
|
30106
|
-
* @returns Promise resolving to transaction response with potential actionable items
|
|
30107
|
-
* @throws Error if SDK is not initialized
|
|
30108
|
-
*
|
|
30109
|
-
* @example
|
|
30110
|
-
* ```typescript
|
|
30111
|
-
* const { createTransaction } = useTransactions();
|
|
30112
|
-
* const request = {
|
|
30113
|
-
* amount: '100',
|
|
30114
|
-
* recipient: '0x123...',
|
|
30115
|
-
* tokenId: 'token-123'
|
|
30116
|
-
* };
|
|
30117
|
-
* const result = await createTransaction(request);
|
|
30118
|
-
* console.log('Transaction created:', result);
|
|
30119
|
-
* ```
|
|
30120
|
-
*/
|
|
30121
|
-
const createTransaction = react.useCallback(async (request) => {
|
|
30122
|
-
if (!isInitialized || !sdk) {
|
|
30123
|
-
throw new Error('SDK not initialized. Call initialize() first.');
|
|
30124
|
-
}
|
|
30125
|
-
try {
|
|
30126
|
-
const result = await sdk.transactions.createTransaction(request);
|
|
30127
|
-
// Cross-platform: Dont handle signature URLs here, leave to caller
|
|
30128
|
-
console.log('Transaction created successfully:', result);
|
|
30129
|
-
return result;
|
|
30130
|
-
}
|
|
30131
|
-
catch (error) {
|
|
30132
|
-
console.error('Failed to create transaction:', error);
|
|
30133
|
-
throw error;
|
|
30134
|
-
}
|
|
30135
|
-
}, [sdk, isInitialized]);
|
|
30136
|
-
/**
|
|
30137
|
-
* Retrieves a specific transaction by its ID
|
|
30138
|
-
*
|
|
30139
|
-
* @param transactionId - Unique identifier of the transaction
|
|
30140
|
-
* @returns Promise resolving to transaction data or null if not found
|
|
30141
|
-
* @throws Error if SDK is not initialized
|
|
30142
|
-
*
|
|
30143
|
-
* @example
|
|
30144
|
-
* ```typescript
|
|
30145
|
-
* const { getTransactionById } = useTransactions();
|
|
30146
|
-
* const transaction = await getTransactionById('txn-123');
|
|
30147
|
-
* console.log('Transaction details:', transaction);
|
|
30148
|
-
* ```
|
|
30149
|
-
*/
|
|
30150
|
-
const getTransactionById = react.useCallback(async (transactionId) => {
|
|
30151
|
-
if (!isInitialized || !sdk) {
|
|
30152
|
-
throw new Error('SDK not initialized. Call initialize() first.');
|
|
30153
|
-
}
|
|
30154
|
-
try {
|
|
30155
|
-
const result = await sdk.transactions.getTransactionById(transactionId);
|
|
30156
|
-
console.log('Transaction fetched successfully:', result);
|
|
30157
|
-
return result;
|
|
30158
|
-
}
|
|
30159
|
-
catch (error) {
|
|
30160
|
-
console.error('Failed to fetch transaction:', error);
|
|
30161
|
-
throw error;
|
|
30162
|
-
}
|
|
30163
|
-
}, [sdk, isInitialized]);
|
|
30164
|
-
/**
|
|
30165
|
-
* Retrieves transaction history for the authenticated user, filtered by type
|
|
30166
|
-
*
|
|
30167
|
-
* @param type - Transaction type filter (defaults to 'all')
|
|
30168
|
-
* @returns Promise resolving to array of user's transactions
|
|
30169
|
-
* @throws Error if SDK is not initialized
|
|
30170
|
-
*
|
|
30171
|
-
* @example
|
|
30172
|
-
* ```typescript
|
|
30173
|
-
* const { getUserTransactionHistory } = useTransactions();
|
|
30174
|
-
* const transactions = await getUserTransactionHistory('credit');
|
|
30175
|
-
* console.log('Credit transactions:', transactions);
|
|
30176
|
-
* ```
|
|
30177
|
-
*/
|
|
30178
|
-
const getUserTransactionHistory = react.useCallback(async (type = 'all') => {
|
|
30179
|
-
if (!isInitialized || !sdk) {
|
|
30180
|
-
throw new Error('SDK not initialized. Call initialize() first.');
|
|
30181
|
-
}
|
|
30182
|
-
try {
|
|
30183
|
-
const result = await sdk.transactions.getUserTransactionHistory(type);
|
|
30184
|
-
console.log('Transaction history fetched successfully:', result);
|
|
30185
|
-
return result;
|
|
30186
|
-
}
|
|
30187
|
-
catch (error) {
|
|
30188
|
-
console.error('Failed to fetch transaction history:', error);
|
|
30189
|
-
throw error;
|
|
30190
|
-
}
|
|
30191
|
-
}, [sdk, isInitialized]);
|
|
30192
|
-
const getTenantTransactions = react.useCallback(async () => {
|
|
30193
|
-
if (!isInitialized || !sdk) {
|
|
30194
|
-
throw new Error('SDK not initialized. Call initialize() first.');
|
|
30195
|
-
}
|
|
30196
|
-
try {
|
|
30197
|
-
const result = await sdk.transactions.getTenantTransactions();
|
|
30198
|
-
console.log('Tenant transactions fetched successfully:', result);
|
|
30199
|
-
return result;
|
|
30200
|
-
}
|
|
30201
|
-
catch (error) {
|
|
30202
|
-
console.error('Failed to fetch tenant transactions:', error);
|
|
30203
|
-
throw error;
|
|
30204
|
-
}
|
|
30205
|
-
}, [sdk, isInitialized]);
|
|
30206
|
-
const getPaginatedTransactions = react.useCallback(async (params) => {
|
|
30207
|
-
if (!isInitialized || !sdk) {
|
|
30208
|
-
throw new Error('SDK not initialized. Call initialize() first.');
|
|
30209
|
-
}
|
|
30210
|
-
try {
|
|
30211
|
-
const result = await sdk.transactions.getPaginatedTransactions(params);
|
|
30212
|
-
console.log('Paginated transactions fetched successfully:', result);
|
|
30213
|
-
return result;
|
|
30214
|
-
}
|
|
30215
|
-
catch (error) {
|
|
30216
|
-
console.error('Failed to fetch paginated transactions:', error);
|
|
30217
|
-
throw error;
|
|
30218
|
-
}
|
|
30219
|
-
}, [sdk, isInitialized]);
|
|
30220
|
-
const exportTransactionsCSV = react.useCallback(async () => {
|
|
30221
|
-
if (!isInitialized || !sdk) {
|
|
30222
|
-
throw new Error('SDK not initialized. Call initialize() first.');
|
|
30223
|
-
}
|
|
30224
|
-
try {
|
|
30225
|
-
const result = await sdk.transactions.exportTransactionsCSV();
|
|
30226
|
-
console.log('Transactions CSV exported successfully');
|
|
30227
|
-
return result;
|
|
30228
|
-
}
|
|
30229
|
-
catch (error) {
|
|
30230
|
-
console.error('Failed to export transactions CSV:', error);
|
|
30231
|
-
throw error;
|
|
30232
|
-
}
|
|
30233
|
-
}, [sdk, isInitialized]);
|
|
30234
|
-
return {
|
|
30235
|
-
createTransaction,
|
|
30236
|
-
getTransactionById,
|
|
30237
|
-
getUserTransactionHistory,
|
|
30238
|
-
getTenantTransactions,
|
|
30239
|
-
getPaginatedTransactions,
|
|
30240
|
-
exportTransactionsCSV,
|
|
30241
|
-
isAvailable: isInitialized && !!sdk?.transactions,
|
|
30242
|
-
};
|
|
30243
|
-
};
|
|
30244
|
-
|
|
30245
30058
|
// Dynamic import the signer SDK to avoid build issues with static dependencies
|
|
30246
30059
|
let createPersSignerSDK = null;
|
|
30247
30060
|
try {
|
|
@@ -30427,6 +30240,222 @@ const useTransactionSigner = () => {
|
|
|
30427
30240
|
};
|
|
30428
30241
|
};
|
|
30429
30242
|
|
|
30243
|
+
/**
|
|
30244
|
+
* React hook for transaction operations in the PERS SDK
|
|
30245
|
+
*
|
|
30246
|
+
* Provides comprehensive transaction management including creation, retrieval, history,
|
|
30247
|
+
* and administrative operations. Supports pagination and CSV export functionality.
|
|
30248
|
+
*
|
|
30249
|
+
* @returns Transaction hook with methods for transaction management
|
|
30250
|
+
*
|
|
30251
|
+
* @example
|
|
30252
|
+
* ```typescript
|
|
30253
|
+
* function TransactionsComponent() {
|
|
30254
|
+
* const {
|
|
30255
|
+
* createTransaction,
|
|
30256
|
+
* getUserTransactionHistory
|
|
30257
|
+
* } = useTransactions();
|
|
30258
|
+
*
|
|
30259
|
+
* const handleCreateTransaction = async (request) => {
|
|
30260
|
+
* try {
|
|
30261
|
+
* const result = await createTransaction(request);
|
|
30262
|
+
* console.log('Transaction created:', result);
|
|
30263
|
+
* // Handle signature URL if returned
|
|
30264
|
+
* } catch (error) {
|
|
30265
|
+
* console.error('Transaction failed:', error);
|
|
30266
|
+
* }
|
|
30267
|
+
* };
|
|
30268
|
+
*
|
|
30269
|
+
* return (
|
|
30270
|
+
* <div>
|
|
30271
|
+
* <button onClick={() => handleCreateTransaction(transactionRequest)}>
|
|
30272
|
+
* Create Transaction
|
|
30273
|
+
* </button>
|
|
30274
|
+
* </div>
|
|
30275
|
+
* );
|
|
30276
|
+
* }
|
|
30277
|
+
* ```
|
|
30278
|
+
*/
|
|
30279
|
+
const useTransactions = () => {
|
|
30280
|
+
const { sdk, isInitialized, isAuthenticated } = usePersSDK();
|
|
30281
|
+
const { signTransactionWithJWT, isSignerAvailable } = useTransactionSigner();
|
|
30282
|
+
if (!isAuthenticated && isInitialized) {
|
|
30283
|
+
console.warn('SDK not authenticated. Some transaction operations may fail.');
|
|
30284
|
+
}
|
|
30285
|
+
/**
|
|
30286
|
+
* Creates a new transaction in the system
|
|
30287
|
+
*
|
|
30288
|
+
* Automatically handles signature URLs by opening them in the device's browser.
|
|
30289
|
+
* The transaction may require user approval through external wallet applications.
|
|
30290
|
+
*
|
|
30291
|
+
* @param request - Transaction request data including amount, recipient, etc.
|
|
30292
|
+
* @returns Promise resolving to transaction response with potential actionable items
|
|
30293
|
+
* @throws Error if SDK is not initialized
|
|
30294
|
+
*
|
|
30295
|
+
* @example
|
|
30296
|
+
* ```typescript
|
|
30297
|
+
* const { createTransaction } = useTransactions();
|
|
30298
|
+
* const request = {
|
|
30299
|
+
* amount: '100',
|
|
30300
|
+
* recipient: '0x123...',
|
|
30301
|
+
* tokenId: 'token-123'
|
|
30302
|
+
* };
|
|
30303
|
+
* const result = await createTransaction(request);
|
|
30304
|
+
* console.log('Transaction created:', result);
|
|
30305
|
+
* ```
|
|
30306
|
+
*/
|
|
30307
|
+
const createTransaction = react.useCallback(async (request) => {
|
|
30308
|
+
if (!isInitialized || !sdk) {
|
|
30309
|
+
throw new Error('SDK not initialized. Call initialize() first.');
|
|
30310
|
+
}
|
|
30311
|
+
try {
|
|
30312
|
+
const result = await sdk.transactions.createTransaction(request);
|
|
30313
|
+
console.log('Transaction created successfully:', result);
|
|
30314
|
+
// Check if transaction requires signing (contains actionable authToken)
|
|
30315
|
+
// Type assertion needed as TransactionRequestResponseDTO type may not include all dynamic properties
|
|
30316
|
+
const txToken = result?.actionable?.authToken;
|
|
30317
|
+
if (txToken) {
|
|
30318
|
+
console.log('[useTransactions] Transaction requires signing, attempting automatic signature...');
|
|
30319
|
+
try {
|
|
30320
|
+
if (!isSignerAvailable) {
|
|
30321
|
+
console.warn('[useTransactions] Transaction signer not available, skipping automatic signing');
|
|
30322
|
+
return result;
|
|
30323
|
+
}
|
|
30324
|
+
// Automatically sign the transaction using the authToken
|
|
30325
|
+
const signingResult = await signTransactionWithJWT(txToken);
|
|
30326
|
+
if (signingResult.success) {
|
|
30327
|
+
console.log('[useTransactions] Transaction signed successfully:', signingResult.transactionHash);
|
|
30328
|
+
// Return the original result - the transaction is now signed and will be processed
|
|
30329
|
+
return result;
|
|
30330
|
+
}
|
|
30331
|
+
else {
|
|
30332
|
+
console.error('[useTransactions] Transaction signing failed:', signingResult.error);
|
|
30333
|
+
// Don't throw error - return the original result so caller can handle signature URL manually
|
|
30334
|
+
return result;
|
|
30335
|
+
}
|
|
30336
|
+
}
|
|
30337
|
+
catch (signingError) {
|
|
30338
|
+
console.error('[useTransactions] Blockchain signing error:', signingError);
|
|
30339
|
+
// Don't throw error - return the original result so caller can handle signature URL manually
|
|
30340
|
+
return result;
|
|
30341
|
+
}
|
|
30342
|
+
}
|
|
30343
|
+
return result;
|
|
30344
|
+
}
|
|
30345
|
+
catch (error) {
|
|
30346
|
+
console.error('Failed to create transaction:', error);
|
|
30347
|
+
throw error;
|
|
30348
|
+
}
|
|
30349
|
+
}, [sdk, isInitialized, signTransactionWithJWT, isSignerAvailable]);
|
|
30350
|
+
/**
|
|
30351
|
+
* Retrieves a specific transaction by its ID
|
|
30352
|
+
*
|
|
30353
|
+
* @param transactionId - Unique identifier of the transaction
|
|
30354
|
+
* @returns Promise resolving to transaction data or null if not found
|
|
30355
|
+
* @throws Error if SDK is not initialized
|
|
30356
|
+
*
|
|
30357
|
+
* @example
|
|
30358
|
+
* ```typescript
|
|
30359
|
+
* const { getTransactionById } = useTransactions();
|
|
30360
|
+
* const transaction = await getTransactionById('txn-123');
|
|
30361
|
+
* console.log('Transaction details:', transaction);
|
|
30362
|
+
* ```
|
|
30363
|
+
*/
|
|
30364
|
+
const getTransactionById = react.useCallback(async (transactionId) => {
|
|
30365
|
+
if (!isInitialized || !sdk) {
|
|
30366
|
+
throw new Error('SDK not initialized. Call initialize() first.');
|
|
30367
|
+
}
|
|
30368
|
+
try {
|
|
30369
|
+
const result = await sdk.transactions.getTransactionById(transactionId);
|
|
30370
|
+
console.log('Transaction fetched successfully:', result);
|
|
30371
|
+
return result;
|
|
30372
|
+
}
|
|
30373
|
+
catch (error) {
|
|
30374
|
+
console.error('Failed to fetch transaction:', error);
|
|
30375
|
+
throw error;
|
|
30376
|
+
}
|
|
30377
|
+
}, [sdk, isInitialized]);
|
|
30378
|
+
/**
|
|
30379
|
+
* Retrieves transaction history for the authenticated user, filtered by type
|
|
30380
|
+
*
|
|
30381
|
+
* @param type - Transaction type filter (defaults to 'all')
|
|
30382
|
+
* @returns Promise resolving to array of user's transactions
|
|
30383
|
+
* @throws Error if SDK is not initialized
|
|
30384
|
+
*
|
|
30385
|
+
* @example
|
|
30386
|
+
* ```typescript
|
|
30387
|
+
* const { getUserTransactionHistory } = useTransactions();
|
|
30388
|
+
* const transactions = await getUserTransactionHistory('credit');
|
|
30389
|
+
* console.log('Credit transactions:', transactions);
|
|
30390
|
+
* ```
|
|
30391
|
+
*/
|
|
30392
|
+
const getUserTransactionHistory = react.useCallback(async (type = 'all') => {
|
|
30393
|
+
if (!isInitialized || !sdk) {
|
|
30394
|
+
throw new Error('SDK not initialized. Call initialize() first.');
|
|
30395
|
+
}
|
|
30396
|
+
try {
|
|
30397
|
+
const result = await sdk.transactions.getUserTransactionHistory(type);
|
|
30398
|
+
console.log('Transaction history fetched successfully:', result);
|
|
30399
|
+
return result;
|
|
30400
|
+
}
|
|
30401
|
+
catch (error) {
|
|
30402
|
+
console.error('Failed to fetch transaction history:', error);
|
|
30403
|
+
throw error;
|
|
30404
|
+
}
|
|
30405
|
+
}, [sdk, isInitialized]);
|
|
30406
|
+
const getTenantTransactions = react.useCallback(async () => {
|
|
30407
|
+
if (!isInitialized || !sdk) {
|
|
30408
|
+
throw new Error('SDK not initialized. Call initialize() first.');
|
|
30409
|
+
}
|
|
30410
|
+
try {
|
|
30411
|
+
const result = await sdk.transactions.getTenantTransactions();
|
|
30412
|
+
console.log('Tenant transactions fetched successfully:', result);
|
|
30413
|
+
return result;
|
|
30414
|
+
}
|
|
30415
|
+
catch (error) {
|
|
30416
|
+
console.error('Failed to fetch tenant transactions:', error);
|
|
30417
|
+
throw error;
|
|
30418
|
+
}
|
|
30419
|
+
}, [sdk, isInitialized]);
|
|
30420
|
+
const getPaginatedTransactions = react.useCallback(async (params) => {
|
|
30421
|
+
if (!isInitialized || !sdk) {
|
|
30422
|
+
throw new Error('SDK not initialized. Call initialize() first.');
|
|
30423
|
+
}
|
|
30424
|
+
try {
|
|
30425
|
+
const result = await sdk.transactions.getPaginatedTransactions(params);
|
|
30426
|
+
console.log('Paginated transactions fetched successfully:', result);
|
|
30427
|
+
return result;
|
|
30428
|
+
}
|
|
30429
|
+
catch (error) {
|
|
30430
|
+
console.error('Failed to fetch paginated transactions:', error);
|
|
30431
|
+
throw error;
|
|
30432
|
+
}
|
|
30433
|
+
}, [sdk, isInitialized]);
|
|
30434
|
+
const exportTransactionsCSV = react.useCallback(async () => {
|
|
30435
|
+
if (!isInitialized || !sdk) {
|
|
30436
|
+
throw new Error('SDK not initialized. Call initialize() first.');
|
|
30437
|
+
}
|
|
30438
|
+
try {
|
|
30439
|
+
const result = await sdk.transactions.exportTransactionsCSV();
|
|
30440
|
+
console.log('Transactions CSV exported successfully');
|
|
30441
|
+
return result;
|
|
30442
|
+
}
|
|
30443
|
+
catch (error) {
|
|
30444
|
+
console.error('Failed to export transactions CSV:', error);
|
|
30445
|
+
throw error;
|
|
30446
|
+
}
|
|
30447
|
+
}, [sdk, isInitialized]);
|
|
30448
|
+
return {
|
|
30449
|
+
createTransaction,
|
|
30450
|
+
getTransactionById,
|
|
30451
|
+
getUserTransactionHistory,
|
|
30452
|
+
getTenantTransactions,
|
|
30453
|
+
getPaginatedTransactions,
|
|
30454
|
+
exportTransactionsCSV,
|
|
30455
|
+
isAvailable: isInitialized && !!sdk?.transactions,
|
|
30456
|
+
};
|
|
30457
|
+
};
|
|
30458
|
+
|
|
30430
30459
|
/**
|
|
30431
30460
|
* React hook for business operations in the PERS SDK
|
|
30432
30461
|
*
|