@explorins/pers-sdk-react-native 2.3.6 → 2.3.8
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/LICENSE +21 -0
- package/README.md +1266 -1244
- package/dist/__tests__/PersSDKProvider.test.js +33 -0
- package/dist/hooks/useBusiness.d.ts +2 -2
- package/dist/hooks/useBusiness.d.ts.map +1 -1
- package/dist/hooks/useBusiness.js +2 -2
- package/dist/hooks/useIPFSUrl.d.ts +3 -3
- package/dist/hooks/useIPFSUrl.d.ts.map +1 -1
- package/dist/hooks/useIPFSUrl.js +7 -7
- package/dist/hooks/useTransactions.d.ts.map +1 -1
- package/dist/hooks/useTransactions.js +13 -5
- package/dist/hooks/useWeb3.js +4 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2412 -492
- package/dist/index.js.map +1 -1
- package/dist/providers/PersSDKProvider.d.ts +4 -0
- package/dist/providers/PersSDKProvider.d.ts.map +1 -1
- package/dist/providers/PersSDKProvider.js +14 -0
- package/dist/providers/react-native-http-client.d.ts +2 -0
- package/dist/providers/react-native-http-client.d.ts.map +1 -1
- package/dist/providers/react-native-http-client.js +5 -2
- package/dist/storage/rn-secure-storage.d.ts.map +1 -1
- package/dist/storage/rn-secure-storage.js +21 -8
- package/package.json +3 -3
- package/src/__tests__/PersSDKProvider.test.tsx +484 -420
- package/src/__tests__/setup.ts +40 -40
- package/src/hooks/index.ts +60 -60
- package/src/hooks/useAnalytics.ts +327 -327
- package/src/hooks/useAuth.ts +265 -265
- package/src/hooks/useBookings.ts +191 -191
- package/src/hooks/useBusiness.ts +251 -251
- package/src/hooks/useCampaigns.ts +500 -500
- package/src/hooks/useDonations.ts +66 -66
- package/src/hooks/useEvents.ts +372 -372
- package/src/hooks/useFiles.ts +155 -155
- package/src/hooks/useIPFSUrl.ts +192 -192
- package/src/hooks/usePurchases.ts +65 -65
- package/src/hooks/useRedemptions.ts +467 -467
- package/src/hooks/useTenants.ts +72 -72
- package/src/hooks/useTokenBalances.ts +385 -385
- package/src/hooks/useTokens.ts +313 -313
- package/src/hooks/useTransactionSigner.ts +611 -611
- package/src/hooks/useTransactions.ts +299 -290
- package/src/hooks/useTriggerSources.ts +301 -301
- package/src/hooks/useUserStatus.ts +61 -61
- package/src/hooks/useUsers.ts +167 -167
- package/src/hooks/useWeb3.ts +355 -355
- package/src/index.ts +777 -774
- package/src/polyfills/index.ts +160 -160
- package/src/polyfills/web3-polyfills.ts +97 -97
- package/src/providers/PersSDKProvider.tsx +393 -374
- package/src/providers/react-native-auth-provider.ts +110 -110
- package/src/providers/react-native-http-client.ts +150 -145
- package/src/providers/rn-dpop-provider.ts +190 -190
- package/src/storage/async-storage-token-storage.ts +185 -185
- package/src/storage/rn-secure-storage.ts +182 -170
- package/src/types/react-native-globals.d.ts +45 -45
- package/src/utils/index.ts +8 -8
- package/src/utils/platform-detection.ts +86 -86
- package/dist/index-CzLxqePZ.js +0 -7717
- package/dist/index-CzLxqePZ.js.map +0 -1
|
@@ -1,291 +1,300 @@
|
|
|
1
|
-
import { useCallback } from 'react';
|
|
2
|
-
import { usePersSDK } from '../providers/PersSDKProvider';
|
|
3
|
-
import { useTransactionSigner, OnStatusUpdateFn } from './useTransactionSigner';
|
|
4
|
-
import type {
|
|
5
|
-
TransactionRequestDTO,
|
|
6
|
-
TransactionRequestResponseDTO,
|
|
7
|
-
TransactionDTO,
|
|
8
|
-
TransactionPaginationRequestDTO,
|
|
9
|
-
PaginatedResponseDTO,
|
|
10
|
-
TransactionIncludeRelation
|
|
11
|
-
} from '@explorins/pers-sdk';
|
|
12
|
-
import type { TransactionQueryOptions } from '@explorins/pers-sdk/transaction';
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
export
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
* @
|
|
69
|
-
* @
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
* const
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
* });
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
//
|
|
95
|
-
|
|
96
|
-
if (
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
180
|
-
*
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
*
|
|
188
|
-
* const
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
*
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
*
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
*
|
|
232
|
-
*
|
|
233
|
-
*
|
|
234
|
-
*
|
|
235
|
-
*
|
|
236
|
-
*
|
|
237
|
-
*
|
|
238
|
-
* });
|
|
239
|
-
*
|
|
240
|
-
*
|
|
241
|
-
*
|
|
242
|
-
*
|
|
243
|
-
*
|
|
244
|
-
*
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
import { usePersSDK } from '../providers/PersSDKProvider';
|
|
3
|
+
import { useTransactionSigner, OnStatusUpdateFn } from './useTransactionSigner';
|
|
4
|
+
import type {
|
|
5
|
+
TransactionRequestDTO,
|
|
6
|
+
TransactionRequestResponseDTO,
|
|
7
|
+
TransactionDTO,
|
|
8
|
+
TransactionPaginationRequestDTO,
|
|
9
|
+
PaginatedResponseDTO,
|
|
10
|
+
TransactionIncludeRelation
|
|
11
|
+
} from '@explorins/pers-sdk';
|
|
12
|
+
import type { TransactionQueryOptions } from '@explorins/pers-sdk/transaction';
|
|
13
|
+
import { needsSubmission } from '@explorins/pers-sdk/transaction';
|
|
14
|
+
|
|
15
|
+
// Re-export for consumers
|
|
16
|
+
export type { TransactionQueryOptions } from '@explorins/pers-sdk/transaction';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* React hook for transaction operations in the PERS SDK
|
|
20
|
+
*
|
|
21
|
+
* Provides comprehensive transaction management including creation, retrieval, history,
|
|
22
|
+
* and administrative operations. Supports pagination and CSV export functionality.
|
|
23
|
+
*
|
|
24
|
+
* @returns Transaction hook with methods for transaction management
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* function TransactionsComponent() {
|
|
29
|
+
* const {
|
|
30
|
+
* createTransaction,
|
|
31
|
+
* getUserTransactionHistory
|
|
32
|
+
* } = useTransactions();
|
|
33
|
+
*
|
|
34
|
+
* const handleCreateTransaction = async (request) => {
|
|
35
|
+
* try {
|
|
36
|
+
* const result = await createTransaction(request);
|
|
37
|
+
* console.log('Transaction created:', result);
|
|
38
|
+
* // Handle signature URL if returned
|
|
39
|
+
* } catch (error) {
|
|
40
|
+
* console.error('Transaction failed:', error);
|
|
41
|
+
* }
|
|
42
|
+
* };
|
|
43
|
+
*
|
|
44
|
+
* return (
|
|
45
|
+
* <div>
|
|
46
|
+
* <button onClick={() => handleCreateTransaction(transactionRequest)}>
|
|
47
|
+
* Create Transaction
|
|
48
|
+
* </button>
|
|
49
|
+
* </div>
|
|
50
|
+
* );
|
|
51
|
+
* }
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export const useTransactions = () => {
|
|
55
|
+
const { sdk, isInitialized, isAuthenticated } = usePersSDK();
|
|
56
|
+
const { signAndSubmitTransactionWithJWT, isSignerAvailable, currentStatus, statusMessage } = useTransactionSigner();
|
|
57
|
+
|
|
58
|
+
if (!isAuthenticated && isInitialized) {
|
|
59
|
+
console.warn('SDK not authenticated. Some transaction operations may fail.');
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Creates a new transaction in the system
|
|
64
|
+
*
|
|
65
|
+
* Automatically handles signature URLs by opening them in the device's browser.
|
|
66
|
+
* The transaction may require user approval through external wallet applications.
|
|
67
|
+
*
|
|
68
|
+
* @param request - Transaction request data including amount, recipient, etc.
|
|
69
|
+
* @returns Promise resolving to transaction response with potential actionable items
|
|
70
|
+
* @throws Error if SDK is not initialized
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* const { createTransaction } = useTransactions();
|
|
75
|
+
* const request = {
|
|
76
|
+
* amount: '100',
|
|
77
|
+
* recipient: '0x123...',
|
|
78
|
+
* tokenId: 'token-123'
|
|
79
|
+
* };
|
|
80
|
+
* const result = await createTransaction(request, (status, message) => {
|
|
81
|
+
* console.log(`Status: ${status} - ${message}`);
|
|
82
|
+
* });
|
|
83
|
+
* console.log('Transaction created:', result);
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
const createTransaction = useCallback(async (request: TransactionRequestDTO, onStatusUpdate?: OnStatusUpdateFn): Promise<TransactionRequestResponseDTO> => {
|
|
87
|
+
if (!isInitialized || !sdk) {
|
|
88
|
+
throw new Error('SDK not initialized. Call initialize() first.');
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
try {
|
|
92
|
+
const result = await sdk.transactions.createTransaction(request);
|
|
93
|
+
|
|
94
|
+
// If backend already signed custodially, return as-is so caller can build QR
|
|
95
|
+
// from result.signatureData directly (no client signing needed)
|
|
96
|
+
if (needsSubmission(result)) {
|
|
97
|
+
return result;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// If client signer is unavailable, return as-is so caller can fall back to
|
|
101
|
+
// result.actionable.actionUrl (external signing URL) if present
|
|
102
|
+
if (!isSignerAvailable) {
|
|
103
|
+
console.warn('[useTransactions] Transaction signer not available, returning result for caller to handle');
|
|
104
|
+
return result;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Check if transaction requires client signing (contains actionable authToken)
|
|
108
|
+
// Type assertion needed as TransactionRequestResponseDTO type may not include all dynamic properties
|
|
109
|
+
const txToken = result?.actionable?.authToken;
|
|
110
|
+
if (txToken) {
|
|
111
|
+
|
|
112
|
+
try {
|
|
113
|
+
// Automatically sign the transaction using the authToken
|
|
114
|
+
const signingResult = await signAndSubmitTransactionWithJWT(txToken, onStatusUpdate);
|
|
115
|
+
|
|
116
|
+
if (signingResult.success) {
|
|
117
|
+
console.log('[useTransactions] Transaction signed successfully:', signingResult.transactionHash);
|
|
118
|
+
// Return the original result - the transaction is now signed and will be processed
|
|
119
|
+
return result;
|
|
120
|
+
} else {
|
|
121
|
+
console.error('[useTransactions] Transaction signing failed:', signingResult.error);
|
|
122
|
+
// Don't throw error - return the original result so caller can handle signature URL manually
|
|
123
|
+
return result;
|
|
124
|
+
}
|
|
125
|
+
} catch (signingError) {
|
|
126
|
+
console.error('[useTransactions] Blockchain signing error:', signingError);
|
|
127
|
+
// Don't throw error - return the original result so caller can handle signature URL manually
|
|
128
|
+
return result;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return result;
|
|
133
|
+
} catch (error) {
|
|
134
|
+
console.error('Failed to create transaction:', error);
|
|
135
|
+
throw error;
|
|
136
|
+
}
|
|
137
|
+
}, [sdk, isInitialized, signAndSubmitTransactionWithJWT, isSignerAvailable]);
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Retrieves a specific transaction by its ID with optional include relations
|
|
141
|
+
*
|
|
142
|
+
* @param transactionId - Unique identifier of the transaction
|
|
143
|
+
* @param include - Optional relations to include (sender, recipient, business) for enriched entity data
|
|
144
|
+
* @returns Promise resolving to transaction data or null if not found
|
|
145
|
+
* @throws Error if SDK is not initialized
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```typescript
|
|
149
|
+
* const { getTransactionById } = useTransactions();
|
|
150
|
+
*
|
|
151
|
+
* // Basic retrieval
|
|
152
|
+
* const transaction = await getTransactionById('txn-123');
|
|
153
|
+
*
|
|
154
|
+
* // With enriched sender/recipient data
|
|
155
|
+
* const enrichedTx = await getTransactionById('txn-123', ['sender', 'recipient', 'business']);
|
|
156
|
+
* console.log('Sender:', enrichedTx?.included?.sender);
|
|
157
|
+
* console.log('Business:', enrichedTx?.included?.engagedBusiness?.displayName);
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
const getTransactionById = useCallback(async (
|
|
161
|
+
transactionId: string,
|
|
162
|
+
include?: TransactionIncludeRelation[]
|
|
163
|
+
): Promise<TransactionDTO | null> => {
|
|
164
|
+
if (!isInitialized || !sdk) {
|
|
165
|
+
throw new Error('SDK not initialized. Call initialize() first.');
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
try {
|
|
169
|
+
return await sdk.transactions.getTransactionById(transactionId, include);
|
|
170
|
+
} catch (error) {
|
|
171
|
+
console.error('Failed to fetch transaction:', error);
|
|
172
|
+
throw error;
|
|
173
|
+
}
|
|
174
|
+
}, [sdk, isInitialized]);
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Retrieves transaction history for the authenticated user with comprehensive filtering
|
|
178
|
+
*
|
|
179
|
+
* Supports filtering by role, status, type, business, token, and more.
|
|
180
|
+
* Optionally enrich with related entities (sender, recipient, business).
|
|
181
|
+
*
|
|
182
|
+
* @param options - Query options including filters, pagination, and include relations
|
|
183
|
+
* @returns Promise resolving to paginated array of user's transactions
|
|
184
|
+
* @throws Error if SDK is not initialized
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* ```typescript
|
|
188
|
+
* const { getUserTransactionHistory } = useTransactions();
|
|
189
|
+
*
|
|
190
|
+
* // Simple: Get all transactions
|
|
191
|
+
* const allTransactions = await getUserTransactionHistory();
|
|
192
|
+
*
|
|
193
|
+
* // Filter by role (legacy support)
|
|
194
|
+
* const sentTransactions = await getUserTransactionHistory({ role: 'SENDER' });
|
|
195
|
+
*
|
|
196
|
+
* // Advanced filtering with include relations
|
|
197
|
+
* const filtered = await getUserTransactionHistory({
|
|
198
|
+
* role: 'SENDER',
|
|
199
|
+
* status: 'COMPLETED',
|
|
200
|
+
* engagedBusinessId: 'business-123',
|
|
201
|
+
* include: ['recipient', 'business'],
|
|
202
|
+
* page: 1,
|
|
203
|
+
* limit: 20
|
|
204
|
+
* });
|
|
205
|
+
*
|
|
206
|
+
* // Access enriched data
|
|
207
|
+
* filtered.data.forEach(tx => {
|
|
208
|
+
* console.log('Recipient:', tx.included?.recipient);
|
|
209
|
+
* console.log('Business:', tx.included?.engagedBusiness?.displayName);
|
|
210
|
+
* });
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
213
|
+
const getUserTransactionHistory = useCallback(async (
|
|
214
|
+
options?: TransactionQueryOptions
|
|
215
|
+
): Promise<PaginatedResponseDTO<TransactionDTO>> => {
|
|
216
|
+
if (!isInitialized || !sdk) {
|
|
217
|
+
throw new Error('SDK not initialized. Call initialize() first.');
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
try {
|
|
221
|
+
return await sdk.transactions.getUserTransactionHistory(options);
|
|
222
|
+
} catch (error) {
|
|
223
|
+
console.error('Failed to fetch transaction history:', error);
|
|
224
|
+
throw error;
|
|
225
|
+
}
|
|
226
|
+
}, [sdk, isInitialized]);
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Admin: Get paginated transactions with optional include relations
|
|
230
|
+
*
|
|
231
|
+
* @param params - Pagination and filtering parameters
|
|
232
|
+
* @param include - Optional relations to include for enriched entity data
|
|
233
|
+
* @returns Promise resolving to paginated transaction results
|
|
234
|
+
* @throws Error if SDK is not initialized
|
|
235
|
+
*
|
|
236
|
+
* @example
|
|
237
|
+
* ```typescript
|
|
238
|
+
* const { getPaginatedTransactions } = useTransactions();
|
|
239
|
+
*
|
|
240
|
+
* // Basic pagination
|
|
241
|
+
* const result = await getPaginatedTransactions({ page: 1, limit: 50 });
|
|
242
|
+
*
|
|
243
|
+
* // With include relations
|
|
244
|
+
* const enrichedResult = await getPaginatedTransactions(
|
|
245
|
+
* { page: 1, limit: 50, sortBy: 'createdAt', sortOrder: 'DESC' },
|
|
246
|
+
* include: ['sender', 'recipient', 'business']
|
|
247
|
+
* });
|
|
248
|
+
*
|
|
249
|
+
* enrichedResult.data.forEach(tx => {
|
|
250
|
+
* console.log('From:', tx.included?.sender);
|
|
251
|
+
* console.log('To:', tx.included?.recipient);
|
|
252
|
+
* });
|
|
253
|
+
* ```
|
|
254
|
+
*/
|
|
255
|
+
const getPaginatedTransactions = useCallback(async (
|
|
256
|
+
options: TransactionPaginationRequestDTO & {
|
|
257
|
+
include?: TransactionIncludeRelation[];
|
|
258
|
+
}
|
|
259
|
+
): Promise<PaginatedResponseDTO<TransactionDTO>> => {
|
|
260
|
+
if (!isInitialized || !sdk) {
|
|
261
|
+
throw new Error('SDK not initialized. Call initialize() first.');
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
try {
|
|
265
|
+
const result = await sdk.transactions.getPaginatedTransactions(options);
|
|
266
|
+
return result;
|
|
267
|
+
} catch (error) {
|
|
268
|
+
console.error('Failed to fetch paginated transactions:', error);
|
|
269
|
+
throw error;
|
|
270
|
+
}
|
|
271
|
+
}, [sdk, isInitialized]);
|
|
272
|
+
|
|
273
|
+
const exportTransactionsCSV = useCallback(async (): Promise<Blob> => {
|
|
274
|
+
if (!isInitialized || !sdk) {
|
|
275
|
+
throw new Error('SDK not initialized. Call initialize() first.');
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
try {
|
|
279
|
+
const result = await sdk.transactions.exportTransactionsCSV();
|
|
280
|
+
return result;
|
|
281
|
+
} catch (error) {
|
|
282
|
+
console.error('Failed to export transactions CSV:', error);
|
|
283
|
+
throw error;
|
|
284
|
+
}
|
|
285
|
+
}, [sdk, isInitialized]);
|
|
286
|
+
|
|
287
|
+
return {
|
|
288
|
+
createTransaction,
|
|
289
|
+
getTransactionById,
|
|
290
|
+
getUserTransactionHistory,
|
|
291
|
+
getPaginatedTransactions,
|
|
292
|
+
exportTransactionsCSV,
|
|
293
|
+
isAvailable: isInitialized && !!sdk?.transactions,
|
|
294
|
+
// Expose signing status for UI feedback
|
|
295
|
+
signingStatus: currentStatus,
|
|
296
|
+
signingStatusMessage: statusMessage,
|
|
297
|
+
};
|
|
298
|
+
};
|
|
299
|
+
|
|
291
300
|
export type TransactionHook = ReturnType<typeof useTransactions>;
|