@explorins/pers-sdk-react-native 1.3.2 → 1.5.2

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.
Files changed (94) hide show
  1. package/README.md +276 -123
  2. package/dist/hooks/index.d.ts +10 -0
  3. package/dist/hooks/index.d.ts.map +1 -1
  4. package/dist/hooks/index.js +8 -0
  5. package/dist/hooks/useAnalytics.d.ts +96 -0
  6. package/dist/hooks/useAnalytics.d.ts.map +1 -0
  7. package/dist/hooks/useAnalytics.js +73 -0
  8. package/dist/hooks/useAuth.d.ts +52 -7
  9. package/dist/hooks/useAuth.d.ts.map +1 -1
  10. package/dist/hooks/useAuth.js +250 -3
  11. package/dist/hooks/useBusiness.d.ts +45 -3
  12. package/dist/hooks/useBusiness.d.ts.map +1 -1
  13. package/dist/hooks/useBusiness.js +182 -28
  14. package/dist/hooks/useCampaigns.d.ts +11 -4
  15. package/dist/hooks/useCampaigns.d.ts.map +1 -1
  16. package/dist/hooks/useCampaigns.js +101 -39
  17. package/dist/hooks/useDonations.d.ts +33 -0
  18. package/dist/hooks/useDonations.d.ts.map +1 -0
  19. package/dist/hooks/useDonations.js +62 -0
  20. package/dist/hooks/useFiles.d.ts +50 -0
  21. package/dist/hooks/useFiles.d.ts.map +1 -0
  22. package/dist/hooks/useFiles.js +140 -0
  23. package/dist/hooks/usePurchases.d.ts +9 -0
  24. package/dist/hooks/usePurchases.d.ts.map +1 -0
  25. package/dist/hooks/usePurchases.js +56 -0
  26. package/dist/hooks/useRedemptions.d.ts +10 -5
  27. package/dist/hooks/useRedemptions.d.ts.map +1 -1
  28. package/dist/hooks/useRedemptions.js +118 -66
  29. package/dist/hooks/useTenants.d.ts +10 -0
  30. package/dist/hooks/useTenants.d.ts.map +1 -0
  31. package/dist/hooks/useTenants.js +68 -0
  32. package/dist/hooks/useTokens.d.ts +36 -2
  33. package/dist/hooks/useTokens.d.ts.map +1 -1
  34. package/dist/hooks/useTokens.js +180 -19
  35. package/dist/hooks/useTransactionSigner.d.ts +73 -0
  36. package/dist/hooks/useTransactionSigner.d.ts.map +1 -0
  37. package/dist/hooks/useTransactionSigner.js +216 -0
  38. package/dist/hooks/useTransactions.d.ts +45 -3
  39. package/dist/hooks/useTransactions.d.ts.map +1 -1
  40. package/dist/hooks/useTransactions.js +149 -39
  41. package/dist/hooks/useUserStatus.d.ts +9 -0
  42. package/dist/hooks/useUserStatus.d.ts.map +1 -0
  43. package/dist/hooks/useUserStatus.js +57 -0
  44. package/dist/hooks/useUsers.d.ts +17 -0
  45. package/dist/hooks/useUsers.d.ts.map +1 -0
  46. package/dist/hooks/useUsers.js +120 -0
  47. package/dist/hooks/useWeb3.d.ts +69 -6
  48. package/dist/hooks/useWeb3.d.ts.map +1 -1
  49. package/dist/hooks/useWeb3.js +177 -17
  50. package/dist/index.d.ts +6 -4
  51. package/dist/index.d.ts.map +1 -1
  52. package/dist/index.js +31540 -794
  53. package/dist/index.js.map +1 -1
  54. package/dist/polyfills/index.d.ts +1 -1
  55. package/dist/polyfills/index.d.ts.map +1 -1
  56. package/dist/polyfills/index.js +155 -9
  57. package/dist/polyfills/web3-polyfills.d.ts +7 -0
  58. package/dist/polyfills/web3-polyfills.d.ts.map +1 -0
  59. package/dist/polyfills/web3-polyfills.js +85 -0
  60. package/dist/providers/PersSDKProvider.d.ts +28 -18
  61. package/dist/providers/PersSDKProvider.d.ts.map +1 -1
  62. package/dist/providers/PersSDKProvider.js +63 -129
  63. package/dist/providers/react-native-auth-provider.d.ts +19 -64
  64. package/dist/providers/react-native-auth-provider.d.ts.map +1 -1
  65. package/dist/providers/react-native-auth-provider.js +57 -175
  66. package/package.json +177 -157
  67. package/src/hooks/index.ts +13 -1
  68. package/src/hooks/useAnalytics.ts +150 -0
  69. package/src/hooks/useAuth.ts +286 -27
  70. package/src/hooks/useBusiness.ts +193 -30
  71. package/src/hooks/useCampaigns.ts +121 -43
  72. package/src/hooks/useDonations.ts +68 -0
  73. package/src/hooks/useFiles.ts +160 -0
  74. package/src/hooks/usePurchases.ts +69 -0
  75. package/src/hooks/useRedemptions.ts +135 -68
  76. package/src/hooks/useTenants.ts +77 -0
  77. package/src/hooks/useTokens.ts +189 -21
  78. package/src/hooks/useTransactionSigner.ts +287 -0
  79. package/src/hooks/useTransactions.ts +163 -41
  80. package/src/hooks/useUserStatus.ts +65 -0
  81. package/src/hooks/useUsers.ts +133 -0
  82. package/src/hooks/useWeb3.ts +201 -21
  83. package/src/index.ts +22 -17
  84. package/src/polyfills/index.ts +163 -10
  85. package/src/polyfills/web3-polyfills.ts +98 -0
  86. package/src/providers/PersSDKProvider.tsx +114 -178
  87. package/src/providers/react-native-auth-provider.ts +65 -208
  88. package/dist/index.esm.js +0 -1057
  89. package/dist/index.esm.js.map +0 -1
  90. package/dist/polyfills/index.simple.d.ts +0 -2
  91. package/dist/polyfills/index.simple.d.ts.map +0 -1
  92. package/dist/polyfills/index.simple.js +0 -17
  93. package/src/polyfills/index.simple.ts +0 -22
  94. package/src/types/external-modules.d.ts +0 -13
@@ -1,78 +1,188 @@
1
1
  import { useCallback } from 'react';
2
2
  import { usePersSDK } from '../providers/PersSDKProvider';
3
+ /**
4
+ * React hook for transaction operations in the PERS SDK
5
+ *
6
+ * Provides comprehensive transaction management including creation, retrieval, history,
7
+ * and administrative operations. Supports pagination and CSV export functionality.
8
+ *
9
+ * @returns Transaction hook with methods for transaction management
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * function TransactionsComponent() {
14
+ * const {
15
+ * createTransaction,
16
+ * getUserTransactionHistory
17
+ * } = useTransactions();
18
+ *
19
+ * const handleCreateTransaction = async (request) => {
20
+ * try {
21
+ * const result = await createTransaction(request);
22
+ * console.log('Transaction created:', result);
23
+ * // Handle signature URL if returned
24
+ * } catch (error) {
25
+ * console.error('Transaction failed:', error);
26
+ * }
27
+ * };
28
+ *
29
+ * return (
30
+ * <div>
31
+ * <button onClick={() => handleCreateTransaction(transactionRequest)}>
32
+ * Create Transaction
33
+ * </button>
34
+ * </div>
35
+ * );
36
+ * }
37
+ * ```
38
+ */
3
39
  export const useTransactions = () => {
4
- const { transactions, isInitialized, isAuthenticated } = usePersSDK();
40
+ const { sdk, isInitialized, isAuthenticated } = usePersSDK();
5
41
  if (!isAuthenticated && isInitialized) {
6
42
  console.warn('SDK not authenticated. Some transaction operations may fail.');
7
43
  }
44
+ /**
45
+ * Creates a new transaction in the system
46
+ *
47
+ * Automatically handles signature URLs by opening them in the device's browser.
48
+ * The transaction may require user approval through external wallet applications.
49
+ *
50
+ * @param request - Transaction request data including amount, recipient, etc.
51
+ * @returns Promise resolving to transaction response with potential actionable items
52
+ * @throws Error if SDK is not initialized
53
+ *
54
+ * @example
55
+ * ```typescript
56
+ * const { createTransaction } = useTransactions();
57
+ * const request = {
58
+ * amount: '100',
59
+ * recipient: '0x123...',
60
+ * tokenId: 'token-123'
61
+ * };
62
+ * const result = await createTransaction(request);
63
+ * console.log('Transaction created:', result);
64
+ * ```
65
+ */
8
66
  const createTransaction = useCallback(async (request) => {
9
- if (!isInitialized) {
67
+ if (!isInitialized || !sdk) {
10
68
  throw new Error('SDK not initialized. Call initialize() first.');
11
69
  }
12
- if (!transactions?.createTransaction) {
13
- throw new Error('createTransaction method not available');
14
- }
15
70
  try {
16
- console.log('🔄 Creating transaction with request:', request);
17
- const result = await transactions.createTransaction(request);
18
- // React Native specific: Handle signature URLs
19
- if (result?.actionable?.actionUrl) {
20
- try {
21
- const { Linking } = require('react-native');
22
- console.log('🔗 Opening signature URL:', result.actionable.actionUrl);
23
- await Linking.openURL(result.actionable.actionUrl);
24
- }
25
- catch (linkingError) {
26
- console.error('❌ Failed to open signature URL:', linkingError);
27
- }
28
- }
29
- console.log('✅ Transaction created successfully:', result);
71
+ const result = await sdk.transactions.createTransaction(request);
72
+ // Cross-platform: Dont handle signature URLs here, leave to caller
73
+ console.log('Transaction created successfully:', result);
30
74
  return result;
31
75
  }
32
76
  catch (error) {
33
- console.error('Failed to create transaction:', error);
77
+ console.error('Failed to create transaction:', error);
34
78
  throw error;
35
79
  }
36
- }, [transactions]);
80
+ }, [sdk, isInitialized]);
81
+ /**
82
+ * Retrieves a specific transaction by its ID
83
+ *
84
+ * @param transactionId - Unique identifier of the transaction
85
+ * @returns Promise resolving to transaction data or null if not found
86
+ * @throws Error if SDK is not initialized
87
+ *
88
+ * @example
89
+ * ```typescript
90
+ * const { getTransactionById } = useTransactions();
91
+ * const transaction = await getTransactionById('txn-123');
92
+ * console.log('Transaction details:', transaction);
93
+ * ```
94
+ */
37
95
  const getTransactionById = useCallback(async (transactionId) => {
38
- if (!isInitialized) {
96
+ if (!isInitialized || !sdk) {
39
97
  throw new Error('SDK not initialized. Call initialize() first.');
40
98
  }
41
- if (!transactions?.getTransactionById) {
42
- throw new Error('getTransactionById method not available');
99
+ try {
100
+ const result = await sdk.transactions.getTransactionById(transactionId);
101
+ console.log('Transaction fetched successfully:', result);
102
+ return result;
103
+ }
104
+ catch (error) {
105
+ console.error('Failed to fetch transaction:', error);
106
+ throw error;
107
+ }
108
+ }, [sdk, isInitialized]);
109
+ /**
110
+ * Retrieves transaction history for the authenticated user, filtered by type
111
+ *
112
+ * @param type - Transaction type filter (defaults to 'all')
113
+ * @returns Promise resolving to array of user's transactions
114
+ * @throws Error if SDK is not initialized
115
+ *
116
+ * @example
117
+ * ```typescript
118
+ * const { getUserTransactionHistory } = useTransactions();
119
+ * const transactions = await getUserTransactionHistory('credit');
120
+ * console.log('Credit transactions:', transactions);
121
+ * ```
122
+ */
123
+ const getUserTransactionHistory = useCallback(async (type = 'all') => {
124
+ if (!isInitialized || !sdk) {
125
+ throw new Error('SDK not initialized. Call initialize() first.');
43
126
  }
44
127
  try {
45
- const result = await transactions.getTransactionById(transactionId);
46
- console.log('Transaction fetched successfully:', result);
128
+ const result = await sdk.transactions.getUserTransactionHistory(type);
129
+ console.log('Transaction history fetched successfully:', result);
47
130
  return result;
48
131
  }
49
132
  catch (error) {
50
- console.error('Failed to fetch transaction:', error);
133
+ console.error('Failed to fetch transaction history:', error);
51
134
  throw error;
52
135
  }
53
- }, [transactions]);
54
- const getTransactionHistory = useCallback(async (filters) => {
55
- if (!isInitialized) {
136
+ }, [sdk, isInitialized]);
137
+ const getTenantTransactions = useCallback(async () => {
138
+ if (!isInitialized || !sdk) {
56
139
  throw new Error('SDK not initialized. Call initialize() first.');
57
140
  }
58
- if (!transactions?.getTransactionHistory) {
59
- console.warn('getTransactionHistory method not available');
60
- return [];
141
+ try {
142
+ const result = await sdk.transactions.getTenantTransactions();
143
+ console.log('Tenant transactions fetched successfully:', result);
144
+ return result;
145
+ }
146
+ catch (error) {
147
+ console.error('Failed to fetch tenant transactions:', error);
148
+ throw error;
149
+ }
150
+ }, [sdk, isInitialized]);
151
+ const getPaginatedTransactions = useCallback(async (params) => {
152
+ if (!isInitialized || !sdk) {
153
+ throw new Error('SDK not initialized. Call initialize() first.');
154
+ }
155
+ try {
156
+ const result = await sdk.transactions.getPaginatedTransactions(params);
157
+ console.log('Paginated transactions fetched successfully:', result);
158
+ return result;
159
+ }
160
+ catch (error) {
161
+ console.error('Failed to fetch paginated transactions:', error);
162
+ throw error;
163
+ }
164
+ }, [sdk, isInitialized]);
165
+ const exportTransactionsCSV = useCallback(async () => {
166
+ if (!isInitialized || !sdk) {
167
+ throw new Error('SDK not initialized. Call initialize() first.');
61
168
  }
62
169
  try {
63
- const result = await transactions.getTransactionHistory(filters);
64
- console.log(' Transaction history fetched successfully:', result);
170
+ const result = await sdk.transactions.exportTransactionsCSV();
171
+ console.log('Transactions CSV exported successfully');
65
172
  return result;
66
173
  }
67
174
  catch (error) {
68
- console.error('Failed to fetch transaction history:', error);
175
+ console.error('Failed to export transactions CSV:', error);
69
176
  throw error;
70
177
  }
71
- }, [transactions]);
178
+ }, [sdk, isInitialized]);
72
179
  return {
73
180
  createTransaction,
74
181
  getTransactionById,
75
- getTransactionHistory,
76
- isAvailable: isInitialized && !!transactions,
182
+ getUserTransactionHistory,
183
+ getTenantTransactions,
184
+ getPaginatedTransactions,
185
+ exportTransactionsCSV,
186
+ isAvailable: isInitialized && !!sdk?.transactions,
77
187
  };
78
188
  };
@@ -0,0 +1,9 @@
1
+ import type { UserStatusTypeDTO } from '@explorins/pers-shared';
2
+ export declare const useUserStatus: () => {
3
+ getUserStatusTypes: () => Promise<UserStatusTypeDTO[]>;
4
+ getEarnedUserStatus: () => Promise<UserStatusTypeDTO[]>;
5
+ createUserStatusType: (userStatusType: UserStatusTypeDTO) => Promise<UserStatusTypeDTO>;
6
+ isAvailable: boolean;
7
+ };
8
+ export type UserStatusHook = ReturnType<typeof useUserStatus>;
9
+ //# sourceMappingURL=useUserStatus.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useUserStatus.d.ts","sourceRoot":"","sources":["../../src/hooks/useUserStatus.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAEhE,eAAO,MAAM,aAAa;8BAGyB,QAAQ,iBAAiB,EAAE,CAAC;+BAe3B,QAAQ,iBAAiB,EAAE,CAAC;2CAmBd,iBAAiB,KAAG,QAAQ,iBAAiB,CAAC;;CAqB/G,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC"}
@@ -0,0 +1,57 @@
1
+ import { useCallback } from 'react';
2
+ import { usePersSDK } from '../providers/PersSDKProvider';
3
+ export const useUserStatus = () => {
4
+ const { sdk, isInitialized, isAuthenticated } = usePersSDK();
5
+ const getUserStatusTypes = useCallback(async () => {
6
+ if (!isInitialized || !sdk) {
7
+ throw new Error('SDK not initialized. Call initialize() first.');
8
+ }
9
+ try {
10
+ const result = await sdk.userStatus.getUserStatusTypes();
11
+ console.log('User status types fetched successfully:', result);
12
+ return result;
13
+ }
14
+ catch (error) {
15
+ console.error('Failed to fetch user status types:', error);
16
+ throw error;
17
+ }
18
+ }, [sdk, isInitialized]);
19
+ const getEarnedUserStatus = useCallback(async () => {
20
+ if (!isInitialized || !sdk) {
21
+ throw new Error('SDK not initialized. Call initialize() first.');
22
+ }
23
+ if (!isAuthenticated) {
24
+ throw new Error('SDK not authenticated. getEarnedUserStatus requires authentication.');
25
+ }
26
+ try {
27
+ const result = await sdk.userStatus.getEarnedUserStatus();
28
+ console.log('Earned user status fetched successfully:', result);
29
+ return result;
30
+ }
31
+ catch (error) {
32
+ console.error('Failed to fetch earned user status:', error);
33
+ throw error;
34
+ }
35
+ }, [sdk, isInitialized, isAuthenticated]);
36
+ // Admin methods
37
+ const createUserStatusType = useCallback(async (userStatusType) => {
38
+ if (!isInitialized || !sdk) {
39
+ throw new Error('SDK not initialized. Call initialize() first.');
40
+ }
41
+ try {
42
+ const result = await sdk.userStatus.createUserStatusType(userStatusType);
43
+ console.log('User status type created successfully:', result);
44
+ return result;
45
+ }
46
+ catch (error) {
47
+ console.error('Failed to create user status type:', error);
48
+ throw error;
49
+ }
50
+ }, [sdk, isInitialized]);
51
+ return {
52
+ getUserStatusTypes,
53
+ getEarnedUserStatus,
54
+ createUserStatusType,
55
+ isAvailable: isInitialized && !!sdk?.userStatus,
56
+ };
57
+ };
@@ -0,0 +1,17 @@
1
+ import type { UserDTO, UserCreateRequestDTO } from '@explorins/pers-shared';
2
+ import type { UserPublicProfileDTO } from '@explorins/pers-sdk/user';
3
+ export declare const useUsers: () => {
4
+ getCurrentUser: () => Promise<UserDTO>;
5
+ updateCurrentUser: (userData: UserCreateRequestDTO) => Promise<UserDTO>;
6
+ getUserById: (userId: string) => Promise<UserDTO>;
7
+ getAllUsersPublic: (filter?: {
8
+ key: string;
9
+ value: string;
10
+ }) => Promise<UserPublicProfileDTO[]>;
11
+ getAllUsers: () => Promise<UserDTO[]>;
12
+ updateUser: (userId: string, userData: UserCreateRequestDTO) => Promise<UserDTO>;
13
+ toggleUserStatus: (user: UserDTO) => Promise<UserDTO>;
14
+ isAvailable: boolean;
15
+ };
16
+ export type UserHook = ReturnType<typeof useUsers>;
17
+ //# sourceMappingURL=useUsers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useUsers.d.ts","sourceRoot":"","sources":["../../src/hooks/useUsers.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC5E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAErE,eAAO,MAAM,QAAQ;0BAG0B,QAAQ,OAAO,CAAC;kCAkBN,oBAAoB,KAAG,QAAQ,OAAO,CAAC;0BAkB/C,MAAM,KAAG,QAAQ,OAAO,CAAC;iCAelB;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,KAAG,QAAQ,oBAAoB,EAAE,CAAC;uBAgB5E,QAAQ,OAAO,EAAE,CAAC;yBAed,MAAM,YAAY,oBAAoB,KAAG,QAAQ,OAAO,CAAC;6BAerD,OAAO,KAAG,QAAQ,OAAO,CAAC;;CAyB7E,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG,UAAU,CAAC,OAAO,QAAQ,CAAC,CAAC"}
@@ -0,0 +1,120 @@
1
+ import { useCallback } from 'react';
2
+ import { usePersSDK } from '../providers/PersSDKProvider';
3
+ export const useUsers = () => {
4
+ const { sdk, isInitialized, isAuthenticated } = usePersSDK();
5
+ const getCurrentUser = useCallback(async () => {
6
+ if (!isInitialized || !sdk) {
7
+ throw new Error('SDK not initialized. Call initialize() first.');
8
+ }
9
+ if (!isAuthenticated) {
10
+ throw new Error('SDK not authenticated. getCurrentUser requires authentication.');
11
+ }
12
+ try {
13
+ const result = await sdk.users.getCurrentUser();
14
+ console.log('Current user fetched successfully:', result);
15
+ return result;
16
+ }
17
+ catch (error) {
18
+ console.error('Failed to fetch current user:', error);
19
+ throw error;
20
+ }
21
+ }, [sdk, isInitialized, isAuthenticated]);
22
+ const updateCurrentUser = useCallback(async (userData) => {
23
+ if (!isInitialized || !sdk) {
24
+ throw new Error('SDK not initialized. Call initialize() first.');
25
+ }
26
+ if (!isAuthenticated) {
27
+ throw new Error('SDK not authenticated. updateCurrentUser requires authentication.');
28
+ }
29
+ try {
30
+ const result = await sdk.users.updateCurrentUser(userData);
31
+ console.log('Current user updated successfully:', result);
32
+ return result;
33
+ }
34
+ catch (error) {
35
+ console.error('Failed to update current user:', error);
36
+ throw error;
37
+ }
38
+ }, [sdk, isInitialized, isAuthenticated]);
39
+ const getUserById = useCallback(async (userId) => {
40
+ if (!isInitialized || !sdk) {
41
+ throw new Error('SDK not initialized. Call initialize() first.');
42
+ }
43
+ try {
44
+ const result = await sdk.users.getUserById(userId);
45
+ console.log('User fetched successfully:', result);
46
+ return result;
47
+ }
48
+ catch (error) {
49
+ console.error('Failed to fetch user:', error);
50
+ throw error;
51
+ }
52
+ }, [sdk, isInitialized]);
53
+ const getAllUsersPublic = useCallback(async (filter) => {
54
+ if (!isInitialized || !sdk) {
55
+ throw new Error('SDK not initialized. Call initialize() first.');
56
+ }
57
+ try {
58
+ const result = await sdk.users.getAllUsersPublic(filter);
59
+ console.log('Public users fetched successfully:', result);
60
+ return result;
61
+ }
62
+ catch (error) {
63
+ console.error('Failed to fetch public users:', error);
64
+ throw error;
65
+ }
66
+ }, [sdk, isInitialized]);
67
+ // Admin methods
68
+ const getAllUsers = useCallback(async () => {
69
+ if (!isInitialized || !sdk) {
70
+ throw new Error('SDK not initialized. Call initialize() first.');
71
+ }
72
+ try {
73
+ const result = await sdk.users.getAllUsers();
74
+ console.log('All users fetched successfully:', result);
75
+ return result;
76
+ }
77
+ catch (error) {
78
+ console.error('Failed to fetch all users:', error);
79
+ throw error;
80
+ }
81
+ }, [sdk, isInitialized]);
82
+ const updateUser = useCallback(async (userId, userData) => {
83
+ if (!isInitialized || !sdk) {
84
+ throw new Error('SDK not initialized. Call initialize() first.');
85
+ }
86
+ try {
87
+ const result = await sdk.users.updateUser(userId, userData);
88
+ console.log('User updated successfully:', result);
89
+ return result;
90
+ }
91
+ catch (error) {
92
+ console.error('Failed to update user:', error);
93
+ throw error;
94
+ }
95
+ }, [sdk, isInitialized]);
96
+ const toggleUserStatus = useCallback(async (user) => {
97
+ if (!isInitialized || !sdk) {
98
+ throw new Error('SDK not initialized. Call initialize() first.');
99
+ }
100
+ try {
101
+ const result = await sdk.users.toggleUserStatus(user);
102
+ console.log('User status toggled successfully:', result);
103
+ return result;
104
+ }
105
+ catch (error) {
106
+ console.error('Failed to toggle user status:', error);
107
+ throw error;
108
+ }
109
+ }, [sdk, isInitialized]);
110
+ return {
111
+ getCurrentUser,
112
+ updateCurrentUser,
113
+ getUserById,
114
+ getAllUsersPublic,
115
+ getAllUsers,
116
+ updateUser,
117
+ toggleUserStatus,
118
+ isAvailable: isInitialized && !!sdk?.users,
119
+ };
120
+ };
@@ -1,11 +1,74 @@
1
+ import type { TokenBalance, TokenBalanceRequest, TokenCollectionRequest, TokenCollection, TokenMetadata } from '@explorins/pers-sdk/web3';
2
+ import type { ChainData } from '@explorins/pers-sdk/web3-chain';
3
+ interface WalletInfo {
4
+ address: string | null;
5
+ isConnected: boolean;
6
+ }
7
+ /**
8
+ * React hook for Web3 operations in the PERS SDK
9
+ *
10
+ * Provides comprehensive Web3 functionality including token balance queries,
11
+ * metadata retrieval, collection management, IPFS resolution, and blockchain
12
+ * explorer integration. Supports multi-chain operations and wallet management.
13
+ *
14
+ * @returns Web3 hook with methods for blockchain operations
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * function Web3Component() {
19
+ * const {
20
+ * getTokenBalance,
21
+ * getTokenMetadata,
22
+ * getWalletInfo,
23
+ * accountAddress
24
+ * } = useWeb3();
25
+ *
26
+ * const loadTokenData = async () => {
27
+ * try {
28
+ * if (!accountAddress) {
29
+ * console.log('No wallet connected');
30
+ * return;
31
+ * }
32
+ *
33
+ * const balance = await getTokenBalance({
34
+ * walletAddress: accountAddress,
35
+ * contractAddress: '0x123...',
36
+ * chainId: 1
37
+ * });
38
+ *
39
+ * console.log('Token balance:', balance);
40
+ * } catch (error) {
41
+ * console.error('Failed to load token data:', error);
42
+ * }
43
+ * };
44
+ *
45
+ * return (
46
+ * <div>
47
+ * {accountAddress ? (
48
+ * <div>
49
+ * <p>Wallet: {accountAddress}</p>
50
+ * <button onClick={loadTokenData}>Load Tokens</button>
51
+ * </div>
52
+ * ) : (
53
+ * <p>No wallet connected</p>
54
+ * )}
55
+ * </div>
56
+ * );
57
+ * }
58
+ * ```
59
+ */
1
60
  export declare const useWeb3: () => {
2
- getTokenBalance: (request: any) => Promise<any>;
3
- getTokenCollection: (request: any) => Promise<any>;
4
- getWalletInfo: () => Promise<{
5
- address: string;
6
- isConnected: boolean;
7
- } | null>;
61
+ getTokenBalance: (request: TokenBalanceRequest) => Promise<TokenBalance>;
62
+ getTokenMetadata: (request: TokenBalanceRequest) => Promise<TokenMetadata | null>;
63
+ getTokenCollection: (request: TokenCollectionRequest) => Promise<TokenCollection>;
64
+ resolveIPFSUrl: (url: string, chainId: number) => Promise<string>;
65
+ fetchAndProcessMetadata: (tokenUri: string, chainId: number) => Promise<TokenMetadata | null>;
66
+ getChainDataById: (chainId: number) => Promise<ChainData | null>;
67
+ getExplorerUrl: (chainId: number, address: string, type: 'address' | 'tx') => Promise<string>;
68
+ getWalletInfo: () => Promise<WalletInfo | null>;
8
69
  accountAddress: string | null;
9
70
  isAvailable: boolean;
10
71
  };
72
+ export type Web3Hook = ReturnType<typeof useWeb3>;
73
+ export {};
11
74
  //# sourceMappingURL=useWeb3.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useWeb3.d.ts","sourceRoot":"","sources":["../../src/hooks/useWeb3.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,OAAO;+BAOkC,GAAG;kCAkBA,GAAG;;;;;;;CAyC3D,CAAC"}
1
+ {"version":3,"file":"useWeb3.d.ts","sourceRoot":"","sources":["../../src/hooks/useWeb3.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,YAAY,EACZ,mBAAmB,EACnB,sBAAsB,EACtB,eAAe,EACf,aAAa,EACd,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAEhE,UAAU,UAAU;IAClB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,WAAW,EAAE,OAAO,CAAC;CACtB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AACH,eAAO,MAAM,OAAO;+BA0BkC,mBAAmB,KAAG,QAAQ,YAAY,CAAC;gCAmC1C,mBAAmB,KAAG,QAAQ,aAAa,GAAG,IAAI,CAAC;kCAejD,sBAAsB,KAAG,QAAQ,eAAe,CAAC;0BAezD,MAAM,WAAW,MAAM,KAAG,QAAQ,MAAM,CAAC;wCAe3B,MAAM,WAAW,MAAM,KAAG,QAAQ,aAAa,GAAG,IAAI,CAAC;gCAe/D,MAAM,KAAG,QAAQ,SAAS,GAAG,IAAI,CAAC;8BAepC,MAAM,WAAW,MAAM,QAAQ,SAAS,GAAG,IAAI,KAAG,QAAQ,MAAM,CAAC;yBAexE,QAAQ,UAAU,GAAG,IAAI,CAAC;;;CA2BvE,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG,UAAU,CAAC,OAAO,OAAO,CAAC,CAAC"}