@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,129 +1,196 @@
1
1
  import { useCallback } from 'react';
2
2
  import { usePersSDK } from '../providers/PersSDKProvider';
3
+ import { useTransactionSigner } from './useTransactionSigner';
4
+ import type { TransactionSigningResult } from './useTransactionSigner';
5
+ import type {
6
+ RedemptionCreateRequestDTO,
7
+ RedemptionDTO,
8
+ RedemptionRedeemDTO,
9
+ RedemptionRedeemRequestResponseDTO,
10
+ RedemptionTypeDTO,
11
+ TokenUnitCreateRequestDTO
12
+ } from '@explorins/pers-shared';
3
13
 
4
14
  export const useRedemptions = () => {
5
- const { redemptions, isInitialized, isAuthenticated } = usePersSDK();
15
+ const { sdk, isInitialized, isAuthenticated } = usePersSDK();
16
+ const { signTransaction, isSignerAvailable } = useTransactionSigner();
6
17
 
7
- // Admin method: Create new redemption offers
8
- const createRedemption = useCallback(async (redemptionData: any) => {
9
- if (!isInitialized) {
18
+ const getActiveRedemptions = useCallback(async (): Promise<RedemptionDTO[]> => {
19
+ if (!isInitialized || !sdk) {
10
20
  throw new Error('SDK not initialized. Call initialize() first.');
11
21
  }
12
- if (!redemptions?.createRedemption) {
13
- throw new Error('createRedemption method not available - admin access required');
14
- }
15
22
 
16
23
  try {
17
- console.log('🔄 Creating redemption offer with data:', redemptionData);
18
- const result = await redemptions.createRedemption(redemptionData);
19
- console.log('✅ Redemption offer created successfully:', result);
24
+ const result = await sdk.redemptions.getActiveRedemptions();
25
+ console.log('Active redemptions fetched successfully:', result);
20
26
  return result;
21
27
  } catch (error) {
22
- console.error('Failed to create redemption offer:', error);
28
+ console.error('Failed to fetch active redemptions:', error);
23
29
  throw error;
24
30
  }
25
- }, [redemptions]);
31
+ }, [sdk, isInitialized]);
26
32
 
27
- const getActiveRedemptions = useCallback(async () => {
28
- if (!isInitialized) {
33
+ const getUserRedemptions = useCallback(async (): Promise<RedemptionRedeemDTO[]> => {
34
+ if (!isInitialized || !sdk) {
29
35
  throw new Error('SDK not initialized. Call initialize() first.');
30
36
  }
31
- if (!redemptions?.getActiveRedemptions) {
32
- console.warn('getActiveRedemptions method not available');
37
+ if (!isAuthenticated) {
38
+ console.warn('SDK not authenticated. getUserRedemptions requires authentication.');
33
39
  return [];
34
40
  }
35
41
 
36
42
  try {
37
- const result = await redemptions.getActiveRedemptions();
38
- console.log(' Active redemptions fetched successfully:', result);
43
+ const result = await sdk.redemptions.getUserRedemptions();
44
+ console.log('User redemptions fetched successfully:', result);
39
45
  return result;
40
46
  } catch (error) {
41
- console.error('Failed to fetch active redemptions:', error);
47
+ console.error('Failed to fetch user redemptions:', error);
42
48
  throw error;
43
49
  }
44
- }, [redemptions]);
50
+ }, [sdk, isInitialized, isAuthenticated]);
45
51
 
46
- const getUserRedeems = useCallback(async () => {
47
- if (!isInitialized) {
52
+ const redeemOffer = useCallback(async (redemptionId: string): Promise<RedemptionRedeemRequestResponseDTO> => {
53
+ if (!isInitialized || !sdk) {
48
54
  throw new Error('SDK not initialized. Call initialize() first.');
49
55
  }
50
56
  if (!isAuthenticated) {
51
- console.warn('SDK not authenticated. getUserRedeems requires authentication.');
52
- return [];
57
+ throw new Error('SDK not authenticated. redeemOffer requires authentication.');
53
58
  }
54
- if (!redemptions?.getUserRedeems) {
55
- console.warn('getUserRedeems method not available');
56
- return [];
59
+
60
+ try {
61
+ console.log('Redeeming redemption:', redemptionId);
62
+ const result = await sdk.redemptions.redeemOffer(redemptionId);
63
+
64
+ // Check if result has signing fields and sign transaction if required and signer is available
65
+ console.log('Redemption processed successfully:', result);
66
+
67
+
68
+ const txToken = result.senderTransaction?.actionable?.authToken;
69
+ if (txToken && isSignerAvailable) {
70
+ console.log('Transaction requires blockchain signing, processing with WebAuthn signer...');
71
+
72
+ try {
73
+ const signingResult: TransactionSigningResult = await signTransaction(txToken);
74
+ console.log('Blockchain signing result:', signingResult);
75
+ if (signingResult.success) {
76
+ console.log('Transaction signed successfully:', signingResult.transactionHash);
77
+ // Return enhanced result with signing information
78
+ return {
79
+ ...result,
80
+ transactionHash: signingResult.transactionHash,
81
+ signature: signingResult.signature,
82
+ isSigned: true,
83
+ signedAt: new Date().toISOString()
84
+ } as RedemptionRedeemRequestResponseDTO;
85
+ } else {
86
+ console.error('Transaction signing failed:', signingResult.error);
87
+ throw new Error(signingResult.error || 'Transaction signing failed');
88
+ }
89
+ } catch (signingError) {
90
+ console.error('Blockchain signing error:', signingError);
91
+ throw new Error(`Transaction signing failed: ${signingError}`);
92
+ }
93
+ } else if (txToken && !isSignerAvailable) {
94
+ console.warn('Transaction requires signature but signer is not available');
95
+ throw new Error('Transaction requires signature but blockchain signer is not initialized');
96
+ }
97
+
98
+ // Return original result if no signing was required
99
+ return result;
100
+ } catch (error) {
101
+ console.error('Failed to redeem redemption:', error);
102
+ throw error;
103
+ }
104
+ }, [sdk, isInitialized, isAuthenticated, signTransaction, isSignerAvailable]);
105
+
106
+ // Admin methods
107
+ const createRedemption = useCallback(async (redemptionData: RedemptionCreateRequestDTO): Promise<RedemptionDTO> => {
108
+ if (!isInitialized || !sdk) {
109
+ throw new Error('SDK not initialized. Call initialize() first.');
57
110
  }
58
111
 
59
112
  try {
60
- const result = await redemptions.getUserRedeems();
61
- console.log('✅ User redemptions fetched successfully:', result);
113
+ console.log('Creating redemption offer with data:', redemptionData);
114
+ const result = await sdk.redemptions.createRedemption(redemptionData);
115
+ console.log('Redemption offer created successfully:', result);
62
116
  return result;
63
117
  } catch (error) {
64
- console.error('Failed to fetch user redemptions:', error);
118
+ console.error('Failed to create redemption offer:', error);
65
119
  throw error;
66
120
  }
67
- }, [isInitialized, isAuthenticated, redemptions]);
121
+ }, [sdk, isInitialized]);
68
122
 
69
- const redeemRedemption = useCallback(async (redemptionId: string) => {
70
- if (!isInitialized) {
123
+ const getAllRedemptions = useCallback(async (active?: boolean): Promise<RedemptionDTO[]> => {
124
+ if (!isInitialized || !sdk) {
71
125
  throw new Error('SDK not initialized. Call initialize() first.');
72
126
  }
73
- if (!isAuthenticated) {
74
- throw new Error('SDK not authenticated. redeemRedemption requires authentication.');
127
+
128
+ try {
129
+ const result = await sdk.redemptions.getAllRedemptions(active);
130
+ console.log('All redemptions fetched successfully:', result);
131
+ return result;
132
+ } catch (error) {
133
+ console.error('Failed to fetch all redemptions:', error);
134
+ throw error;
75
135
  }
76
- if (!redemptions?.redeemRedemption) {
77
- throw new Error('redeemRedemption method not available');
136
+ }, [sdk, isInitialized]);
137
+
138
+ const getRedemptionTypes = useCallback(async (): Promise<RedemptionTypeDTO[]> => {
139
+ if (!isInitialized || !sdk) {
140
+ throw new Error('SDK not initialized. Call initialize() first.');
78
141
  }
79
142
 
80
143
  try {
81
- console.log('🔄 Redeeming redemption:', redemptionId);
82
- const result = await redemptions.redeemRedemption(redemptionId);
83
-
84
- // React Native specific: Handle signature URLs for redemptions
85
- if (result?.actionable?.actionUrl) {
86
- try {
87
- const { Linking } = require('react-native');
88
- console.log('🔗 Opening redemption signature URL:', result.actionable.actionUrl);
89
- await Linking.openURL(result.actionable.actionUrl);
90
- } catch (linkingError) {
91
- console.error('❌ Failed to open redemption signature URL:', linkingError);
92
- }
93
- }
94
-
95
- console.log('✅ Redemption processed successfully:', result);
144
+ const result = await sdk.redemptions.getRedemptionTypes();
145
+ console.log('Redemption types fetched successfully:', result);
96
146
  return result;
97
147
  } catch (error) {
98
- console.error('Failed to redeem redemption:', error);
148
+ console.error('Failed to fetch redemption types:', error);
99
149
  throw error;
100
150
  }
101
- }, [isInitialized, isAuthenticated, redemptions]);
151
+ }, [sdk, isInitialized]);
102
152
 
103
- const getRedemptionById = useCallback(async (redemptionId: string) => {
104
- if (!isInitialized) {
153
+ const updateRedemption = useCallback(async (redemptionId: string, redemptionData: RedemptionCreateRequestDTO): Promise<RedemptionDTO> => {
154
+ if (!isInitialized || !sdk) {
105
155
  throw new Error('SDK not initialized. Call initialize() first.');
106
156
  }
107
- if (!redemptions?.getRedemptionById) {
108
- throw new Error('getRedemptionById method not available');
157
+
158
+ try {
159
+ const result = await sdk.redemptions.updateRedemption(redemptionId, redemptionData);
160
+ console.log('Redemption updated successfully:', result);
161
+ return result;
162
+ } catch (error) {
163
+ console.error('Failed to update redemption:', error);
164
+ throw error;
165
+ }
166
+ }, [sdk, isInitialized]);
167
+
168
+ const toggleRedemptionStatus = useCallback(async (redemptionId: string): Promise<RedemptionDTO> => {
169
+ if (!isInitialized || !sdk) {
170
+ throw new Error('SDK not initialized. Call initialize() first.');
109
171
  }
110
172
 
111
173
  try {
112
- const result = await redemptions.getRedemptionById(redemptionId);
113
- console.log('Redemption fetched successfully:', result);
174
+ const result = await sdk.redemptions.toggleRedemptionStatus(redemptionId);
175
+ console.log('Redemption status toggled successfully:', result);
114
176
  return result;
115
177
  } catch (error) {
116
- console.error('Failed to fetch redemption:', error);
178
+ console.error('Failed to toggle redemption status:', error);
117
179
  throw error;
118
180
  }
119
- }, [redemptions]);
181
+ }, [sdk, isInitialized]);
120
182
 
121
183
  return {
122
- createRedemption,
123
184
  getActiveRedemptions,
124
- getUserRedeems,
125
- redeemRedemption,
126
- getRedemptionById,
127
- isAvailable: isInitialized && !!redemptions,
185
+ getUserRedemptions,
186
+ redeemOffer,
187
+ getRedemptionTypes,
188
+ createRedemption,
189
+ getAllRedemptions,
190
+ updateRedemption,
191
+ toggleRedemptionStatus,
192
+ isAvailable: isInitialized && !!sdk?.redemptions,
128
193
  };
129
- };
194
+ };
195
+
196
+ export type RedemptionHook = ReturnType<typeof useRedemptions>;
@@ -0,0 +1,77 @@
1
+ import { useCallback } from 'react';
2
+ import { usePersSDK } from '../providers/PersSDKProvider';
3
+ import type { TenantPublicDTO, TenantClientConfigDTO, AdminDTO } from '@explorins/pers-shared';
4
+
5
+ export const useTenants = () => {
6
+ const { sdk, isInitialized } = usePersSDK();
7
+
8
+ const getTenantInfo = useCallback(async (): Promise<TenantPublicDTO> => {
9
+ if (!isInitialized || !sdk) {
10
+ throw new Error('SDK not initialized. Call initialize() first.');
11
+ }
12
+
13
+ try {
14
+ const result = await sdk.tenants.getTenantInfo();
15
+ console.log('Tenant info fetched successfully:', result);
16
+ return result;
17
+ } catch (error) {
18
+ console.error('Failed to fetch tenant info:', error);
19
+ throw error;
20
+ }
21
+ }, [sdk, isInitialized]);
22
+
23
+ const getClientConfig = useCallback(async (): Promise<TenantClientConfigDTO> => {
24
+ if (!isInitialized || !sdk) {
25
+ throw new Error('SDK not initialized. Call initialize() first.');
26
+ }
27
+
28
+ try {
29
+ const result = await sdk.tenants.getClientConfig();
30
+ console.log('Client config fetched successfully:', result);
31
+ return result;
32
+ } catch (error) {
33
+ console.error('Failed to fetch client config:', error);
34
+ throw error;
35
+ }
36
+ }, [sdk, isInitialized]);
37
+
38
+ const getLoginToken = useCallback(async (): Promise<string> => {
39
+ if (!isInitialized || !sdk) {
40
+ throw new Error('SDK not initialized. Call initialize() first.');
41
+ }
42
+
43
+ try {
44
+ const result = await sdk.tenants.getLoginToken();
45
+ console.log('Login token fetched successfully');
46
+ return result;
47
+ } catch (error) {
48
+ console.error('Failed to fetch login token:', error);
49
+ throw error;
50
+ }
51
+ }, [sdk, isInitialized]);
52
+
53
+ const getAdmins = useCallback(async (): Promise<AdminDTO[]> => {
54
+ if (!isInitialized || !sdk) {
55
+ throw new Error('SDK not initialized. Call initialize() first.');
56
+ }
57
+
58
+ try {
59
+ const result = await sdk.tenants.getAdmins();
60
+ console.log('Admins fetched successfully:', result);
61
+ return result;
62
+ } catch (error) {
63
+ console.error('Failed to fetch admins:', error);
64
+ throw error;
65
+ }
66
+ }, [sdk, isInitialized]);
67
+
68
+ return {
69
+ getTenantInfo,
70
+ getClientConfig,
71
+ getLoginToken,
72
+ getAdmins,
73
+ isAvailable: isInitialized && !!sdk?.tenants,
74
+ };
75
+ };
76
+
77
+ export type TenantHook = ReturnType<typeof useTenants>;
@@ -1,53 +1,221 @@
1
1
  import { useCallback } from 'react';
2
2
  import { usePersSDK } from '../providers/PersSDKProvider';
3
+ import type { TokenDTO } from '@explorins/pers-shared';
3
4
 
5
+ /**
6
+ * React hook for token operations in the PERS SDK
7
+ *
8
+ * Provides methods for fetching various types of tokens including credit, reward, and status tokens.
9
+ * Supports both general token queries and specific contract-based token retrieval.
10
+ *
11
+ * @returns Token hook with methods for token management
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * function TokensComponent() {
16
+ * const { getTokens, getActiveCreditToken, getRewardTokens } = useTokens();
17
+ *
18
+ * const loadTokens = async () => {
19
+ * try {
20
+ * const tokens = await getTokens();
21
+ * const creditToken = await getActiveCreditToken();
22
+ * console.log('Loaded tokens:', tokens);
23
+ * console.log('Active credit token:', creditToken);
24
+ * } catch (error) {
25
+ * console.error('Failed to load tokens:', error);
26
+ * }
27
+ * };
28
+ *
29
+ * return <button onClick={loadTokens}>Load Tokens</button>;
30
+ * }
31
+ * ```
32
+ */
4
33
  export const useTokens = () => {
5
- const { tokens, isInitialized, isAuthenticated } = usePersSDK();
34
+ const { sdk, isInitialized, isAuthenticated } = usePersSDK();
6
35
 
7
36
  if (!isAuthenticated && isInitialized) {
8
37
  console.warn('SDK not authenticated. Some token operations may fail.');
9
38
  }
10
39
 
11
- const getTokens = useCallback(async () => {
12
- if (!isInitialized) {
40
+ /**
41
+ * Retrieves all tokens available to the current user
42
+ *
43
+ * @returns Promise resolving to array of tokens
44
+ * @throws Error if SDK is not initialized
45
+ *
46
+ * @example
47
+ * ```typescript
48
+ * const { getTokens } = useTokens();
49
+ * const tokens = await getTokens();
50
+ * console.log('Available tokens:', tokens);
51
+ * ```
52
+ */
53
+ const getTokens = useCallback(async (): Promise<TokenDTO[]> => {
54
+ if (!isInitialized || !sdk) {
13
55
  throw new Error('SDK not initialized. Call initialize() first.');
14
56
  }
15
- if (!tokens?.getTokens) {
16
- console.warn('getTokens method not available');
17
- return [];
57
+
58
+ try {
59
+ const result = await sdk.tokens.getTokens();
60
+ console.log('Tokens fetched successfully:', result);
61
+ return result;
62
+ } catch (error) {
63
+ console.error('Failed to fetch tokens:', error);
64
+ throw error;
65
+ }
66
+ }, [sdk, isInitialized]);
67
+
68
+ /**
69
+ * Retrieves the currently active credit token
70
+ *
71
+ * @returns Promise resolving to active credit token
72
+ * @throws Error if SDK is not initialized
73
+ *
74
+ * @example
75
+ * ```typescript
76
+ * const { getActiveCreditToken } = useTokens();
77
+ * const creditToken = await getActiveCreditToken();
78
+ * console.log('Active credit token:', creditToken.name);
79
+ * ```
80
+ */
81
+ const getActiveCreditToken = useCallback(async (): Promise<TokenDTO> => {
82
+ if (!isInitialized || !sdk) {
83
+ throw new Error('SDK not initialized. Call initialize() first.');
18
84
  }
19
85
 
20
86
  try {
21
- const result = await tokens.getTokens();
22
- console.log(' Tokens fetched successfully:', result);
87
+ const result = await sdk.tokens.getActiveCreditToken();
88
+ console.log('Active credit token fetched successfully:', result);
23
89
  return result;
24
90
  } catch (error) {
25
- console.error('Failed to fetch tokens:', error);
91
+ console.error('Failed to fetch active credit token:', error);
26
92
  throw error;
27
93
  }
28
- }, [tokens]);
94
+ }, [sdk, isInitialized]);
29
95
 
30
- const getTokenById = useCallback(async (tokenId: string) => {
31
- if (!isInitialized) {
96
+ /**
97
+ * Retrieves all reward tokens available in the system
98
+ *
99
+ * @returns Promise resolving to array of reward tokens
100
+ * @throws Error if SDK is not initialized
101
+ *
102
+ * @example
103
+ * ```typescript
104
+ * const { getRewardTokens } = useTokens();
105
+ * const rewardTokens = await getRewardTokens();
106
+ * console.log('Reward tokens:', rewardTokens);
107
+ * ```
108
+ */
109
+ const getRewardTokens = useCallback(async (): Promise<TokenDTO[]> => {
110
+ if (!isInitialized || !sdk) {
32
111
  throw new Error('SDK not initialized. Call initialize() first.');
33
112
  }
34
- if (!tokens?.getTokenById) {
35
- throw new Error('getTokenById method not available');
113
+
114
+ try {
115
+ const result = await sdk.tokens.getRewardTokens();
116
+ console.log('Reward tokens fetched successfully:', result);
117
+ return result;
118
+ } catch (error) {
119
+ console.error('Failed to fetch reward tokens:', error);
120
+ throw error;
121
+ }
122
+ }, [sdk, isInitialized]);
123
+
124
+ /**
125
+ * Retrieves all available token types in the system
126
+ *
127
+ * @returns Promise resolving to array of token types
128
+ * @throws Error if SDK is not initialized
129
+ *
130
+ * @example
131
+ * ```typescript
132
+ * const { getTokenTypes } = useTokens();
133
+ * const types = await getTokenTypes();
134
+ * console.log('Token types:', types);
135
+ * ```
136
+ */
137
+ const getTokenTypes = useCallback(async (): Promise<any> => {
138
+ if (!isInitialized || !sdk) {
139
+ throw new Error('SDK not initialized. Call initialize() first.');
36
140
  }
37
141
 
38
142
  try {
39
- const result = await tokens.getTokenById(tokenId);
40
- console.log('Token fetched successfully:', result);
143
+ const result = await sdk.tokens.getTokenTypes();
144
+ console.log('Token types fetched successfully:', result);
41
145
  return result;
42
146
  } catch (error) {
43
- console.error('Failed to fetch token:', error);
147
+ console.error('Failed to fetch token types:', error);
44
148
  throw error;
45
149
  }
46
- }, [tokens]);
150
+ }, [sdk, isInitialized]);
151
+
152
+ /**
153
+ * Retrieves all status tokens (tokens that represent user status/achievements)
154
+ *
155
+ * @returns Promise resolving to array of status tokens
156
+ * @throws Error if SDK is not initialized
157
+ *
158
+ * @example
159
+ * ```typescript
160
+ * const { getStatusTokens } = useTokens();
161
+ * const statusTokens = await getStatusTokens();
162
+ * console.log('Status tokens:', statusTokens);
163
+ * ```
164
+ */
165
+ const getStatusTokens = useCallback(async (): Promise<TokenDTO[]> => {
166
+ if (!isInitialized || !sdk) {
167
+ throw new Error('SDK not initialized. Call initialize() first.');
168
+ }
169
+
170
+ try {
171
+ const result = await sdk.tokens.getStatusTokens();
172
+ console.log('Status tokens fetched successfully:', result);
173
+ return result;
174
+ } catch (error) {
175
+ console.error('Failed to fetch status tokens:', error);
176
+ throw error;
177
+ }
178
+ }, [sdk, isInitialized]);
179
+
180
+ /**
181
+ * Retrieves a specific token by its contract address and optional token ID
182
+ *
183
+ * @param contractAddress - The contract address of the token
184
+ * @param contractTokenId - Optional specific token ID within the contract
185
+ * @returns Promise resolving to the token data
186
+ * @throws Error if SDK is not initialized
187
+ *
188
+ * @example
189
+ * ```typescript
190
+ * const { getTokenByContract } = useTokens();
191
+ * const token = await getTokenByContract('0x123...', 'token-1');
192
+ * console.log('Token from contract:', token);
193
+ * ```
194
+ */
195
+ const getTokenByContract = useCallback(async (contractAddress: string, contractTokenId?: string | null): Promise<TokenDTO> => {
196
+ if (!isInitialized || !sdk) {
197
+ throw new Error('SDK not initialized. Call initialize() first.');
198
+ }
199
+
200
+ try {
201
+ const result = await sdk.tokens.getTokenByContract(contractAddress, contractTokenId);
202
+ console.log('Token by contract fetched successfully:', result);
203
+ return result;
204
+ } catch (error) {
205
+ console.error('Failed to fetch token by contract:', error);
206
+ throw error;
207
+ }
208
+ }, [sdk, isInitialized]);
47
209
 
48
210
  return {
49
211
  getTokens,
50
- getTokenById,
51
- isAvailable: isInitialized && !!tokens,
212
+ getActiveCreditToken,
213
+ getRewardTokens,
214
+ getTokenTypes,
215
+ getStatusTokens,
216
+ getTokenByContract,
217
+ isAvailable: isInitialized && !!sdk?.tokens,
52
218
  };
53
- };
219
+ };
220
+
221
+ export type TokenHook = ReturnType<typeof useTokens>;