@explorins/pers-sdk-react-native 2.3.7 → 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.
Files changed (58) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1266 -1244
  3. package/dist/__tests__/PersSDKProvider.test.js +33 -0
  4. package/dist/hooks/useBusiness.d.ts +2 -2
  5. package/dist/hooks/useBusiness.d.ts.map +1 -1
  6. package/dist/hooks/useBusiness.js +2 -2
  7. package/dist/hooks/useIPFSUrl.d.ts +3 -3
  8. package/dist/hooks/useIPFSUrl.d.ts.map +1 -1
  9. package/dist/hooks/useIPFSUrl.js +7 -7
  10. package/dist/hooks/useWeb3.js +4 -4
  11. package/dist/index.js +2400 -487
  12. package/dist/index.js.map +1 -1
  13. package/dist/providers/PersSDKProvider.d.ts +4 -0
  14. package/dist/providers/PersSDKProvider.d.ts.map +1 -1
  15. package/dist/providers/PersSDKProvider.js +14 -0
  16. package/dist/providers/react-native-http-client.d.ts +2 -0
  17. package/dist/providers/react-native-http-client.d.ts.map +1 -1
  18. package/dist/providers/react-native-http-client.js +5 -2
  19. package/dist/storage/rn-secure-storage.d.ts.map +1 -1
  20. package/dist/storage/rn-secure-storage.js +21 -8
  21. package/package.json +3 -3
  22. package/src/__tests__/PersSDKProvider.test.tsx +484 -420
  23. package/src/__tests__/setup.ts +40 -40
  24. package/src/hooks/index.ts +60 -60
  25. package/src/hooks/useAnalytics.ts +327 -327
  26. package/src/hooks/useAuth.ts +265 -265
  27. package/src/hooks/useBookings.ts +191 -191
  28. package/src/hooks/useBusiness.ts +251 -251
  29. package/src/hooks/useCampaigns.ts +500 -500
  30. package/src/hooks/useDonations.ts +66 -66
  31. package/src/hooks/useEvents.ts +372 -372
  32. package/src/hooks/useFiles.ts +155 -155
  33. package/src/hooks/useIPFSUrl.ts +192 -192
  34. package/src/hooks/usePurchases.ts +65 -65
  35. package/src/hooks/useRedemptions.ts +467 -467
  36. package/src/hooks/useTenants.ts +72 -72
  37. package/src/hooks/useTokenBalances.ts +385 -385
  38. package/src/hooks/useTokens.ts +313 -313
  39. package/src/hooks/useTransactionSigner.ts +611 -611
  40. package/src/hooks/useTransactions.ts +299 -299
  41. package/src/hooks/useTriggerSources.ts +301 -301
  42. package/src/hooks/useUserStatus.ts +61 -61
  43. package/src/hooks/useUsers.ts +167 -167
  44. package/src/hooks/useWeb3.ts +355 -355
  45. package/src/index.ts +777 -777
  46. package/src/polyfills/index.ts +160 -160
  47. package/src/polyfills/web3-polyfills.ts +97 -97
  48. package/src/providers/PersSDKProvider.tsx +393 -374
  49. package/src/providers/react-native-auth-provider.ts +110 -110
  50. package/src/providers/react-native-http-client.ts +150 -145
  51. package/src/providers/rn-dpop-provider.ts +190 -190
  52. package/src/storage/async-storage-token-storage.ts +185 -185
  53. package/src/storage/rn-secure-storage.ts +182 -170
  54. package/src/types/react-native-globals.d.ts +45 -45
  55. package/src/utils/index.ts +8 -8
  56. package/src/utils/platform-detection.ts +86 -86
  57. package/dist/index-CzLxqePZ.js +0 -7717
  58. package/dist/index-CzLxqePZ.js.map +0 -1
@@ -1,192 +1,192 @@
1
- import { useState, useEffect, useCallback } from 'react';
2
- import { usePersSDK } from '../providers/PersSDKProvider';
3
- import type { TokenMetadata } from '@explorins/pers-sdk';
4
-
5
- /**
6
- * React hook for resolving media URLs (IPFS or HTTPS).
7
- *
8
- * Automatically handles IPFS URLs by resolving them to HTTPS via tenant's gateway.
9
- * Non-IPFS URLs are returned as-is. Handles loading and error states.
10
- *
11
- * Uses sdk.tenants for IPFS resolution (lightweight, no Web3 deps).
12
- *
13
- * @param url - The URL to resolve (can be ipfs://, https://, or undefined)
14
- * @returns Object with resolved URL, loading state, and error
15
- *
16
- * @example
17
- * ```tsx
18
- * function NFTImage({ metadataUri }: { metadataUri?: string }) {
19
- * const { url, isLoading } = useResolvedUrl(metadataUri);
20
- *
21
- * if (isLoading) return <ActivityIndicator />;
22
- * return <Image source={{ uri: url }} />;
23
- * }
24
- * ```
25
- */
26
- export function useResolvedUrl(url: string | undefined | null) {
27
- const { sdk, isInitialized } = usePersSDK();
28
- const [resolvedUrl, setResolvedUrl] = useState<string | null>(null);
29
- const [isLoading, setIsLoading] = useState(false);
30
- const [error, setError] = useState<string | null>(null);
31
-
32
- useEffect(() => {
33
- if (!url || !isInitialized || !sdk) {
34
- setResolvedUrl(null);
35
- return;
36
- }
37
-
38
- // Non-IPFS URLs don't need resolution
39
- if (!url.startsWith('ipfs://')) {
40
- setResolvedUrl(url);
41
- return;
42
- }
43
-
44
- setIsLoading(true);
45
- setError(null);
46
-
47
- sdk.tenants.resolveIpfsUrl(url)
48
- .then((resolved) => {
49
- setResolvedUrl(resolved);
50
- })
51
- .catch((err) => {
52
- setError(err instanceof Error ? err.message : 'Failed to resolve URL');
53
- setResolvedUrl(null);
54
- })
55
- .finally(() => {
56
- setIsLoading(false);
57
- });
58
- }, [url, isInitialized, sdk]);
59
-
60
- return {
61
- /** Resolved HTTPS URL (or original if not IPFS) */
62
- url: resolvedUrl,
63
- /** Whether resolution is in progress */
64
- isLoading,
65
- /** Error message if resolution failed */
66
- error,
67
- };
68
- }
69
-
70
- /**
71
- * React hook for fetching NFT/token metadata from a URI.
72
- *
73
- * Handles IPFS resolution automatically and returns parsed metadata
74
- * with all nested IPFS URLs already resolved to HTTPS.
75
- *
76
- * Uses sdk.tenants for metadata fetching (lightweight, no Web3 deps).
77
- *
78
- * @param metadataUri - The metadata URI to fetch (can be ipfs:// or https://)
79
- * @returns Object with metadata, loading state, error, and refresh function
80
- *
81
- * @example
82
- * ```tsx
83
- * function NFTDetails({ metadataUri }: { metadataUri?: string }) {
84
- * const { metadata, isLoading, error } = useMetadata(metadataUri);
85
- *
86
- * if (isLoading) return <ActivityIndicator />;
87
- * if (error) return <Text>Error: {error}</Text>;
88
- * if (!metadata) return null;
89
- *
90
- * return (
91
- * <View>
92
- * <Image source={{ uri: metadata.imageUrl }} />
93
- * <Text>{metadata.name}</Text>
94
- * <Text>{metadata.description}</Text>
95
- * </View>
96
- * );
97
- * }
98
- * ```
99
- */
100
- export function useMetadata(metadataUri: string | undefined | null) {
101
- const { sdk, isInitialized } = usePersSDK();
102
- const [metadata, setMetadata] = useState<TokenMetadata | null>(null);
103
- const [isLoading, setIsLoading] = useState(false);
104
- const [error, setError] = useState<string | null>(null);
105
-
106
- const fetchMetadata = useCallback(async () => {
107
- if (!metadataUri || !isInitialized || !sdk) {
108
- setMetadata(null);
109
- return;
110
- }
111
-
112
- setIsLoading(true);
113
- setError(null);
114
-
115
- try {
116
- const result = await sdk.tenants.fetchAndProcessMetadata(metadataUri);
117
- setMetadata(result);
118
- } catch (err) {
119
- setError(err instanceof Error ? err.message : 'Failed to fetch metadata');
120
- setMetadata(null);
121
- } finally {
122
- setIsLoading(false);
123
- }
124
- }, [metadataUri, isInitialized, sdk]);
125
-
126
- useEffect(() => {
127
- fetchMetadata();
128
- }, [fetchMetadata]);
129
-
130
- return {
131
- /** Parsed metadata with resolved IPFS URLs (imageUrl, animationUrl, etc.) */
132
- metadata,
133
- /** Whether fetch is in progress */
134
- isLoading,
135
- /** Error message if fetch failed */
136
- error,
137
- /** Manually refresh metadata */
138
- refresh: fetchMetadata,
139
- };
140
- }
141
-
142
- // Re-export with descriptive aliases
143
- export { useResolvedUrl as useIPFSUrl };
144
-
145
- /**
146
- * React hook for loading transaction/token metadata.
147
- *
148
- * Convenience wrapper around useMetadata specifically for transaction items.
149
- * Pass a transaction's metadataUri to get the NFT image, name, description, etc.
150
- *
151
- * @param transaction - Transaction object with optional metadataUri field
152
- * @returns Object with metadata, loading state, and image URL
153
- *
154
- * @example
155
- * ```tsx
156
- * import { useTransactionMetadata } from '@explorins/pers-sdk-react-native';
157
- *
158
- * function TransactionItem({ tx }: { tx: TransactionDTO }) {
159
- * const { metadata, isLoading, imageUrl } = useTransactionMetadata(tx);
160
- *
161
- * if (isLoading) return <ActivityIndicator />;
162
- *
163
- * return (
164
- * <View>
165
- * {imageUrl && <Image source={{ uri: imageUrl }} style={{ width: 60, height: 60 }} />}
166
- * <Text>{metadata?.name || tx.type}</Text>
167
- * <Text>{tx.amount} tokens</Text>
168
- * </View>
169
- * );
170
- * }
171
- * ```
172
- */
173
- export function useTransactionMetadata(transaction: { metadataUri?: string | null } | null | undefined) {
174
- const { metadata, isLoading, error, refresh } = useMetadata(transaction?.metadataUri);
175
-
176
- return {
177
- /** Parsed metadata with resolved URLs */
178
- metadata,
179
- /** Whether metadata is loading */
180
- isLoading,
181
- /** Error message if fetch failed */
182
- error,
183
- /** Convenience: resolved image URL (or undefined) */
184
- imageUrl: metadata?.imageUrl,
185
- /** Convenience: token/NFT name (or undefined) */
186
- name: metadata?.name,
187
- /** Convenience: token/NFT description (or undefined) */
188
- description: metadata?.description,
189
- /** Manually refresh metadata */
190
- refresh,
191
- };
192
- }
1
+ import { useState, useEffect, useCallback } from 'react';
2
+ import { usePersSDK } from '../providers/PersSDKProvider';
3
+ import type { TokenMetadata } from '@explorins/pers-sdk';
4
+
5
+ /**
6
+ * React hook for resolving media URLs (IPFS or HTTPS).
7
+ *
8
+ * Automatically handles IPFS URLs by resolving them to HTTPS via tenant's gateway.
9
+ * Non-IPFS URLs are returned as-is. Handles loading and error states.
10
+ *
11
+ * Uses sdk.ipfs for IPFS resolution (lightweight, no Web3 deps).
12
+ *
13
+ * @param url - The URL to resolve (can be ipfs://, https://, or undefined)
14
+ * @returns Object with resolved URL, loading state, and error
15
+ *
16
+ * @example
17
+ * ```tsx
18
+ * function NFTImage({ metadataUri }: { metadataUri?: string }) {
19
+ * const { url, isLoading } = useResolvedUrl(metadataUri);
20
+ *
21
+ * if (isLoading) return <ActivityIndicator />;
22
+ * return <Image source={{ uri: url }} />;
23
+ * }
24
+ * ```
25
+ */
26
+ export function useResolvedUrl(url: string | undefined | null) {
27
+ const { sdk, isInitialized } = usePersSDK();
28
+ const [resolvedUrl, setResolvedUrl] = useState<string | null>(null);
29
+ const [isLoading, setIsLoading] = useState(false);
30
+ const [error, setError] = useState<string | null>(null);
31
+
32
+ useEffect(() => {
33
+ if (!url || !isInitialized || !sdk) {
34
+ setResolvedUrl(null);
35
+ return;
36
+ }
37
+
38
+ // Non-IPFS URLs don't need resolution
39
+ if (!url.startsWith('ipfs://')) {
40
+ setResolvedUrl(url);
41
+ return;
42
+ }
43
+
44
+ setIsLoading(true);
45
+ setError(null);
46
+
47
+ sdk.ipfs.resolveUrl(url)
48
+ .then((resolved) => {
49
+ setResolvedUrl(resolved);
50
+ })
51
+ .catch((err) => {
52
+ setError(err instanceof Error ? err.message : 'Failed to resolve URL');
53
+ setResolvedUrl(null);
54
+ })
55
+ .finally(() => {
56
+ setIsLoading(false);
57
+ });
58
+ }, [url, isInitialized, sdk]);
59
+
60
+ return {
61
+ /** Resolved HTTPS URL (or original if not IPFS) */
62
+ url: resolvedUrl,
63
+ /** Whether resolution is in progress */
64
+ isLoading,
65
+ /** Error message if resolution failed */
66
+ error,
67
+ };
68
+ }
69
+
70
+ /**
71
+ * React hook for fetching NFT/token metadata from a URI.
72
+ *
73
+ * Handles IPFS resolution automatically and returns parsed metadata
74
+ * with all nested IPFS URLs already resolved to HTTPS.
75
+ *
76
+ * Uses sdk.ipfs for metadata fetching (lightweight, no Web3 deps).
77
+ *
78
+ * @param metadataUri - The metadata URI to fetch (can be ipfs:// or https://)
79
+ * @returns Object with metadata, loading state, error, and refresh function
80
+ *
81
+ * @example
82
+ * ```tsx
83
+ * function NFTDetails({ metadataUri }: { metadataUri?: string }) {
84
+ * const { metadata, isLoading, error } = useMetadata(metadataUri);
85
+ *
86
+ * if (isLoading) return <ActivityIndicator />;
87
+ * if (error) return <Text>Error: {error}</Text>;
88
+ * if (!metadata) return null;
89
+ *
90
+ * return (
91
+ * <View>
92
+ * <Image source={{ uri: metadata.imageUrl }} />
93
+ * <Text>{metadata.name}</Text>
94
+ * <Text>{metadata.description}</Text>
95
+ * </View>
96
+ * );
97
+ * }
98
+ * ```
99
+ */
100
+ export function useMetadata(metadataUri: string | undefined | null) {
101
+ const { sdk, isInitialized, locale } = usePersSDK();
102
+ const [metadata, setMetadata] = useState<TokenMetadata | null>(null);
103
+ const [isLoading, setIsLoading] = useState(false);
104
+ const [error, setError] = useState<string | null>(null);
105
+
106
+ const fetchMetadata = useCallback(async () => {
107
+ if (!metadataUri || !isInitialized || !sdk) {
108
+ setMetadata(null);
109
+ return;
110
+ }
111
+
112
+ setIsLoading(true);
113
+ setError(null);
114
+
115
+ try {
116
+ const result = await sdk.ipfs.fetchMetadata(metadataUri);
117
+ setMetadata(result);
118
+ } catch (err) {
119
+ setError(err instanceof Error ? err.message : 'Failed to fetch metadata');
120
+ setMetadata(null);
121
+ } finally {
122
+ setIsLoading(false);
123
+ }
124
+ }, [metadataUri, isInitialized, sdk, locale]);
125
+
126
+ useEffect(() => {
127
+ fetchMetadata();
128
+ }, [fetchMetadata]);
129
+
130
+ return {
131
+ /** Parsed metadata with resolved IPFS URLs (imageUrl, animationUrl, etc.), localized for the current locale */
132
+ metadata,
133
+ /** Whether fetch is in progress */
134
+ isLoading,
135
+ /** Error message if fetch failed */
136
+ error,
137
+ /** Manually refresh metadata */
138
+ refresh: fetchMetadata,
139
+ };
140
+ }
141
+
142
+ // Re-export with descriptive aliases
143
+ export { useResolvedUrl as useIPFSUrl };
144
+
145
+ /**
146
+ * React hook for loading transaction/token metadata.
147
+ *
148
+ * Convenience wrapper around useMetadata specifically for transaction items.
149
+ * Pass a transaction's metadataUri to get the NFT image, name, description, etc.
150
+ *
151
+ * @param transaction - Transaction object with optional metadataUri field
152
+ * @returns Object with metadata, loading state, and image URL
153
+ *
154
+ * @example
155
+ * ```tsx
156
+ * import { useTransactionMetadata } from '@explorins/pers-sdk-react-native';
157
+ *
158
+ * function TransactionItem({ tx }: { tx: TransactionDTO }) {
159
+ * const { metadata, isLoading, imageUrl } = useTransactionMetadata(tx);
160
+ *
161
+ * if (isLoading) return <ActivityIndicator />;
162
+ *
163
+ * return (
164
+ * <View>
165
+ * {imageUrl && <Image source={{ uri: imageUrl }} style={{ width: 60, height: 60 }} />}
166
+ * <Text>{metadata?.name || tx.type}</Text>
167
+ * <Text>{tx.amount} tokens</Text>
168
+ * </View>
169
+ * );
170
+ * }
171
+ * ```
172
+ */
173
+ export function useTransactionMetadata(transaction: { metadataUri?: string | null } | null | undefined) {
174
+ const { metadata, isLoading, error, refresh } = useMetadata(transaction?.metadataUri);
175
+
176
+ return {
177
+ /** Parsed metadata with resolved URLs */
178
+ metadata,
179
+ /** Whether metadata is loading */
180
+ isLoading,
181
+ /** Error message if fetch failed */
182
+ error,
183
+ /** Convenience: resolved image URL (or undefined) */
184
+ imageUrl: metadata?.imageUrl,
185
+ /** Convenience: token/NFT name (or undefined) */
186
+ name: metadata?.name,
187
+ /** Convenience: token/NFT description (or undefined) */
188
+ description: metadata?.description,
189
+ /** Manually refresh metadata */
190
+ refresh,
191
+ };
192
+ }
@@ -1,66 +1,66 @@
1
- import { useCallback } from 'react';
2
- import { usePersSDK } from '../providers/PersSDKProvider';
3
- import type { PurchaseTokenDTO, PurchaseDTO, PaginatedResponseDTO } from '@explorins/pers-sdk';
4
-
5
- export const usePurchases = () => {
6
- const { sdk, isInitialized, isAuthenticated } = usePersSDK();
7
-
8
- const createPaymentIntent = useCallback(async (
9
- amount: number,
10
- currency: string,
11
- receiptEmail: string,
12
- description: string
13
- ) => {
14
- if (!isInitialized || !sdk) {
15
- throw new Error('SDK not initialized. Call initialize() first.');
16
- }
17
-
18
- try {
19
- const result = await sdk.purchases.createPaymentIntent(amount, currency, receiptEmail, description);
20
- return result;
21
- } catch (error) {
22
- console.error('Failed to create payment intent:', error);
23
- throw error;
24
- }
25
- }, [sdk, isInitialized]);
26
-
27
- const getActivePurchaseTokens = useCallback(async (): Promise<PaginatedResponseDTO<PurchaseTokenDTO>> => {
28
- if (!isInitialized || !sdk) {
29
- throw new Error('SDK not initialized. Call initialize() first.');
30
- }
31
-
32
- try {
33
- const result = await sdk.purchases.getActivePurchaseTokens();
34
- return result;
35
- } catch (error) {
36
- console.error('Failed to fetch active purchase tokens:', error);
37
- throw error;
38
- }
39
- }, [sdk, isInitialized]);
40
-
41
- const getAllUserPurchases = useCallback(async (): Promise<PaginatedResponseDTO<PurchaseDTO>> => {
42
- if (!isInitialized || !sdk) {
43
- throw new Error('SDK not initialized. Call initialize() first.');
44
- }
45
- if (!isAuthenticated) {
46
- throw new Error('SDK not authenticated. getAllUserPurchases requires authentication.');
47
- }
48
-
49
- try {
50
- const result = await sdk.purchases.getAllUserPurchases();
51
- return result;
52
- } catch (error) {
53
- console.error('Failed to fetch user purchases:', error);
54
- throw error;
55
- }
56
- }, [sdk, isInitialized, isAuthenticated]);
57
-
58
- return {
59
- createPaymentIntent,
60
- getActivePurchaseTokens,
61
- getAllUserPurchases,
62
- isAvailable: isInitialized && !!sdk?.purchases,
63
- };
64
- };
65
-
1
+ import { useCallback } from 'react';
2
+ import { usePersSDK } from '../providers/PersSDKProvider';
3
+ import type { PurchaseTokenDTO, PurchaseDTO, PaginatedResponseDTO } from '@explorins/pers-sdk';
4
+
5
+ export const usePurchases = () => {
6
+ const { sdk, isInitialized, isAuthenticated } = usePersSDK();
7
+
8
+ const createPaymentIntent = useCallback(async (
9
+ amount: number,
10
+ currency: string,
11
+ receiptEmail: string,
12
+ description: string
13
+ ) => {
14
+ if (!isInitialized || !sdk) {
15
+ throw new Error('SDK not initialized. Call initialize() first.');
16
+ }
17
+
18
+ try {
19
+ const result = await sdk.purchases.createPaymentIntent(amount, currency, receiptEmail, description);
20
+ return result;
21
+ } catch (error) {
22
+ console.error('Failed to create payment intent:', error);
23
+ throw error;
24
+ }
25
+ }, [sdk, isInitialized]);
26
+
27
+ const getActivePurchaseTokens = useCallback(async (): Promise<PaginatedResponseDTO<PurchaseTokenDTO>> => {
28
+ if (!isInitialized || !sdk) {
29
+ throw new Error('SDK not initialized. Call initialize() first.');
30
+ }
31
+
32
+ try {
33
+ const result = await sdk.purchases.getActivePurchaseTokens();
34
+ return result;
35
+ } catch (error) {
36
+ console.error('Failed to fetch active purchase tokens:', error);
37
+ throw error;
38
+ }
39
+ }, [sdk, isInitialized]);
40
+
41
+ const getAllUserPurchases = useCallback(async (): Promise<PaginatedResponseDTO<PurchaseDTO>> => {
42
+ if (!isInitialized || !sdk) {
43
+ throw new Error('SDK not initialized. Call initialize() first.');
44
+ }
45
+ if (!isAuthenticated) {
46
+ throw new Error('SDK not authenticated. getAllUserPurchases requires authentication.');
47
+ }
48
+
49
+ try {
50
+ const result = await sdk.purchases.getAllUserPurchases();
51
+ return result;
52
+ } catch (error) {
53
+ console.error('Failed to fetch user purchases:', error);
54
+ throw error;
55
+ }
56
+ }, [sdk, isInitialized, isAuthenticated]);
57
+
58
+ return {
59
+ createPaymentIntent,
60
+ getActivePurchaseTokens,
61
+ getAllUserPurchases,
62
+ isAvailable: isInitialized && !!sdk?.purchases,
63
+ };
64
+ };
65
+
66
66
  export type PurchaseHook = ReturnType<typeof usePurchases>;