@eluvio/elv-client-js 4.0.17 → 4.0.19

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.
@@ -1310,8 +1310,22 @@ exports.DropStatus = async function({marketplace, eventId, dropId}) {
1310
1310
 
1311
1311
 
1312
1312
  /* OFFERS */
1313
- // TODO: Document
1314
1313
 
1314
+ /**
1315
+ * Retrieve offers for the specified parameters
1316
+ *
1317
+ * @methodGroup Offers
1318
+ * @namedParams
1319
+ * @param {string=} contractAddress - The address of an NFT contract
1320
+ * @param {string=} tokenId - The token ID of an NFT
1321
+ * @param {string=} buyerAddress - The address of the offerrer
1322
+ * @param {string=} sellerAddress - The address of the offerree
1323
+ * @param {Array<String>=} statuses - Status to filter results by. Allowed values: "ACTIVE", "ACCEPTED", "CANCELLED", "DECLINED", "INVALID"
1324
+ * @param {number} start=0 - The index to start from
1325
+ * @param {number=} limit=10 - The maximum number of results to return
1326
+ *
1327
+ * @returns {Promise<Array<Object>>} - Offers matching the specified filters
1328
+ */
1315
1329
  exports.MarketplaceOffers = async function({contractAddress, tokenId, buyerAddress, sellerAddress, statuses, start=0, limit=10}) {
1316
1330
  let path = UrlJoin("as", "mkt", "offers", "ls");
1317
1331
  if(buyerAddress) {
@@ -1354,6 +1368,21 @@ exports.MarketplaceOffers = async function({contractAddress, tokenId, buyerAddre
1354
1368
  }));
1355
1369
  };
1356
1370
 
1371
+ /**
1372
+ * <b><i>Requires login</i></b>
1373
+ *
1374
+ * Create or update an offer on the specified NFT
1375
+ *
1376
+ * @methodGroup Offers
1377
+ * @namedParams
1378
+ * @param {string} contractAddress - The contract address of the NFT
1379
+ * @param {string} tokenId - The token ID of the NFT
1380
+ * @param {string=} offerId - IF modifying an existing offer, the ID of the offer
1381
+ * @param {number} price - The amount to offer
1382
+ * @param {number=} expiresAt - The time (in epoch ms) the offer will expire
1383
+ *
1384
+ * @returns {Promise<Object>} - Info about the created/updated offer
1385
+ */
1357
1386
  exports.CreateMarketplaceOffer = async function({contractAddress, tokenId, offerId, price, expiresAt}) {
1358
1387
  let response;
1359
1388
  if(offerId) {
@@ -1391,6 +1420,15 @@ exports.CreateMarketplaceOffer = async function({contractAddress, tokenId, offer
1391
1420
  return response.offer_id;
1392
1421
  };
1393
1422
 
1423
+ /**
1424
+ * <b><i>Requires login</i></b>
1425
+ *
1426
+ * Cancel the specified offer
1427
+ *
1428
+ * @methodGroup Offers
1429
+ * @namedParams
1430
+ * @param {string} offerId - The ID of the offer
1431
+ */
1394
1432
  exports.RemoveMarketplaceOffer = async function({offerId}) {
1395
1433
  return await this.client.authClient.MakeAuthServiceRequest({
1396
1434
  path: UrlJoin("as", "wlt", "mkt", "offers", offerId),
@@ -1401,7 +1439,15 @@ exports.RemoveMarketplaceOffer = async function({offerId}) {
1401
1439
  });
1402
1440
  };
1403
1441
 
1404
-
1442
+ /**
1443
+ * <b><i>Requires login</i></b>
1444
+ *
1445
+ * Accept the specified offer
1446
+ *
1447
+ * @methodGroup Offers
1448
+ * @namedParams
1449
+ * @param {string} offerId - The ID of the offer
1450
+ */
1405
1451
  exports.AcceptMarketplaceOffer = async function({offerId}) {
1406
1452
  return await this.client.authClient.MakeAuthServiceRequest({
1407
1453
  path: UrlJoin("as", "wlt", "mkt", "offers", "accept", offerId),
@@ -1412,6 +1458,15 @@ exports.AcceptMarketplaceOffer = async function({offerId}) {
1412
1458
  });
1413
1459
  };
1414
1460
 
1461
+ /**
1462
+ * <b><i>Requires login</i></b>
1463
+ *
1464
+ * Reject the specified offer
1465
+ *
1466
+ * @methodGroup Offers
1467
+ * @namedParams
1468
+ * @param {string} offerId - The ID of the offer
1469
+ */
1415
1470
  exports.RejectMarketplaceOffer = async function({offerId}) {
1416
1471
  return await this.client.authClient.MakeAuthServiceRequest({
1417
1472
  path: UrlJoin("as", "wlt", "mkt", "offers", "decline", offerId),
@@ -1421,3 +1476,77 @@ exports.RejectMarketplaceOffer = async function({offerId}) {
1421
1476
  }
1422
1477
  });
1423
1478
  };
1479
+
1480
+
1481
+ /* Voting */
1482
+
1483
+ /**
1484
+ * Retrieve the current status of the specified voting event
1485
+ *
1486
+ * @methodGroup Voting
1487
+ * @namedParams
1488
+ * @param {string} tenantId - The tenant ID of the marketplace in which the voting event is specified
1489
+ * @param {string} votingEventId - The ID of the voting event
1490
+ *
1491
+ * @returns {Promise<Object>} - Info about the voting event, including the current user's votes and the current total voting tally
1492
+ */
1493
+ exports.VoteStatus = async function ({tenantId, votingEventId}) {
1494
+ return await Utils.ResponseToJson(
1495
+ this.client.authClient.MakeAuthServiceRequest({
1496
+ path: UrlJoin("as", "votes", tenantId, votingEventId),
1497
+ headers: {
1498
+ Authorization: `Bearer ${this.AuthToken()}`
1499
+ }
1500
+ })
1501
+ );
1502
+ };
1503
+
1504
+ /**
1505
+ * <b><i>Requires login</i></b>
1506
+ *
1507
+ * Cast a vote for the specified item in the specified voting event
1508
+ *
1509
+ * @methodGroup Voting
1510
+ * @namedParams
1511
+ * @param {string} tenantId - The tenant ID of the marketplace in which the voting event is specified
1512
+ * @param {string} votingEventId - The ID of the voting event
1513
+ * @param {string} sku - The SKU of the item to vote for
1514
+ *
1515
+ * @returns {Promise<Object>} - Info about the voting event, including the current user's votes and the current total voting tally
1516
+ */
1517
+ exports.CastVote = async function ({tenantId, votingEventId, sku}) {
1518
+ return await Utils.ResponseToJson(
1519
+ this.client.authClient.MakeAuthServiceRequest({
1520
+ path: UrlJoin("as", "votes", tenantId, votingEventId, sku),
1521
+ method: "POST",
1522
+ headers: {
1523
+ Authorization: `Bearer ${this.AuthToken()}`
1524
+ }
1525
+ })
1526
+ );
1527
+ };
1528
+
1529
+ /**
1530
+ * <b><i>Requires login</i></b>
1531
+ *
1532
+ * Revoke a previously cast vote for the specified item in the specified voting event
1533
+ *
1534
+ * @methodGroup Voting
1535
+ * @namedParams
1536
+ * @param {string} tenantId - The tenant ID of the marketplace in which the voting event is specified
1537
+ * @param {string} votingEventId - The ID of the voting event
1538
+ * @param {string} sku - The SKU of the item to vote for
1539
+ *
1540
+ * @returns {Promise<Object>} - Info about the voting event, including the current user's votes and the current total voting tally
1541
+ */
1542
+ exports.RevokeVote = async function ({tenantId, votingEventId, sku}) {
1543
+ return await Utils.ResponseToJson(
1544
+ this.client.authClient.MakeAuthServiceRequest({
1545
+ path: UrlJoin("as", "votes", tenantId, votingEventId, sku),
1546
+ method: "DELETE",
1547
+ headers: {
1548
+ Authorization: `Bearer ${this.AuthToken()}`
1549
+ }
1550
+ })
1551
+ );
1552
+ };
@@ -2,6 +2,7 @@ let WalletConfiguration = {
2
2
  demo: {
3
3
  configUrl: "https://demov3.net955210.contentfabric.io/config",
4
4
  stateStoreUrls: ["https://appsvc.svc.eluv.io/dv3"],
5
+ badgerAddress: "0x39e9d567137217e8f7dae73bf168db28d242bb31",
5
6
  staging: {
6
7
  siteLibraryId: "ilib36Wi5fJDLXix8ckL7ZfaAJwJXWGD",
7
8
  siteId: "iq__2gkNh8CCZqFFnoRpEUmz7P3PaBQG",
@@ -12,6 +13,7 @@ let WalletConfiguration = {
12
13
  main: {
13
14
  configUrl: "https://main.net955305.contentfabric.io/config",
14
15
  stateStoreUrls: ["https://appsvc.svc.eluv.io/main"],
16
+ badgerAddress: "0xa042a585bbbac4419ba39c397f35ab749fc470f0",
15
17
  staging: {
16
18
  siteLibraryId: "ilib2GdaYEFxB7HyLPhSDPKMyPLhV8x9",
17
19
  siteId: "iq__inauxD1KLyKWPHargCWjdCh2ayr",
@@ -116,7 +116,7 @@ exports.RemoveProfileMetadata = async function({type="app", mode="public", appId
116
116
  };
117
117
 
118
118
  /**
119
- * Retrieve profile info for the specified user, including address, username and profile image (if set)
119
+ * Retrieve profile info for the specified user, including address, username, profile image (if set) and badges (if any)
120
120
  *
121
121
  * @methodGroup Profile
122
122
  * @param {string=} userAddress - Address of the user
@@ -139,10 +139,33 @@ exports.Profile = async function({userAddress, userName}) {
139
139
 
140
140
  const imageUrl = await this.ProfileMetadata({type: "user", userAddress, key: "icon_url"});
141
141
 
142
+ let badgeData = await this.ProfileMetadata({
143
+ type: "app",
144
+ mode: "public",
145
+ appId: "elv-badge-srv",
146
+ userAddress: this.badgerAddress,
147
+ key: `badges_${Utils.FormatAddress(userAddress)}`
148
+ });
149
+
150
+ let badges = [];
151
+ if(badgeData) {
152
+ try {
153
+ badgeData = (JSON.parse(badgeData)).badges;
154
+ badges = Object.keys(badgeData).map(badgeName => ({
155
+ ...badgeData[badgeName],
156
+ name: badgeName
157
+ }));
158
+ } catch(error) {
159
+ this.Log(`Failed to load badge info for ${userName || userAddress}`, true);
160
+ this.Log(error, true);
161
+ }
162
+ }
163
+
142
164
  return {
143
165
  userAddress: Utils.FormatAddress(userAddress),
144
166
  userName,
145
- imageUrl
167
+ imageUrl,
168
+ badges
146
169
  };
147
170
  };
148
171
 
@@ -51,6 +51,7 @@ class ElvWalletClient {
51
51
 
52
52
  this.stateStoreUrls = Configuration[network].stateStoreUrls;
53
53
  this.stateStoreClient = new HTTPClient({uris: this.stateStoreUrls});
54
+ this.badgerAddress = Configuration[network].badgerAddress;
54
55
 
55
56
  // Caches
56
57
  this.cachedMarketplaces = {};