@explorins/pers-sdk-react-native 2.1.6 → 2.1.7
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/dist/index.js +22 -40
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -38805,7 +38805,12 @@ class Web3ChainService {
|
|
|
38805
38805
|
|
|
38806
38806
|
// type ContractAnalysis = ReturnType<ContractDomainService['analyzeContract']>;
|
|
38807
38807
|
/**
|
|
38808
|
-
* TokenDomainService - Clean, focused token operations
|
|
38808
|
+
* TokenDomainService - Clean, focused token operations
|
|
38809
|
+
*
|
|
38810
|
+
* Caching strategy:
|
|
38811
|
+
* - Balance/ownership: NO CACHING - always fetch fresh from blockchain
|
|
38812
|
+
* (event-based updates in consuming apps handle refresh)
|
|
38813
|
+
* - Metadata: CACHED 24h - IPFS content is immutable
|
|
38809
38814
|
*/
|
|
38810
38815
|
class TokenDomainService {
|
|
38811
38816
|
constructor(web3Api, metadataService, contractService) {
|
|
@@ -38875,12 +38880,20 @@ class TokenDomainService {
|
|
|
38875
38880
|
}
|
|
38876
38881
|
return this.processTokenBatch(params, params.tokenIds, batchSize, 'ERC-1155');
|
|
38877
38882
|
}
|
|
38878
|
-
// ERC-721:
|
|
38883
|
+
// ERC-721: Enumerate tokens directly (no caching)
|
|
38879
38884
|
if (analysis.isERC721) {
|
|
38880
38885
|
if (analysis.hasEnumeration) {
|
|
38881
|
-
|
|
38886
|
+
// Get current balance to know how many tokens to enumerate
|
|
38887
|
+
const currentBalance = await this.web3Api.getTokenBalance({
|
|
38888
|
+
...params, abi, tokenId: null
|
|
38889
|
+
});
|
|
38890
|
+
if (currentBalance === 0) {
|
|
38891
|
+
return this.emptyCollection(params, 'No tokens owned');
|
|
38892
|
+
}
|
|
38893
|
+
const maxTokens = Math.min(params.maxTokens || currentBalance, currentBalance, 100);
|
|
38894
|
+
const tokenIds = await this.getTokenIdsByEnumeration(params, abi, maxTokens);
|
|
38882
38895
|
if (tokenIds.length === 0) {
|
|
38883
|
-
return this.emptyCollection(params,
|
|
38896
|
+
return this.emptyCollection(params, 'No tokens owned');
|
|
38884
38897
|
}
|
|
38885
38898
|
return this.processTokenBatch(params, tokenIds, batchSize, 'ERC-721');
|
|
38886
38899
|
}
|
|
@@ -38900,44 +38913,13 @@ class TokenDomainService {
|
|
|
38900
38913
|
}
|
|
38901
38914
|
}
|
|
38902
38915
|
/**
|
|
38903
|
-
*
|
|
38916
|
+
* Enumerate token IDs owned by account (no caching - fresh data each call)
|
|
38904
38917
|
*/
|
|
38905
|
-
async getCachedTokenOwnership(params, abi) {
|
|
38906
|
-
const ownershipCacheKey = `ownership:${params.contractAddress}:${params.accountAddress}:${params.chainId}`;
|
|
38907
|
-
// ALWAYS check current balance first to detect changes
|
|
38908
|
-
const currentBalance = await this.web3Api.getTokenBalance({
|
|
38909
|
-
...params, abi, tokenId: null
|
|
38910
|
-
});
|
|
38911
|
-
if (currentBalance === 0) {
|
|
38912
|
-
// Clear any existing cache and return empty
|
|
38913
|
-
this.cache.delete(ownershipCacheKey);
|
|
38914
|
-
return { tokenIds: [], fromCache: false };
|
|
38915
|
-
}
|
|
38916
|
-
// Check ownership cache with balance validation
|
|
38917
|
-
const cached = this.cache.get(ownershipCacheKey);
|
|
38918
|
-
const cacheAge = cached ? Date.now() - cached.timestamp : Infinity;
|
|
38919
|
-
if (cached && cacheAge < CacheTTL.SHORT && cached.balance === currentBalance) {
|
|
38920
|
-
return { tokenIds: cached.tokenIds, fromCache: true };
|
|
38921
|
-
}
|
|
38922
|
-
// Enumerate tokens
|
|
38923
|
-
const maxTokens = Math.min(params.maxTokens || currentBalance, currentBalance, 100);
|
|
38924
|
-
const tokenIds = await this.getTokenIdsByEnumeration(params, abi, maxTokens);
|
|
38925
|
-
// Cache with current balance for validation
|
|
38926
|
-
this.cache.set(ownershipCacheKey, { tokenIds, balance: currentBalance, timestamp: Date.now() }, CacheTTL.SHORT);
|
|
38927
|
-
return { tokenIds, fromCache: false };
|
|
38928
|
-
}
|
|
38929
38918
|
async getTokenIdsByEnumeration(params, abi, maxTokens) {
|
|
38930
|
-
|
|
38931
|
-
|
|
38932
|
-
|
|
38933
|
-
|
|
38934
|
-
...params, abi, tokenIndex: i
|
|
38935
|
-
}).catch(error => {
|
|
38936
|
-
// Silently handle token enumeration errors (index out of bounds is normal)
|
|
38937
|
-
return null;
|
|
38938
|
-
}), CacheTTL.SHORT // 5 minutes - enumeration results rarely change
|
|
38939
|
-
);
|
|
38940
|
-
});
|
|
38919
|
+
const promises = Array.from({ length: maxTokens }, (_, i) => this.web3Api.getTokenOfOwnerByIndex({
|
|
38920
|
+
...params, abi, tokenIndex: i
|
|
38921
|
+
}).catch(() => null) // Silently handle index out of bounds
|
|
38922
|
+
);
|
|
38941
38923
|
const results = await Promise.all(promises);
|
|
38942
38924
|
return results.filter((id) => id !== null);
|
|
38943
38925
|
}
|