@explorins/pers-sdk 1.1.2 → 1.2.0
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/analytics/api/analytics-api.d.ts +17 -0
- package/dist/analytics/api/analytics-api.d.ts.map +1 -0
- package/{src/analytics/index.ts → dist/analytics/index.d.ts} +28 -52
- package/dist/analytics/index.d.ts.map +1 -0
- package/dist/analytics/models/index.d.ts +61 -0
- package/dist/analytics/models/index.d.ts.map +1 -0
- package/dist/analytics/services/analytics-service.d.ts +19 -0
- package/dist/analytics/services/analytics-service.d.ts.map +1 -0
- package/dist/analytics.cjs +76 -0
- package/dist/analytics.cjs.map +1 -0
- package/dist/analytics.js +72 -0
- package/dist/analytics.js.map +1 -0
- package/dist/auth-admin/api/auth-admin-api.d.ts +27 -0
- package/dist/auth-admin/api/auth-admin-api.d.ts.map +1 -0
- package/dist/auth-admin/index.d.ts +26 -0
- package/dist/auth-admin/index.d.ts.map +1 -0
- package/dist/auth-admin/services/auth-admin-service.d.ts +23 -0
- package/dist/auth-admin/services/auth-admin-service.d.ts.map +1 -0
- package/dist/auth-admin.cjs +96 -0
- package/dist/auth-admin.cjs.map +1 -0
- package/dist/auth-admin.js +92 -0
- package/dist/auth-admin.js.map +1 -0
- package/dist/business/api/business-api.d.ts +133 -0
- package/dist/business/api/business-api.d.ts.map +1 -0
- package/dist/business/index.d.ts +34 -0
- package/dist/business/index.d.ts.map +1 -0
- package/dist/business/models/index.d.ts +8 -0
- package/dist/business/models/index.d.ts.map +1 -0
- package/dist/business/services/business-service.d.ts +51 -0
- package/dist/business/services/business-service.d.ts.map +1 -0
- package/dist/business.cjs +303 -0
- package/dist/business.cjs.map +1 -0
- package/dist/business.js +299 -0
- package/dist/business.js.map +1 -0
- package/dist/campaign/api/campaign-api.d.ts +213 -0
- package/dist/campaign/api/campaign-api.d.ts.map +1 -0
- package/dist/campaign/index.d.ts +44 -0
- package/dist/campaign/index.d.ts.map +1 -0
- package/dist/campaign/services/campaign-service.d.ts +88 -0
- package/dist/campaign/services/campaign-service.d.ts.map +1 -0
- package/dist/campaign.cjs +506 -0
- package/dist/campaign.cjs.map +1 -0
- package/dist/campaign.js +502 -0
- package/dist/campaign.js.map +1 -0
- package/dist/core/abstractions/http-client.d.ts +22 -0
- package/dist/core/abstractions/http-client.d.ts.map +1 -0
- package/dist/core/auth/auth-provider.interface.d.ts +12 -0
- package/dist/core/auth/auth-provider.interface.d.ts.map +1 -0
- package/dist/core/auth/create-auth-provider.d.ts +27 -0
- package/dist/core/auth/create-auth-provider.d.ts.map +1 -0
- package/dist/core/auth/simple-auth-config.interface.d.ts +15 -0
- package/dist/core/auth/simple-auth-config.interface.d.ts.map +1 -0
- package/dist/core/index.d.ts +13 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/pers-api-client.d.ts +54 -0
- package/dist/core/pers-api-client.d.ts.map +1 -0
- package/dist/core/pers-config.d.ts +38 -0
- package/dist/core/pers-config.d.ts.map +1 -0
- package/dist/core/utils/jwt.function.d.ts +2 -0
- package/dist/core/utils/jwt.function.d.ts.map +1 -0
- package/dist/core.cjs +506 -0
- package/dist/core.cjs.map +1 -0
- package/dist/core.js +497 -0
- package/dist/core.js.map +1 -0
- package/dist/donation/api/donation-api.d.ts +18 -0
- package/dist/donation/api/donation-api.d.ts.map +1 -0
- package/dist/donation/index.d.ts +25 -0
- package/dist/donation/index.d.ts.map +1 -0
- package/{src/donation/models/index.ts → dist/donation/models/index.d.ts} +8 -11
- package/dist/donation/models/index.d.ts.map +1 -0
- package/dist/donation/services/donation-service.d.ts +19 -0
- package/dist/donation/services/donation-service.d.ts.map +1 -0
- package/dist/donation.cjs +78 -0
- package/dist/donation.cjs.map +1 -0
- package/dist/donation.js +74 -0
- package/dist/donation.js.map +1 -0
- package/dist/index.cjs +4217 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4164 -0
- package/dist/index.js.map +1 -0
- package/dist/package.json +129 -0
- package/dist/payment/api/payment-api.d.ts +105 -0
- package/dist/payment/api/payment-api.d.ts.map +1 -0
- package/dist/payment/index.d.ts +36 -0
- package/dist/payment/index.d.ts.map +1 -0
- package/dist/payment/models/index.d.ts +12 -0
- package/dist/payment/models/index.d.ts.map +1 -0
- package/dist/payment/services/payment-service.d.ts +40 -0
- package/dist/payment/services/payment-service.d.ts.map +1 -0
- package/dist/payment.cjs +258 -0
- package/dist/payment.cjs.map +1 -0
- package/dist/payment.js +254 -0
- package/dist/payment.js.map +1 -0
- package/dist/pers-sdk.d.ts +29 -0
- package/dist/pers-sdk.d.ts.map +1 -0
- package/dist/redemption/api/redemption-api.d.ts +147 -0
- package/dist/redemption/api/redemption-api.d.ts.map +1 -0
- package/dist/redemption/index.d.ts +35 -0
- package/dist/redemption/index.d.ts.map +1 -0
- package/dist/redemption/models/index.d.ts +8 -0
- package/dist/redemption/models/index.d.ts.map +1 -0
- package/dist/redemption/services/redemption-service.d.ts +56 -0
- package/dist/redemption/services/redemption-service.d.ts.map +1 -0
- package/dist/redemption.cjs +333 -0
- package/dist/redemption.cjs.map +1 -0
- package/dist/redemption.js +329 -0
- package/dist/redemption.js.map +1 -0
- package/dist/shared/interfaces/pers-shared-lib.interfaces.d.ts +18 -0
- package/dist/shared/interfaces/pers-shared-lib.interfaces.d.ts.map +1 -0
- package/dist/tenant/api/tenant-api.d.ts +56 -0
- package/dist/tenant/api/tenant-api.d.ts.map +1 -0
- package/dist/tenant/index.d.ts +34 -0
- package/dist/tenant/index.d.ts.map +1 -0
- package/dist/tenant/models/index.d.ts +11 -0
- package/dist/tenant/models/index.d.ts.map +1 -0
- package/dist/tenant/services/tenant-service.d.ts +46 -0
- package/dist/tenant/services/tenant-service.d.ts.map +1 -0
- package/dist/tenant.cjs +177 -0
- package/dist/tenant.cjs.map +1 -0
- package/dist/tenant.js +173 -0
- package/dist/tenant.js.map +1 -0
- package/dist/token/api/token-api.d.ts +64 -0
- package/dist/token/api/token-api.d.ts.map +1 -0
- package/dist/token/base/base-token-service.d.ts +87 -0
- package/dist/token/base/base-token-service.d.ts.map +1 -0
- package/dist/token/index.d.ts +13 -0
- package/dist/token/index.d.ts.map +1 -0
- package/dist/token/models/index.d.ts +18 -0
- package/dist/token/models/index.d.ts.map +1 -0
- package/dist/token/services/token-service.d.ts +68 -0
- package/dist/token/services/token-service.d.ts.map +1 -0
- package/dist/token/token-sdk.d.ts +140 -0
- package/dist/token/token-sdk.d.ts.map +1 -0
- package/dist/token.cjs +537 -0
- package/dist/token.cjs.map +1 -0
- package/dist/token.js +532 -0
- package/dist/token.js.map +1 -0
- package/dist/transaction/api/transaction-api.d.ts +133 -0
- package/dist/transaction/api/transaction-api.d.ts.map +1 -0
- package/dist/transaction/index.d.ts +38 -0
- package/dist/transaction/index.d.ts.map +1 -0
- package/dist/transaction/models/index.d.ts +42 -0
- package/dist/transaction/models/index.d.ts.map +1 -0
- package/dist/transaction/services/transaction-service.d.ts +56 -0
- package/dist/transaction/services/transaction-service.d.ts.map +1 -0
- package/dist/transaction.cjs +394 -0
- package/dist/transaction.cjs.map +1 -0
- package/dist/transaction.js +390 -0
- package/dist/transaction.js.map +1 -0
- package/dist/user/api/user-api.d.ts +56 -0
- package/dist/user/api/user-api.d.ts.map +1 -0
- package/dist/user/index.d.ts +36 -0
- package/dist/user/index.d.ts.map +1 -0
- package/{src/user/models/index.ts → dist/user/models/index.d.ts} +12 -10
- package/dist/user/models/index.d.ts.map +1 -0
- package/dist/user/services/user-service.d.ts +46 -0
- package/dist/user/services/user-service.d.ts.map +1 -0
- package/dist/user-status/api/user-status-api.d.ts +37 -0
- package/dist/user-status/api/user-status-api.d.ts.map +1 -0
- package/dist/user-status/index.d.ts +28 -0
- package/dist/user-status/index.d.ts.map +1 -0
- package/{src/user-status/models/index.ts → dist/user-status/models/index.d.ts} +8 -11
- package/dist/user-status/models/index.d.ts.map +1 -0
- package/dist/user-status/services/user-status-service.d.ts +26 -0
- package/dist/user-status/services/user-status-service.d.ts.map +1 -0
- package/dist/user-status.cjs +147 -0
- package/dist/user-status.cjs.map +1 -0
- package/dist/user-status.js +143 -0
- package/dist/user-status.js.map +1 -0
- package/dist/user.cjs +188 -0
- package/dist/user.cjs.map +1 -0
- package/dist/user.js +184 -0
- package/dist/user.js.map +1 -0
- package/dist/web3/api/web3-api.d.ts +27 -0
- package/dist/web3/api/web3-api.d.ts.map +1 -0
- package/dist/web3/index.d.ts +16 -0
- package/dist/web3/index.d.ts.map +1 -0
- package/dist/web3/models/index.d.ts +92 -0
- package/dist/web3/models/index.d.ts.map +1 -0
- package/dist/web3/services/web3-service.d.ts +21 -0
- package/dist/web3/services/web3-service.d.ts.map +1 -0
- package/dist/web3-chain/api/web3-chain-api.d.ts +19 -0
- package/dist/web3-chain/api/web3-chain-api.d.ts.map +1 -0
- package/dist/web3-chain/index.d.ts +17 -0
- package/dist/web3-chain/index.d.ts.map +1 -0
- package/{src/web3-chain/models/index.ts → dist/web3-chain/models/index.d.ts} +38 -45
- package/dist/web3-chain/models/index.d.ts.map +1 -0
- package/dist/web3-chain/services/getWeb3FCD.service.d.ts +8 -0
- package/dist/web3-chain/services/getWeb3FCD.service.d.ts.map +1 -0
- package/dist/web3-chain/services/provider.service.d.ts +15 -0
- package/dist/web3-chain/services/provider.service.d.ts.map +1 -0
- package/dist/web3-chain/services/public-http-provider.service.d.ts +8 -0
- package/dist/web3-chain/services/public-http-provider.service.d.ts.map +1 -0
- package/dist/web3-chain/services/web3-chain-service.d.ts +17 -0
- package/dist/web3-chain/services/web3-chain-service.d.ts.map +1 -0
- package/dist/web3-chain.cjs +316 -0
- package/dist/web3-chain.cjs.map +1 -0
- package/dist/web3-chain.js +310 -0
- package/dist/web3-chain.js.map +1 -0
- package/dist/web3.cjs +516 -0
- package/dist/web3.cjs.map +1 -0
- package/dist/web3.js +513 -0
- package/dist/web3.js.map +1 -0
- package/package.json +56 -72
- package/config/domains.js +0 -22
- package/explorins-pers-sdk-1.0.0-alpha.1.tgz +0 -0
- package/rollup.config.js +0 -74
- package/scripts/copy-declarations.js +0 -147
- package/src/analytics/api/analytics-api.ts +0 -24
- package/src/analytics/models/index.ts +0 -74
- package/src/analytics/services/analytics-service.ts +0 -28
- package/src/auth-admin/api/auth-admin-api.ts +0 -42
- package/src/auth-admin/index.ts +0 -47
- package/src/auth-admin/services/auth-admin-service.ts +0 -36
- package/src/business/api/business-api.ts +0 -234
- package/src/business/index.ts +0 -53
- package/src/business/models/index.ts +0 -13
- package/src/business/services/business-service.ts +0 -88
- package/src/campaign/api/campaign-api.ts +0 -376
- package/src/campaign/index.ts +0 -67
- package/src/campaign/services/campaign-service.ts +0 -164
- package/src/core/abstractions/http-client.ts +0 -24
- package/src/core/auth/auth-provider.interface.ts +0 -16
- package/src/core/auth/create-auth-provider.ts +0 -136
- package/src/core/auth/simple-auth-config.interface.ts +0 -15
- package/src/core/index.ts +0 -33
- package/src/core/pers-api-client.ts +0 -343
- package/src/core/pers-config.ts +0 -65
- package/src/core/utils/jwt.function.ts +0 -24
- package/src/donation/api/donation-api.ts +0 -24
- package/src/donation/index.ts +0 -47
- package/src/donation/services/donation-service.ts +0 -25
- package/src/index.ts +0 -55
- package/src/payment/api/payment-api.ts +0 -185
- package/src/payment/index.ts +0 -64
- package/src/payment/models/index.ts +0 -29
- package/src/payment/services/payment-service.ts +0 -70
- package/src/pers-sdk.ts +0 -45
- package/src/redemption/api/redemption-api.ts +0 -241
- package/src/redemption/index.ts +0 -60
- package/src/redemption/models/index.ts +0 -17
- package/src/redemption/services/redemption-service.ts +0 -103
- package/src/shared/interfaces/pers-shared-lib.interfaces.ts +0 -99
- package/src/tenant/api/tenant-api.ts +0 -92
- package/src/tenant/index.ts +0 -61
- package/src/tenant/models/index.ts +0 -20
- package/src/tenant/services/tenant-service.ts +0 -78
- package/src/token/api/token-api.ts +0 -129
- package/src/token/base/base-token-service.ts +0 -167
- package/src/token/index.ts +0 -38
- package/src/token/models/index.ts +0 -30
- package/src/token/services/token-service.ts +0 -125
- package/src/token/token-sdk.ts +0 -231
- package/src/transaction/api/transaction-api.ts +0 -296
- package/src/transaction/index.ts +0 -65
- package/src/transaction/models/index.ts +0 -60
- package/src/transaction/services/transaction-service.ts +0 -104
- package/src/user/api/user-api.ts +0 -98
- package/src/user/index.ts +0 -62
- package/src/user/services/user-service.ts +0 -75
- package/src/user-status/api/user-status-api.ts +0 -78
- package/src/user-status/index.ts +0 -55
- package/src/user-status/services/user-status-service.ts +0 -51
- package/src/web3/api/web3-api.ts +0 -68
- package/src/web3/index.ts +0 -38
- package/src/web3/models/index.ts +0 -150
- package/src/web3/services/web3-service.ts +0 -338
- package/src/web3-chain/api/web3-chain-api.ts +0 -42
- package/src/web3-chain/index.ts +0 -27
- package/src/web3-chain/services/getWeb3FCD.service.ts +0 -47
- package/src/web3-chain/services/provider.service.ts +0 -123
- package/src/web3-chain/services/public-http-provider.service.ts +0 -26
- package/src/web3-chain/services/web3-chain-service.ts +0 -131
- package/tsconfig.json +0 -28
package/src/web3/models/index.ts
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import type { ContractAbi, Web3 } from 'web3';
|
|
2
|
-
import type { TokenDTO } from '../../shared/interfaces/pers-shared-lib.interfaces';
|
|
3
|
-
|
|
4
|
-
// ✅ REMOVE: Custom Web3ContractAbi type (no longer needed)
|
|
5
|
-
// export type Web3ContractAbi = readonly AbiFragment[] | AbiFragment[];
|
|
6
|
-
|
|
7
|
-
export interface Web3BalanceRequest {
|
|
8
|
-
accountAddress: string;
|
|
9
|
-
token: TokenDTO;
|
|
10
|
-
tokenId: string | null;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export interface Web3BalanceResponse {
|
|
14
|
-
rawBalance: number;
|
|
15
|
-
formattedBalance: string;
|
|
16
|
-
decimals: number;
|
|
17
|
-
symbol: string;
|
|
18
|
-
hasBalance: boolean;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface Web3TokenConfig {
|
|
22
|
-
token: TokenDTO;
|
|
23
|
-
tokenIds?: (string | null)[];
|
|
24
|
-
metadata?: any[];
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export interface Web3TokenListRequest {
|
|
28
|
-
accountAddress: string;
|
|
29
|
-
tokens: Web3TokenConfig[];
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export interface Web3TokenResult {
|
|
33
|
-
tokenId: string | null;
|
|
34
|
-
balance: number;
|
|
35
|
-
formattedBalance: string;
|
|
36
|
-
hasBalance: boolean;
|
|
37
|
-
metadata: any | null;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export interface Web3TokenListResponse {
|
|
41
|
-
accountAddress: string;
|
|
42
|
-
tokens: {
|
|
43
|
-
token: TokenDTO;
|
|
44
|
-
results: Web3TokenResult[];
|
|
45
|
-
}[];
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export interface NFTItem {
|
|
49
|
-
tokenId: string;
|
|
50
|
-
name: string;
|
|
51
|
-
description: string;
|
|
52
|
-
imageUrl: string;
|
|
53
|
-
rawBalance: number;
|
|
54
|
-
formattedBalance: string;
|
|
55
|
-
hasBalance: boolean;
|
|
56
|
-
metadata: any;
|
|
57
|
-
tokenIndex: number;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export interface ERC721CollectionRequest {
|
|
61
|
-
accountAddress: string;
|
|
62
|
-
nftContracts: TokenDTO[];
|
|
63
|
-
maxNFTsPerContract?: number;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export interface ERC721CollectionResponse {
|
|
67
|
-
accountAddress: string;
|
|
68
|
-
contracts: {
|
|
69
|
-
token: TokenDTO;
|
|
70
|
-
totalNFTs: number;
|
|
71
|
-
nfts: NFTItem[];
|
|
72
|
-
hasMore: boolean;
|
|
73
|
-
}[];
|
|
74
|
-
summary: {
|
|
75
|
-
totalContracts: number;
|
|
76
|
-
totalNFTs: number;
|
|
77
|
-
loadingTime: number;
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// ✅ NEW: ERC20 Balance types (simplified)
|
|
82
|
-
export interface ERC20BalanceRequest {
|
|
83
|
-
accountAddress: string;
|
|
84
|
-
token: TokenDTO;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// ✅ NEW: ERC1155 Collection types (clearer naming)
|
|
88
|
-
export interface ERC1155CollectionRequest {
|
|
89
|
-
accountAddress: string;
|
|
90
|
-
tokens: TokenDTO[];
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// ✅ RE-EXPORT: Standard Web3.js types for consumers
|
|
94
|
-
export type { ContractAbi } from 'web3';
|
|
95
|
-
|
|
96
|
-
// ✅ CACHE: Simple cache interface with TTL
|
|
97
|
-
export interface CacheEntry<T> {
|
|
98
|
-
data: T;
|
|
99
|
-
timestamp: number;
|
|
100
|
-
ttl: number;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export interface CacheStorage {
|
|
104
|
-
[key: string]: CacheEntry<unknown>;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
export class SimpleCache {
|
|
108
|
-
private storage: CacheStorage = {};
|
|
109
|
-
private readonly defaultTTL = 10 * 1000; // 10 seconds
|
|
110
|
-
|
|
111
|
-
set<T>(key: string, data: T, ttl?: number): void {
|
|
112
|
-
this.storage[key] = {
|
|
113
|
-
data,
|
|
114
|
-
timestamp: Date.now(),
|
|
115
|
-
ttl: ttl ?? this.defaultTTL
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
get<T>(key: string): T | null {
|
|
120
|
-
const entry = this.storage[key];
|
|
121
|
-
|
|
122
|
-
if (!entry) {
|
|
123
|
-
return null;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
const now = Date.now();
|
|
127
|
-
const isExpired = (now - entry.timestamp) > entry.ttl;
|
|
128
|
-
|
|
129
|
-
if (isExpired) {
|
|
130
|
-
delete this.storage[key];
|
|
131
|
-
return null;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
return entry.data as T;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
clear(): void {
|
|
138
|
-
this.storage = {};
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
cleanup(): void {
|
|
142
|
-
const now = Date.now();
|
|
143
|
-
Object.keys(this.storage).forEach(key => {
|
|
144
|
-
const entry = this.storage[key];
|
|
145
|
-
if ((now - entry.timestamp) > entry.ttl) {
|
|
146
|
-
delete this.storage[key];
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
}
|
|
@@ -1,338 +0,0 @@
|
|
|
1
|
-
import { Web3ChainService } from '../../web3-chain';
|
|
2
|
-
import { Web3Api } from '../api/web3-api';
|
|
3
|
-
import {
|
|
4
|
-
ERC20BalanceRequest,
|
|
5
|
-
ERC1155CollectionRequest,
|
|
6
|
-
ERC721CollectionRequest,
|
|
7
|
-
ERC721CollectionResponse,
|
|
8
|
-
NFTItem,
|
|
9
|
-
Web3BalanceResponse,
|
|
10
|
-
Web3TokenListResponse,
|
|
11
|
-
Web3TokenResult,
|
|
12
|
-
SimpleCache
|
|
13
|
-
} from '../models';
|
|
14
|
-
|
|
15
|
-
export class Web3Service {
|
|
16
|
-
//temporary fix, remove when the backend supports custom gateways
|
|
17
|
-
private readonly defaultIpfsGatewayDomain = 'pers.mypinata.cloud';
|
|
18
|
-
|
|
19
|
-
// ✅ CACHE: Simple 10-second cache instance
|
|
20
|
-
private cache = new SimpleCache();
|
|
21
|
-
private cleanupInterval: NodeJS.Timeout | null = null;
|
|
22
|
-
|
|
23
|
-
constructor(
|
|
24
|
-
private web3Api: Web3Api,
|
|
25
|
-
private web3ChainService: Web3ChainService
|
|
26
|
-
) {
|
|
27
|
-
this.cleanupInterval = setInterval(() => {
|
|
28
|
-
this.cache.cleanup();
|
|
29
|
-
}, 30 * 1000);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
destroy(): void {
|
|
33
|
-
if (this.cleanupInterval) {
|
|
34
|
-
clearInterval(this.cleanupInterval);
|
|
35
|
-
this.cleanupInterval = null;
|
|
36
|
-
}
|
|
37
|
-
this.cache.clear();
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
async getERC20Balance(request: ERC20BalanceRequest): Promise<Web3BalanceResponse> {
|
|
41
|
-
|
|
42
|
-
const cacheKey = `erc20_balance_${request.accountAddress}_${request.token.contractAddress}_${request.token.chainId}`;
|
|
43
|
-
|
|
44
|
-
// ✅ CACHE CHECK: Try to get from cache first
|
|
45
|
-
const cached = this.cache.get<Web3BalanceResponse>(cacheKey);
|
|
46
|
-
if (cached) {
|
|
47
|
-
console.debug(`💾 [Web3Service] Using cached ERC20 balance for ${request.token.symbol}`);
|
|
48
|
-
return cached;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
console.debug(`🔄 [Web3Service] Fetching fresh ERC20 balance for ${request.token.symbol}`);
|
|
52
|
-
|
|
53
|
-
const rawBalance = await this.web3Api.getTokenBalance({
|
|
54
|
-
accountAddress: request.accountAddress,
|
|
55
|
-
contractAddress: request.token.contractAddress,
|
|
56
|
-
abi: request.token.abi,
|
|
57
|
-
tokenId: null, // Always null for ERC20
|
|
58
|
-
chainId: request.token.chainId
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
const decimals = request.token.decimals ?? 18;
|
|
62
|
-
const symbol = request.token.symbol ?? 'UNKNOWN';
|
|
63
|
-
|
|
64
|
-
const response: Web3BalanceResponse = {
|
|
65
|
-
rawBalance,
|
|
66
|
-
formattedBalance: this.formatBalance(rawBalance, decimals),
|
|
67
|
-
decimals,
|
|
68
|
-
symbol,
|
|
69
|
-
hasBalance: rawBalance > 0
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
// ✅ CACHE SET: Store result in cache
|
|
73
|
-
this.cache.set(cacheKey, response);
|
|
74
|
-
|
|
75
|
-
return response;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
async getERC1155Collection(request: ERC1155CollectionRequest): Promise<Web3TokenListResponse> {
|
|
79
|
-
|
|
80
|
-
// ✅ CACHE KEY: Create unique cache key for collection request
|
|
81
|
-
const contractAddresses = request.tokens.map(t => t.contractAddress).sort().join(',');
|
|
82
|
-
const cacheKey = `erc1155_collection_${request.accountAddress}_${contractAddresses}`;
|
|
83
|
-
|
|
84
|
-
// ✅ CACHE CHECK: Try to get from cache first
|
|
85
|
-
const cached = this.cache.get<Web3TokenListResponse>(cacheKey);
|
|
86
|
-
if (cached) {
|
|
87
|
-
console.debug(`💾 [Web3Service] Using cached ERC1155 collection for ${request.accountAddress}`);
|
|
88
|
-
return cached;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
console.debug(`🔄 [Web3Service] Fetching fresh ERC1155 collection for ${request.accountAddress}`);
|
|
92
|
-
|
|
93
|
-
const tokenResults = await Promise.all(
|
|
94
|
-
request.tokens.map(async (token) => {
|
|
95
|
-
// ✅ FIXED: Handle null metadata properly
|
|
96
|
-
const tokenIds: string[] = token.metadata?.map(m =>
|
|
97
|
-
m.tokenMetadataIncrementalId?.toString()
|
|
98
|
-
).filter((id): id is string => id !== undefined) ?? [];
|
|
99
|
-
|
|
100
|
-
// Check balance for each known tokenId
|
|
101
|
-
const balanceResults = await Promise.allSettled(
|
|
102
|
-
tokenIds.map(async (tokenId) => {
|
|
103
|
-
try {
|
|
104
|
-
const rawBalance = await this.web3Api.getTokenBalance({
|
|
105
|
-
accountAddress: request.accountAddress,
|
|
106
|
-
contractAddress: token.contractAddress,
|
|
107
|
-
abi: token.abi,
|
|
108
|
-
tokenId,
|
|
109
|
-
chainId: token.chainId
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
const decimals = token.decimals ?? 0; // ERC1155 usually no decimals
|
|
113
|
-
|
|
114
|
-
return {
|
|
115
|
-
tokenId,
|
|
116
|
-
balance: rawBalance,
|
|
117
|
-
formattedBalance: this.formatBalance(rawBalance, decimals),
|
|
118
|
-
hasBalance: rawBalance > 0,
|
|
119
|
-
// ✅ FIXED: Convert null to undefined for findMetadata
|
|
120
|
-
metadata: this.findMetadata(token.metadata ?? undefined, tokenId)
|
|
121
|
-
};
|
|
122
|
-
} catch (error) {
|
|
123
|
-
console.warn(`Failed to get balance for token ${token.contractAddress}:${tokenId}`, error);
|
|
124
|
-
return null; // Skip failed tokens
|
|
125
|
-
}
|
|
126
|
-
})
|
|
127
|
-
);
|
|
128
|
-
|
|
129
|
-
// Filter successful results with balance > 0
|
|
130
|
-
const successfulResults: Web3TokenResult[] = [];
|
|
131
|
-
for (const result of balanceResults) {
|
|
132
|
-
if (result.status === 'fulfilled' && result.value !== null && result.value.hasBalance) {
|
|
133
|
-
successfulResults.push(result.value);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
return {
|
|
138
|
-
token,
|
|
139
|
-
results: successfulResults
|
|
140
|
-
};
|
|
141
|
-
})
|
|
142
|
-
);
|
|
143
|
-
|
|
144
|
-
const response: Web3TokenListResponse = {
|
|
145
|
-
accountAddress: request.accountAddress,
|
|
146
|
-
tokens: tokenResults.filter(t => t.results.length > 0)
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
// ✅ CACHE SET: Store complete collection result
|
|
150
|
-
this.cache.set(cacheKey, response);
|
|
151
|
-
|
|
152
|
-
return response;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
async getERC721Collection(request: ERC721CollectionRequest): Promise<ERC721CollectionResponse> {
|
|
156
|
-
|
|
157
|
-
// ✅ CACHE KEY: Create unique cache key for NFT collection
|
|
158
|
-
const contractAddresses = request.nftContracts.map(t => t.contractAddress).sort().join(',');
|
|
159
|
-
const maxNFTs = request.maxNFTsPerContract || 50;
|
|
160
|
-
const cacheKey = `erc721_collection_${request.accountAddress}_${contractAddresses}_${maxNFTs}`;
|
|
161
|
-
|
|
162
|
-
// ✅ CACHE CHECK: Try to get from cache first
|
|
163
|
-
const cached = this.cache.get<ERC721CollectionResponse>(cacheKey);
|
|
164
|
-
if (cached) {
|
|
165
|
-
console.debug(`💾 [Web3Service] Using cached ERC721 collection for ${request.accountAddress}`);
|
|
166
|
-
return cached;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
console.debug(`🔄 [Web3Service] Fetching fresh ERC721 collection for ${request.accountAddress}`);
|
|
170
|
-
|
|
171
|
-
const startTime = Date.now();
|
|
172
|
-
|
|
173
|
-
const contractResults = await Promise.all(
|
|
174
|
-
request.nftContracts.map(async (token) => {
|
|
175
|
-
try {
|
|
176
|
-
const totalBalance = await this.web3Api.getTokenBalance({
|
|
177
|
-
accountAddress: request.accountAddress,
|
|
178
|
-
contractAddress: token.contractAddress,
|
|
179
|
-
abi: token.abi,
|
|
180
|
-
tokenId: null,
|
|
181
|
-
chainId: token.chainId
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
if (totalBalance === 0) {
|
|
185
|
-
return {
|
|
186
|
-
token,
|
|
187
|
-
totalNFTs: 0,
|
|
188
|
-
nfts: [],
|
|
189
|
-
hasMore: false
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
const nftsToLoad = Math.min(totalBalance, maxNFTs);
|
|
194
|
-
|
|
195
|
-
const nftResults = await Promise.allSettled(
|
|
196
|
-
Array.from({ length: nftsToLoad }, async (_, index): Promise<NFTItem | null> => {
|
|
197
|
-
try {
|
|
198
|
-
const tokenId = await this.web3Api.getTokenOfOwnerByIndex({
|
|
199
|
-
contractAddress: token.contractAddress,
|
|
200
|
-
abi: token.abi,
|
|
201
|
-
accountAddress: request.accountAddress,
|
|
202
|
-
tokenIndex: index,
|
|
203
|
-
chainId: token.chainId
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
const tokenUri = await this.web3Api.getTokenUri({
|
|
207
|
-
contractAddress: token.contractAddress,
|
|
208
|
-
abi: token.abi,
|
|
209
|
-
tokenId,
|
|
210
|
-
chainId: token.chainId
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
const metadata = await this.fetchMetadata(tokenUri, token.chainId);
|
|
214
|
-
|
|
215
|
-
const nftItem: NFTItem = {
|
|
216
|
-
tokenId,
|
|
217
|
-
name: metadata?.name || `Token #${tokenId}`,
|
|
218
|
-
description: metadata?.description || '',
|
|
219
|
-
imageUrl: await this.resolveIPFSUrl(metadata?.image || '', token.chainId),
|
|
220
|
-
rawBalance: 1,
|
|
221
|
-
formattedBalance: '1',
|
|
222
|
-
hasBalance: true,
|
|
223
|
-
metadata,
|
|
224
|
-
tokenIndex: index
|
|
225
|
-
};
|
|
226
|
-
|
|
227
|
-
return nftItem;
|
|
228
|
-
|
|
229
|
-
} catch (error) {
|
|
230
|
-
console.warn(`Failed to load NFT at index ${index} for ${token.symbol}:`, error);
|
|
231
|
-
return null;
|
|
232
|
-
}
|
|
233
|
-
})
|
|
234
|
-
);
|
|
235
|
-
|
|
236
|
-
// ✅ FIXED: Usar tipo específico NFTItem
|
|
237
|
-
const successfulNFTs = nftResults
|
|
238
|
-
.filter((result): result is PromiseFulfilledResult<NFTItem | null> =>
|
|
239
|
-
result.status === 'fulfilled' && result.value !== null
|
|
240
|
-
)
|
|
241
|
-
.map(result => result.value as NFTItem);
|
|
242
|
-
|
|
243
|
-
return {
|
|
244
|
-
token,
|
|
245
|
-
totalNFTs: totalBalance,
|
|
246
|
-
nfts: successfulNFTs,
|
|
247
|
-
hasMore: totalBalance > maxNFTs
|
|
248
|
-
};
|
|
249
|
-
|
|
250
|
-
} catch (error) {
|
|
251
|
-
console.error(`Failed to load NFT collection for ${token.symbol}:`, error);
|
|
252
|
-
return {
|
|
253
|
-
token,
|
|
254
|
-
totalNFTs: 0,
|
|
255
|
-
nfts: [],
|
|
256
|
-
hasMore: false
|
|
257
|
-
};
|
|
258
|
-
}
|
|
259
|
-
})
|
|
260
|
-
);
|
|
261
|
-
|
|
262
|
-
const totalNFTs = contractResults.reduce((sum, contract) => sum + contract.nfts.length, 0);
|
|
263
|
-
const loadingTime = Date.now() - startTime;
|
|
264
|
-
|
|
265
|
-
const response: ERC721CollectionResponse = {
|
|
266
|
-
accountAddress: request.accountAddress,
|
|
267
|
-
contracts: contractResults,
|
|
268
|
-
summary: {
|
|
269
|
-
totalContracts: request.nftContracts.length,
|
|
270
|
-
totalNFTs,
|
|
271
|
-
loadingTime
|
|
272
|
-
}
|
|
273
|
-
};
|
|
274
|
-
|
|
275
|
-
// ✅ CACHE SET: Store complete collection response
|
|
276
|
-
this.cache.set(cacheKey, response);
|
|
277
|
-
|
|
278
|
-
return response;
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
// ==========================================
|
|
282
|
-
// HELPER METHODS
|
|
283
|
-
// ==========================================
|
|
284
|
-
|
|
285
|
-
private formatBalance(rawBalance: number, decimals: number): string {
|
|
286
|
-
const balance = rawBalance / Math.pow(10, decimals);
|
|
287
|
-
|
|
288
|
-
return balance.toLocaleString('en-US', {
|
|
289
|
-
minimumFractionDigits: 0,
|
|
290
|
-
maximumFractionDigits: decimals > 0 ? 2 : 0
|
|
291
|
-
});
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
// ✅ FIXED: Update method signature to handle null properly
|
|
295
|
-
private findMetadata(metadata: any[] | undefined, tokenId: string | null): any | null {
|
|
296
|
-
if (!metadata || tokenId === null) return null;
|
|
297
|
-
return metadata.find(m =>
|
|
298
|
-
m.tokenMetadataIncrementalId?.toString() === tokenId
|
|
299
|
-
) || null;
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
private async fetchMetadata(uri: string, chainId: number): Promise<any> {
|
|
303
|
-
try {
|
|
304
|
-
const httpUrl = await this.resolveIPFSUrl(uri, chainId);
|
|
305
|
-
const response = await fetch(httpUrl);
|
|
306
|
-
|
|
307
|
-
if (!response.ok) {
|
|
308
|
-
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
return await response.json();
|
|
312
|
-
} catch (error) {
|
|
313
|
-
console.warn('Failed to fetch NFT metadata:', error);
|
|
314
|
-
return null;
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
private async getIpfsGatewayDomain(chainId: number): Promise<string> {
|
|
319
|
-
try {
|
|
320
|
-
const chainData = await this.web3ChainService.getChainDataWithCache(chainId);
|
|
321
|
-
return chainData.ipfsGatewayDomain || this.defaultIpfsGatewayDomain;
|
|
322
|
-
} catch (error) {
|
|
323
|
-
console.warn(`Failed to get chain data for chainId ${chainId}, using default IPFS gateway:`, error);
|
|
324
|
-
return this.defaultIpfsGatewayDomain;
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
private async resolveIPFSUrl(url: string, chainId: number): Promise<string> {
|
|
329
|
-
if (!url) return '';
|
|
330
|
-
|
|
331
|
-
if (url.startsWith('ipfs://')) {
|
|
332
|
-
const gatewayDomain = await this.getIpfsGatewayDomain(chainId);
|
|
333
|
-
return `https://${gatewayDomain}/ipfs/${url.slice(7)}`;
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
return url;
|
|
337
|
-
}
|
|
338
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { PersApiClient } from '../../core/pers-api-client';
|
|
2
|
-
import { ChainData } from '../models';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Platform-Agnostic Web3 Chain API Client
|
|
6
|
-
*
|
|
7
|
-
* Handles blockchain chain operations using the PERS backend.
|
|
8
|
-
* Uses @explorins/web3-ts types for perfect framework compatibility.
|
|
9
|
-
*/
|
|
10
|
-
export class Web3ChainApi {
|
|
11
|
-
constructor(private apiClient: PersApiClient) {}
|
|
12
|
-
|
|
13
|
-
private basePath = '/chains';
|
|
14
|
-
|
|
15
|
-
// ==========================================
|
|
16
|
-
// PUBLIC OPERATIONS
|
|
17
|
-
// ==========================================
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* PUBLIC: Get chain data by chain ID
|
|
21
|
-
* ✅ Returns ChainData exactly as framework expects from @explorins/web3-ts
|
|
22
|
-
*/
|
|
23
|
-
async getChainData(chainId: number): Promise<ChainData> {
|
|
24
|
-
try {
|
|
25
|
-
|
|
26
|
-
console.log('🔍 [Web3ChainApi] Fetching chain data for chainId:', chainId);
|
|
27
|
-
const response = await this.apiClient.get<ChainData>(`${this.basePath}/${chainId}`);
|
|
28
|
-
|
|
29
|
-
if (!response) {
|
|
30
|
-
throw new Error(`No chain data received for chainId: ${chainId}`);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return response;
|
|
34
|
-
} catch (error) {
|
|
35
|
-
console.error('❌ [Web3ChainApi] Failed to get chain data:', {
|
|
36
|
-
chainId,
|
|
37
|
-
error: error instanceof Error ? error.message : String(error)
|
|
38
|
-
});
|
|
39
|
-
throw error;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
package/src/web3-chain/index.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { PersApiClient } from '../core/pers-api-client';
|
|
2
|
-
import { Web3ChainApi } from './api/web3-chain-api';
|
|
3
|
-
import { Web3ProviderService } from './services/provider.service';
|
|
4
|
-
|
|
5
|
-
import { Web3ChainService } from './services/web3-chain-service';
|
|
6
|
-
|
|
7
|
-
export function createWeb3ChainSDK(apiClient: PersApiClient, providerService: Web3ProviderService) {
|
|
8
|
-
const web3ChainApi = new Web3ChainApi(apiClient);
|
|
9
|
-
const web3ChainService = new Web3ChainService(web3ChainApi, providerService); // ✅ DIRECT INJECTION
|
|
10
|
-
|
|
11
|
-
return {
|
|
12
|
-
// ✅ REPLICA: Same methods as framework
|
|
13
|
-
getChainDataById: (chainId: number) => web3ChainService.getChainDataById(chainId),
|
|
14
|
-
getWeb3ByChainId: (chainId: number) => web3ChainService.getWeb3ByChainId(chainId),
|
|
15
|
-
|
|
16
|
-
api: web3ChainApi,
|
|
17
|
-
service: web3ChainService
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// ✅ EXPORT: All models and service
|
|
22
|
-
export { Web3ChainApi } from './api/web3-chain-api';
|
|
23
|
-
export { Web3ChainService } from './services/web3-chain-service';
|
|
24
|
-
export { Web3ProviderService } from './services/provider.service';
|
|
25
|
-
export * from './models';
|
|
26
|
-
export type { ChainData } from './models';
|
|
27
|
-
export * from '../shared/interfaces/pers-shared-lib.interfaces';
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
//IMPORTANT//
|
|
3
|
-
//This function is temporary so we install ethers just to make it work, once we delete this function we must uninstall Ethers
|
|
4
|
-
|
|
5
|
-
import { ChainData } from "@explorins/web3-ts";
|
|
6
|
-
import { FetchRequest, JsonRpcProvider } from "ethers";
|
|
7
|
-
|
|
8
|
-
export const getWeb3ProviderFromChainData = (
|
|
9
|
-
chainData: ChainData,
|
|
10
|
-
timeout = 15000,
|
|
11
|
-
customUserAgentName = '',
|
|
12
|
-
tokenRefresher?: () => Promise<string>
|
|
13
|
-
) => {
|
|
14
|
-
|
|
15
|
-
// Fixed ethers provider setup for authenticated requests
|
|
16
|
-
let ethersProvider: JsonRpcProvider;
|
|
17
|
-
|
|
18
|
-
if (chainData.authHeader) {
|
|
19
|
-
// For authenticated requests, create a custom FetchRequest
|
|
20
|
-
const fetchRequest = new FetchRequest(chainData.rpcUrl);
|
|
21
|
-
fetchRequest.timeout = timeout;
|
|
22
|
-
fetchRequest.setHeader('Authorization', chainData.authHeader);
|
|
23
|
-
fetchRequest.setHeader('Content-Type', 'application/json');
|
|
24
|
-
|
|
25
|
-
if (customUserAgentName) {
|
|
26
|
-
fetchRequest.setHeader('User-Agent', customUserAgentName);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// Create provider with the configured FetchRequest
|
|
30
|
-
ethersProvider = new JsonRpcProvider(fetchRequest, undefined, {
|
|
31
|
-
staticNetwork: false,
|
|
32
|
-
polling: false, // Disable polling for better Lambda performance
|
|
33
|
-
});
|
|
34
|
-
} else {
|
|
35
|
-
// For public chains, use simple URL-based provider
|
|
36
|
-
ethersProvider = new JsonRpcProvider(chainData.rpcUrl, undefined, {
|
|
37
|
-
staticNetwork: false,
|
|
38
|
-
polling: false,
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return {
|
|
43
|
-
web3Provider: null,
|
|
44
|
-
ethersProvider: ethersProvider,
|
|
45
|
-
isAuthenticated: !!chainData.authHeader,
|
|
46
|
-
};
|
|
47
|
-
};
|