@explorins/pers-sdk-react-native 1.3.2 → 1.5.1
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/README.md +276 -123
- package/dist/hooks/index.d.ts +8 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +7 -0
- package/dist/hooks/useAnalytics.d.ts +96 -0
- package/dist/hooks/useAnalytics.d.ts.map +1 -0
- package/dist/hooks/useAnalytics.js +73 -0
- package/dist/hooks/useAuth.d.ts +52 -7
- package/dist/hooks/useAuth.d.ts.map +1 -1
- package/dist/hooks/useAuth.js +250 -3
- package/dist/hooks/useBusiness.d.ts +45 -3
- package/dist/hooks/useBusiness.d.ts.map +1 -1
- package/dist/hooks/useBusiness.js +182 -28
- package/dist/hooks/useCampaigns.d.ts +11 -4
- package/dist/hooks/useCampaigns.d.ts.map +1 -1
- package/dist/hooks/useCampaigns.js +101 -39
- package/dist/hooks/useDonations.d.ts +33 -0
- package/dist/hooks/useDonations.d.ts.map +1 -0
- package/dist/hooks/useDonations.js +62 -0
- package/dist/hooks/useFiles.d.ts +50 -0
- package/dist/hooks/useFiles.d.ts.map +1 -0
- package/dist/hooks/useFiles.js +140 -0
- package/dist/hooks/usePurchases.d.ts +9 -0
- package/dist/hooks/usePurchases.d.ts.map +1 -0
- package/dist/hooks/usePurchases.js +56 -0
- package/dist/hooks/useRedemptions.d.ts +10 -5
- package/dist/hooks/useRedemptions.d.ts.map +1 -1
- package/dist/hooks/useRedemptions.js +94 -66
- package/dist/hooks/useTenants.d.ts +10 -0
- package/dist/hooks/useTenants.d.ts.map +1 -0
- package/dist/hooks/useTenants.js +68 -0
- package/dist/hooks/useTokens.d.ts +36 -2
- package/dist/hooks/useTokens.d.ts.map +1 -1
- package/dist/hooks/useTokens.js +180 -19
- package/dist/hooks/useTransactions.d.ts +45 -3
- package/dist/hooks/useTransactions.d.ts.map +1 -1
- package/dist/hooks/useTransactions.js +152 -31
- package/dist/hooks/useUserStatus.d.ts +9 -0
- package/dist/hooks/useUserStatus.d.ts.map +1 -0
- package/dist/hooks/useUserStatus.js +57 -0
- package/dist/hooks/useUsers.d.ts +17 -0
- package/dist/hooks/useUsers.d.ts.map +1 -0
- package/dist/hooks/useUsers.js +120 -0
- package/dist/hooks/useWeb3.d.ts +69 -6
- package/dist/hooks/useWeb3.d.ts.map +1 -1
- package/dist/hooks/useWeb3.js +177 -17
- package/dist/index.d.ts +6 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12199 -796
- package/dist/index.js.map +1 -1
- package/dist/polyfills/index.d.ts +1 -1
- package/dist/polyfills/index.d.ts.map +1 -1
- package/dist/polyfills/index.js +155 -9
- package/dist/polyfills/web3-polyfills.d.ts +7 -0
- package/dist/polyfills/web3-polyfills.d.ts.map +1 -0
- package/dist/polyfills/web3-polyfills.js +85 -0
- package/dist/providers/PersSDKProvider.d.ts +28 -18
- package/dist/providers/PersSDKProvider.d.ts.map +1 -1
- package/dist/providers/PersSDKProvider.js +63 -129
- package/dist/providers/react-native-auth-provider.d.ts +19 -64
- package/dist/providers/react-native-auth-provider.d.ts.map +1 -1
- package/dist/providers/react-native-auth-provider.js +57 -175
- package/package.json +171 -157
- package/src/hooks/index.ts +11 -1
- package/src/hooks/useAnalytics.ts +150 -0
- package/src/hooks/useAuth.ts +286 -27
- package/src/hooks/useBusiness.ts +193 -30
- package/src/hooks/useCampaigns.ts +121 -43
- package/src/hooks/useDonations.ts +68 -0
- package/src/hooks/useFiles.ts +160 -0
- package/src/hooks/usePurchases.ts +69 -0
- package/src/hooks/useRedemptions.ts +109 -68
- package/src/hooks/useTenants.ts +77 -0
- package/src/hooks/useTokens.ts +189 -21
- package/src/hooks/useTransactions.ts +170 -34
- package/src/hooks/useUserStatus.ts +65 -0
- package/src/hooks/useUsers.ts +133 -0
- package/src/hooks/useWeb3.ts +201 -21
- package/src/index.ts +21 -17
- package/src/polyfills/index.ts +163 -10
- package/src/polyfills/web3-polyfills.ts +98 -0
- package/src/providers/PersSDKProvider.tsx +114 -178
- package/src/providers/react-native-auth-provider.ts +65 -208
- package/dist/index.esm.js +0 -1057
- package/dist/index.esm.js.map +0 -1
- package/dist/polyfills/index.simple.d.ts +0 -2
- package/dist/polyfills/index.simple.d.ts.map +0 -1
- package/dist/polyfills/index.simple.js +0 -17
- package/src/polyfills/index.simple.ts +0 -22
- package/src/types/external-modules.d.ts +0 -13
|
@@ -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
|
+
};
|
package/dist/hooks/useWeb3.d.ts
CHANGED
|
@@ -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:
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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":"
|
|
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"}
|
package/dist/hooks/useWeb3.js
CHANGED
|
@@ -1,45 +1,200 @@
|
|
|
1
1
|
import { useCallback } from 'react';
|
|
2
2
|
import { usePersSDK } from '../providers/PersSDKProvider';
|
|
3
|
+
/**
|
|
4
|
+
* React hook for Web3 operations in the PERS SDK
|
|
5
|
+
*
|
|
6
|
+
* Provides comprehensive Web3 functionality including token balance queries,
|
|
7
|
+
* metadata retrieval, collection management, IPFS resolution, and blockchain
|
|
8
|
+
* explorer integration. Supports multi-chain operations and wallet management.
|
|
9
|
+
*
|
|
10
|
+
* @returns Web3 hook with methods for blockchain operations
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* function Web3Component() {
|
|
15
|
+
* const {
|
|
16
|
+
* getTokenBalance,
|
|
17
|
+
* getTokenMetadata,
|
|
18
|
+
* getWalletInfo,
|
|
19
|
+
* accountAddress
|
|
20
|
+
* } = useWeb3();
|
|
21
|
+
*
|
|
22
|
+
* const loadTokenData = async () => {
|
|
23
|
+
* try {
|
|
24
|
+
* if (!accountAddress) {
|
|
25
|
+
* console.log('No wallet connected');
|
|
26
|
+
* return;
|
|
27
|
+
* }
|
|
28
|
+
*
|
|
29
|
+
* const balance = await getTokenBalance({
|
|
30
|
+
* walletAddress: accountAddress,
|
|
31
|
+
* contractAddress: '0x123...',
|
|
32
|
+
* chainId: 1
|
|
33
|
+
* });
|
|
34
|
+
*
|
|
35
|
+
* console.log('Token balance:', balance);
|
|
36
|
+
* } catch (error) {
|
|
37
|
+
* console.error('Failed to load token data:', error);
|
|
38
|
+
* }
|
|
39
|
+
* };
|
|
40
|
+
*
|
|
41
|
+
* return (
|
|
42
|
+
* <div>
|
|
43
|
+
* {accountAddress ? (
|
|
44
|
+
* <div>
|
|
45
|
+
* <p>Wallet: {accountAddress}</p>
|
|
46
|
+
* <button onClick={loadTokenData}>Load Tokens</button>
|
|
47
|
+
* </div>
|
|
48
|
+
* ) : (
|
|
49
|
+
* <p>No wallet connected</p>
|
|
50
|
+
* )}
|
|
51
|
+
* </div>
|
|
52
|
+
* );
|
|
53
|
+
* }
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
3
56
|
export const useWeb3 = () => {
|
|
4
|
-
const {
|
|
57
|
+
const { sdk, isInitialized, isAuthenticated, accountAddress } = usePersSDK();
|
|
5
58
|
if (!isAuthenticated && isInitialized) {
|
|
6
59
|
console.warn('SDK not authenticated. Some web3 operations may fail.');
|
|
7
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Retrieves token balance for a specific wallet and contract
|
|
63
|
+
*
|
|
64
|
+
* @param request - Token balance request containing wallet address, contract, and chain info
|
|
65
|
+
* @returns Promise resolving to token balance data
|
|
66
|
+
* @throws Error if SDK is not initialized
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* const { getTokenBalance } = useWeb3();
|
|
71
|
+
* const balance = await getTokenBalance({
|
|
72
|
+
* walletAddress: '0x123...',
|
|
73
|
+
* contractAddress: '0x456...',
|
|
74
|
+
* chainId: 1,
|
|
75
|
+
* tokenId: '1' // For NFTs
|
|
76
|
+
* });
|
|
77
|
+
* console.log('Balance:', balance.balance);
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
8
80
|
const getTokenBalance = useCallback(async (request) => {
|
|
9
|
-
|
|
81
|
+
console.log('[useWeb3] getTokenBalance called with request:', request);
|
|
82
|
+
if (!isInitialized || !sdk) {
|
|
10
83
|
throw new Error('SDK not initialized. Call initialize() first.');
|
|
11
84
|
}
|
|
12
|
-
|
|
13
|
-
|
|
85
|
+
try {
|
|
86
|
+
const result = await sdk.web3.getTokenBalance(request);
|
|
87
|
+
console.log('Token balance fetched successfully:', result);
|
|
88
|
+
return result;
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
console.error('Failed to fetch token balance:', error);
|
|
92
|
+
throw error;
|
|
93
|
+
}
|
|
94
|
+
}, [sdk, isInitialized]);
|
|
95
|
+
/**
|
|
96
|
+
* Retrieves metadata for a specific token (useful for NFTs)
|
|
97
|
+
*
|
|
98
|
+
* @param request - Token balance request containing contract and token info
|
|
99
|
+
* @returns Promise resolving to token metadata or null if not available
|
|
100
|
+
* @throws Error if SDK is not initialized
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```typescript
|
|
104
|
+
* const { getTokenMetadata } = useWeb3();
|
|
105
|
+
* const metadata = await getTokenMetadata({
|
|
106
|
+
* contractAddress: '0x123...',
|
|
107
|
+
* tokenId: '1',
|
|
108
|
+
* chainId: 1
|
|
109
|
+
* });
|
|
110
|
+
* console.log('NFT name:', metadata?.name);
|
|
111
|
+
* console.log('NFT image:', metadata?.image);
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
const getTokenMetadata = useCallback(async (request) => {
|
|
115
|
+
if (!isInitialized || !sdk) {
|
|
116
|
+
throw new Error('SDK not initialized. Call initialize() first.');
|
|
14
117
|
}
|
|
15
118
|
try {
|
|
16
|
-
const result = await web3.
|
|
17
|
-
console.log('
|
|
119
|
+
const result = await sdk.web3.getTokenMetadata(request);
|
|
120
|
+
console.log('Token metadata fetched successfully:', result);
|
|
18
121
|
return result;
|
|
19
122
|
}
|
|
20
123
|
catch (error) {
|
|
21
|
-
console.error('
|
|
124
|
+
console.error('Failed to fetch token metadata:', error);
|
|
22
125
|
throw error;
|
|
23
126
|
}
|
|
24
|
-
}, [
|
|
127
|
+
}, [sdk, isInitialized]);
|
|
25
128
|
const getTokenCollection = useCallback(async (request) => {
|
|
26
|
-
if (!isInitialized) {
|
|
129
|
+
if (!isInitialized || !sdk) {
|
|
130
|
+
throw new Error('SDK not initialized. Call initialize() first.');
|
|
131
|
+
}
|
|
132
|
+
try {
|
|
133
|
+
const result = await sdk.web3.getTokenCollection(request);
|
|
134
|
+
console.log('Token collection fetched successfully:', result);
|
|
135
|
+
return result;
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
console.error('Failed to fetch token collection:', error);
|
|
139
|
+
throw error;
|
|
140
|
+
}
|
|
141
|
+
}, [sdk, isInitialized]);
|
|
142
|
+
const resolveIPFSUrl = useCallback(async (url, chainId) => {
|
|
143
|
+
if (!isInitialized || !sdk) {
|
|
144
|
+
throw new Error('SDK not initialized. Call initialize() first.');
|
|
145
|
+
}
|
|
146
|
+
try {
|
|
147
|
+
const result = await sdk.web3.resolveIPFSUrl(url, chainId);
|
|
148
|
+
console.log('IPFS URL resolved successfully:', result);
|
|
149
|
+
return result;
|
|
150
|
+
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
console.error('Failed to resolve IPFS URL:', error);
|
|
153
|
+
throw error;
|
|
154
|
+
}
|
|
155
|
+
}, [sdk, isInitialized]);
|
|
156
|
+
const fetchAndProcessMetadata = useCallback(async (tokenUri, chainId) => {
|
|
157
|
+
if (!isInitialized || !sdk) {
|
|
158
|
+
throw new Error('SDK not initialized. Call initialize() first.');
|
|
159
|
+
}
|
|
160
|
+
try {
|
|
161
|
+
const result = await sdk.web3.fetchAndProcessMetadata(tokenUri, chainId);
|
|
162
|
+
console.log('Metadata fetched and processed successfully:', result);
|
|
163
|
+
return result;
|
|
164
|
+
}
|
|
165
|
+
catch (error) {
|
|
166
|
+
console.error('Failed to fetch and process metadata:', error);
|
|
167
|
+
throw error;
|
|
168
|
+
}
|
|
169
|
+
}, [sdk, isInitialized]);
|
|
170
|
+
const getChainDataById = useCallback(async (chainId) => {
|
|
171
|
+
if (!isInitialized || !sdk) {
|
|
27
172
|
throw new Error('SDK not initialized. Call initialize() first.');
|
|
28
173
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
174
|
+
try {
|
|
175
|
+
const result = await sdk.web3.getChainDataById(chainId);
|
|
176
|
+
console.log('Chain data fetched successfully:', result);
|
|
177
|
+
return result;
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
console.error('Failed to fetch chain data:', error);
|
|
181
|
+
throw error;
|
|
182
|
+
}
|
|
183
|
+
}, [sdk, isInitialized]);
|
|
184
|
+
const getExplorerUrl = useCallback(async (chainId, address, type) => {
|
|
185
|
+
if (!isInitialized || !sdk) {
|
|
186
|
+
throw new Error('SDK not initialized. Call initialize() first.');
|
|
32
187
|
}
|
|
33
188
|
try {
|
|
34
|
-
const result = await web3.
|
|
35
|
-
console.log('
|
|
189
|
+
const result = await sdk.web3.getExplorerUrl(chainId, address, type);
|
|
190
|
+
console.log('Explorer URL generated successfully:', result);
|
|
36
191
|
return result;
|
|
37
192
|
}
|
|
38
193
|
catch (error) {
|
|
39
|
-
console.error('
|
|
194
|
+
console.error('Failed to generate explorer URL:', error);
|
|
40
195
|
throw error;
|
|
41
196
|
}
|
|
42
|
-
}, [
|
|
197
|
+
}, [sdk, isInitialized]);
|
|
43
198
|
const getWalletInfo = useCallback(async () => {
|
|
44
199
|
if (!isInitialized) {
|
|
45
200
|
throw new Error('SDK not initialized. Call initialize() first.');
|
|
@@ -55,9 +210,14 @@ export const useWeb3 = () => {
|
|
|
55
210
|
}, [isInitialized, accountAddress]);
|
|
56
211
|
return {
|
|
57
212
|
getTokenBalance,
|
|
213
|
+
getTokenMetadata,
|
|
58
214
|
getTokenCollection,
|
|
215
|
+
resolveIPFSUrl,
|
|
216
|
+
fetchAndProcessMetadata,
|
|
217
|
+
getChainDataById,
|
|
218
|
+
getExplorerUrl,
|
|
59
219
|
getWalletInfo,
|
|
60
220
|
accountAddress: isInitialized ? accountAddress : null,
|
|
61
|
-
isAvailable: isInitialized && !!web3,
|
|
221
|
+
isAvailable: isInitialized && !!sdk?.web3,
|
|
62
222
|
};
|
|
63
223
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import './polyfills';
|
|
2
|
-
export {
|
|
3
|
-
export { PersSDKProvider, usePersSDK, type
|
|
4
|
-
export { useAuth, useTokens, useTransactions, useBusiness, useCampaigns, useRedemptions, useWeb3 } from './hooks';
|
|
2
|
+
export { ReactNativeAuthProvider, type ReactNativeAuthConfig } from './providers/react-native-auth-provider';
|
|
3
|
+
export { PersSDKProvider, usePersSDK, type PersConfig, type PersSDKContext } from './providers/PersSDKProvider';
|
|
4
|
+
export { useAuth, useTokens, useTransactions, useBusiness, useCampaigns, useRedemptions, useWeb3, usePurchases, useTenants, useUsers, useUserStatus, useFiles, useAnalytics, useDonations } from './hooks';
|
|
5
5
|
export { ReactNativeHttpClient } from './providers/react-native-http-client';
|
|
6
|
-
export { initializeReactNativePolyfills
|
|
6
|
+
export { initializeReactNativePolyfills } from './polyfills';
|
|
7
|
+
export * from '@explorins/pers-shared';
|
|
8
|
+
export type { TokenBalanceRequest, TokenBalance, TokenMetadata, TokenCollection, TokenCollectionRequest } from '@explorins/pers-sdk/web3';
|
|
7
9
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,aAAa,CAAC;AAGrB,OAAO,EACL,uBAAuB,EACvB,KAAK,qBAAqB,EAC3B,MAAM,wCAAwC,CAAC;AAGhD,OAAO,EACL,eAAe,EACf,UAAU,EACV,KAAK,UAAU,EACf,KAAK,cAAc,EACpB,MAAM,6BAA6B,CAAC;AAGrC,OAAO,EACL,OAAO,EACP,SAAS,EACT,eAAe,EACf,WAAW,EACX,YAAY,EACZ,cAAc,EACd,OAAO,EACP,YAAY,EACZ,UAAU,EACV,QAAQ,EACR,aAAa,EACb,QAAQ,EACR,YAAY,EACZ,YAAY,EACb,MAAM,SAAS,CAAC;AAEjB,OAAO,EACL,qBAAqB,EACtB,MAAM,sCAAsC,CAAC;AAG9C,OAAO,EACL,8BAA8B,EAC/B,MAAM,aAAa,CAAC;AAGrB,cAAc,wBAAwB,CAAC;AAGvC,YAAY,EACV,mBAAmB,EACnB,YAAY,EACZ,aAAa,EACb,eAAe,EACf,sBAAsB,EACvB,MAAM,0BAA0B,CAAC"}
|