@coinlist-co/react 0.12.1-rc.df659d8 → 0.12.1-rc.e183ffd

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.
@@ -19,7 +19,7 @@ import {
19
19
  generateSecureRandomBase64Url,
20
20
  internalLogger,
21
21
  sha256
22
- } from "./chunk-VSYGGTI6.js";
22
+ } from "./chunk-MOE5S6CE.js";
23
23
 
24
24
  // src/universal/types/oauth.ts
25
25
  var AuthorizationCode = (value) => value;
@@ -354,4 +354,4 @@ export {
354
354
  UserEmail,
355
355
  User
356
356
  };
357
- //# sourceMappingURL=chunk-3EOK47CQ.js.map
357
+ //# sourceMappingURL=chunk-ONLH57LF.js.map
@@ -1317,8 +1317,15 @@ async function fetchAllPages(fetchPage, baseParams) {
1317
1317
  // src/universal/types/pagination.ts
1318
1318
  var Cursor = (value) => value;
1319
1319
  var PaginatedResponse = {
1320
- fromDto: (dto, itemMapper) => ({
1321
- data: dto.data.map(itemMapper),
1320
+ fromDto: (dto, itemMapper) => PaginatedResponse.fromDtoPage(dto, (items) => items.map(itemMapper)),
1321
+ /**
1322
+ * For a mapper that decides the page as a whole - one that drops items it
1323
+ * cannot map, such as `Offer.listFromDto` - rather than item by item. The
1324
+ * cursors are the wire's either way: dropping an item changes what the
1325
+ * page holds, not where the next page starts.
1326
+ */
1327
+ fromDtoPage: (dto, pageMapper) => ({
1328
+ data: pageMapper(dto.data),
1322
1329
  startingAfter: dto.starting_after ? Cursor(dto.starting_after) : null,
1323
1330
  startingBefore: dto.starting_before ? Cursor(dto.starting_before) : null
1324
1331
  })
@@ -1351,6 +1358,40 @@ var Asset = {
1351
1358
  })
1352
1359
  };
1353
1360
 
1361
+ // src/universal/core/shared/utils/wire.ts
1362
+ function unknownTypeError(dto, model) {
1363
+ const type = dto.type;
1364
+ throw new ValidationError(
1365
+ `${model}.type: unknown type ${JSON.stringify(type)}`
1366
+ );
1367
+ }
1368
+ function requiredString(value, field) {
1369
+ const text = notBlankStringOrNull(value);
1370
+ if (text === null) {
1371
+ throw new ValidationError(
1372
+ `${field}: expected a non-blank string, got ${typeof value === "string" ? "a blank string" : String(value)}`
1373
+ );
1374
+ }
1375
+ return text;
1376
+ }
1377
+ function requiredDate(value, field) {
1378
+ const date = typeof value === "string" ? new Date(value) : null;
1379
+ if (date === null || Number.isNaN(date.getTime())) {
1380
+ throw new ValidationError(
1381
+ `${field}: expected a date, got ${JSON.stringify(value)}`
1382
+ );
1383
+ }
1384
+ return date;
1385
+ }
1386
+ function requiredArray(value, field) {
1387
+ if (!Array.isArray(value)) {
1388
+ throw new ValidationError(
1389
+ `${field}: expected an array, got ${typeof value}`
1390
+ );
1391
+ }
1392
+ return value;
1393
+ }
1394
+
1354
1395
  // src/universal/types/blockchain/core.ts
1355
1396
  var ETHEREUM_CHAINS = {
1356
1397
  ethereum_mainnet: true,
@@ -1444,25 +1485,69 @@ var Bps = (value) => value;
1444
1485
  // src/universal/types/offer.ts
1445
1486
  var OfferId = (value) => value;
1446
1487
  var OfferSlug = (value) => value;
1488
+ var OFFER_TYPES = {
1489
+ "coinlist::token_sale": true,
1490
+ "superstate::swap": true,
1491
+ "ondo::swap": true
1492
+ };
1493
+ var isOfferType = (value) => Object.keys(OFFER_TYPES).includes(value);
1494
+ var OfferEditorial = {
1495
+ /**
1496
+ * `model` prefixes the field in the error (`'Offer'`, `'OfferDetail'`), so
1497
+ * the same three checks name the payload that failed them.
1498
+ */
1499
+ fromDto: (dto, model) => ({
1500
+ tagline: requiredString(dto.tagline, `${model}.tagline`),
1501
+ bannerUrl: requiredString(dto.banner_url, `${model}.banner_url`),
1502
+ startsAt: requiredDate(dto.starts_at, `${model}.starts_at`)
1503
+ })
1504
+ };
1447
1505
  var Offer = {
1448
1506
  fromDto: (dto) => {
1449
- if (!Array.isArray(dto.tokens)) {
1450
- throw new ValidationError(
1451
- `Offer.tokens: expected an array, got ${typeof dto.tokens}`
1452
- );
1453
- }
1454
- return {
1507
+ const tokens = requiredArray(dto.tokens, "Offer.tokens");
1508
+ const base2 = {
1455
1509
  id: OfferId(dto.id),
1456
1510
  slug: OfferSlug(dto.slug),
1457
- type: dto.type,
1458
- tagline: dto.tagline,
1459
- bannerUrl: dto.banner_url,
1460
- logoUrl: dto.logo_url,
1461
- startsAt: new Date(dto.starts_at),
1462
1511
  endsAt: dto.ends_at ? new Date(dto.ends_at) : null,
1463
- tokens: OfferToken.listFromDto(dto.tokens)
1512
+ tokens: OfferToken.listFromDto(tokens)
1464
1513
  };
1465
- }
1514
+ switch (dto.type) {
1515
+ case "coinlist::token_sale":
1516
+ return {
1517
+ ...base2,
1518
+ ...OfferEditorial.fromDto(dto, "Offer"),
1519
+ type: dto.type,
1520
+ logoUrl: requiredString(dto.logo_url, "Offer.logo_url")
1521
+ };
1522
+ case "superstate::swap":
1523
+ return {
1524
+ ...base2,
1525
+ ...OfferEditorial.fromDto(dto, "Offer"),
1526
+ type: dto.type,
1527
+ logoUrl: notBlankStringOrNull(dto.logo_url)
1528
+ };
1529
+ // `tagline`, `banner_url` and `starts_at` arrive as `null` and are left
1530
+ // on the wire: copying them would hand every consumer a `startsAt` that
1531
+ // is 1970 for one variant and a date for the others.
1532
+ case "ondo::swap":
1533
+ return {
1534
+ ...base2,
1535
+ type: dto.type,
1536
+ logoUrl: notBlankStringOrNull(dto.logo_url)
1537
+ };
1538
+ default:
1539
+ return unknownTypeError(dto, "Offer");
1540
+ }
1541
+ },
1542
+ /**
1543
+ * Maps a page of offers, dropping every offer whose `type` this SDK does not
1544
+ * name. The same reasoning as {@link OfferToken.listFromDto}: a plain `.map`
1545
+ * would throw out of `fromDto` and, through `PaginatedResponse.fromDto`,
1546
+ * reject the whole page, so one offer of an unknown type would blank the
1547
+ * grid for every offer beside it. A single offer fetched by id still
1548
+ * throws, because there is nothing beside it to keep.
1549
+ */
1550
+ listFromDto: (dtos) => dtos.filter((dto) => isOfferType(dto.type)).map(Offer.fromDto)
1466
1551
  };
1467
1552
  var OfferToken = {
1468
1553
  fromDto: (dto) => ({
@@ -1499,76 +1584,69 @@ var OfferSwapContract = {
1499
1584
  };
1500
1585
  var OfferDetail = {
1501
1586
  fromDto: (dto) => {
1502
- if (!Array.isArray(dto.funding_assets)) {
1503
- throw new ValidationError(
1504
- `OfferDetail.funding_assets: expected an array, got ${typeof dto.funding_assets}`
1505
- );
1506
- }
1507
- if (!Array.isArray(dto.options)) {
1508
- throw new ValidationError(
1509
- `OfferDetail.options: expected an array, got ${typeof dto.options}`
1510
- );
1511
- }
1512
- if (!Array.isArray(dto.terms)) {
1513
- throw new ValidationError(
1514
- `OfferDetail.terms: expected an array, got ${typeof dto.terms}`
1515
- );
1516
- }
1517
- if (!Array.isArray(dto.links)) {
1518
- throw new ValidationError(
1519
- `OfferDetail.links: expected an array, got ${typeof dto.links}`
1520
- );
1521
- }
1522
- if (!Array.isArray(dto.faqs)) {
1523
- throw new ValidationError(
1524
- `OfferDetail.faqs: expected an array, got ${typeof dto.faqs}`
1525
- );
1526
- }
1527
- if (!Array.isArray(dto.milestones)) {
1528
- throw new ValidationError(
1529
- `OfferDetail.milestones: expected an array, got ${typeof dto.milestones}`
1530
- );
1531
- }
1532
- if (!Array.isArray(dto.tokens)) {
1533
- throw new ValidationError(
1534
- `OfferDetail.tokens: expected an array, got ${typeof dto.tokens}`
1535
- );
1536
- }
1537
- const swapContracts = dto.swap_contracts === void 0 ? [] : dto.swap_contracts;
1538
- if (!Array.isArray(swapContracts)) {
1539
- throw new ValidationError(
1540
- `OfferDetail.swap_contracts: expected an array, got ${typeof swapContracts}`
1541
- );
1542
- }
1587
+ const fundingAssets = requiredArray(
1588
+ dto.funding_assets,
1589
+ "OfferDetail.funding_assets"
1590
+ );
1591
+ const options = requiredArray(dto.options, "OfferDetail.options");
1592
+ const terms = requiredArray(dto.terms, "OfferDetail.terms");
1593
+ const links = requiredArray(dto.links, "OfferDetail.links");
1594
+ const faqs = requiredArray(dto.faqs, "OfferDetail.faqs");
1595
+ const milestones = requiredArray(dto.milestones, "OfferDetail.milestones");
1596
+ const tokens = requiredArray(dto.tokens, "OfferDetail.tokens");
1543
1597
  const isin = notBlankStringOrNull(dto.isin);
1544
1598
  const ticker = notBlankStringOrNull(dto.ticker);
1545
- return {
1599
+ const base2 = {
1546
1600
  id: OfferId(dto.id),
1547
1601
  slug: OfferSlug(dto.slug),
1548
- type: dto.type,
1549
1602
  name: dto.name,
1550
1603
  asset: Asset.fromDto(dto.asset),
1551
- fundingAssets: dto.funding_assets.map(Asset.fromDto),
1552
- tokens: OfferToken.listFromDto(dto.tokens),
1553
- swapContracts: swapContracts.map(OfferSwapContract.fromDto),
1604
+ fundingAssets: fundingAssets.map(Asset.fromDto),
1605
+ tokens: OfferToken.listFromDto(tokens),
1554
1606
  about: notBlankStringOrNull(dto.about),
1555
- tagline: dto.tagline,
1556
- bannerUrl: dto.banner_url,
1557
- logoUrl: dto.logo_url,
1558
1607
  category: dto.category,
1559
1608
  issuer: notBlankStringOrNull(dto.issuer),
1560
1609
  isin: isin === null ? null : Isin(isin),
1561
1610
  ticker: ticker === null ? null : Ticker(ticker),
1562
1611
  instrumentType: notBlankStringOrNull(dto.instrument_type),
1563
1612
  listingVenue: notBlankStringOrNull(dto.listing_venue),
1564
- startsAt: new Date(dto.starts_at),
1565
1613
  endsAt: dto.ends_at ? new Date(dto.ends_at) : null,
1566
- faqs: dto.faqs.map(FaqItem.fromDto),
1567
- links: dto.links.map(Link.fromDto),
1568
- milestones: dto.milestones.map(Milestone.fromDto),
1569
- options: dto.options.map(OfferOption.fromDto),
1570
- terms: dto.terms.map(TermItem.fromDto)
1614
+ faqs: faqs.map(FaqItem.fromDto),
1615
+ links: links.map(Link.fromDto),
1616
+ milestones: milestones.map(Milestone.fromDto),
1617
+ options: options.map(OfferOption.fromDto),
1618
+ terms: terms.map(TermItem.fromDto)
1571
1619
  };
1620
+ switch (dto.type) {
1621
+ case "coinlist::token_sale":
1622
+ return {
1623
+ ...base2,
1624
+ ...OfferEditorial.fromDto(dto, "OfferDetail"),
1625
+ type: dto.type,
1626
+ logoUrl: requiredString(dto.logo_url, "OfferDetail.logo_url")
1627
+ };
1628
+ case "superstate::swap":
1629
+ return {
1630
+ ...base2,
1631
+ ...OfferEditorial.fromDto(dto, "OfferDetail"),
1632
+ type: dto.type,
1633
+ logoUrl: notBlankStringOrNull(dto.logo_url)
1634
+ };
1635
+ // `tagline`, `banner_url` and `starts_at` arrive as `null` and are left
1636
+ // on the wire, as in `Offer.fromDto`.
1637
+ case "ondo::swap":
1638
+ return {
1639
+ ...base2,
1640
+ type: dto.type,
1641
+ logoUrl: notBlankStringOrNull(dto.logo_url),
1642
+ swapContracts: requiredArray(
1643
+ dto.swap_contracts,
1644
+ "OfferDetail.swap_contracts"
1645
+ ).map(OfferSwapContract.fromDto)
1646
+ };
1647
+ default:
1648
+ return unknownTypeError(dto, "OfferDetail");
1649
+ }
1572
1650
  }
1573
1651
  };
1574
1652
  var OfferOption = {
@@ -3495,7 +3573,7 @@ async function fetchOffersPage(api, params, clientCreds) {
3495
3573
  Attributes.clientCredentials(clientCreds)
3496
3574
  )
3497
3575
  });
3498
- return PaginatedResponse.fromDto(pageDto, Offer.fromDto);
3576
+ return PaginatedResponse.fromDtoPage(pageDto, Offer.listFromDto);
3499
3577
  }
3500
3578
  async function fetchOfferDetails(api, id, clientCreds) {
3501
3579
  const dto = await api.send({
@@ -7465,7 +7543,7 @@ function stablecoinIconUrl(symbol) {
7465
7543
  }
7466
7544
  }
7467
7545
  function offerIconUrl(offer) {
7468
- return offer.logoUrl === "" ? null : AssetIconUrl(offer.logoUrl);
7546
+ return offer.logoUrl ? AssetIconUrl(offer.logoUrl) : null;
7469
7547
  }
7470
7548
  function tokenLogoUrl(logo, minWidth = 40) {
7471
7549
  switch (logo.kind) {
@@ -12973,11 +13051,11 @@ function CheckoutContainer({
12973
13051
  enabled = true,
12974
13052
  className
12975
13053
  }) {
12976
- return renderOffer(offer.type, {
12977
- ondo: () => /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
13054
+ return renderOffer(offer, {
13055
+ ondo: (ondoOffer) => /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
12978
13056
  OndoCheckoutContainer,
12979
13057
  {
12980
- offer,
13058
+ offer: ondoOffer,
12981
13059
  chain,
12982
13060
  wallets,
12983
13061
  config: config["ondo::swap"],
@@ -12985,10 +13063,10 @@ function CheckoutContainer({
12985
13063
  className
12986
13064
  }
12987
13065
  ),
12988
- superstate: () => /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
13066
+ superstate: (superstateOffer) => /* @__PURE__ */ (0, import_jsx_runtime50.jsx)(
12989
13067
  SuperstateSwapCheckoutContainer,
12990
13068
  {
12991
- offer,
13069
+ offer: superstateOffer,
12992
13070
  chain,
12993
13071
  wallets,
12994
13072
  enabled,
@@ -12996,7 +13074,7 @@ function CheckoutContainer({
12996
13074
  className
12997
13075
  }
12998
13076
  ),
12999
- tokenSale: () => config["coinlist::token_sale"].render(offer)
13077
+ tokenSale: (tokenSaleOffer) => config["coinlist::token_sale"].render(tokenSaleOffer)
13000
13078
  });
13001
13079
  }
13002
13080
  function OndoCheckoutContainer({
@@ -13036,16 +13114,16 @@ function OndoCheckoutContainer({
13036
13114
  )
13037
13115
  });
13038
13116
  }
13039
- function renderOffer(type, branches) {
13040
- switch (type) {
13117
+ function renderOffer(offer, branches) {
13118
+ switch (offer.type) {
13041
13119
  case "ondo::swap":
13042
- return branches.ondo();
13120
+ return branches.ondo(offer);
13043
13121
  case "superstate::swap":
13044
- return branches.superstate();
13122
+ return branches.superstate(offer);
13045
13123
  case "coinlist::token_sale":
13046
- return branches.tokenSale();
13124
+ return branches.tokenSale(offer);
13047
13125
  default: {
13048
- const exhaustive = type;
13126
+ const exhaustive = offer;
13049
13127
  return exhaustive;
13050
13128
  }
13051
13129
  }
@@ -13530,20 +13608,31 @@ function useOffers(options = {}) {
13530
13608
  var OfferSaleCardUi = {
13531
13609
  fromOffer: (offer) => ({
13532
13610
  id: offer.id,
13533
- tagline: offer.tagline,
13611
+ ...saleWindow(offer),
13534
13612
  logoUrl: offer.logoUrl,
13535
- startsAt: offer.startsAt,
13536
13613
  endsAt: offer.endsAt
13537
13614
  }),
13538
13615
  fromDetail: (detail) => ({
13539
13616
  id: detail.id,
13540
13617
  name: detail.name,
13541
- tagline: detail.tagline,
13618
+ ...saleWindow(detail),
13542
13619
  logoUrl: detail.logoUrl,
13543
- startsAt: detail.startsAt,
13544
13620
  endsAt: detail.endsAt
13545
13621
  })
13546
13622
  };
13623
+ function saleWindow(offer) {
13624
+ switch (offer.type) {
13625
+ case "coinlist::token_sale":
13626
+ case "superstate::swap":
13627
+ return { tagline: offer.tagline, startsAt: offer.startsAt };
13628
+ case "ondo::swap":
13629
+ return { tagline: null, startsAt: null };
13630
+ default: {
13631
+ const exhaustive = offer;
13632
+ return exhaustive;
13633
+ }
13634
+ }
13635
+ }
13547
13636
 
13548
13637
  // src/client/hooks/offers/grid/useOffersGridViewModel.ts
13549
13638
  var NOT_AUTHENTICATED_MESSAGE = "Sign in to view available offers.";