@lukso/transaction-view-headless 0.2.2-dev.a8c9315
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/.turbo/turbo-build.log +51 -0
- package/CHANGELOG.md +88 -0
- package/COMPONENT_ARCHITECTURE.md +190 -0
- package/COMPONENT_CONVERSION_ANALYSIS.md +371 -0
- package/CONTEXT_VARIANT_GUIDE.md +425 -0
- package/LAZY_LOADING_GUIDE.md +534 -0
- package/LICENSE +201 -0
- package/PLAYBACK_EXAMPLES.md +658 -0
- package/PLAYBACK_GUIDE.md +402 -0
- package/README.md +43 -0
- package/REGISTRY_SUMMARY.md +638 -0
- package/SUFFERING_ECONOMICS.md +346 -0
- package/SUFFERING_ECONOMICS.zip +0 -0
- package/VIEW_REGISTRATION_GUIDE.md +795 -0
- package/dist/composables/index.cjs +1321 -0
- package/dist/composables/index.cjs.map +1 -0
- package/dist/composables/index.d.cts +6 -0
- package/dist/composables/index.d.ts +6 -0
- package/dist/composables/index.js +1276 -0
- package/dist/composables/index.js.map +1 -0
- package/dist/index-CMLU1hKL.d.ts +374 -0
- package/dist/index-CSDjhiKV.d.cts +374 -0
- package/dist/index.cjs +1534 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +93 -0
- package/dist/index.d.ts +93 -0
- package/dist/index.js +1463 -0
- package/dist/index.js.map +1 -0
- package/dist/registry/index.cjs +522 -0
- package/dist/registry/index.cjs.map +1 -0
- package/dist/registry/index.d.cts +46 -0
- package/dist/registry/index.d.ts +46 -0
- package/dist/registry/index.js +487 -0
- package/dist/registry/index.js.map +1 -0
- package/dist/types/index.cjs +19 -0
- package/dist/types/index.cjs.map +1 -0
- package/dist/types/index.d.cts +203 -0
- package/dist/types/index.d.ts +203 -0
- package/dist/types/index.js +1 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/index.cjs +217 -0
- package/dist/utils/index.cjs.map +1 -0
- package/dist/utils/index.d.cts +47 -0
- package/dist/utils/index.d.ts +47 -0
- package/dist/utils/index.js +188 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/view-loader-dD86QAlQ.d.cts +121 -0
- package/dist/view-loader-ii8AxiQR.d.ts +121 -0
- package/package.json +64 -0
- package/publish.log +0 -0
- package/src/composables/index.ts +59 -0
- package/src/composables/use-image-loader.ts +315 -0
- package/src/composables/use-transaction-playback.ts +396 -0
- package/src/composables/use-transaction-view.ts +309 -0
- package/src/config/lukso-config.ts +171 -0
- package/src/examples/context-aware-views.ts +300 -0
- package/src/examples/example-views.ts +197 -0
- package/src/examples/lit-plus-rn-strategy.ts +448 -0
- package/src/examples/lsp7-custom-matcher-examples.ts +174 -0
- package/src/examples/opt-in-context-examples.ts +372 -0
- package/src/examples/optimized-view-definitions.ts +408 -0
- package/src/examples/vue-to-lit-compilation.ts +358 -0
- package/src/hooks/useAddressQuery.ts +135 -0
- package/src/hooks/useAddressResolution.ts +437 -0
- package/src/index.ts +36 -0
- package/src/registry/index.ts +13 -0
- package/src/registry/view-loader.ts +305 -0
- package/src/registry/view-registry.ts +135 -0
- package/src/types/index.ts +16 -0
- package/src/types/view-contexts.ts +72 -0
- package/src/types/view-matching.ts +173 -0
- package/src/utils/context-matcher.ts +165 -0
- package/src/utils/index.ts +5 -0
- package/src/utils/view-matcher.ts +338 -0
- package/tsconfig.json +20 -0
- package/tsup.config.ts +34 -0
|
@@ -0,0 +1,1276 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
+
var __esm = (fn, res) => function __init() {
|
|
4
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
5
|
+
};
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
// src/config/lukso-config.ts
|
|
12
|
+
import { signal } from "@preact/signals-core";
|
|
13
|
+
function setLuksoConfig(config) {
|
|
14
|
+
globalConfig = { ...globalConfig, ...config };
|
|
15
|
+
clearAddressCache();
|
|
16
|
+
if (typeof window !== "undefined" && window.console) {
|
|
17
|
+
console.log("\u{1F310} LUKSO Config Updated:", {
|
|
18
|
+
chainId: globalConfig.chainId,
|
|
19
|
+
network: globalConfig.chainId === 42 ? "mainnet" : globalConfig.chainId === 4201 ? "testnet" : "custom",
|
|
20
|
+
addressResolution: globalConfig.enableAddressResolution
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function getLuksoConfig() {
|
|
25
|
+
return { ...globalConfig };
|
|
26
|
+
}
|
|
27
|
+
function useLuksoMainnet() {
|
|
28
|
+
setLuksoConfig({
|
|
29
|
+
chainId: 42,
|
|
30
|
+
rpcUrl: "https://rpc.lukso.network"
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
function useLuksoTestnet() {
|
|
34
|
+
setLuksoConfig({
|
|
35
|
+
chainId: 4201,
|
|
36
|
+
rpcUrl: "https://rpc.testnet.lukso.network"
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
function cacheAddress(address, data) {
|
|
40
|
+
if (!globalConfig.enableAddressResolution) return;
|
|
41
|
+
const key = address.toLowerCase();
|
|
42
|
+
addressCache.set(key, data);
|
|
43
|
+
cacheTimestamps.set(key, Date.now());
|
|
44
|
+
}
|
|
45
|
+
function getCachedAddress(address) {
|
|
46
|
+
if (!globalConfig.enableAddressResolution) return null;
|
|
47
|
+
const key = address.toLowerCase();
|
|
48
|
+
const data = addressCache.get(key);
|
|
49
|
+
const timestamp = cacheTimestamps.get(key);
|
|
50
|
+
if (!data || !timestamp) return null;
|
|
51
|
+
if (Date.now() - timestamp > globalConfig.cacheDuration) {
|
|
52
|
+
addressCache.delete(key);
|
|
53
|
+
cacheTimestamps.delete(key);
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
return data;
|
|
57
|
+
}
|
|
58
|
+
function clearAddressCache() {
|
|
59
|
+
addressCache.clear();
|
|
60
|
+
cacheTimestamps.clear();
|
|
61
|
+
}
|
|
62
|
+
function isAddressResolutionEnabled() {
|
|
63
|
+
return globalConfig.enableAddressResolution ?? true;
|
|
64
|
+
}
|
|
65
|
+
async function initializeChainSignal() {
|
|
66
|
+
if (currentChainSignal.value) return;
|
|
67
|
+
try {
|
|
68
|
+
const { lukso, luksoTestnet } = await import("viem/chains");
|
|
69
|
+
const config = getLuksoConfig();
|
|
70
|
+
const chain = config.chainId === 42 ? lukso : luksoTestnet;
|
|
71
|
+
currentChainSignal.value = chain;
|
|
72
|
+
} catch (error) {
|
|
73
|
+
console.warn("Failed to initialize chain signal:", error);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
var DEFAULT_CONFIG, globalConfig, addressCache, cacheTimestamps, currentChainSignal;
|
|
77
|
+
var init_lukso_config = __esm({
|
|
78
|
+
"src/config/lukso-config.ts"() {
|
|
79
|
+
"use strict";
|
|
80
|
+
DEFAULT_CONFIG = {
|
|
81
|
+
chainId: 42,
|
|
82
|
+
// LUKSO mainnet
|
|
83
|
+
rpcUrl: "https://rpc.lukso.network",
|
|
84
|
+
graphqlEndpoint: "/api/graphql",
|
|
85
|
+
// Use local API proxy
|
|
86
|
+
ipfsGateway: "https://api.universalprofile.cloud/ipfs",
|
|
87
|
+
enableAddressResolution: true,
|
|
88
|
+
cacheDuration: 5 * 60 * 1e3
|
|
89
|
+
// 5 minutes
|
|
90
|
+
};
|
|
91
|
+
globalConfig = { ...DEFAULT_CONFIG };
|
|
92
|
+
addressCache = /* @__PURE__ */ new Map();
|
|
93
|
+
cacheTimestamps = /* @__PURE__ */ new Map();
|
|
94
|
+
currentChainSignal = signal(null);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// src/hooks/useAddressResolution.ts
|
|
99
|
+
var useAddressResolution_exports = {};
|
|
100
|
+
__export(useAddressResolution_exports, {
|
|
101
|
+
createAddressResolutionState: () => createAddressResolutionState,
|
|
102
|
+
resolveAddress: () => resolveAddress,
|
|
103
|
+
resolveAddressWithState: () => resolveAddressWithState,
|
|
104
|
+
resolveAddresses: () => resolveAddresses
|
|
105
|
+
});
|
|
106
|
+
function truncateAddress(address, prefixLength = 5, suffixLength = 4) {
|
|
107
|
+
if (!address || address.length <= prefixLength + suffixLength + 2) {
|
|
108
|
+
return address;
|
|
109
|
+
}
|
|
110
|
+
const prefix = address.slice(0, 2 + prefixLength);
|
|
111
|
+
const suffix = address.slice(-suffixLength);
|
|
112
|
+
return `${prefix}...${suffix}`;
|
|
113
|
+
}
|
|
114
|
+
function getBatchState(chainId) {
|
|
115
|
+
let state = chainBatchStates.get(chainId);
|
|
116
|
+
if (!state) {
|
|
117
|
+
state = {
|
|
118
|
+
batchTimeout: null,
|
|
119
|
+
batchQueue: /* @__PURE__ */ new Set(),
|
|
120
|
+
batchResolvers: /* @__PURE__ */ new Map(),
|
|
121
|
+
pendingResolutions: /* @__PURE__ */ new Map(),
|
|
122
|
+
isProcessing: false
|
|
123
|
+
};
|
|
124
|
+
chainBatchStates.set(chainId, state);
|
|
125
|
+
}
|
|
126
|
+
return state;
|
|
127
|
+
}
|
|
128
|
+
async function processBatch(chainId) {
|
|
129
|
+
const state = getBatchState(chainId);
|
|
130
|
+
if (state.batchQueue.size === 0 || state.isProcessing) return;
|
|
131
|
+
state.isProcessing = true;
|
|
132
|
+
const addresses = Array.from(state.batchQueue);
|
|
133
|
+
state.batchQueue.clear();
|
|
134
|
+
try {
|
|
135
|
+
const { fetchMultipleAddresses: fetchMultipleAddresses2, getGraphQLEndpoint: getGraphQLEndpoint2 } = await import("@lukso/transaction-decoder");
|
|
136
|
+
const { lukso, luksoTestnet } = await import("viem/chains");
|
|
137
|
+
const chain = chainId === 42 ? lukso : luksoTestnet;
|
|
138
|
+
const graphqlEndpoint = getGraphQLEndpoint2(chain);
|
|
139
|
+
const dataKeys = addresses;
|
|
140
|
+
const results = await fetchMultipleAddresses2(dataKeys, graphqlEndpoint);
|
|
141
|
+
for (const address of addresses) {
|
|
142
|
+
const normalizedAddress = address.toLowerCase();
|
|
143
|
+
const enhanced = results.get(normalizedAddress);
|
|
144
|
+
let result;
|
|
145
|
+
if (enhanced) {
|
|
146
|
+
const profileImages = enhanced.profileImages;
|
|
147
|
+
const resolvedData = {
|
|
148
|
+
...enhanced,
|
|
149
|
+
hasProfile: !!(enhanced.name || profileImages?.length)
|
|
150
|
+
};
|
|
151
|
+
cacheAddressForChain(address, resolvedData, chainId);
|
|
152
|
+
result = {
|
|
153
|
+
...resolvedData,
|
|
154
|
+
address,
|
|
155
|
+
truncatedAddress: truncateAddress(address)
|
|
156
|
+
};
|
|
157
|
+
} else {
|
|
158
|
+
result = {
|
|
159
|
+
address,
|
|
160
|
+
truncatedAddress: truncateAddress(address),
|
|
161
|
+
hasProfile: false
|
|
162
|
+
};
|
|
163
|
+
cacheAddressForChain(address, { hasProfile: false }, chainId);
|
|
164
|
+
}
|
|
165
|
+
const resolver = state.batchResolvers.get(normalizedAddress);
|
|
166
|
+
if (resolver) {
|
|
167
|
+
resolver(result);
|
|
168
|
+
state.batchResolvers.delete(normalizedAddress);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
} catch (error) {
|
|
172
|
+
console.warn(
|
|
173
|
+
"Batch address resolution failed (falling back to API):",
|
|
174
|
+
error
|
|
175
|
+
);
|
|
176
|
+
try {
|
|
177
|
+
const response = await fetch("/api/resolveAddresses", {
|
|
178
|
+
method: "POST",
|
|
179
|
+
headers: { "Content-Type": "application/json" },
|
|
180
|
+
body: JSON.stringify({
|
|
181
|
+
addresses,
|
|
182
|
+
chainId
|
|
183
|
+
})
|
|
184
|
+
});
|
|
185
|
+
if (!response.ok) {
|
|
186
|
+
throw new Error(`API fallback failed: ${response.status}`);
|
|
187
|
+
}
|
|
188
|
+
const data = await response.json();
|
|
189
|
+
for (const address of addresses) {
|
|
190
|
+
const normalizedAddress = address.toLowerCase();
|
|
191
|
+
const resolved = data.resolved?.[normalizedAddress];
|
|
192
|
+
let result;
|
|
193
|
+
if (resolved) {
|
|
194
|
+
const resolvedData = {
|
|
195
|
+
name: resolved.name,
|
|
196
|
+
profileImage: resolved.profileImage,
|
|
197
|
+
hasProfile: !!(resolved.name || resolved.profileImage)
|
|
198
|
+
};
|
|
199
|
+
cacheAddressForChain(address, resolvedData, chainId);
|
|
200
|
+
result = {
|
|
201
|
+
address,
|
|
202
|
+
truncatedAddress: truncateAddress(address),
|
|
203
|
+
...resolvedData
|
|
204
|
+
};
|
|
205
|
+
} else {
|
|
206
|
+
result = {
|
|
207
|
+
address,
|
|
208
|
+
truncatedAddress: truncateAddress(address),
|
|
209
|
+
hasProfile: false
|
|
210
|
+
};
|
|
211
|
+
cacheAddressForChain(address, { hasProfile: false }, chainId);
|
|
212
|
+
}
|
|
213
|
+
const resolver = state.batchResolvers.get(normalizedAddress);
|
|
214
|
+
if (resolver) {
|
|
215
|
+
resolver(result);
|
|
216
|
+
state.batchResolvers.delete(normalizedAddress);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
} catch (fallbackError) {
|
|
220
|
+
console.warn("Both GraphQL and API resolution failed:", fallbackError);
|
|
221
|
+
for (const address of addresses) {
|
|
222
|
+
const fallback = {
|
|
223
|
+
address,
|
|
224
|
+
truncatedAddress: truncateAddress(address),
|
|
225
|
+
hasProfile: false
|
|
226
|
+
};
|
|
227
|
+
cacheAddressForChain(address, { hasProfile: false }, chainId);
|
|
228
|
+
const resolver = state.batchResolvers.get(address.toLowerCase());
|
|
229
|
+
if (resolver) {
|
|
230
|
+
resolver(fallback);
|
|
231
|
+
state.batchResolvers.delete(address.toLowerCase());
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
} finally {
|
|
236
|
+
state.isProcessing = false;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
function cacheAddressForChain(address, data, chainId) {
|
|
240
|
+
const key = `${address.toLowerCase()}:${chainId}`;
|
|
241
|
+
cacheAddress(key, data);
|
|
242
|
+
}
|
|
243
|
+
function getCachedAddressForChain(address, chainId) {
|
|
244
|
+
const key = `${address.toLowerCase()}:${chainId}`;
|
|
245
|
+
return getCachedAddress(key);
|
|
246
|
+
}
|
|
247
|
+
async function getEffectiveChainId(chainId) {
|
|
248
|
+
if (chainId !== void 0) return chainId;
|
|
249
|
+
await initializeChainSignal();
|
|
250
|
+
const currentChain = currentChainSignal.value;
|
|
251
|
+
if (currentChain) {
|
|
252
|
+
return currentChain.id;
|
|
253
|
+
}
|
|
254
|
+
const config = getLuksoConfig();
|
|
255
|
+
return config.chainId;
|
|
256
|
+
}
|
|
257
|
+
async function resolveAddress(address, chainId) {
|
|
258
|
+
const effectiveChainId = await getEffectiveChainId(chainId);
|
|
259
|
+
const normalizedAddress = address.toLowerCase();
|
|
260
|
+
const fallback = {
|
|
261
|
+
address,
|
|
262
|
+
truncatedAddress: truncateAddress(address),
|
|
263
|
+
hasProfile: false
|
|
264
|
+
};
|
|
265
|
+
if (!isAddressResolutionEnabled()) {
|
|
266
|
+
return fallback;
|
|
267
|
+
}
|
|
268
|
+
const cached = getCachedAddressForChain(address, effectiveChainId);
|
|
269
|
+
if (cached) {
|
|
270
|
+
return {
|
|
271
|
+
...fallback,
|
|
272
|
+
...cached,
|
|
273
|
+
hasProfile: !!(cached.name || cached.profileImage)
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
const state = getBatchState(effectiveChainId);
|
|
277
|
+
const existingPromise = state.pendingResolutions.get(normalizedAddress);
|
|
278
|
+
if (existingPromise) {
|
|
279
|
+
return existingPromise;
|
|
280
|
+
}
|
|
281
|
+
if (state.batchQueue.has(normalizedAddress)) {
|
|
282
|
+
return Promise.resolve(fallback);
|
|
283
|
+
}
|
|
284
|
+
const resolutionPromise = new Promise((resolve) => {
|
|
285
|
+
state.batchQueue.add(normalizedAddress);
|
|
286
|
+
state.batchResolvers.set(normalizedAddress, resolve);
|
|
287
|
+
if (state.batchTimeout) {
|
|
288
|
+
clearTimeout(state.batchTimeout);
|
|
289
|
+
}
|
|
290
|
+
if (!state.isProcessing) {
|
|
291
|
+
state.batchTimeout = setTimeout(() => {
|
|
292
|
+
state.batchTimeout = null;
|
|
293
|
+
processBatch(effectiveChainId);
|
|
294
|
+
}, BATCH_DELAY);
|
|
295
|
+
if (state.batchQueue.size >= BATCH_SIZE) {
|
|
296
|
+
if (state.batchTimeout) {
|
|
297
|
+
clearTimeout(state.batchTimeout);
|
|
298
|
+
state.batchTimeout = null;
|
|
299
|
+
}
|
|
300
|
+
processBatch(effectiveChainId);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
state.pendingResolutions.set(normalizedAddress, resolutionPromise);
|
|
305
|
+
resolutionPromise.finally(() => {
|
|
306
|
+
state.pendingResolutions.delete(normalizedAddress);
|
|
307
|
+
});
|
|
308
|
+
return resolutionPromise;
|
|
309
|
+
}
|
|
310
|
+
async function resolveAddresses(addresses, chainId) {
|
|
311
|
+
const results = /* @__PURE__ */ new Map();
|
|
312
|
+
const resolutionPromises = addresses.map(async (address) => {
|
|
313
|
+
const resolved = await resolveAddress(address, chainId);
|
|
314
|
+
results.set(address.toLowerCase(), resolved);
|
|
315
|
+
});
|
|
316
|
+
await Promise.all(resolutionPromises);
|
|
317
|
+
return results;
|
|
318
|
+
}
|
|
319
|
+
function createAddressResolutionState() {
|
|
320
|
+
return {
|
|
321
|
+
resolved: null,
|
|
322
|
+
loading: false,
|
|
323
|
+
error: null
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
async function resolveAddressWithState(address, _state, updateCallback, chainId) {
|
|
327
|
+
updateCallback({ loading: true, error: null });
|
|
328
|
+
try {
|
|
329
|
+
const resolved = await resolveAddress(address, chainId);
|
|
330
|
+
updateCallback({
|
|
331
|
+
resolved,
|
|
332
|
+
loading: false,
|
|
333
|
+
error: null
|
|
334
|
+
});
|
|
335
|
+
} catch (error) {
|
|
336
|
+
updateCallback({
|
|
337
|
+
loading: false,
|
|
338
|
+
error: error instanceof Error ? error.message : "Resolution failed"
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
var chainBatchStates, BATCH_DELAY, BATCH_SIZE;
|
|
343
|
+
var init_useAddressResolution = __esm({
|
|
344
|
+
"src/hooks/useAddressResolution.ts"() {
|
|
345
|
+
"use strict";
|
|
346
|
+
init_lukso_config();
|
|
347
|
+
chainBatchStates = /* @__PURE__ */ new Map();
|
|
348
|
+
BATCH_DELAY = 0;
|
|
349
|
+
BATCH_SIZE = 50;
|
|
350
|
+
}
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
// src/composables/index.ts
|
|
354
|
+
init_lukso_config();
|
|
355
|
+
init_useAddressResolution();
|
|
356
|
+
|
|
357
|
+
// src/composables/use-image-loader.ts
|
|
358
|
+
console.log(
|
|
359
|
+
"\u{1F525} LOADING NEW useAddressResolver CODE - should see GraphQL integration"
|
|
360
|
+
);
|
|
361
|
+
var imageLoadCache = /* @__PURE__ */ new Map();
|
|
362
|
+
function getImageCacheKey(imageData, options) {
|
|
363
|
+
const imageUrls = imageData.filter((img) => img?.url || img?.src).map((img) => img.url || img.src).sort().join(",");
|
|
364
|
+
const sizeKey = `${options.width || 32}x${options.height || options.width || 32}@${options.dpr || 1}`;
|
|
365
|
+
return `${imageUrls}-${sizeKey}`;
|
|
366
|
+
}
|
|
367
|
+
function useImageLoader() {
|
|
368
|
+
async function loadImage(imageData, options = {}) {
|
|
369
|
+
try {
|
|
370
|
+
if (!imageData || imageData.length === 0) {
|
|
371
|
+
return null;
|
|
372
|
+
}
|
|
373
|
+
const loadOptions = {
|
|
374
|
+
width: options.width || 32,
|
|
375
|
+
height: options.height || options.width || 32,
|
|
376
|
+
dpr: options.dpr || (typeof window !== "undefined" ? window.devicePixelRatio : 1),
|
|
377
|
+
ignoreHead: true
|
|
378
|
+
// Skip HEAD requests in component context
|
|
379
|
+
};
|
|
380
|
+
const cacheKey = getImageCacheKey(imageData, loadOptions);
|
|
381
|
+
const cachedPromise = imageLoadCache.get(cacheKey);
|
|
382
|
+
if (cachedPromise) {
|
|
383
|
+
console.log("\u{1F4F8} loadImage: Using cached promise for", cacheKey);
|
|
384
|
+
return cachedPromise;
|
|
385
|
+
}
|
|
386
|
+
console.log(
|
|
387
|
+
"\u{1F4F8} loadImage: Creating new request for",
|
|
388
|
+
imageData.length,
|
|
389
|
+
"options:",
|
|
390
|
+
loadOptions
|
|
391
|
+
);
|
|
392
|
+
const loadingPromise = (async () => {
|
|
393
|
+
const { getImage } = await import("@lukso/transaction-decoder");
|
|
394
|
+
const result = await getImage(imageData, loadOptions);
|
|
395
|
+
if (result?.src) {
|
|
396
|
+
console.log("\u{1F4F8} loadImage: Selected image:", result.src);
|
|
397
|
+
return {
|
|
398
|
+
src: result.src,
|
|
399
|
+
width: result.width,
|
|
400
|
+
height: result.height
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
return null;
|
|
404
|
+
})();
|
|
405
|
+
imageLoadCache.set(cacheKey, loadingPromise);
|
|
406
|
+
loadingPromise.finally(() => {
|
|
407
|
+
loadingPromise.then((result) => {
|
|
408
|
+
if (!result) {
|
|
409
|
+
imageLoadCache.delete(cacheKey);
|
|
410
|
+
}
|
|
411
|
+
}).catch(() => {
|
|
412
|
+
imageLoadCache.delete(cacheKey);
|
|
413
|
+
});
|
|
414
|
+
});
|
|
415
|
+
return loadingPromise;
|
|
416
|
+
} catch (error) {
|
|
417
|
+
console.warn("Failed to load image:", error);
|
|
418
|
+
return null;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
async function loadProfileImage(addressData, options = {}) {
|
|
422
|
+
if (addressData.__gqltype === "Profile") {
|
|
423
|
+
if (addressData.profileImages?.length) {
|
|
424
|
+
const result = await loadImage(addressData.profileImages, options);
|
|
425
|
+
if (result) return result;
|
|
426
|
+
}
|
|
427
|
+
if (addressData.icons?.length) {
|
|
428
|
+
const result = await loadImage(addressData.icons, options);
|
|
429
|
+
if (result) return result;
|
|
430
|
+
}
|
|
431
|
+
if (addressData.images?.length) {
|
|
432
|
+
return loadImage(addressData.images, options);
|
|
433
|
+
}
|
|
434
|
+
return null;
|
|
435
|
+
}
|
|
436
|
+
if (addressData.icons?.length) {
|
|
437
|
+
const result = await loadImage(addressData.icons, options);
|
|
438
|
+
if (result) return result;
|
|
439
|
+
}
|
|
440
|
+
if (addressData.images?.length) {
|
|
441
|
+
return loadImage(addressData.images, options);
|
|
442
|
+
}
|
|
443
|
+
return null;
|
|
444
|
+
}
|
|
445
|
+
async function loadBackgroundImage(addressData, options = {}) {
|
|
446
|
+
const imageGroup = addressData.backgroundImages || [];
|
|
447
|
+
return loadImage(imageGroup, options);
|
|
448
|
+
}
|
|
449
|
+
function getFallbackImage(addressData) {
|
|
450
|
+
const isProfile = addressData.__gqltype === "Profile";
|
|
451
|
+
return {
|
|
452
|
+
src: isProfile ? "/assets/images/profile-default.svg" : "/assets/images/token-default.svg"
|
|
453
|
+
};
|
|
454
|
+
}
|
|
455
|
+
function isContractAddress(addressData) {
|
|
456
|
+
return addressData.__gqltype !== "Profile";
|
|
457
|
+
}
|
|
458
|
+
return {
|
|
459
|
+
loadImage,
|
|
460
|
+
loadProfileImage,
|
|
461
|
+
loadBackgroundImage,
|
|
462
|
+
getFallbackImage,
|
|
463
|
+
isContractAddress
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
function useAddressResolver() {
|
|
467
|
+
async function resolveAddress2(address) {
|
|
468
|
+
console.log("\u{1F525} useAddressResolver.resolveAddress called with:", address);
|
|
469
|
+
try {
|
|
470
|
+
const { resolveAddress: batchedResolve } = await Promise.resolve().then(() => (init_useAddressResolution(), useAddressResolution_exports));
|
|
471
|
+
console.log("\u{1F525} useAddressResolver: calling batchedResolve...");
|
|
472
|
+
const resolved = await batchedResolve(address);
|
|
473
|
+
console.log("\u{1F525} useAddressResolver: batchedResolve returned:", resolved);
|
|
474
|
+
const result = {
|
|
475
|
+
// Preserve all image arrays from GraphQL
|
|
476
|
+
...resolved,
|
|
477
|
+
// Override with computed values only if not already set by GraphQL
|
|
478
|
+
address: resolved.address,
|
|
479
|
+
name: resolved.name || "",
|
|
480
|
+
__gqltype: resolved.__gqltype || (resolved.hasProfile ? "Profile" : "Contract")
|
|
481
|
+
};
|
|
482
|
+
console.log("\u{1F525} useAddressResolver: returning result:", result);
|
|
483
|
+
return result;
|
|
484
|
+
} catch (error) {
|
|
485
|
+
console.error("\u{1F525} useAddressResolver: Failed to resolve address:", error);
|
|
486
|
+
return {
|
|
487
|
+
address,
|
|
488
|
+
name: "",
|
|
489
|
+
__gqltype: "Contract",
|
|
490
|
+
profileImages: [],
|
|
491
|
+
avatar: [],
|
|
492
|
+
icon: []
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
function formatDisplayName(addressData) {
|
|
497
|
+
const baseName = addressData.name?.toLowerCase?.() || addressData.lsp4TokenName || addressData.baseAsset?.lsp4TokenName || "";
|
|
498
|
+
const symbol = addressData.lsp4TokenSymbol || addressData.baseAsset?.lsp4TokenSymbol || "";
|
|
499
|
+
return symbol ? `${baseName} (${symbol})` : baseName;
|
|
500
|
+
}
|
|
501
|
+
function getAddressPrefix(addressData) {
|
|
502
|
+
return addressData.__gqltype !== "Profile" ? "\u{1FA99} " : "@";
|
|
503
|
+
}
|
|
504
|
+
function shouldShowNameColor(addressData) {
|
|
505
|
+
return addressData.__gqltype === "Profile";
|
|
506
|
+
}
|
|
507
|
+
return {
|
|
508
|
+
resolveAddress: resolveAddress2,
|
|
509
|
+
formatDisplayName,
|
|
510
|
+
getAddressPrefix,
|
|
511
|
+
shouldShowNameColor
|
|
512
|
+
};
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
// src/utils/view-matcher.ts
|
|
516
|
+
var CRITERIA_WEIGHTS = {
|
|
517
|
+
recordType: 0.25,
|
|
518
|
+
// Most specific to transaction type
|
|
519
|
+
functionName: 0.2,
|
|
520
|
+
// Function-level specificity
|
|
521
|
+
context: 0.2,
|
|
522
|
+
// Context specificity (when opt-in)
|
|
523
|
+
standard: 0.15,
|
|
524
|
+
// LSP standard specificity
|
|
525
|
+
contractAddress: 0.1,
|
|
526
|
+
// Contract-specific logic
|
|
527
|
+
contextRequirements: 0.05,
|
|
528
|
+
// Context requirement matching
|
|
529
|
+
chainId: 0.03,
|
|
530
|
+
// Network-specific behavior
|
|
531
|
+
customMatcher: 0.02
|
|
532
|
+
// Custom logic (lowest weight due to unpredictability)
|
|
533
|
+
};
|
|
534
|
+
function calculateMatchScore(transaction, view, options) {
|
|
535
|
+
const { criteria } = view;
|
|
536
|
+
const matchedCriteria = [];
|
|
537
|
+
let totalWeight = 0;
|
|
538
|
+
let matchedWeight = 0;
|
|
539
|
+
for (const [criterion, weight] of Object.entries(CRITERIA_WEIGHTS)) {
|
|
540
|
+
const criterionKey = criterion;
|
|
541
|
+
const criterionValue = criteria[criterionKey];
|
|
542
|
+
if (criterionValue === void 0) continue;
|
|
543
|
+
totalWeight += weight;
|
|
544
|
+
if (criterionKey === "customMatcher" && typeof criterionValue === "function") {
|
|
545
|
+
try {
|
|
546
|
+
const matchCount = criterionValue(transaction);
|
|
547
|
+
if (matchCount > 0) {
|
|
548
|
+
matchedCriteria.push(criterionKey);
|
|
549
|
+
const normalizedScore = Math.min(matchCount / 10, 1);
|
|
550
|
+
matchedWeight += weight * normalizedScore;
|
|
551
|
+
}
|
|
552
|
+
} catch (error) {
|
|
553
|
+
console.warn("Custom matcher threw error:", error);
|
|
554
|
+
}
|
|
555
|
+
continue;
|
|
556
|
+
}
|
|
557
|
+
if (doesCriterionMatch(transaction, criterionKey, criterionValue, options)) {
|
|
558
|
+
matchedCriteria.push(criterionKey);
|
|
559
|
+
matchedWeight += weight;
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
const viewHasContext = criteria.context !== void 0;
|
|
563
|
+
const requestHasContext = options?.context !== void 0;
|
|
564
|
+
if (viewHasContext && !requestHasContext) {
|
|
565
|
+
matchedWeight *= 0.1;
|
|
566
|
+
} else if (!viewHasContext && requestHasContext) {
|
|
567
|
+
matchedWeight *= 0.9;
|
|
568
|
+
}
|
|
569
|
+
if (totalWeight === 0) return { score: 0, matchedCriteria: [] };
|
|
570
|
+
const score = matchedWeight / totalWeight;
|
|
571
|
+
return { score, matchedCriteria };
|
|
572
|
+
}
|
|
573
|
+
function doesCriterionMatch(transaction, criterion, criterionValue, options) {
|
|
574
|
+
switch (criterion) {
|
|
575
|
+
case "recordType":
|
|
576
|
+
return matchesStringOrArray(
|
|
577
|
+
transaction.recordType,
|
|
578
|
+
criterionValue
|
|
579
|
+
);
|
|
580
|
+
case "functionName":
|
|
581
|
+
return matchesStringOrArray(
|
|
582
|
+
transaction.functionName,
|
|
583
|
+
criterionValue
|
|
584
|
+
);
|
|
585
|
+
case "standard":
|
|
586
|
+
return matchesStringOrArray(
|
|
587
|
+
transaction.standard,
|
|
588
|
+
criterionValue
|
|
589
|
+
);
|
|
590
|
+
case "contractAddress":
|
|
591
|
+
return matchesStringOrArray(
|
|
592
|
+
transaction.contractAddress,
|
|
593
|
+
criterionValue
|
|
594
|
+
);
|
|
595
|
+
case "chainId":
|
|
596
|
+
return matchesNumberOrArray(transaction.chainId, criterionValue);
|
|
597
|
+
case "context":
|
|
598
|
+
if (!options?.context) return false;
|
|
599
|
+
return matchesStringOrArray(options.context, criterionValue);
|
|
600
|
+
case "contextRequirements":
|
|
601
|
+
if (!options?.contextRequirements || !criterionValue) return false;
|
|
602
|
+
return areContextRequirementsCompatible(
|
|
603
|
+
options.contextRequirements,
|
|
604
|
+
criterionValue
|
|
605
|
+
);
|
|
606
|
+
case "customMatcher":
|
|
607
|
+
if (typeof criterionValue === "function") {
|
|
608
|
+
try {
|
|
609
|
+
const matchCount = criterionValue(transaction);
|
|
610
|
+
return matchCount > 0;
|
|
611
|
+
} catch (error) {
|
|
612
|
+
console.warn("Custom matcher threw error:", error);
|
|
613
|
+
return false;
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
return false;
|
|
617
|
+
default:
|
|
618
|
+
return false;
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
function matchesStringOrArray(value, criteria) {
|
|
622
|
+
if (!value || !criteria) return false;
|
|
623
|
+
if (Array.isArray(criteria)) {
|
|
624
|
+
return criteria.includes(value);
|
|
625
|
+
}
|
|
626
|
+
return value === criteria;
|
|
627
|
+
}
|
|
628
|
+
function matchesNumberOrArray(value, criteria) {
|
|
629
|
+
if (value === void 0 || criteria === void 0) return false;
|
|
630
|
+
if (Array.isArray(criteria)) {
|
|
631
|
+
return criteria.includes(value);
|
|
632
|
+
}
|
|
633
|
+
return value === criteria;
|
|
634
|
+
}
|
|
635
|
+
function areContextRequirementsCompatible(requested, viewRequirements) {
|
|
636
|
+
if (requested.detailLevel && viewRequirements.detailLevel) {
|
|
637
|
+
const detailOrder = ["minimal", "summary", "full", "debug"];
|
|
638
|
+
const requestedLevel = detailOrder.indexOf(requested.detailLevel);
|
|
639
|
+
const viewLevel = detailOrder.indexOf(viewRequirements.detailLevel);
|
|
640
|
+
if (viewLevel < requestedLevel) return false;
|
|
641
|
+
}
|
|
642
|
+
if (requested.maxHeight && viewRequirements.maxHeight) {
|
|
643
|
+
if (viewRequirements.maxHeight > requested.maxHeight) return false;
|
|
644
|
+
}
|
|
645
|
+
return true;
|
|
646
|
+
}
|
|
647
|
+
function calculateNativeFrameworkBonus(view, requestedFramework) {
|
|
648
|
+
if (requestedFramework === "lit") {
|
|
649
|
+
return 0;
|
|
650
|
+
}
|
|
651
|
+
if (requestedFramework === "vue" && view.frameworks.vue) {
|
|
652
|
+
return 0.15;
|
|
653
|
+
}
|
|
654
|
+
if (requestedFramework === "rn" && view.frameworks.rn) {
|
|
655
|
+
return 0.15;
|
|
656
|
+
}
|
|
657
|
+
return 0;
|
|
658
|
+
}
|
|
659
|
+
function findMatchingViews(transaction, views, options) {
|
|
660
|
+
const matches = [];
|
|
661
|
+
const minScore = options.minScore ?? 0;
|
|
662
|
+
for (const view of views) {
|
|
663
|
+
if (!view.frameworks[options.framework]) {
|
|
664
|
+
continue;
|
|
665
|
+
}
|
|
666
|
+
const { score, matchedCriteria } = calculateMatchScore(transaction, view, {
|
|
667
|
+
context: options.context,
|
|
668
|
+
contextRequirements: options.contextRequirements
|
|
669
|
+
});
|
|
670
|
+
if (score < minScore) {
|
|
671
|
+
continue;
|
|
672
|
+
}
|
|
673
|
+
const frameworkBonus = calculateNativeFrameworkBonus(
|
|
674
|
+
view,
|
|
675
|
+
options.framework
|
|
676
|
+
);
|
|
677
|
+
const finalScore = Math.min(1, score + frameworkBonus);
|
|
678
|
+
const match = {
|
|
679
|
+
view,
|
|
680
|
+
score: finalScore,
|
|
681
|
+
matchedCriteria,
|
|
682
|
+
frameworkConfig: options.includeFrameworkConfig ? view.frameworks[options.framework] : void 0
|
|
683
|
+
};
|
|
684
|
+
matches.push(match);
|
|
685
|
+
}
|
|
686
|
+
matches.sort((a, b) => {
|
|
687
|
+
if (a.score !== b.score) {
|
|
688
|
+
return b.score - a.score;
|
|
689
|
+
}
|
|
690
|
+
return b.view.priority - a.view.priority;
|
|
691
|
+
});
|
|
692
|
+
if (options.maxMatches) {
|
|
693
|
+
return matches.slice(0, options.maxMatches);
|
|
694
|
+
}
|
|
695
|
+
return matches;
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
// src/registry/view-registry.ts
|
|
699
|
+
var DefaultViewRegistry = class {
|
|
700
|
+
views = /* @__PURE__ */ new Map();
|
|
701
|
+
register(view) {
|
|
702
|
+
if (this.views.has(view.id)) {
|
|
703
|
+
console.warn(
|
|
704
|
+
`View with id "${view.id}" is already registered. Overwriting.`
|
|
705
|
+
);
|
|
706
|
+
}
|
|
707
|
+
this.views.set(view.id, view);
|
|
708
|
+
}
|
|
709
|
+
unregister(viewId) {
|
|
710
|
+
this.views.delete(viewId);
|
|
711
|
+
}
|
|
712
|
+
getAllViews() {
|
|
713
|
+
return Array.from(this.views.values());
|
|
714
|
+
}
|
|
715
|
+
findMatches(transaction, options) {
|
|
716
|
+
const allViews = this.getAllViews();
|
|
717
|
+
return findMatchingViews(transaction, allViews, options);
|
|
718
|
+
}
|
|
719
|
+
getView(viewId) {
|
|
720
|
+
return this.views.get(viewId);
|
|
721
|
+
}
|
|
722
|
+
clear() {
|
|
723
|
+
this.views.clear();
|
|
724
|
+
}
|
|
725
|
+
/**
|
|
726
|
+
* Get the best matching view (highest score) for a transaction
|
|
727
|
+
*/
|
|
728
|
+
getBestMatch(transaction, options) {
|
|
729
|
+
const matches = this.findMatches(transaction, { ...options, maxMatches: 1 });
|
|
730
|
+
return matches[0] || null;
|
|
731
|
+
}
|
|
732
|
+
/**
|
|
733
|
+
* Bulk register multiple views
|
|
734
|
+
*/
|
|
735
|
+
registerMany(views) {
|
|
736
|
+
for (const view of views) {
|
|
737
|
+
this.register(view);
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
/**
|
|
741
|
+
* Get stats about registered views
|
|
742
|
+
*/
|
|
743
|
+
getStats() {
|
|
744
|
+
const allViews = this.getAllViews();
|
|
745
|
+
const totalViews = allViews.length;
|
|
746
|
+
const viewsByFramework = {};
|
|
747
|
+
const viewsByRecordType = {};
|
|
748
|
+
for (const view of allViews) {
|
|
749
|
+
for (const framework of Object.keys(view.frameworks)) {
|
|
750
|
+
viewsByFramework[framework] = (viewsByFramework[framework] || 0) + 1;
|
|
751
|
+
}
|
|
752
|
+
const recordType = view.criteria.recordType;
|
|
753
|
+
if (recordType) {
|
|
754
|
+
const types = Array.isArray(recordType) ? recordType : [recordType];
|
|
755
|
+
for (const type of types) {
|
|
756
|
+
viewsByRecordType[type] = (viewsByRecordType[type] || 0) + 1;
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
return {
|
|
761
|
+
totalViews,
|
|
762
|
+
viewsByFramework,
|
|
763
|
+
viewsByRecordType
|
|
764
|
+
};
|
|
765
|
+
}
|
|
766
|
+
};
|
|
767
|
+
var globalRegistry = null;
|
|
768
|
+
function getGlobalRegistry() {
|
|
769
|
+
if (!globalRegistry) {
|
|
770
|
+
globalRegistry = new DefaultViewRegistry();
|
|
771
|
+
}
|
|
772
|
+
return globalRegistry;
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
// src/composables/use-transaction-playback.ts
|
|
776
|
+
function isBatchTransaction(transaction) {
|
|
777
|
+
return transaction.resultType === "executeBatch" || transaction.resultType === "setDataBatch" || !!transaction.children?.length;
|
|
778
|
+
}
|
|
779
|
+
function getBatchChildren(transaction) {
|
|
780
|
+
if (!isBatchTransaction(transaction)) {
|
|
781
|
+
return [];
|
|
782
|
+
}
|
|
783
|
+
return transaction.children || [];
|
|
784
|
+
}
|
|
785
|
+
function selectViewAtIndex(rootTransaction, index, options) {
|
|
786
|
+
const {
|
|
787
|
+
registry = getGlobalRegistry(),
|
|
788
|
+
framework = "lit",
|
|
789
|
+
fallbackViewId,
|
|
790
|
+
minScore = 0,
|
|
791
|
+
includeFrameworkConfig = true
|
|
792
|
+
} = options;
|
|
793
|
+
const isBatch = isBatchTransaction(rootTransaction);
|
|
794
|
+
const children = getBatchChildren(rootTransaction);
|
|
795
|
+
const childCount = children.length;
|
|
796
|
+
const result = {
|
|
797
|
+
match: null,
|
|
798
|
+
transaction: null,
|
|
799
|
+
indexInfo: {
|
|
800
|
+
requested: index,
|
|
801
|
+
childIndex: null,
|
|
802
|
+
isBatchSummary: false,
|
|
803
|
+
isValid: false
|
|
804
|
+
},
|
|
805
|
+
batchInfo: {
|
|
806
|
+
isBatch,
|
|
807
|
+
childCount,
|
|
808
|
+
availableIndices: []
|
|
809
|
+
}
|
|
810
|
+
};
|
|
811
|
+
if (isBatch) {
|
|
812
|
+
result.batchInfo.availableIndices = Array.from(
|
|
813
|
+
{ length: childCount + 1 },
|
|
814
|
+
(_, i) => i
|
|
815
|
+
);
|
|
816
|
+
} else {
|
|
817
|
+
result.batchInfo.availableIndices = [0, 1];
|
|
818
|
+
}
|
|
819
|
+
if (index < 0) {
|
|
820
|
+
return result;
|
|
821
|
+
}
|
|
822
|
+
if (!isBatch) {
|
|
823
|
+
if (index === 0 || index === 1) {
|
|
824
|
+
result.indexInfo.isValid = true;
|
|
825
|
+
result.transaction = rootTransaction;
|
|
826
|
+
const matchOptions = {
|
|
827
|
+
framework,
|
|
828
|
+
minScore,
|
|
829
|
+
maxMatches: 1,
|
|
830
|
+
includeFrameworkConfig
|
|
831
|
+
};
|
|
832
|
+
const matches = registry.findMatches(rootTransaction, matchOptions);
|
|
833
|
+
result.match = matches[0] || null;
|
|
834
|
+
if (!result.match && fallbackViewId) {
|
|
835
|
+
const fallbackView = registry.getView(fallbackViewId);
|
|
836
|
+
if (fallbackView && fallbackView.frameworks[framework]) {
|
|
837
|
+
result.match = {
|
|
838
|
+
view: fallbackView,
|
|
839
|
+
score: 0,
|
|
840
|
+
matchedCriteria: [],
|
|
841
|
+
frameworkConfig: includeFrameworkConfig ? fallbackView.frameworks[framework] : void 0
|
|
842
|
+
};
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
return result;
|
|
846
|
+
}
|
|
847
|
+
return result;
|
|
848
|
+
}
|
|
849
|
+
if (index === 0) {
|
|
850
|
+
result.indexInfo.isValid = true;
|
|
851
|
+
result.indexInfo.isBatchSummary = true;
|
|
852
|
+
result.transaction = rootTransaction;
|
|
853
|
+
const matchOptions = {
|
|
854
|
+
framework,
|
|
855
|
+
minScore,
|
|
856
|
+
maxMatches: 1,
|
|
857
|
+
includeFrameworkConfig
|
|
858
|
+
};
|
|
859
|
+
const matches = registry.findMatches(rootTransaction, matchOptions);
|
|
860
|
+
result.match = matches[0] || null;
|
|
861
|
+
if (!result.match && fallbackViewId) {
|
|
862
|
+
const fallbackView = registry.getView(fallbackViewId);
|
|
863
|
+
if (fallbackView && fallbackView.frameworks[framework]) {
|
|
864
|
+
result.match = {
|
|
865
|
+
view: fallbackView,
|
|
866
|
+
score: 0,
|
|
867
|
+
matchedCriteria: [],
|
|
868
|
+
frameworkConfig: includeFrameworkConfig ? fallbackView.frameworks[framework] : void 0
|
|
869
|
+
};
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
return result;
|
|
873
|
+
}
|
|
874
|
+
const childIndex = index - 1;
|
|
875
|
+
if (childIndex >= 0 && childIndex < childCount) {
|
|
876
|
+
result.indexInfo.isValid = true;
|
|
877
|
+
result.indexInfo.childIndex = childIndex;
|
|
878
|
+
result.transaction = children[childIndex];
|
|
879
|
+
const matchOptions = {
|
|
880
|
+
framework,
|
|
881
|
+
minScore,
|
|
882
|
+
maxMatches: 1,
|
|
883
|
+
includeFrameworkConfig
|
|
884
|
+
};
|
|
885
|
+
const matches = registry.findMatches(result.transaction, matchOptions);
|
|
886
|
+
result.match = matches[0] || null;
|
|
887
|
+
if (!result.match && fallbackViewId) {
|
|
888
|
+
const fallbackView = registry.getView(fallbackViewId);
|
|
889
|
+
if (fallbackView && fallbackView.frameworks[framework]) {
|
|
890
|
+
result.match = {
|
|
891
|
+
view: fallbackView,
|
|
892
|
+
score: 0,
|
|
893
|
+
matchedCriteria: [],
|
|
894
|
+
frameworkConfig: includeFrameworkConfig ? fallbackView.frameworks[framework] : void 0
|
|
895
|
+
};
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
return result;
|
|
899
|
+
}
|
|
900
|
+
return result;
|
|
901
|
+
}
|
|
902
|
+
function createTransactionPlayback(rootTransaction, options = {}) {
|
|
903
|
+
const isBatch = isBatchTransaction(rootTransaction);
|
|
904
|
+
const children = getBatchChildren(rootTransaction);
|
|
905
|
+
const childCount = children.length;
|
|
906
|
+
const indexCount = isBatch ? childCount + 1 : 2;
|
|
907
|
+
const availableIndices = isBatch ? Array.from({ length: childCount + 1 }, (_, i) => i) : [0, 1];
|
|
908
|
+
return {
|
|
909
|
+
rootTransaction,
|
|
910
|
+
isBatch,
|
|
911
|
+
children,
|
|
912
|
+
indexCount,
|
|
913
|
+
batchInfo: {
|
|
914
|
+
isBatch,
|
|
915
|
+
childCount,
|
|
916
|
+
availableIndices
|
|
917
|
+
},
|
|
918
|
+
getViewAtIndex: (index) => selectViewAtIndex(rootTransaction, index, options),
|
|
919
|
+
getAllViews: () => {
|
|
920
|
+
const views = [];
|
|
921
|
+
for (let i = 0; i < indexCount; i++) {
|
|
922
|
+
views.push(selectViewAtIndex(rootTransaction, i, options));
|
|
923
|
+
}
|
|
924
|
+
return views;
|
|
925
|
+
}
|
|
926
|
+
};
|
|
927
|
+
}
|
|
928
|
+
function useTransactionPlayback(rootTransaction, index, options = {}) {
|
|
929
|
+
return selectViewAtIndex(rootTransaction, index, options);
|
|
930
|
+
}
|
|
931
|
+
function isValidPlaybackIndex(transaction, index) {
|
|
932
|
+
const isBatch = isBatchTransaction(transaction);
|
|
933
|
+
if (!isBatch) {
|
|
934
|
+
return index === 0 || index === 1;
|
|
935
|
+
}
|
|
936
|
+
const childCount = getBatchChildren(transaction).length;
|
|
937
|
+
return index >= 0 && index <= childCount;
|
|
938
|
+
}
|
|
939
|
+
function getValidPlaybackIndices(transaction) {
|
|
940
|
+
const isBatch = isBatchTransaction(transaction);
|
|
941
|
+
if (!isBatch) {
|
|
942
|
+
return [0, 1];
|
|
943
|
+
}
|
|
944
|
+
const childCount = getBatchChildren(transaction).length;
|
|
945
|
+
return Array.from({ length: childCount + 1 }, (_, i) => i);
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
// src/composables/use-transaction-view.ts
|
|
949
|
+
import {
|
|
950
|
+
fetchMultipleAddresses,
|
|
951
|
+
getGraphQLEndpoint
|
|
952
|
+
} from "@lukso/transaction-decoder";
|
|
953
|
+
|
|
954
|
+
// src/registry/view-loader.ts
|
|
955
|
+
var ViewLoadingError = class extends Error {
|
|
956
|
+
loader;
|
|
957
|
+
config;
|
|
958
|
+
cause;
|
|
959
|
+
constructor(message, loader, config, cause) {
|
|
960
|
+
super(message);
|
|
961
|
+
this.name = "ViewLoadingError";
|
|
962
|
+
this.loader = loader;
|
|
963
|
+
this.config = config;
|
|
964
|
+
this.cause = cause;
|
|
965
|
+
}
|
|
966
|
+
};
|
|
967
|
+
var UniversalViewLoader = class {
|
|
968
|
+
cache = /* @__PURE__ */ new Map();
|
|
969
|
+
/**
|
|
970
|
+
* Load a component based on the framework configuration
|
|
971
|
+
*/
|
|
972
|
+
async loadComponent(config) {
|
|
973
|
+
const cacheKey = this.getCacheKey(config);
|
|
974
|
+
if (this.cache.has(cacheKey)) {
|
|
975
|
+
return this.cache.get(cacheKey);
|
|
976
|
+
}
|
|
977
|
+
try {
|
|
978
|
+
const component = await this.loadByStrategy(config.loader);
|
|
979
|
+
this.cache.set(cacheKey, component);
|
|
980
|
+
return component;
|
|
981
|
+
} catch (error) {
|
|
982
|
+
throw new ViewLoadingError(
|
|
983
|
+
`Failed to load component "${config.component}"`,
|
|
984
|
+
config.loader,
|
|
985
|
+
config,
|
|
986
|
+
error instanceof Error ? error : new Error(String(error))
|
|
987
|
+
);
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
/**
|
|
991
|
+
* Load a component from a view match
|
|
992
|
+
*/
|
|
993
|
+
async loadFromMatch(match) {
|
|
994
|
+
if (!match.frameworkConfig) {
|
|
995
|
+
throw new ViewLoadingError(
|
|
996
|
+
`No framework config available for view "${match.view.id}"`,
|
|
997
|
+
{ type: "dynamic-import", path: "" },
|
|
998
|
+
{}
|
|
999
|
+
);
|
|
1000
|
+
}
|
|
1001
|
+
return this.loadComponent(match.frameworkConfig);
|
|
1002
|
+
}
|
|
1003
|
+
/**
|
|
1004
|
+
* Load component using the specific strategy
|
|
1005
|
+
*/
|
|
1006
|
+
async loadByStrategy(loader) {
|
|
1007
|
+
switch (loader.type) {
|
|
1008
|
+
case "dynamic-import":
|
|
1009
|
+
return this.loadDynamicImport(loader.path);
|
|
1010
|
+
case "static-import":
|
|
1011
|
+
return this.loadStaticImport(loader.path);
|
|
1012
|
+
case "custom-element":
|
|
1013
|
+
return this.loadCustomElement(loader.tagName);
|
|
1014
|
+
case "registry-lookup":
|
|
1015
|
+
return this.loadFromRegistry(loader.registryKey);
|
|
1016
|
+
case "custom":
|
|
1017
|
+
return loader.loader({});
|
|
1018
|
+
// Will be passed proper config in real usage
|
|
1019
|
+
default:
|
|
1020
|
+
throw new Error(`Unknown loader type: ${loader.type}`);
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
/**
|
|
1024
|
+
* Dynamic import strategy (most common)
|
|
1025
|
+
* Supports both static strings and lazy-loaded callbacks
|
|
1026
|
+
*/
|
|
1027
|
+
async loadDynamicImport(path) {
|
|
1028
|
+
if (typeof path === "function") {
|
|
1029
|
+
const module2 = await path();
|
|
1030
|
+
if (module2.default) {
|
|
1031
|
+
return module2.default;
|
|
1032
|
+
}
|
|
1033
|
+
return module2;
|
|
1034
|
+
}
|
|
1035
|
+
const module = await import(path);
|
|
1036
|
+
if (module.default) {
|
|
1037
|
+
return module.default;
|
|
1038
|
+
}
|
|
1039
|
+
return module;
|
|
1040
|
+
}
|
|
1041
|
+
/**
|
|
1042
|
+
* Static import strategy (requires bundler support)
|
|
1043
|
+
* Supports both static strings and lazy-loaded callbacks
|
|
1044
|
+
*/
|
|
1045
|
+
async loadStaticImport(path) {
|
|
1046
|
+
if (typeof path === "function") {
|
|
1047
|
+
const module = await path();
|
|
1048
|
+
if (module.default) {
|
|
1049
|
+
return module.default;
|
|
1050
|
+
}
|
|
1051
|
+
return module;
|
|
1052
|
+
}
|
|
1053
|
+
console.warn(
|
|
1054
|
+
"Static import not implemented, falling back to dynamic import"
|
|
1055
|
+
);
|
|
1056
|
+
return this.loadDynamicImport(path);
|
|
1057
|
+
}
|
|
1058
|
+
/**
|
|
1059
|
+
* Custom element strategy (for Lit components)
|
|
1060
|
+
*/
|
|
1061
|
+
async loadCustomElement(tagName) {
|
|
1062
|
+
if (typeof window !== "undefined" && window.customElements) {
|
|
1063
|
+
await window.customElements.whenDefined(tagName);
|
|
1064
|
+
return { tagName, type: "custom-element" };
|
|
1065
|
+
}
|
|
1066
|
+
throw new Error("Custom elements not available in this environment");
|
|
1067
|
+
}
|
|
1068
|
+
/**
|
|
1069
|
+
* Registry lookup strategy (for pre-registered components)
|
|
1070
|
+
*/
|
|
1071
|
+
async loadFromRegistry(registryKey) {
|
|
1072
|
+
throw new Error(`Registry lookup not implemented for key: ${registryKey}`);
|
|
1073
|
+
}
|
|
1074
|
+
/**
|
|
1075
|
+
* Generate cache key for component config
|
|
1076
|
+
*/
|
|
1077
|
+
getCacheKey(config) {
|
|
1078
|
+
const { loader, component, package: pkg } = config;
|
|
1079
|
+
return JSON.stringify({ loader, component, package: pkg });
|
|
1080
|
+
}
|
|
1081
|
+
/**
|
|
1082
|
+
* Clear the component cache
|
|
1083
|
+
*/
|
|
1084
|
+
clearCache() {
|
|
1085
|
+
this.cache.clear();
|
|
1086
|
+
}
|
|
1087
|
+
/**
|
|
1088
|
+
* Get cache statistics
|
|
1089
|
+
*/
|
|
1090
|
+
getCacheStats() {
|
|
1091
|
+
return {
|
|
1092
|
+
size: this.cache.size,
|
|
1093
|
+
keys: Array.from(this.cache.keys())
|
|
1094
|
+
};
|
|
1095
|
+
}
|
|
1096
|
+
};
|
|
1097
|
+
var globalLoader = null;
|
|
1098
|
+
function getGlobalLoader() {
|
|
1099
|
+
if (!globalLoader) {
|
|
1100
|
+
globalLoader = new UniversalViewLoader();
|
|
1101
|
+
}
|
|
1102
|
+
return globalLoader;
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
// src/composables/use-transaction-view.ts
|
|
1106
|
+
function useTransactionView(transaction, options) {
|
|
1107
|
+
const {
|
|
1108
|
+
registry = getGlobalRegistry(),
|
|
1109
|
+
autoLoad = false,
|
|
1110
|
+
fallbackViewId,
|
|
1111
|
+
framework = "lit",
|
|
1112
|
+
minScore = 0,
|
|
1113
|
+
maxMatches,
|
|
1114
|
+
includeFrameworkConfig = true,
|
|
1115
|
+
resolve = false,
|
|
1116
|
+
chain,
|
|
1117
|
+
addressCache: addressCache2
|
|
1118
|
+
} = options;
|
|
1119
|
+
const loader = getGlobalLoader();
|
|
1120
|
+
let matches = [];
|
|
1121
|
+
let bestMatch = null;
|
|
1122
|
+
let component = null;
|
|
1123
|
+
let isLoading = false;
|
|
1124
|
+
let error = null;
|
|
1125
|
+
let isResolvingAddresses = false;
|
|
1126
|
+
let resolvedAddresses = {};
|
|
1127
|
+
const refreshMatches = () => {
|
|
1128
|
+
const matchOptions = {
|
|
1129
|
+
framework,
|
|
1130
|
+
minScore,
|
|
1131
|
+
maxMatches,
|
|
1132
|
+
includeFrameworkConfig
|
|
1133
|
+
};
|
|
1134
|
+
matches = registry.findMatches(transaction, matchOptions);
|
|
1135
|
+
bestMatch = matches[0] || null;
|
|
1136
|
+
if (!bestMatch && fallbackViewId) {
|
|
1137
|
+
const fallbackView = registry.getView(fallbackViewId);
|
|
1138
|
+
if (fallbackView && fallbackView.frameworks[framework]) {
|
|
1139
|
+
bestMatch = {
|
|
1140
|
+
view: fallbackView,
|
|
1141
|
+
score: 0,
|
|
1142
|
+
matchedCriteria: [],
|
|
1143
|
+
frameworkConfig: includeFrameworkConfig ? fallbackView.frameworks[framework] : void 0
|
|
1144
|
+
};
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
};
|
|
1148
|
+
const loadMatch = async (match) => {
|
|
1149
|
+
if (!match.frameworkConfig) {
|
|
1150
|
+
throw new ViewLoadingError(
|
|
1151
|
+
`No framework config for view "${match.view.id}" and framework "${framework}"`,
|
|
1152
|
+
{ type: "dynamic-import", path: "" },
|
|
1153
|
+
{}
|
|
1154
|
+
);
|
|
1155
|
+
}
|
|
1156
|
+
isLoading = true;
|
|
1157
|
+
error = null;
|
|
1158
|
+
try {
|
|
1159
|
+
const loadedComponent = await loader.loadFromMatch(match);
|
|
1160
|
+
component = loadedComponent;
|
|
1161
|
+
return loadedComponent;
|
|
1162
|
+
} catch (err) {
|
|
1163
|
+
error = err instanceof ViewLoadingError ? err : new ViewLoadingError(
|
|
1164
|
+
"Unknown loading error",
|
|
1165
|
+
match.frameworkConfig.loader,
|
|
1166
|
+
match.frameworkConfig,
|
|
1167
|
+
err instanceof Error ? err : new Error(String(err))
|
|
1168
|
+
);
|
|
1169
|
+
throw error;
|
|
1170
|
+
} finally {
|
|
1171
|
+
isLoading = false;
|
|
1172
|
+
}
|
|
1173
|
+
};
|
|
1174
|
+
const loadBestMatch = async () => {
|
|
1175
|
+
if (!bestMatch) {
|
|
1176
|
+
throw new Error("No matching view found for transaction");
|
|
1177
|
+
}
|
|
1178
|
+
return loadMatch(bestMatch);
|
|
1179
|
+
};
|
|
1180
|
+
const resolveAddressesFunc = async () => {
|
|
1181
|
+
if (!resolve || !transaction.addresses || transaction.addresses.length === 0) {
|
|
1182
|
+
return;
|
|
1183
|
+
}
|
|
1184
|
+
if (!chain) {
|
|
1185
|
+
console.warn(
|
|
1186
|
+
"Address resolution requested but no chain provided. Pass chain option to resolve addresses."
|
|
1187
|
+
);
|
|
1188
|
+
return;
|
|
1189
|
+
}
|
|
1190
|
+
isResolvingAddresses = true;
|
|
1191
|
+
try {
|
|
1192
|
+
const dataKeys = transaction.addresses.filter((addr) => addr && typeof addr === "string").map((addr) => addr.toLowerCase());
|
|
1193
|
+
if (dataKeys.length === 0) {
|
|
1194
|
+
return;
|
|
1195
|
+
}
|
|
1196
|
+
const endpoint = getGraphQLEndpoint(chain);
|
|
1197
|
+
const resolvedMap = await fetchMultipleAddresses(
|
|
1198
|
+
dataKeys,
|
|
1199
|
+
endpoint,
|
|
1200
|
+
addressCache2
|
|
1201
|
+
);
|
|
1202
|
+
const resolved = {};
|
|
1203
|
+
resolvedMap.forEach((enhancedInfo, dataKey) => {
|
|
1204
|
+
resolved[dataKey] = enhancedInfo;
|
|
1205
|
+
});
|
|
1206
|
+
resolvedAddresses = resolved;
|
|
1207
|
+
} catch (err) {
|
|
1208
|
+
console.error("Address resolution failed:", err);
|
|
1209
|
+
} finally {
|
|
1210
|
+
isResolvingAddresses = false;
|
|
1211
|
+
}
|
|
1212
|
+
};
|
|
1213
|
+
refreshMatches();
|
|
1214
|
+
if (resolve) {
|
|
1215
|
+
resolveAddressesFunc().catch((err) => {
|
|
1216
|
+
console.error("Auto address resolution failed:", err);
|
|
1217
|
+
});
|
|
1218
|
+
}
|
|
1219
|
+
if (autoLoad && bestMatch) {
|
|
1220
|
+
loadBestMatch().catch((err) => {
|
|
1221
|
+
console.error("Auto-load failed:", err);
|
|
1222
|
+
});
|
|
1223
|
+
}
|
|
1224
|
+
return {
|
|
1225
|
+
matches,
|
|
1226
|
+
bestMatch,
|
|
1227
|
+
component,
|
|
1228
|
+
isLoading,
|
|
1229
|
+
error,
|
|
1230
|
+
isResolvingAddresses,
|
|
1231
|
+
resolvedAddresses,
|
|
1232
|
+
loadMatch,
|
|
1233
|
+
loadBestMatch,
|
|
1234
|
+
refreshMatches,
|
|
1235
|
+
resolveAddresses: resolveAddressesFunc
|
|
1236
|
+
};
|
|
1237
|
+
}
|
|
1238
|
+
function findBestTransactionView(transaction, framework, registry) {
|
|
1239
|
+
const reg = registry || getGlobalRegistry();
|
|
1240
|
+
const matches = reg.findMatches(transaction, {
|
|
1241
|
+
framework,
|
|
1242
|
+
includeFrameworkConfig: true
|
|
1243
|
+
});
|
|
1244
|
+
return matches.length > 0 ? matches[0] : null;
|
|
1245
|
+
}
|
|
1246
|
+
function findAllTransactionViews(transaction, framework, registry) {
|
|
1247
|
+
const reg = registry || getGlobalRegistry();
|
|
1248
|
+
return reg.findMatches(transaction, {
|
|
1249
|
+
framework,
|
|
1250
|
+
includeFrameworkConfig: true
|
|
1251
|
+
});
|
|
1252
|
+
}
|
|
1253
|
+
export {
|
|
1254
|
+
cacheAddress,
|
|
1255
|
+
clearAddressCache,
|
|
1256
|
+
createAddressResolutionState,
|
|
1257
|
+
createTransactionPlayback,
|
|
1258
|
+
findAllTransactionViews,
|
|
1259
|
+
findBestTransactionView,
|
|
1260
|
+
getCachedAddress,
|
|
1261
|
+
getLuksoConfig,
|
|
1262
|
+
getValidPlaybackIndices,
|
|
1263
|
+
isAddressResolutionEnabled,
|
|
1264
|
+
isValidPlaybackIndex,
|
|
1265
|
+
resolveAddress,
|
|
1266
|
+
resolveAddressWithState,
|
|
1267
|
+
resolveAddresses,
|
|
1268
|
+
setLuksoConfig,
|
|
1269
|
+
useAddressResolver,
|
|
1270
|
+
useImageLoader,
|
|
1271
|
+
useLuksoMainnet,
|
|
1272
|
+
useLuksoTestnet,
|
|
1273
|
+
useTransactionPlayback,
|
|
1274
|
+
useTransactionView
|
|
1275
|
+
};
|
|
1276
|
+
//# sourceMappingURL=index.js.map
|