@manifoldxyz/marketplace-sdk 4.0.1 → 4.0.2
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/classes/Token.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ interface IToken {
|
|
|
11
11
|
attributes: Array<object> | undefined;
|
|
12
12
|
tokenData: JSON | undefined;
|
|
13
13
|
originalURI: string;
|
|
14
|
+
burnt?: boolean;
|
|
14
15
|
}
|
|
15
16
|
declare class Token implements IToken {
|
|
16
17
|
address: string;
|
|
@@ -25,6 +26,7 @@ declare class Token implements IToken {
|
|
|
25
26
|
attributes: Array<object> | undefined;
|
|
26
27
|
tokenData: JSON | undefined;
|
|
27
28
|
originalURI: string;
|
|
28
|
-
|
|
29
|
+
burnt?: boolean | undefined;
|
|
30
|
+
constructor(address: string, id: string, lazy: boolean, image_url: string, original_image_url: string | undefined, animation_url: string | undefined, original_animation_url: string | undefined, name: string, description: string, attributes: Array<object> | undefined, tokenData: JSON | undefined, originalURI: string, burnt?: boolean);
|
|
29
31
|
}
|
|
30
32
|
export default Token;
|
package/dist/classes/Token.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
class Token {
|
|
4
4
|
constructor(address, id, lazy, image_url, original_image_url, animation_url, original_animation_url, name, description,
|
|
5
5
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
6
|
-
attributes, tokenData, originalURI) {
|
|
6
|
+
attributes, tokenData, originalURI, burnt) {
|
|
7
7
|
this.address = address;
|
|
8
8
|
this.id = id;
|
|
9
9
|
this.lazy = lazy;
|
|
@@ -16,6 +16,7 @@ class Token {
|
|
|
16
16
|
this.attributes = attributes;
|
|
17
17
|
this.tokenData = tokenData;
|
|
18
18
|
this.originalURI = originalURI;
|
|
19
|
+
this.burnt = burnt;
|
|
19
20
|
}
|
|
20
21
|
}
|
|
21
22
|
exports.default = Token;
|
|
@@ -1221,7 +1221,7 @@ class MarketplaceListing {
|
|
|
1221
1221
|
* Get token details for this listing
|
|
1222
1222
|
*/
|
|
1223
1223
|
getTokenDetails() {
|
|
1224
|
-
var _a, _b, _c, _d;
|
|
1224
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
1225
1225
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1226
1226
|
let tokenURI;
|
|
1227
1227
|
let tokenSpec = '';
|
|
@@ -1259,9 +1259,25 @@ class MarketplaceListing {
|
|
|
1259
1259
|
bridgeContract = this._getLazyDeliveryContract(false, true);
|
|
1260
1260
|
contractFunctionName = 'assetURI';
|
|
1261
1261
|
}
|
|
1262
|
-
|
|
1263
|
-
// Parse token data and return
|
|
1262
|
+
// Try to get tokenURI from contract, but if token is burnt, fall back to cached data
|
|
1264
1263
|
let tokenData;
|
|
1264
|
+
try {
|
|
1265
|
+
tokenURI = yield (0, Web3Protocol_1.callWeb3)(contract, bridgeContract, contractFunctionName, [tokenId]);
|
|
1266
|
+
}
|
|
1267
|
+
catch (error) {
|
|
1268
|
+
// Token might be burnt - try to get cached data from API, include token details to get name, description
|
|
1269
|
+
const cachedData = yield this._fetchCachedTokenData(tokenId, tokenLazy, true);
|
|
1270
|
+
if (cachedData) {
|
|
1271
|
+
return new Token_1.default(
|
|
1272
|
+
// @ts-expect-error TS2532: Object is possibly 'undefined'.
|
|
1273
|
+
this.listing.tokenAddress, tokenId, tokenSpec == '', cachedData.image_url, cachedData.original_image_url, cachedData.animation_url, cachedData.original_animation_url, (_a = cachedData.tokenDetails) === null || _a === void 0 ? void 0 : _a.name, (_c = (_b = cachedData.tokenDetails) === null || _b === void 0 ? void 0 : _b.metadata) === null || _c === void 0 ? void 0 : _c.description, cachedData.attributes, cachedData, cachedData.token_uri, ((_e = (_d = cachedData.tokenDetails) === null || _d === void 0 ? void 0 : _d.ownerAddress) === null || _e === void 0 ? void 0 : _e.toLowerCase()) ===
|
|
1274
|
+
'0x000000000000000000000000000000000000dead' ||
|
|
1275
|
+
((_g = (_f = cachedData.tokenDetails) === null || _f === void 0 ? void 0 : _f.ownerAddress) === null || _g === void 0 ? void 0 : _g.toLowerCase()) ===
|
|
1276
|
+
'0x0000000000000000000000000000000000000000');
|
|
1277
|
+
}
|
|
1278
|
+
throw error;
|
|
1279
|
+
}
|
|
1280
|
+
// Parse token data and return
|
|
1265
1281
|
try {
|
|
1266
1282
|
if (tokenURI.startsWith('data:application/json')) {
|
|
1267
1283
|
// Handling inline metadata
|
|
@@ -1312,31 +1328,25 @@ class MarketplaceListing {
|
|
|
1312
1328
|
}
|
|
1313
1329
|
tokenURI = this._cleanURI(tokenURI);
|
|
1314
1330
|
// @ts-expect-error TS2345: Argument of type 'string | undefined' is not assignable to parameter of type 'string'.
|
|
1315
|
-
tokenData = yield this._fetchMetadata((
|
|
1331
|
+
tokenData = yield this._fetchMetadata((_h = this.listing) === null || _h === void 0 ? void 0 : _h.tokenAddress, tokenId, tokenURI);
|
|
1316
1332
|
}
|
|
1317
1333
|
}
|
|
1318
1334
|
catch (error) {
|
|
1319
|
-
console.error(`ERROR: tokenDetails: ${(
|
|
1335
|
+
console.error(`ERROR: tokenDetails: ${(_j = this.listing) === null || _j === void 0 ? void 0 : _j.tokenAddress}/${tokenId}: ${tokenURI}`);
|
|
1320
1336
|
throw error;
|
|
1321
1337
|
}
|
|
1322
1338
|
this._processTokenData(tokenData);
|
|
1323
1339
|
// Try to get cache optimized image
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
if (
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
if (apiData.animation_status == 'ok' && apiData.original_animation_url)
|
|
1335
|
-
tokenData.original_animation_url = apiData.original_animation_url;
|
|
1336
|
-
}
|
|
1337
|
-
}
|
|
1338
|
-
catch (error) {
|
|
1339
|
-
// Do nothing
|
|
1340
|
+
const cachedData = yield this._fetchCachedTokenData(tokenId, tokenLazy);
|
|
1341
|
+
if (cachedData) {
|
|
1342
|
+
if (cachedData.image_status == 'ok' && cachedData.image_url)
|
|
1343
|
+
tokenData.image = cachedData.image_url;
|
|
1344
|
+
if (cachedData.image_status == 'ok' && cachedData.original_image_url)
|
|
1345
|
+
tokenData.original_image_url = cachedData.original_image_url;
|
|
1346
|
+
if (cachedData.animation_status == 'ok' && cachedData.animation_url)
|
|
1347
|
+
tokenData.animation_url = cachedData.animation_url;
|
|
1348
|
+
if (cachedData.animation_status == 'ok' && cachedData.original_animation_url)
|
|
1349
|
+
tokenData.original_animation_url = cachedData.original_animation_url;
|
|
1340
1350
|
}
|
|
1341
1351
|
return new Token_1.default(
|
|
1342
1352
|
// @ts-expect-error TS2532: Object is possibly 'undefined'.
|
|
@@ -1390,6 +1400,24 @@ class MarketplaceListing {
|
|
|
1390
1400
|
}
|
|
1391
1401
|
return uri;
|
|
1392
1402
|
}
|
|
1403
|
+
/**
|
|
1404
|
+
* Fetch cached token data from API
|
|
1405
|
+
*/
|
|
1406
|
+
_fetchCachedTokenData(tokenId, tokenLazy, withTokenDetails) {
|
|
1407
|
+
var _a, _b;
|
|
1408
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1409
|
+
try {
|
|
1410
|
+
const apiResponse = yield fetch(`${this._getEndpoint()}/token/${(_a = this.listing) === null || _a === void 0 ? void 0 : _a.tokenAddress}/${tokenId}/media?${((_b = this.overrides) === null || _b === void 0 ? void 0 : _b.mediaOptimization) ? this.overrides.mediaOptimization : 'max_width=1280'}${tokenLazy ? '&lazy=true' : ''}${withTokenDetails ? '&withTokenDetails=true' : ''}`);
|
|
1411
|
+
if (apiResponse.status === 200) {
|
|
1412
|
+
return apiResponse.json();
|
|
1413
|
+
}
|
|
1414
|
+
}
|
|
1415
|
+
catch (error) {
|
|
1416
|
+
// Return null if fetch fails
|
|
1417
|
+
}
|
|
1418
|
+
return null;
|
|
1419
|
+
});
|
|
1420
|
+
}
|
|
1393
1421
|
/**
|
|
1394
1422
|
* Get the bid history
|
|
1395
1423
|
*/
|