@0xsequence/marketplace-sdk 0.5.4 → 0.5.5

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.
Files changed (44) hide show
  1. package/dist/{chunk-WGGZEQHL.js → chunk-3BLBZYQX.js} +2 -2
  2. package/dist/{chunk-JWNONWD6.js → chunk-AXTDPTRD.js} +278 -154
  3. package/dist/chunk-AXTDPTRD.js.map +1 -0
  4. package/dist/{chunk-ZGVCOQ4I.js → chunk-CIPPTQDA.js} +89 -32
  5. package/dist/chunk-CIPPTQDA.js.map +1 -0
  6. package/dist/{chunk-TLNRD4BQ.js → chunk-P7UNMRZ5.js} +2 -2
  7. package/dist/{chunk-WSCUPAGR.js → chunk-SA3U25NU.js} +2 -1
  8. package/dist/{chunk-WSCUPAGR.js.map → chunk-SA3U25NU.js.map} +1 -1
  9. package/dist/index.js +6 -6
  10. package/dist/react/_internal/api/index.d.ts +1 -0
  11. package/dist/react/_internal/api/index.js +1 -1
  12. package/dist/react/_internal/databeat/index.js +4 -4
  13. package/dist/react/_internal/index.js +1 -1
  14. package/dist/react/hooks/index.d.ts +149 -1
  15. package/dist/react/hooks/index.js +13 -3
  16. package/dist/react/index.d.ts +1 -1
  17. package/dist/react/index.js +16 -6
  18. package/dist/react/ssr/index.js +1 -0
  19. package/dist/react/ssr/index.js.map +1 -1
  20. package/dist/react/ui/components/collectible-card/index.js +6 -6
  21. package/dist/react/ui/index.js +6 -6
  22. package/dist/react/ui/modals/_internal/components/actionModal/index.js +4 -4
  23. package/dist/types/index.js +1 -1
  24. package/dist/utils/abi/index.js +5 -5
  25. package/dist/utils/index.js +6 -6
  26. package/package.json +1 -1
  27. package/src/react/_internal/api/query-keys.ts +1 -0
  28. package/src/react/hooks/__tests__/useComparePrices.test.tsx +215 -0
  29. package/src/react/hooks/__tests__/useConvertPriceToUSD.test.tsx +173 -0
  30. package/src/react/hooks/index.ts +2 -0
  31. package/src/react/hooks/useComparePrices.tsx +106 -0
  32. package/src/react/hooks/useConvertPriceToUSD.tsx +102 -0
  33. package/src/react/ui/components/collectible-card/CollectibleCard.tsx +1 -0
  34. package/src/react/ui/components/collectible-card/Footer.tsx +10 -2
  35. package/src/react/ui/modals/BuyModal/hooks/useBuyCollectable.ts +30 -3
  36. package/src/react/ui/modals/_internal/components/floorPriceText/index.tsx +30 -12
  37. package/src/react/ui/modals/_internal/components/priceInput/__tests__/index.test.tsx +51 -4
  38. package/src/react/ui/modals/_internal/components/priceInput/index.tsx +24 -3
  39. package/tsconfig.tsbuildinfo +1 -1
  40. package/dist/chunk-JWNONWD6.js.map +0 -1
  41. package/dist/chunk-ZGVCOQ4I.js.map +0 -1
  42. /package/dist/{chunk-WGGZEQHL.js.map → chunk-3BLBZYQX.js.map} +0 -0
  43. /package/dist/{chunk-TLNRD4BQ.js.map → chunk-P7UNMRZ5.js.map} +0 -0
  44. /package/src/react/ui/modals/BuyModal/hooks/__tests__/{useBuyCollectable.test.tsx → useBuyCollectable.test.tsx.bak} +0 -0
@@ -3,16 +3,16 @@ import {
3
3
  ActionModal,
4
4
  CustomSelect,
5
5
  useCurrencyBalance
6
- } from "./chunk-TLNRD4BQ.js";
7
- import {
8
- useAnalytics
9
- } from "./chunk-WGGZEQHL.js";
6
+ } from "./chunk-P7UNMRZ5.js";
10
7
  import {
11
8
  CalendarIcon_default,
12
9
  MinusIcon_default,
13
10
  PlusIcon_default,
14
11
  PositiveCircleIcon_default
15
12
  } from "./chunk-6YHHCGGY.js";
13
+ import {
14
+ useAnalytics
15
+ } from "./chunk-3BLBZYQX.js";
16
16
  import {
17
17
  actionWrapper,
18
18
  closeButton,
@@ -44,6 +44,7 @@ import {
44
44
  useBalanceOfCollectible,
45
45
  useCollectible,
46
46
  useCollection,
47
+ useComparePrices,
47
48
  useConfig,
48
49
  useCurrencies,
49
50
  useCurrency,
@@ -57,12 +58,11 @@ import {
57
58
  useSwitchChainModal,
58
59
  useTransferTokens,
59
60
  useWallet
60
- } from "./chunk-JWNONWD6.js";
61
+ } from "./chunk-AXTDPTRD.js";
61
62
  import {
62
63
  iconVariants
63
64
  } from "./chunk-TQWM4ER6.js";
64
65
  import {
65
- calculatePriceDifferencePercentage,
66
66
  truncateMiddle
67
67
  } from "./chunk-7C7ADZ2H.js";
68
68
  import {
@@ -73,7 +73,7 @@ import {
73
73
  collectableKeys,
74
74
  getMarketplaceClient,
75
75
  getQueryClient
76
- } from "./chunk-WSCUPAGR.js";
76
+ } from "./chunk-SA3U25NU.js";
77
77
  import {
78
78
  InvalidContractTypeError,
79
79
  InvalidStepError
@@ -1280,15 +1280,27 @@ function FloorPriceText({
1280
1280
  }
1281
1281
  });
1282
1282
  const floorPriceRaw = listing?.order?.priceAmount;
1283
- if (!floorPriceRaw || listingLoading || price.amountRaw === "0") {
1283
+ const { data: priceComparison, isLoading: comparisonLoading } = useComparePrices({
1284
+ chainId,
1285
+ priceAmountRaw: price.amountRaw || "0",
1286
+ priceCurrencyAddress: price.currency.contractAddress,
1287
+ compareToPriceAmountRaw: floorPriceRaw || "0",
1288
+ compareToPriceCurrencyAddress: listing?.order?.priceCurrencyAddress || price.currency.contractAddress,
1289
+ query: {
1290
+ enabled: !!floorPriceRaw && !listingLoading && price.amountRaw !== "0"
1291
+ }
1292
+ });
1293
+ if (!floorPriceRaw || listingLoading || price.amountRaw === "0" || comparisonLoading) {
1284
1294
  return null;
1285
1295
  }
1286
- const floorPriceDifference = calculatePriceDifferencePercentage({
1287
- inputPriceRaw: BigInt(price.amountRaw),
1288
- basePriceRaw: BigInt(floorPriceRaw),
1289
- decimals: price.currency.decimals
1290
- });
1291
- const floorPriceDifferenceText = floorPriceRaw === price.amountRaw ? "Same as floor price" : `${floorPriceDifference}% ${floorPriceRaw > price.amountRaw ? "below" : "above"} floor price`;
1296
+ let floorPriceDifferenceText = "Same as floor price";
1297
+ if (priceComparison) {
1298
+ if (priceComparison.status === "same") {
1299
+ floorPriceDifferenceText = "Same as floor price";
1300
+ } else {
1301
+ floorPriceDifferenceText = `${priceComparison.percentageDifferenceFormatted}% ${priceComparison.status === "below" ? "below" : "above"} floor price`;
1302
+ }
1303
+ }
1292
1304
  return /* @__PURE__ */ jsx10(
1293
1305
  Text7,
1294
1306
  {
@@ -1305,6 +1317,8 @@ function FloorPriceText({
1305
1317
 
1306
1318
  // src/react/ui/modals/_internal/components/priceInput/index.tsx
1307
1319
  import { Box as Box8, NumericInput, Text as Text8 } from "@0xsequence/design-system";
1320
+ import { use$ as use$2 } from "@legendapp/state/react";
1321
+ import { useEffect as useEffect5, useRef, useState as useState5 } from "react";
1308
1322
  import { parseUnits } from "viem";
1309
1323
  import { useAccount } from "wagmi";
1310
1324
 
@@ -1411,8 +1425,6 @@ var CurrencyOptionsSelect = observer3(function CurrencyOptionsSelect2({
1411
1425
  var currencyOptionsSelect_default = CurrencyOptionsSelect;
1412
1426
 
1413
1427
  // src/react/ui/modals/_internal/components/priceInput/index.tsx
1414
- import { use$ as use$2 } from "@legendapp/state/react";
1415
- import { useState as useState5 } from "react";
1416
1428
  import { jsx as jsx13, jsxs as jsxs6 } from "react/jsx-runtime";
1417
1429
  function PriceInput({
1418
1430
  chainId,
@@ -1437,6 +1449,21 @@ function PriceInput({
1437
1449
  checkBalance.callback(balanceError);
1438
1450
  }
1439
1451
  const [value, setValue] = useState5("0");
1452
+ const prevCurrencyDecimals = useRef(currencyDecimals);
1453
+ useEffect5(() => {
1454
+ if (prevCurrencyDecimals.current !== currencyDecimals && value !== "0") {
1455
+ try {
1456
+ const parsedAmount = parseUnits(value, Number(currencyDecimals));
1457
+ $price.amountRaw.set(parsedAmount.toString());
1458
+ if (onPriceChange && parsedAmount !== 0n) {
1459
+ onPriceChange();
1460
+ }
1461
+ } catch {
1462
+ $price.amountRaw.set("0");
1463
+ }
1464
+ }
1465
+ prevCurrencyDecimals.current = currencyDecimals;
1466
+ }, [currencyDecimals, $price.amountRaw, value, onPriceChange]);
1440
1467
  const handleChange = (event) => {
1441
1468
  const newValue = event.target.value;
1442
1469
  setValue(newValue);
@@ -1997,7 +2024,7 @@ function TransactionHeader({
1997
2024
  }
1998
2025
 
1999
2026
  // src/react/ui/modals/SellModal/hooks/useSell.tsx
2000
- import { useEffect as useEffect5 } from "react";
2027
+ import { useEffect as useEffect6 } from "react";
2001
2028
 
2002
2029
  // src/react/ui/modals/SellModal/hooks/useGetTokenApproval.tsx
2003
2030
  import { skipToken as skipToken3, useQuery as useQuery3 } from "@tanstack/react-query";
@@ -2269,7 +2296,7 @@ var useSell = ({
2269
2296
  ordersData,
2270
2297
  marketplace
2271
2298
  });
2272
- useEffect5(() => {
2299
+ useEffect6(() => {
2273
2300
  if (tokenApproval?.step && !tokenApprovalIsLoading) {
2274
2301
  steps$.approval.exist.set(true);
2275
2302
  }
@@ -3028,7 +3055,7 @@ var createListingModal$ = observable7({
3028
3055
  });
3029
3056
 
3030
3057
  // src/react/ui/modals/CreateListingModal/hooks/useCreateListing.tsx
3031
- import { useEffect as useEffect6 } from "react";
3058
+ import { useEffect as useEffect7 } from "react";
3032
3059
 
3033
3060
  // src/react/ui/modals/CreateListingModal/hooks/useGetTokenApproval.ts
3034
3061
  import { skipToken as skipToken4, useQuery as useQuery4 } from "@tanstack/react-query";
@@ -3285,7 +3312,7 @@ var useCreateListing = ({
3285
3312
  enabled: !marketplaceIsLoading
3286
3313
  }
3287
3314
  });
3288
- useEffect6(() => {
3315
+ useEffect7(() => {
3289
3316
  if (tokenApproval?.step && !tokenApprovalIsLoading) {
3290
3317
  steps$.approval.exist.set(true);
3291
3318
  }
@@ -3496,6 +3523,7 @@ import { use$ as use$3 } from "@legendapp/state/react";
3496
3523
 
3497
3524
  // src/react/ui/modals/BuyModal/hooks/useBuyCollectable.ts
3498
3525
  import { useSelectPaymentModal } from "@0xsequence/kit-checkout";
3526
+ import { zeroAddress } from "viem";
3499
3527
 
3500
3528
  // src/react/ui/modals/BuyModal/store.ts
3501
3529
  import { observable as observable8 } from "@legendapp/state";
@@ -3590,9 +3618,28 @@ var useBuyCollectable = ({
3590
3618
  additionalFees: [fees],
3591
3619
  walletType: "unknown" /* unknown */
3592
3620
  });
3621
+ const order = await marketplaceClient.getOrders({
3622
+ input: [
3623
+ {
3624
+ orderId: input.orderId,
3625
+ contractAddress: collectionAddress,
3626
+ marketplace: input.marketplace
3627
+ }
3628
+ ]
3629
+ });
3593
3630
  setCheckoutModalLoaded(true);
3594
3631
  setCheckoutModalIsLoading(false);
3595
- const step = steps3[0];
3632
+ const step = steps3.find((step2) => step2.id === "buy" /* buy */);
3633
+ if (!step) {
3634
+ throw new Error("Buy step not found");
3635
+ }
3636
+ const feesBps = BigInt(fees.amount);
3637
+ let price = String(
3638
+ BigInt(order.orders[0].priceAmount) * BigInt(input.quantity) * (10000n + feesBps) / 10000n
3639
+ );
3640
+ if (order.orders[0].priceCurrencyAddress !== zeroAddress) {
3641
+ price = "0";
3642
+ }
3596
3643
  openSelectPaymentModal({
3597
3644
  chain: chainId,
3598
3645
  collectibles: [
@@ -3603,7 +3650,7 @@ var useBuyCollectable = ({
3603
3650
  }
3604
3651
  ],
3605
3652
  currencyAddress: priceCurrencyAddress,
3606
- price: step.value,
3653
+ price,
3607
3654
  targetContractAddress: step.to,
3608
3655
  txData: step.data,
3609
3656
  collectionAddress,
@@ -3712,10 +3759,10 @@ var useLoadData = ({
3712
3759
  };
3713
3760
 
3714
3761
  // src/react/ui/modals/BuyModal/modals/CheckoutModal.tsx
3715
- import { useEffect as useEffect7 } from "react";
3762
+ import { useEffect as useEffect8 } from "react";
3716
3763
  import { parseUnits as parseUnits5 } from "viem";
3717
3764
  function CheckoutModal({ buy, collectable, order }) {
3718
- useEffect7(() => {
3765
+ useEffect8(() => {
3719
3766
  if (buyModal$.state.checkoutModalIsLoading.get() || buyModal$.state.checkoutModalLoaded.get())
3720
3767
  return;
3721
3768
  const executeBuy = () => {
@@ -3992,7 +4039,7 @@ var DiamondEye_default = SvgDiamondEyeIcon;
3992
4039
  import { observer as observer12 } from "@legendapp/state/react";
3993
4040
 
3994
4041
  // src/react/ui/components/_internals/action-button/hooks/useActionButtonLogic.ts
3995
- import { useEffect as useEffect8 } from "react";
4042
+ import { useEffect as useEffect9 } from "react";
3996
4043
  import { useAccount as useAccount6 } from "wagmi";
3997
4044
 
3998
4045
  // src/react/ui/components/_internals/action-button/store.ts
@@ -4034,7 +4081,7 @@ var useActionButtonLogic = ({
4034
4081
  "Make an offer" /* OFFER */
4035
4082
  ];
4036
4083
  const pendingActionType = actionButtonStore.pendingAction.type.get();
4037
- useEffect8(() => {
4084
+ useEffect9(() => {
4038
4085
  if (owned && actionButtonStore.pendingAction.get() && address && !actionsThatOwnersCannotPerform.includes(action) && actionButtonStore.pendingAction.get()?.collectibleId === tokenId) {
4039
4086
  onCannotPerformAction?.(
4040
4087
  pendingActionType
@@ -4050,7 +4097,7 @@ var useActionButtonLogic = ({
4050
4097
  onCannotPerformAction,
4051
4098
  pendingActionType
4052
4099
  ]);
4053
- useEffect8(() => {
4100
+ useEffect9(() => {
4054
4101
  if (address && !owned && actionButtonStore.pendingAction.get() && actionButtonStore.pendingAction.get()?.collectibleId === tokenId) {
4055
4102
  setTimeout(() => {
4056
4103
  executePendingActionIfExists();
@@ -4389,6 +4436,7 @@ var formatPrice = (amount, currency) => {
4389
4436
  var Footer = ({
4390
4437
  name,
4391
4438
  type,
4439
+ decimals,
4392
4440
  onOfferClick,
4393
4441
  highestOffer,
4394
4442
  lowestListingPriceAmount,
@@ -4471,16 +4519,24 @@ var Footer = ({
4471
4519
  }
4472
4520
  )
4473
4521
  ] }),
4474
- /* @__PURE__ */ jsx35(TokenTypeBalancePill, { balance, type })
4522
+ /* @__PURE__ */ jsx35(
4523
+ TokenTypeBalancePill,
4524
+ {
4525
+ balance,
4526
+ type,
4527
+ decimals
4528
+ }
4529
+ )
4475
4530
  ]
4476
4531
  }
4477
4532
  );
4478
4533
  };
4479
4534
  var TokenTypeBalancePill = ({
4480
4535
  balance,
4481
- type
4536
+ type,
4537
+ decimals
4482
4538
  }) => {
4483
- const displayText = type === "ERC1155" /* ERC1155 */ ? balance ? `Owned: ${balance}` : "ERC-1155" : "ERC-721";
4539
+ const displayText = type === "ERC1155" /* ERC1155 */ ? balance ? `Owned: ${formatUnits8(BigInt(balance), decimals ?? 0)}` : "ERC-1155" : "ERC-721";
4484
4540
  return /* @__PURE__ */ jsx35(
4485
4541
  Text16,
4486
4542
  {
@@ -4632,7 +4688,8 @@ function CollectibleCard({
4632
4688
  highestOffer,
4633
4689
  lowestListingPriceAmount: lowestListing?.order?.priceAmount,
4634
4690
  lowestListingCurrency,
4635
- balance
4691
+ balance,
4692
+ decimals: collectibleMetadata?.decimals
4636
4693
  }
4637
4694
  ),
4638
4695
  (highestOffer || lowestListing) && /* @__PURE__ */ jsx36(
@@ -4678,4 +4735,4 @@ export {
4678
4735
  useBuyModal,
4679
4736
  CollectibleCard
4680
4737
  };
4681
- //# sourceMappingURL=chunk-ZGVCOQ4I.js.map
4738
+ //# sourceMappingURL=chunk-CIPPTQDA.js.map