@manifoldxyz/marketplace-sdk 4.0.0 → 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;
|
|
@@ -75,7 +75,7 @@ declare class MarketplaceListing {
|
|
|
75
75
|
*/
|
|
76
76
|
private _setupInternalListeners;
|
|
77
77
|
/**
|
|
78
|
-
* Get the server time
|
|
78
|
+
* Get the server time offset
|
|
79
79
|
*/
|
|
80
80
|
private static _fetchServerTime;
|
|
81
81
|
/**
|
|
@@ -182,6 +182,10 @@ declare class MarketplaceListing {
|
|
|
182
182
|
*/
|
|
183
183
|
private _fetchMetadata;
|
|
184
184
|
private _cleanURI;
|
|
185
|
+
/**
|
|
186
|
+
* Fetch cached token data from API
|
|
187
|
+
*/
|
|
188
|
+
private _fetchCachedTokenData;
|
|
185
189
|
/**
|
|
186
190
|
* Get the bid history
|
|
187
191
|
*/
|
|
@@ -38,7 +38,7 @@ const Offer_1 = require("../classes/Offer");
|
|
|
38
38
|
const Purchase_1 = require("../classes/Purchase");
|
|
39
39
|
const Token_1 = __importDefault(require("../classes/Token"));
|
|
40
40
|
const Web3Protocol_1 = require("./Web3Protocol");
|
|
41
|
-
let
|
|
41
|
+
let serverTimeOffset;
|
|
42
42
|
let serverTimeFetch;
|
|
43
43
|
var MarketplaceTopic;
|
|
44
44
|
(function (MarketplaceTopic) {
|
|
@@ -361,13 +361,14 @@ class MarketplaceListing {
|
|
|
361
361
|
}
|
|
362
362
|
}
|
|
363
363
|
/**
|
|
364
|
-
* Get the server time
|
|
364
|
+
* Get the server time offset
|
|
365
365
|
*/
|
|
366
366
|
static _fetchServerTime() {
|
|
367
367
|
return __awaiter(this, void 0, void 0, function* () {
|
|
368
368
|
const serverTimeResponse = yield MarketplaceListing._fetchWithTimeout('https://oauth2.manifoldxyz.dev/time', {}, 1500);
|
|
369
369
|
if ((serverTimeResponse === null || serverTimeResponse === void 0 ? void 0 : serverTimeResponse.status) === 200) {
|
|
370
|
-
serverTime = (yield serverTimeResponse.json()).time;
|
|
370
|
+
const serverTime = (yield serverTimeResponse.json()).time;
|
|
371
|
+
serverTimeOffset = serverTime - Date.now();
|
|
371
372
|
}
|
|
372
373
|
});
|
|
373
374
|
}
|
|
@@ -376,22 +377,19 @@ class MarketplaceListing {
|
|
|
376
377
|
*/
|
|
377
378
|
static fetchOffset() {
|
|
378
379
|
return __awaiter(this, void 0, void 0, function* () {
|
|
379
|
-
let offset = 0;
|
|
380
380
|
try {
|
|
381
|
-
if (
|
|
381
|
+
if (serverTimeOffset === undefined) {
|
|
382
382
|
if (!serverTimeFetch) {
|
|
383
383
|
serverTimeFetch = MarketplaceListing._fetchServerTime();
|
|
384
|
-
yield serverTimeFetch;
|
|
385
384
|
}
|
|
385
|
+
yield serverTimeFetch;
|
|
386
386
|
}
|
|
387
|
-
if (serverTime)
|
|
388
|
-
offset = serverTime - Date.now();
|
|
389
387
|
}
|
|
390
388
|
catch (e) {
|
|
391
389
|
// Do nothing, not critical to get offset
|
|
392
390
|
console.log(`server time sync fetch error ${e}`);
|
|
393
391
|
}
|
|
394
|
-
return
|
|
392
|
+
return serverTimeOffset || 0;
|
|
395
393
|
});
|
|
396
394
|
}
|
|
397
395
|
/**
|
|
@@ -1223,7 +1221,7 @@ class MarketplaceListing {
|
|
|
1223
1221
|
* Get token details for this listing
|
|
1224
1222
|
*/
|
|
1225
1223
|
getTokenDetails() {
|
|
1226
|
-
var _a, _b, _c, _d;
|
|
1224
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
1227
1225
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1228
1226
|
let tokenURI;
|
|
1229
1227
|
let tokenSpec = '';
|
|
@@ -1261,9 +1259,25 @@ class MarketplaceListing {
|
|
|
1261
1259
|
bridgeContract = this._getLazyDeliveryContract(false, true);
|
|
1262
1260
|
contractFunctionName = 'assetURI';
|
|
1263
1261
|
}
|
|
1264
|
-
|
|
1265
|
-
// Parse token data and return
|
|
1262
|
+
// Try to get tokenURI from contract, but if token is burnt, fall back to cached data
|
|
1266
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
|
|
1267
1281
|
try {
|
|
1268
1282
|
if (tokenURI.startsWith('data:application/json')) {
|
|
1269
1283
|
// Handling inline metadata
|
|
@@ -1314,31 +1328,25 @@ class MarketplaceListing {
|
|
|
1314
1328
|
}
|
|
1315
1329
|
tokenURI = this._cleanURI(tokenURI);
|
|
1316
1330
|
// @ts-expect-error TS2345: Argument of type 'string | undefined' is not assignable to parameter of type 'string'.
|
|
1317
|
-
tokenData = yield this._fetchMetadata((
|
|
1331
|
+
tokenData = yield this._fetchMetadata((_h = this.listing) === null || _h === void 0 ? void 0 : _h.tokenAddress, tokenId, tokenURI);
|
|
1318
1332
|
}
|
|
1319
1333
|
}
|
|
1320
1334
|
catch (error) {
|
|
1321
|
-
console.error(`ERROR: tokenDetails: ${(
|
|
1335
|
+
console.error(`ERROR: tokenDetails: ${(_j = this.listing) === null || _j === void 0 ? void 0 : _j.tokenAddress}/${tokenId}: ${tokenURI}`);
|
|
1322
1336
|
throw error;
|
|
1323
1337
|
}
|
|
1324
1338
|
this._processTokenData(tokenData);
|
|
1325
1339
|
// Try to get cache optimized image
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
if (
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
if (apiData.animation_status == 'ok' && apiData.original_animation_url)
|
|
1337
|
-
tokenData.original_animation_url = apiData.original_animation_url;
|
|
1338
|
-
}
|
|
1339
|
-
}
|
|
1340
|
-
catch (error) {
|
|
1341
|
-
// 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;
|
|
1342
1350
|
}
|
|
1343
1351
|
return new Token_1.default(
|
|
1344
1352
|
// @ts-expect-error TS2532: Object is possibly 'undefined'.
|
|
@@ -1392,6 +1400,24 @@ class MarketplaceListing {
|
|
|
1392
1400
|
}
|
|
1393
1401
|
return uri;
|
|
1394
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
|
+
}
|
|
1395
1421
|
/**
|
|
1396
1422
|
* Get the bid history
|
|
1397
1423
|
*/
|