@0xsequence/marketplace-sdk 1.2.1 → 2.0.1
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/.storybook/preview.tsx +4 -7
- package/CHANGELOG.md +179 -0
- package/compile-tailwind.js +1 -1
- package/dist/BellIcon.js +7 -4
- package/dist/BellIcon.js.map +1 -1
- package/dist/Card.js +831 -0
- package/dist/Card.js.map +1 -0
- package/dist/ShopCard.d.ts +83 -0
- package/dist/_internal.js +57 -1
- package/dist/_internal.js.map +1 -1
- package/dist/abi.js +24 -1
- package/dist/abi.js.map +1 -1
- package/dist/alertMessage.js +29 -0
- package/dist/alertMessage.js.map +1 -0
- package/dist/api.js +95 -108
- package/dist/api.js.map +1 -1
- package/dist/builder-api.js +17 -4
- package/dist/builder-api.js.map +1 -1
- package/dist/calendar.js +51 -0
- package/dist/calendar.js.map +1 -0
- package/dist/checkout.js +52 -0
- package/dist/checkout.js.map +1 -0
- package/dist/collectible.js +620 -0
- package/dist/collectible.js.map +1 -0
- package/dist/collection.js +396 -0
- package/dist/collection.js.map +1 -0
- package/dist/{marketplaceConfig.js → config.js} +25 -31
- package/dist/config.js.map +1 -0
- package/dist/consts.d.ts +7 -0
- package/dist/consts.js +8 -0
- package/dist/consts.js.map +1 -0
- package/dist/contracts.js +22 -2
- package/dist/contracts.js.map +1 -1
- package/dist/create-config.d.ts +12037 -1801
- package/dist/create-config.js +9 -7
- package/dist/create-config.js.map +1 -1
- package/dist/currency.js +186 -0
- package/dist/currency.js.map +1 -0
- package/dist/currencyImage.js +28 -0
- package/dist/currencyImage.js.map +1 -0
- package/dist/dist.js +2771 -0
- package/dist/dist.js.map +1 -0
- package/dist/expirationDateSelect.js +245 -0
- package/dist/expirationDateSelect.js.map +1 -0
- package/dist/filter-state.d.ts +153 -0
- package/dist/filters.d.ts +14 -45
- package/dist/hooks.js +26 -0
- package/dist/hooks.js.map +1 -0
- package/dist/hooks2.js +24 -0
- package/dist/hooks2.js.map +1 -0
- package/dist/index.d.ts +12 -8
- package/dist/index.js +7 -10
- package/dist/index10.d.ts +39 -261
- package/dist/index11.d.ts +461 -220
- package/dist/index12.d.ts +511 -85
- package/dist/index13.d.ts +17 -493
- package/dist/index14.d.ts +15 -66
- package/dist/index15.d.ts +25 -1
- package/dist/index16.d.ts +5 -47
- package/dist/index17.d.ts +840 -108
- package/dist/index18.d.ts +552 -1
- package/dist/index19.d.ts +317 -147
- package/dist/index2.d.ts +2172 -5
- package/dist/index21.d.ts +306 -93
- package/dist/index22.d.ts +230 -1
- package/dist/index23.d.ts +323 -797
- package/dist/index24.d.ts +22 -445
- package/dist/index25.d.ts +1 -357
- package/dist/index26.d.ts +20 -151
- package/dist/index27.d.ts +18 -794
- package/dist/index28.d.ts +109 -58
- package/dist/index29.d.ts +1 -24
- package/dist/index3.d.ts +2212 -51
- package/dist/index30.d.ts +1 -0
- package/dist/index31.d.ts +48 -0
- package/dist/index32.d.ts +1 -0
- package/dist/index33.d.ts +56 -0
- package/dist/index34.d.ts +99 -0
- package/dist/index35.d.ts +171 -0
- package/dist/index36.d.ts +131 -0
- package/dist/index37.d.ts +137 -0
- package/dist/index38.d.ts +85 -0
- package/dist/index39.d.ts +91 -0
- package/dist/index4.d.ts +2634 -17
- package/dist/index40.d.ts +46 -0
- package/dist/index5.d.ts +535 -2267
- package/dist/index6.d.ts +2025 -1287
- package/dist/index7.d.ts +1798 -116
- package/dist/index8.d.ts +123 -12
- package/dist/index9.d.ts +42 -56
- package/dist/inventory.d.ts +46 -0
- package/dist/inventory.js +58 -35
- package/dist/inventory.js.map +1 -1
- package/dist/marketplace-logos.js +1 -1
- package/dist/marketplace-logos.js.map +1 -1
- package/dist/marketplace2.js +70 -0
- package/dist/marketplace2.js.map +1 -0
- package/dist/metadata.d.ts +733 -0
- package/dist/network.js +1 -1
- package/dist/networkconfigToWagmiChain.js.map +1 -1
- package/dist/primary-sale-checkout-options.d.ts +29 -0
- package/dist/quantityInput.js +93 -0
- package/dist/quantityInput.js.map +1 -0
- package/dist/ranges.d.ts +125 -0
- package/dist/react/_internal/api/index.d.ts +5 -2
- package/dist/react/_internal/api/index.js +4 -7
- package/dist/react/_internal/databeat/index.d.ts +4 -1
- package/dist/react/_internal/databeat/index.js +4 -37
- package/dist/react/_internal/index.d.ts +5 -2
- package/dist/react/_internal/index.js +5 -10
- package/dist/react/_internal/wagmi/index.d.ts +4 -1
- package/dist/react/_internal/wagmi/index.js +1 -4
- package/dist/react/hooks/_deprecated/index.d.ts +47 -0
- package/dist/react/hooks/_deprecated/index.js +4 -0
- package/dist/react/hooks/checkout/index.d.ts +7 -0
- package/dist/react/hooks/checkout/index.js +7 -0
- package/dist/react/hooks/collectible/index.d.ts +7 -0
- package/dist/react/hooks/collectible/index.js +7 -0
- package/dist/react/hooks/collection/index.d.ts +11 -0
- package/dist/react/hooks/collection/index.js +7 -0
- package/dist/react/hooks/config/index.d.ts +5 -4
- package/dist/react/hooks/config/index.js +4 -37
- package/dist/react/hooks/contracts/index.d.ts +4 -7
- package/dist/react/hooks/contracts/index.js +3 -16
- package/dist/react/hooks/currency/index.d.ts +47 -0
- package/dist/react/hooks/currency/index.js +7 -0
- package/dist/react/hooks/index.d.ts +41 -31
- package/dist/react/hooks/index.js +14 -38
- package/dist/react/hooks/inventory/index.d.ts +7 -0
- package/dist/react/hooks/inventory/index.js +4 -0
- package/dist/react/hooks/token/index.d.ts +7 -0
- package/dist/react/hooks/token/index.js +7 -0
- package/dist/react/hooks/transactions/index.d.ts +5 -2
- package/dist/react/hooks/transactions/index.js +5 -38
- package/dist/react/hooks/ui/card-data/index.d.ts +8 -0
- package/dist/react/hooks/ui/card-data/index.js +4 -0
- package/dist/react/hooks/ui/index.d.ts +9 -3
- package/dist/react/hooks/ui/index.js +8 -38
- package/dist/react/hooks/ui/url-state/index.d.ts +7 -0
- package/dist/react/hooks/ui/url-state/index.js +4 -0
- package/dist/react/hooks/utils/index.d.ts +3 -34
- package/dist/react/hooks/utils/index.js +5 -38
- package/dist/react/index.d.ts +45 -35
- package/dist/react/index.js +19 -37
- package/dist/react/providers/index.d.ts +6 -0
- package/dist/react/providers/index.js +6 -0
- package/dist/react/queries/checkout/index.d.ts +7 -0
- package/dist/react/queries/checkout/index.js +4 -0
- package/dist/react/queries/collectible/index.d.ts +7 -0
- package/dist/react/queries/collectible/index.js +5 -0
- package/dist/react/queries/collection/index.d.ts +11 -0
- package/dist/react/queries/collection/index.js +4 -0
- package/dist/react/queries/currency/index.d.ts +6 -0
- package/dist/react/queries/currency/index.js +4 -0
- package/dist/react/queries/index.d.ts +20 -21
- package/dist/react/queries/index.js +11 -30
- package/dist/react/queries/inventory/index.d.ts +6 -2
- package/dist/react/queries/inventory/index.js +3 -21
- package/dist/react/queries/marketplace/index.d.ts +7 -0
- package/dist/react/queries/marketplace/index.js +5 -0
- package/dist/react/queries/token/index.d.ts +7 -0
- package/dist/react/queries/token/index.js +4 -0
- package/dist/react/ssr/index.d.ts +12 -24
- package/dist/react/ssr/index.js +13 -33
- package/dist/react/ui/components/marketplace-collectible-card/ActionButton/index.d.ts +6 -0
- package/dist/react/ui/components/marketplace-collectible-card/ActionButton/index.js +6 -0
- package/dist/react/ui/components/marketplace-collectible-card/Card/index.d.ts +10 -0
- package/dist/react/ui/components/marketplace-collectible-card/Card/index.js +6 -0
- package/dist/react/ui/components/marketplace-collectible-card/index.d.ts +44 -4
- package/dist/react/ui/components/marketplace-collectible-card/index.js +6 -38
- package/dist/react/ui/components/marketplace-collectible-card/utils/index.d.ts +5 -2
- package/dist/react/ui/components/marketplace-collectible-card/utils/index.js +3 -12
- package/dist/react/ui/components/marketplace-logos/index.d.ts +23 -22
- package/dist/react/ui/hooks/index.d.ts +47 -0
- package/dist/react/ui/hooks/index.js +15 -0
- package/dist/react/ui/icons/index.d.ts +3 -1
- package/dist/react/ui/icons/index.js +3 -14
- package/dist/react/ui/index.d.ts +47 -5
- package/dist/react/ui/index.js +6 -38
- package/dist/react/ui/modals/BuyModal/index.d.ts +47 -0
- package/dist/react/ui/modals/BuyModal/index.js +4 -0
- package/dist/react/ui/modals/CreateListingModal/index.d.ts +4 -0
- package/dist/react/ui/modals/CreateListingModal/index.js +6 -0
- package/dist/react/ui/modals/CreateListingModal/internal/hooks/index.d.ts +190 -0
- package/dist/react/ui/modals/CreateListingModal/internal/hooks/index.js +4 -0
- package/dist/react/ui/modals/MakeOfferModal/index.d.ts +4 -0
- package/dist/react/ui/modals/MakeOfferModal/index.js +4 -0
- package/dist/react/ui/modals/MakeOfferModal/internal/hooks/index.d.ts +188 -0
- package/dist/react/ui/modals/MakeOfferModal/internal/hooks/index.js +3 -0
- package/dist/react/ui/modals/SellModal/index.d.ts +6 -0
- package/dist/react/ui/modals/SellModal/index.js +6 -0
- package/dist/react/ui/modals/TransferModal/index.d.ts +47 -0
- package/dist/react/ui/modals/TransferModal/index.js +6 -0
- package/dist/react/ui/modals/_internal/components/alertMessage/index.d.ts +14 -0
- package/dist/react/ui/modals/_internal/components/alertMessage/index.js +3 -0
- package/dist/react/ui/modals/_internal/components/baseModal/index.d.ts +144 -0
- package/dist/react/ui/modals/_internal/components/baseModal/index.js +6 -0
- package/dist/react/ui/modals/_internal/components/calendar/index.d.ts +73 -0
- package/dist/react/ui/modals/_internal/components/calendar/index.js +5 -0
- package/dist/react/ui/modals/_internal/components/calendarDropdown/index.d.ts +21 -0
- package/dist/react/ui/modals/_internal/components/calendarDropdown/index.js +6 -0
- package/dist/react/ui/modals/_internal/components/currencyImage/index.d.ts +15 -0
- package/dist/react/ui/modals/_internal/components/currencyImage/index.js +5 -0
- package/dist/react/ui/modals/_internal/components/currencyOptionsSelect/index.d.ts +30 -0
- package/dist/react/ui/modals/_internal/components/currencyOptionsSelect/index.js +6 -0
- package/dist/react/ui/modals/_internal/components/expirationDateSelect/index.d.ts +2 -0
- package/dist/react/ui/modals/_internal/components/expirationDateSelect/index.js +6 -0
- package/dist/react/ui/modals/_internal/components/floorPriceText/index.d.ts +24 -0
- package/dist/react/ui/modals/_internal/components/floorPriceText/index.js +6 -0
- package/dist/react/ui/modals/_internal/components/priceInput/index.d.ts +43 -0
- package/dist/react/ui/modals/_internal/components/priceInput/index.js +6 -0
- package/dist/react/ui/modals/_internal/components/quantityInput/index.d.ts +24 -0
- package/dist/react/ui/modals/_internal/components/quantityInput/index.js +6 -0
- package/dist/react/ui/modals/_internal/components/selectWaasFeeOptions/index.d.ts +18 -0
- package/dist/react/ui/modals/_internal/components/selectWaasFeeOptions/index.js +6 -0
- package/dist/react/ui/modals/_internal/components/switchChainErrorModal/index.d.ts +14 -0
- package/dist/react/ui/modals/_internal/components/switchChainErrorModal/index.js +6 -0
- package/dist/react/ui/modals/_internal/components/timeAgo/index.d.ts +12 -0
- package/dist/react/ui/modals/_internal/components/timeAgo/index.js +5 -0
- package/dist/react/ui/modals/_internal/components/tokenPreview/index.d.ts +19 -0
- package/dist/react/ui/modals/_internal/components/tokenPreview/index.js +6 -0
- package/dist/react/ui/modals/_internal/components/transaction-footer/index.d.ts +26 -0
- package/dist/react/ui/modals/_internal/components/transaction-footer/index.js +4 -0
- package/dist/react/ui/modals/_internal/components/transactionDetails/index.d.ts +28 -0
- package/dist/react/ui/modals/_internal/components/transactionDetails/index.js +6 -0
- package/dist/react/ui/modals/_internal/components/transactionHeader/index.d.ts +16 -0
- package/dist/react/ui/modals/_internal/components/transactionHeader/index.js +3 -0
- package/dist/react/ui/modals/_internal/components/transactionPreview/index.d.ts +36 -0
- package/dist/react/ui/modals/_internal/components/transactionPreview/index.js +6 -0
- package/dist/react/ui/modals/_internal/components/transactionStatusModal/index.d.ts +27 -0
- package/dist/react/ui/modals/_internal/components/transactionStatusModal/index.js +6 -0
- package/dist/react/utils/index.d.ts +6 -19
- package/dist/react/utils/index.js +3 -8
- package/dist/react.js +12726 -9828
- package/dist/react.js.map +1 -1
- package/dist/src.js +0 -8
- package/dist/ssr.js +26 -0
- package/dist/ssr.js.map +1 -0
- package/dist/steps.d.ts +85 -0
- package/dist/styles/index.css +2056 -376
- package/dist/switchChainErrorModal.js +97 -0
- package/dist/switchChainErrorModal.js.map +1 -0
- package/dist/timeAgo.js +29 -0
- package/dist/timeAgo.js.map +1 -0
- package/dist/token-balances.d.ts +359 -0
- package/dist/token-balances.js +62 -0
- package/dist/token-balances.js.map +1 -0
- package/dist/token2.js +247 -0
- package/dist/token2.js.map +1 -0
- package/dist/transaction-footer.js +45 -0
- package/dist/transaction-footer.js.map +1 -0
- package/dist/transaction.js +1 -7
- package/dist/transaction.js.map +1 -1
- package/dist/transactionHeader.js +32 -0
- package/dist/transactionHeader.js.map +1 -0
- package/dist/types/index.d.ts +5 -2
- package/dist/types/index.js +3 -4
- package/dist/types.d.ts +26 -16
- package/dist/types.js +29 -1
- package/dist/types.js.map +1 -1
- package/dist/url-state.js +170 -0
- package/dist/url-state.js.map +1 -0
- package/dist/utils/abi/index.d.ts +6 -5
- package/dist/utils/abi/index.js +2 -2
- package/dist/utils/abi/marketplace/index.d.ts +1 -1
- package/dist/utils/abi/primary-sale/index.d.ts +1 -1
- package/dist/utils/abi/token/index.d.ts +1 -1
- package/dist/utils/index.d.ts +9 -7
- package/dist/utils/index.js +5 -9
- package/dist/utils.js +20 -9
- package/dist/utils.js.map +1 -1
- package/dist/utils2.js +64 -106
- package/dist/utils2.js.map +1 -1
- package/dist/waas-types.d.ts +19 -0
- package/dist/xstate-store.cjs.d.ts +18 -0
- package/eslint/sequence-types.js +1069 -0
- package/eslint.config.mjs +337 -9
- package/image.d.ts +5 -0
- package/package.json +49 -47
- package/postcss.config.mjs +1 -1
- package/preserve-directives.ts +235 -0
- package/public/mockServiceWorker.js +0 -1
- package/src/react/_internal/api/builder-api.ts +26 -4
- package/src/react/_internal/api/index.ts +1 -2
- package/src/react/_internal/api/marketplace-api.ts +57 -25
- package/src/react/_internal/api/services.ts +56 -4
- package/src/react/_internal/api-mocks.ts +8 -0
- package/src/react/_internal/databeat/index.ts +4 -0
- package/src/react/_internal/databeat/types.ts +24 -28
- package/src/react/_internal/index.ts +70 -0
- package/src/react/_internal/query-builder.ts +203 -0
- package/src/react/_internal/types.ts +88 -18
- package/src/react/_internal/utils.ts +34 -52
- package/src/react/_internal/wagmi/__tests__/create-config.test.ts +11 -5
- package/src/react/_internal/wagmi/create-config.ts +2 -2
- package/src/react/_internal/wagmi/get-connectors.ts +10 -6
- package/src/react/hooks/_deprecated/index.ts +61 -0
- package/src/react/hooks/checkout/index.ts +1 -0
- package/src/react/hooks/{utils/useCheckoutOptionsSalesContract.test.tsx → checkout/primary-sale-checkout-options.test.tsx} +23 -23
- package/src/react/hooks/{utils/useCheckoutOptionsSalesContract.tsx → checkout/primary-sale-checkout-options.tsx} +35 -32
- package/src/react/hooks/{data/collectibles/useBalanceOfCollectible.test.tsx → collectible/balance.test.tsx} +37 -29
- package/src/react/hooks/{data/collectibles/useBalanceOfCollectible.tsx → collectible/balance.tsx} +11 -11
- package/src/react/hooks/{data/primary-sales/useErc721SalesData.tsx → collectible/erc721-sale-details.tsx} +6 -6
- package/src/react/hooks/collectible/index.ts +16 -0
- package/src/react/hooks/{data/collectibles/useCountOfCollectables.test.tsx → collectible/market-count.test.tsx} +21 -16
- package/src/react/hooks/{data/collectibles/useCountOfCollectables.tsx → collectible/market-count.tsx} +13 -8
- package/src/react/hooks/{data/orders/useHighestOffer.test.tsx → collectible/market-highest-offer.test.tsx} +35 -24
- package/src/react/hooks/{data/orders/useHighestOffer.tsx → collectible/market-highest-offer.tsx} +12 -10
- package/src/react/hooks/{data/collectibles/useListCollectiblesPaginated.test.tsx → collectible/market-list-paginated.test.tsx} +18 -18
- package/src/react/hooks/{data/collectibles/useListCollectiblesPaginated.tsx → collectible/market-list-paginated.tsx} +12 -10
- package/src/react/hooks/{data/collectibles/useListCollectibles.test.tsx → collectible/market-list.test.tsx} +51 -39
- package/src/react/hooks/{data/collectibles/useListCollectibles.tsx → collectible/market-list.tsx} +11 -10
- package/src/react/hooks/{data/orders/useCountListingsForCollectible.test.tsx → collectible/market-listings-count.test.tsx} +13 -10
- package/src/react/hooks/{data/orders/useCountListingsForCollectible.tsx → collectible/market-listings-count.tsx} +11 -11
- package/src/react/hooks/{data/orders/useListListingsForCollectible.test.tsx → collectible/market-listings.test.tsx} +19 -19
- package/src/react/hooks/{data/orders/useListListingsForCollectible.tsx → collectible/market-listings.tsx} +17 -19
- package/src/react/hooks/{data/orders/useLowestListing.test.tsx → collectible/market-lowest-listing.test.tsx} +35 -24
- package/src/react/hooks/{data/orders/useLowestListing.tsx → collectible/market-lowest-listing.tsx} +12 -10
- package/src/react/hooks/{data/orders/useCountOffersForCollectible.test.tsx → collectible/market-offers-count.test.tsx} +13 -10
- package/src/react/hooks/{data/orders/useCountOffersForCollectible.tsx → collectible/market-offers-count.tsx} +11 -11
- package/src/react/hooks/{data/orders/useListOffersForCollectible.test.tsx → collectible/market-offers.test.tsx} +17 -17
- package/src/react/hooks/{data/orders/useListOffersForCollectible.tsx → collectible/market-offers.tsx} +16 -17
- package/src/react/hooks/{data/collectibles/useCollectible.test.tsx → collectible/metadata.test.tsx} +25 -23
- package/src/react/hooks/{data/collectibles/useCollectible.tsx → collectible/metadata.tsx} +17 -14
- package/src/react/hooks/collectible/primary-sale-item.test.tsx +503 -0
- package/src/react/hooks/{data/primary-sales/usePrimarySaleItem.tsx → collectible/primary-sale-item.tsx} +6 -8
- package/src/react/hooks/collectible/primary-sale-items-count.test.tsx +154 -0
- package/src/react/hooks/collectible/primary-sale-items-count.tsx +22 -0
- package/src/react/hooks/collectible/primary-sale-items.test.tsx +259 -0
- package/src/react/hooks/{data/primary-sales/useListPrimarySaleItems.tsx → collectible/primary-sale-items.tsx} +9 -9
- package/src/react/hooks/{data/collectibles/useTokenBalances.test.tsx → collectible/token-balances.test.tsx} +52 -28
- package/src/react/hooks/{data/collectibles/useTokenBalances.tsx → collectible/token-balances.tsx} +10 -10
- package/src/react/hooks/{data/collections/__snapshots__/useListCollections.test.tsx.snap → collection/__snapshots__/list.test.tsx.snap} +20 -20
- package/src/react/hooks/{data/collections/useCollectionBalanceDetails.test.tsx → collection/balance-details.test.tsx} +13 -8
- package/src/react/hooks/{data/collections/useCollectionBalanceDetails.tsx → collection/balance-details.tsx} +3 -3
- package/src/react/hooks/collection/index.ts +11 -0
- package/src/react/hooks/{data/collections/useListCollections.test.tsx → collection/list.test.tsx} +15 -14
- package/src/react/hooks/{data/collections/useListCollections.tsx → collection/list.tsx} +7 -7
- package/src/react/hooks/collection/market-detail-polling.test.tsx +146 -0
- package/src/react/hooks/{data/collections/useCollectionDetailsPolling.tsx → collection/market-detail-polling.tsx} +13 -12
- package/src/react/hooks/collection/market-filtered-count.test.tsx +121 -0
- package/src/react/hooks/{data/orders/useGetCountOfFilteredOrders.tsx → collection/market-filtered-count.tsx} +6 -6
- package/src/react/hooks/{data/orders/useFloorOrder.test.tsx → collection/market-floor.test.tsx} +19 -15
- package/src/react/hooks/{data/orders/useFloorOrder.tsx → collection/market-floor.tsx} +13 -9
- package/src/react/hooks/collection/market-items-count.test.tsx +121 -0
- package/src/react/hooks/{data/orders/useCountItemsOrdersForCollection.tsx → collection/market-items-count.tsx} +9 -9
- package/src/react/hooks/collection/market-items-paginated.test.tsx +142 -0
- package/src/react/hooks/{data/orders/useListItemsOrdersForCollectionPaginated.tsx → collection/market-items-paginated.tsx} +11 -9
- package/src/react/hooks/collection/market-items.test.tsx +184 -0
- package/src/react/hooks/{data/orders/useListItemsOrdersForCollection.tsx → collection/market-items.tsx} +16 -14
- package/src/react/hooks/{data/collections/useCollection.test.tsx → collection/metadata.test.tsx} +18 -13
- package/src/react/hooks/{data/collections/useCollection.tsx → collection/metadata.tsx} +16 -7
- package/src/react/hooks/collection/useCollectionActiveListingsCurrencies.test.tsx +150 -0
- package/src/react/hooks/{data/collections → collection}/useCollectionActiveListingsCurrencies.tsx +3 -3
- package/src/react/hooks/collection/useCollectionActiveOffersCurrencies.test.tsx +150 -0
- package/src/react/hooks/{data/collections → collection}/useCollectionActiveOffersCurrencies.tsx +3 -3
- package/src/react/hooks/config/__snapshots__/useMarketplaceConfig.test.tsx.snap +12 -11
- package/src/react/hooks/config/useConnectorMetadata.tsx +1 -1
- package/src/react/hooks/config/useMarketplaceConfig.test.tsx +3 -1
- package/src/react/hooks/config/useMarketplaceConfig.tsx +1 -1
- package/src/react/hooks/contracts/index.ts +1 -0
- package/src/react/hooks/contracts/useERC721Owner.test.tsx +82 -0
- package/src/react/hooks/contracts/useERC721Owner.tsx +47 -0
- package/src/react/hooks/contracts/useSalesContractABI.ts +2 -2
- package/src/react/hooks/{utils/useComparePrices.test.tsx → currency/compare-prices.test.tsx} +17 -11
- package/src/react/hooks/{utils/useComparePrices.tsx → currency/compare-prices.tsx} +8 -6
- package/src/react/hooks/{utils/useConvertPriceToUSD.test.tsx → currency/convert-to-usd.test.tsx} +17 -16
- package/src/react/hooks/{utils/useConvertPriceToUSD.tsx → currency/convert-to-usd.tsx} +6 -6
- package/src/react/hooks/{data/market/useCurrency.test.tsx → currency/currency.test.tsx} +18 -14
- package/src/react/hooks/{data/market/useCurrency.tsx → currency/currency.tsx} +3 -3
- package/src/react/hooks/currency/index.ts +4 -0
- package/src/react/hooks/{data/market/useMarketCurrencies.test.tsx → currency/list.test.tsx} +55 -59
- package/src/react/hooks/{data/market/useMarketCurrencies.tsx → currency/list.tsx} +7 -7
- package/src/react/hooks/data/orders/useOrders.test.tsx +143 -0
- package/src/react/hooks/data/orders/useOrders.tsx +73 -0
- package/src/react/hooks/data/tokens/useCurrencyBalance.tsx +1 -1
- package/src/react/hooks/index.ts +9 -12
- package/src/react/hooks/inventory/index.ts +1 -0
- package/src/react/hooks/{data/inventory/useInventory.test.tsx → inventory/inventory.test.tsx} +12 -14
- package/src/react/hooks/inventory/inventory.tsx +17 -0
- package/src/react/hooks/{data/tokens/useListBalances.test.tsx → token/balances.test.tsx} +22 -11
- package/src/react/hooks/token/balances.tsx +59 -0
- package/src/react/hooks/{data/tokens/useCurrencyBalance.test.tsx → token/currency-balance.test.tsx} +6 -6
- package/src/react/hooks/token/currency-balance.tsx +151 -0
- package/src/react/hooks/token/index.ts +5 -0
- package/src/react/hooks/{data/tokens/useSearchTokenMetadata.test.tsx → token/metadata-search.test.tsx} +38 -30
- package/src/react/hooks/{data/tokens/useSearchTokenMetadata.tsx → token/metadata-search.tsx} +27 -24
- package/src/react/hooks/{data/tokens/useListTokenMetadata.test.tsx → token/metadata.test.tsx} +27 -24
- package/src/react/hooks/{data/tokens/useListTokenMetadata.tsx → token/metadata.tsx} +7 -7
- package/src/react/hooks/{data/tokens/useGetTokenRanges.test.tsx → token/ranges.test.tsx} +15 -14
- package/src/react/hooks/{data/tokens/useGetTokenRanges.tsx → token/ranges.tsx} +12 -13
- package/src/react/hooks/transactions/index.ts +5 -0
- package/src/react/hooks/transactions/useBuyTransaction.tsx +95 -0
- package/src/react/hooks/transactions/useCancelOrder.test.tsx +15 -35
- package/src/react/hooks/transactions/useCancelOrder.tsx +3 -9
- package/src/react/hooks/transactions/useCancelTransactionSteps.tsx +3 -9
- package/src/react/hooks/transactions/useGenerateCancelTransaction.test.tsx +23 -12
- package/src/react/hooks/transactions/useGenerateCancelTransaction.tsx +16 -11
- package/src/react/hooks/transactions/useGenerateListingTransaction.test.tsx +17 -57
- package/src/react/hooks/transactions/useGenerateListingTransaction.tsx +17 -12
- package/src/react/hooks/transactions/useGenerateOfferTransaction.test.tsx +14 -15
- package/src/react/hooks/transactions/useGenerateOfferTransaction.tsx +11 -11
- package/src/react/hooks/transactions/useGenerateSellTransaction.test.tsx +28 -38
- package/src/react/hooks/transactions/useGenerateSellTransaction.tsx +16 -15
- package/src/react/hooks/transactions/useMarketTransactionSteps.test.tsx +105 -0
- package/src/react/hooks/transactions/useMarketTransactionSteps.tsx +129 -0
- package/src/react/hooks/transactions/useOrderSteps.tsx +23 -36
- package/src/react/hooks/transactions/usePrimarySaleTransactionSteps.ts +196 -0
- package/src/react/hooks/transactions/useProcessStep.test.tsx +63 -59
- package/src/react/hooks/transactions/useProcessStep.ts +52 -54
- package/src/react/hooks/transactions/useTransactionExecution.test.tsx +99 -0
- package/src/react/hooks/transactions/useTransactionExecution.ts +31 -0
- package/src/react/hooks/transactions/useTransactionType.ts +20 -0
- package/src/react/hooks/transactions/useTransferTokens.test.tsx +16 -16
- package/src/react/hooks/transactions/useTransferTokens.tsx +17 -5
- package/src/react/hooks/ui/card-data/index.ts +4 -0
- package/src/react/hooks/ui/card-data/market-card-data-paged.test.tsx +375 -0
- package/src/react/hooks/ui/card-data/market-card-data-paged.tsx +265 -0
- package/src/react/hooks/{data/market/useListMarketCardData.test.tsx → ui/card-data/market-card-data.test.tsx} +30 -28
- package/src/react/hooks/{data/market/useListMarketCardData.tsx → ui/card-data/market-card-data.tsx} +44 -31
- package/src/react/hooks/{data/primary-sales/useList1155ShopCardData.tsx → ui/card-data/primary-sale-1155-card-data.tsx} +24 -31
- package/src/react/hooks/{data/primary-sales/useList721ShopCardData.tsx → ui/card-data/primary-sale-721-card-data.tsx} +70 -37
- package/src/react/hooks/ui/index.ts +3 -1
- package/src/react/hooks/ui/url-state/filter-state.test.tsx +569 -0
- package/src/react/hooks/ui/{useFilterState.tsx → url-state/filter-state.tsx} +34 -20
- package/src/react/hooks/ui/url-state/index.ts +1 -0
- package/src/react/hooks/ui/useCollectibleCardOfferState.test.tsx +75 -0
- package/src/react/hooks/ui/useCollectibleCardOfferState.ts +47 -0
- package/src/react/hooks/ui/useFilters.test.tsx +4 -1
- package/src/react/hooks/ui/useFilters.tsx +2 -2
- package/src/react/hooks/util/optimisticCancelUpdates.test.ts +489 -0
- package/src/react/hooks/util/optimisticCancelUpdates.ts +21 -22
- package/src/react/hooks/utils/index.ts +0 -4
- package/src/react/hooks/utils/useAutoSelectFeeOption.test.tsx +8 -5
- package/src/react/hooks/utils/useAutoSelectFeeOption.tsx +33 -17
- package/src/react/hooks/utils/useRoyalty.test.tsx +1 -1
- package/src/react/hooks/utils/useRoyalty.tsx +99 -34
- package/src/react/hooks/utils/useWaasFeeOptions.tsx +234 -0
- package/src/react/hooks/utils/waasFeeOptionsStore.ts +141 -0
- package/src/react/index.ts +3 -0
- package/src/react/providers/index.tsx +3 -3
- package/src/react/providers/modal-provider.tsx +6 -17
- package/src/react/providers/provider.test.tsx +1 -1
- package/src/react/providers/shadow-root.tsx +1 -1
- package/src/react/providers/theme-provider.tsx +1 -1
- package/src/react/queries/checkout/index.ts +1 -0
- package/src/react/queries/checkout/primary-sale-checkout-options.ts +118 -0
- package/src/react/queries/collectible/balance.ts +113 -0
- package/src/react/queries/collectible/index.ts +15 -0
- package/src/react/queries/collectible/market-count.ts +91 -0
- package/src/react/queries/collectible/market-highest-offer.ts +74 -0
- package/src/react/queries/collectible/market-list-paginated.ts +110 -0
- package/src/react/queries/collectible/market-list.ts +118 -0
- package/src/react/queries/collectible/market-listings-count.ts +70 -0
- package/src/react/queries/collectible/market-listings.ts +71 -0
- package/src/react/queries/collectible/market-lowest-listing.ts +74 -0
- package/src/react/queries/collectible/market-offers-count.ts +70 -0
- package/src/react/queries/collectible/market-offers.ts +90 -0
- package/src/react/queries/collectible/metadata.ts +84 -0
- package/src/react/queries/collectible/primary-sale-item.ts +79 -0
- package/src/react/queries/collectible/primary-sale-items-count.ts +67 -0
- package/src/react/queries/collectible/primary-sale-items.ts +96 -0
- package/src/react/queries/collectible/queryKeys.ts +12 -0
- package/src/react/queries/collectible/token-balances.ts +83 -0
- package/src/react/queries/collection/activeListingsCurrencies.ts +74 -0
- package/src/react/queries/collection/activeOffersCurrencies.ts +74 -0
- package/src/react/queries/collection/balance-details.ts +103 -0
- package/src/react/queries/collection/index.ts +9 -0
- package/src/react/queries/collection/list.ts +195 -0
- package/src/react/queries/collection/market-detail.ts +60 -0
- package/src/react/queries/collection/market-filtered-count.ts +67 -0
- package/src/react/queries/collection/market-floor.ts +58 -0
- package/src/react/queries/collection/market-items-count.ts +69 -0
- package/src/react/queries/collection/market-items-paginated.ts +84 -0
- package/src/react/queries/collection/market-items.ts +72 -0
- package/src/react/queries/collection/metadata.ts +60 -0
- package/src/react/queries/collection/queryKeys.ts +12 -0
- package/src/react/queries/currency/compare-prices.ts +122 -0
- package/src/react/queries/currency/convert-to-usd.ts +99 -0
- package/src/react/queries/currency/currency.ts +82 -0
- package/src/react/queries/currency/index.ts +4 -0
- package/src/react/queries/currency/list.ts +103 -0
- package/src/react/queries/index.ts +6 -7
- package/src/react/queries/inventory/inventory.ts +144 -94
- package/src/react/queries/marketplace/config.ts +85 -0
- package/src/react/queries/marketplace/filters.ts +141 -0
- package/src/react/queries/marketplace/index.ts +2 -0
- package/src/react/queries/marketplace/queryKeys.ts +12 -0
- package/src/react/queries/orders.ts +48 -0
- package/src/react/queries/token/balances.ts +107 -0
- package/src/react/queries/token/index.ts +5 -0
- package/src/react/queries/token/metadata-search.ts +95 -0
- package/src/react/queries/token/metadata.ts +80 -0
- package/src/react/queries/token/queryKeys.ts +12 -0
- package/src/react/queries/token/ranges.ts +74 -0
- package/src/react/queries/token/supplies.ts +86 -0
- package/src/react/ssr/__tests__/__snapshots__/create-ssr-client.test.ts.snap +11 -10
- package/src/react/ssr/create-ssr-client.ts +1 -1
- package/src/react/ssr/index.ts +5 -0
- package/src/react/types/query.ts +8 -7
- package/src/react/ui/components/_internals/ErrorDisplay.tsx +87 -0
- package/src/react/ui/components/_internals/ErrorLogBox.tsx +8 -1
- package/src/react/ui/components/_internals/custom-select/CustomSelect.tsx +13 -14
- package/src/react/ui/components/_internals/pill/__tests__/Pill.test.tsx +9 -5
- package/src/react/ui/components/{_internals/action-button → marketplace-collectible-card/ActionButton}/ActionButton.stories.tsx +24 -29
- package/src/react/ui/components/{_internals/action-button → marketplace-collectible-card/ActionButton}/ActionButton.tsx +20 -14
- package/src/react/ui/components/{_internals/action-button → marketplace-collectible-card/ActionButton}/__tests__/ActionButtonBody.test.tsx +7 -5
- package/src/react/ui/components/{_internals/action-button → marketplace-collectible-card/ActionButton}/__tests__/NonOwnerActions.test.tsx +11 -6
- package/src/react/ui/components/{_internals/action-button → marketplace-collectible-card/ActionButton}/__tests__/OwnerActions.test.tsx +8 -6
- package/src/react/ui/components/{_internals/action-button → marketplace-collectible-card/ActionButton}/__tests__/useActionButtonLogic.test.tsx +6 -4
- package/src/react/ui/components/{_internals/action-button → marketplace-collectible-card/ActionButton}/components/ActionButtonBody.tsx +14 -9
- package/src/react/ui/components/{_internals/action-button → marketplace-collectible-card/ActionButton}/components/NonOwnerActions.tsx +26 -35
- package/src/react/ui/components/{_internals/action-button → marketplace-collectible-card/ActionButton}/components/OwnerActions.tsx +21 -13
- package/src/react/ui/components/{_internals/action-button → marketplace-collectible-card/ActionButton}/hooks/useActionButtonLogic.ts +3 -3
- package/src/react/ui/components/marketplace-collectible-card/ActionButton/index.ts +1 -0
- package/src/react/ui/components/{_internals/action-button → marketplace-collectible-card/ActionButton}/store.ts +4 -4
- package/src/react/ui/components/marketplace-collectible-card/Card/card-badge.tsx +37 -0
- package/src/react/ui/components/marketplace-collectible-card/Card/card-content.tsx +27 -0
- package/src/react/ui/components/marketplace-collectible-card/Card/card-footer.tsx +38 -0
- package/src/react/ui/components/marketplace-collectible-card/Card/card-media.tsx +69 -0
- package/src/react/ui/components/marketplace-collectible-card/Card/card-price.tsx +44 -0
- package/src/react/ui/components/marketplace-collectible-card/Card/card-sale-details.tsx +37 -0
- package/src/react/ui/components/marketplace-collectible-card/Card/card-skeleton.tsx +39 -0
- package/src/react/ui/components/marketplace-collectible-card/Card/card-title.tsx +109 -0
- package/src/react/ui/components/marketplace-collectible-card/Card/card.tsx +51 -0
- package/src/react/ui/components/marketplace-collectible-card/Card/index.ts +30 -0
- package/src/react/ui/components/marketplace-collectible-card/CollectibleCardSkeleton.tsx +1 -1
- package/src/react/ui/components/marketplace-collectible-card/_internals/PriceDisplay.tsx +87 -0
- package/src/react/ui/components/marketplace-collectible-card/constants.ts +20 -0
- package/src/react/ui/components/marketplace-collectible-card/index.ts +6 -0
- package/src/react/ui/components/marketplace-collectible-card/types.ts +31 -16
- package/src/react/ui/components/marketplace-collectible-card/utils/determineCardAction.ts +63 -0
- package/src/react/ui/components/marketplace-collectible-card/utils/formatPrice.ts +71 -2
- package/src/react/ui/components/marketplace-collectible-card/utils/index.ts +3 -0
- package/src/react/ui/components/marketplace-collectible-card/utils/renderSkeleton.tsx +44 -0
- package/src/react/ui/components/marketplace-collectible-card/utils/shopCardState.ts +83 -0
- package/src/react/ui/components/marketplace-collectible-card/utils/supplyStatus.ts +5 -5
- package/src/react/ui/components/marketplace-collectible-card/variants/MarketCard.tsx +63 -78
- package/src/react/ui/components/marketplace-collectible-card/variants/MarketCardPresentation.tsx +170 -0
- package/src/react/ui/components/marketplace-collectible-card/variants/NonTradableInventoryCard.tsx +56 -38
- package/src/react/ui/components/marketplace-collectible-card/variants/ShopCard.tsx +55 -65
- package/src/react/ui/components/marketplace-collectible-card/variants/ShopCardPresentation.tsx +144 -0
- package/src/react/ui/components/marketplace-logos/marketplace-logos.tsx +1 -5
- package/src/react/ui/components/media/Media.tsx +1 -1
- package/src/react/ui/components/media/MediaSkeleton.tsx +1 -1
- package/src/react/ui/hooks/index.ts +2 -0
- package/src/react/ui/icons/BellIcon.tsx +7 -3
- package/src/react/ui/icons/iconVariants.ts +11 -0
- package/src/react/ui/icons/index.ts +0 -3
- package/src/react/ui/index.ts +37 -8
- package/src/react/ui/modals/BuyModal/components/BuyModalContent.tsx +195 -0
- package/src/react/ui/modals/BuyModal/components/CollectibleMetadataSummary.tsx +141 -0
- package/src/react/ui/modals/BuyModal/components/CryptoPaymentModal.tsx +177 -0
- package/src/react/ui/modals/BuyModal/components/CryptoPaymentModalSkeleton.tsx +48 -0
- package/src/react/ui/modals/BuyModal/components/Modal.tsx +2 -2
- package/src/react/ui/modals/BuyModal/components/TrailsCss.ts +216 -0
- package/src/react/ui/modals/BuyModal/components/{ERC1155QuantityModal.tsx → sequence-checkout/ERC1155QuantityModal.tsx} +71 -82
- package/src/react/ui/modals/BuyModal/components/sequence-checkout/SequenceCheckoutNew.tsx +161 -0
- package/src/react/ui/modals/BuyModal/{hooks → components/sequence-checkout}/usePaymentModalParams.ts +73 -112
- package/src/react/ui/modals/BuyModal/components/types.ts +6 -5
- package/src/react/ui/modals/BuyModal/hooks/__tests__/useERC1155SalePaymentParams.test.tsx +2 -14
- package/src/react/ui/modals/BuyModal/hooks/useBuyModalData.ts +151 -0
- package/src/react/ui/modals/BuyModal/hooks/useERC1155SalePaymentParams.ts +15 -28
- package/src/react/ui/modals/BuyModal/hooks/useExecuteBundledTransactions.ts +167 -0
- package/src/react/ui/modals/BuyModal/hooks/useHasSufficientBalance.ts +30 -0
- package/src/react/ui/modals/BuyModal/hooks/useMarketPlatformFee.ts +7 -7
- package/src/react/ui/modals/BuyModal/index.tsx +6 -3
- package/src/react/ui/modals/BuyModal/internal/__tests__/determineCheckoutMode.test.ts +119 -0
- package/src/react/ui/modals/BuyModal/internal/buyModalContext.ts +146 -0
- package/src/react/ui/modals/BuyModal/internal/cryptoPaymentModalContext.tsx +399 -0
- package/src/react/ui/modals/BuyModal/internal/determineCheckoutMode.ts +49 -0
- package/src/react/ui/modals/BuyModal/store.ts +25 -94
- package/src/react/ui/modals/CreateListingModal/Modal.tsx +141 -308
- package/src/react/ui/modals/CreateListingModal/__tests__/Modal.test.tsx +35 -61
- package/src/react/ui/modals/CreateListingModal/index.tsx +16 -9
- package/src/react/ui/modals/CreateListingModal/internal/context.ts +416 -0
- package/src/react/ui/modals/CreateListingModal/internal/helpers/validation.ts +79 -0
- package/src/react/ui/modals/CreateListingModal/internal/hooks/index.ts +1 -0
- package/src/react/ui/modals/CreateListingModal/internal/hooks/use-collectible-approval.ts +49 -0
- package/src/react/ui/modals/CreateListingModal/internal/listing-mutations.ts +267 -0
- package/src/react/ui/modals/CreateListingModal/internal/store.ts +153 -0
- package/src/react/ui/modals/MakeOfferModal/Modal.tsx +130 -348
- package/src/react/ui/modals/MakeOfferModal/__stories__/MakeOfferModal.mock-data.ts +494 -0
- package/src/react/ui/modals/MakeOfferModal/__stories__/MakeOfferModal.stories.tsx +699 -0
- package/src/react/ui/modals/MakeOfferModal/__tests__/Modal.test.tsx +28 -155
- package/src/react/ui/modals/MakeOfferModal/index.tsx +17 -11
- package/src/react/ui/modals/MakeOfferModal/internal/context.ts +472 -0
- package/src/react/ui/modals/MakeOfferModal/internal/helpers/validation.ts +114 -0
- package/src/react/ui/modals/MakeOfferModal/internal/hooks/index.ts +1 -0
- package/src/react/ui/modals/MakeOfferModal/internal/hooks/use-erc20-allowance.ts +43 -0
- package/src/react/ui/modals/MakeOfferModal/internal/offer-mutations.ts +231 -0
- package/src/react/ui/modals/MakeOfferModal/internal/store.ts +153 -0
- package/src/react/ui/modals/SellModal/Modal.tsx +74 -213
- package/src/react/ui/modals/SellModal/index.tsx +5 -11
- package/src/react/ui/modals/SellModal/internal/context.ts +284 -0
- package/src/react/ui/modals/SellModal/internal/sell-mutations.ts +163 -0
- package/src/react/ui/modals/SellModal/internal/store.ts +79 -0
- package/src/react/ui/modals/SellModal/internal/use-generate-sell-transaction.ts +93 -0
- package/src/react/ui/modals/TransferModal/__tests__/store.test.ts +51 -345
- package/src/react/ui/modals/TransferModal/_views/enterWalletAddress/_components/TokenQuantityInput.tsx +36 -34
- package/src/react/ui/modals/TransferModal/_views/enterWalletAddress/_components/WalletAddressInput.tsx +19 -28
- package/src/react/ui/modals/TransferModal/index.tsx +98 -119
- package/src/react/ui/modals/TransferModal/internal/context.ts +404 -0
- package/src/react/ui/modals/TransferModal/internal/store.ts +118 -0
- package/src/react/ui/modals/_internal/components/alertMessage/index.tsx +2 -3
- package/src/react/ui/modals/_internal/components/baseModal/ActionModal.tsx +338 -0
- package/src/react/ui/modals/_internal/components/baseModal/BaseModal.tsx +51 -0
- package/src/react/ui/modals/_internal/components/baseModal/ErrorBoundary.tsx +83 -0
- package/src/react/ui/modals/_internal/components/baseModal/ErrorModal.tsx +51 -0
- package/src/react/ui/modals/_internal/components/baseModal/LoadingModal.tsx +35 -0
- package/src/react/ui/modals/_internal/components/baseModal/SmartErrorHandler.tsx +31 -0
- package/src/react/ui/modals/_internal/components/baseModal/__tests__/ErrorBoundary.test.tsx +390 -0
- package/src/react/ui/modals/_internal/components/baseModal/errors/ModalInitializationError.tsx +93 -0
- package/src/react/ui/modals/_internal/components/baseModal/errors/errorActionType.ts +5 -0
- package/src/react/ui/modals/_internal/components/baseModal/index.ts +13 -0
- package/src/react/ui/modals/_internal/components/calendarDropdown/TimeSelector.tsx +1 -1
- package/src/react/ui/modals/_internal/components/calendarDropdown/index.tsx +14 -9
- package/src/react/ui/modals/_internal/components/consts.ts +19 -5
- package/src/react/ui/modals/_internal/components/currencyImage/index.tsx +5 -7
- package/src/react/ui/modals/_internal/components/currencyOptionsSelect/__tests__/index.test.tsx +6 -14
- package/src/react/ui/modals/_internal/components/currencyOptionsSelect/index.tsx +17 -24
- package/src/react/ui/modals/_internal/components/expirationDateSelect/index.tsx +1 -1
- package/src/react/ui/modals/_internal/components/floorPriceText/__tests__/FloorPriceText.test.tsx +61 -40
- package/src/react/ui/modals/_internal/components/floorPriceText/index.tsx +23 -19
- package/src/react/ui/modals/_internal/components/priceInput/__tests__/PriceInput.test.tsx +3 -3
- package/src/react/ui/modals/_internal/components/priceInput/index.tsx +68 -75
- package/src/react/ui/modals/_internal/components/quantityInput/__tests__/index.test.tsx +22 -137
- package/src/react/ui/modals/_internal/components/quantityInput/index.tsx +84 -131
- package/src/react/ui/modals/_internal/components/selectWaasFeeOptions/__tests__/SelectWaasFeeOptions.test.tsx +14 -31
- package/src/react/ui/modals/_internal/components/selectWaasFeeOptions/_components/ActionButtons.tsx +37 -25
- package/src/react/ui/modals/_internal/components/selectWaasFeeOptions/index.tsx +13 -6
- package/src/react/ui/modals/_internal/components/selectWaasFeeOptions/store.ts +9 -26
- package/src/react/ui/modals/_internal/components/selectWaasFeeOptions/useWaasFeeOptionManager.tsx +27 -29
- package/src/react/ui/modals/_internal/components/switchChainErrorModal/store.ts +2 -2
- package/src/react/ui/modals/_internal/components/tokenPreview/index.tsx +10 -9
- package/src/react/ui/modals/_internal/components/transactionDetails/index.tsx +16 -9
- package/src/react/ui/modals/_internal/components/transactionPreview/index.tsx +8 -7
- package/src/react/ui/modals/_internal/components/transactionPreview/useTransactionPreviewTitle.tsx +1 -1
- package/src/react/ui/modals/_internal/components/transactionStatusModal/__tests__/TransactionStatusModal.test.tsx +3 -5
- package/src/react/ui/modals/_internal/components/transactionStatusModal/__tests__/utils.test.ts +3 -3
- package/src/react/ui/modals/_internal/components/transactionStatusModal/hooks/useTransactionStatus.ts +4 -15
- package/src/react/ui/modals/_internal/components/transactionStatusModal/index.tsx +14 -15
- package/src/react/ui/modals/_internal/components/transactionStatusModal/store.ts +8 -11
- package/src/react/ui/modals/_internal/components/waasFeeOptionsSelect/WaasFeeOptionsSelect.tsx +65 -10
- package/src/react/ui/modals/_internal/constants/opensea-currencies.ts +484 -0
- package/src/react/ui/modals/_internal/helpers/currency.ts +56 -0
- package/src/react/ui/modals/_internal/helpers/dnum-utils.ts +40 -0
- package/src/react/ui/modals/_internal/helpers/flow-state.ts +269 -0
- package/src/react/ui/modals/_internal/helpers/step-guards.ts +131 -0
- package/src/react/ui/modals/_internal/types/steps.ts +145 -0
- package/src/react/ui/modals/_internal/types.ts +2 -9
- package/src/react/utils/index.ts +2 -0
- package/src/react/utils/normalize-attributes.test.ts +94 -0
- package/src/react/utils/normalize-attributes.ts +89 -0
- package/src/react/utils/normalize-properties.test.ts +77 -0
- package/src/react/utils/normalize-properties.ts +60 -0
- package/src/react/utils/normalizePriceFilters.ts +25 -0
- package/src/react/utils/waitForTransactionReceipt.ts +2 -2
- package/src/styles/index.css +2 -0
- package/src/styles/styles.ts +2056 -376
- package/src/types/api-types.ts +6 -14
- package/src/types/buyModalErrors.ts +24 -30
- package/src/types/index.ts +4 -2
- package/src/types/sdk-config.ts +14 -1
- package/src/types/transactions.ts +10 -0
- package/src/types/types.ts +93 -14
- package/src/utils/__tests__/getMarketplaceDetails.test.ts +1 -1
- package/src/utils/_internal/error/base.ts +1 -1
- package/src/utils/_internal/error/transaction.ts +4 -5
- package/src/utils/abi/helpers.ts +38 -0
- package/src/utils/abi/index.ts +1 -0
- package/src/utils/collection.ts +19 -0
- package/src/utils/decode/erc20.ts +2 -2
- package/src/utils/errors.ts +527 -0
- package/src/utils/getConduitAddressForOrderbook.ts +38 -0
- package/src/utils/getErrorMessage.ts +37 -0
- package/src/utils/getMarketplaceDetails.ts +1 -1
- package/src/utils/getSequenceMarketRequestId.ts +3 -7
- package/src/utils/getWagmiErrorMessage.ts +241 -0
- package/src/utils/getWebRPCErrorMessage.ts +63 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/networkconfigToWagmiChain.ts +2 -1
- package/src/utils/price.ts +12 -10
- package/test/const.ts +3 -3
- package/test/globalSetup.ts +4 -5
- package/test/handlers.ts +2 -2
- package/test/server-setup.ts +8 -8
- package/test/setup.ts +11 -0
- package/test/test-utils.tsx +23 -6
- package/tsconfig.json +8 -1
- package/tsdown.config.ts +12 -3
- package/dist/CartIcon.js +0 -102
- package/dist/CartIcon.js.map +0 -1
- package/dist/CollectibleCard.d.ts +0 -8
- package/dist/builder.gen.js +0 -300
- package/dist/builder.gen.js.map +0 -1
- package/dist/collectibles.js +0 -319
- package/dist/collectibles.js.map +0 -1
- package/dist/collections.js +0 -320
- package/dist/collections.js.map +0 -1
- package/dist/components.js +0 -117
- package/dist/components.js.map +0 -1
- package/dist/listCollectiblesPaginated.d.ts +0 -322
- package/dist/listCollections.d.ts +0 -821
- package/dist/lowestListing.d.ts +0 -465
- package/dist/market.js +0 -207
- package/dist/market.js.map +0 -1
- package/dist/marketCurrencies.d.ts +0 -163
- package/dist/marketCurrencies.js +0 -56
- package/dist/marketCurrencies.js.map +0 -1
- package/dist/marketplace.gen.js +0 -1144
- package/dist/marketplace.gen.js.map +0 -1
- package/dist/marketplaceConfig.js.map +0 -1
- package/dist/orders.js +0 -462
- package/dist/orders.js.map +0 -1
- package/dist/primary-sales.js +0 -152
- package/dist/primary-sales.js.map +0 -1
- package/dist/query.d.ts +0 -31
- package/dist/react/hooks/data/collectibles/index.d.ts +0 -5
- package/dist/react/hooks/data/collectibles/index.js +0 -39
- package/dist/react/hooks/data/collections/index.d.ts +0 -11
- package/dist/react/hooks/data/collections/index.js +0 -39
- package/dist/react/hooks/data/index.d.ts +0 -37
- package/dist/react/hooks/data/index.js +0 -39
- package/dist/react/hooks/data/inventory/index.d.ts +0 -37
- package/dist/react/hooks/data/inventory/index.js +0 -39
- package/dist/react/hooks/data/market/index.d.ts +0 -6
- package/dist/react/hooks/data/market/index.js +0 -39
- package/dist/react/hooks/data/orders/index.d.ts +0 -5
- package/dist/react/hooks/data/orders/index.js +0 -39
- package/dist/react/hooks/data/primary-sales/index.d.ts +0 -37
- package/dist/react/hooks/data/primary-sales/index.js +0 -39
- package/dist/react/hooks/data/tokens/index.d.ts +0 -5
- package/dist/react/hooks/data/tokens/index.js +0 -39
- package/dist/react/queries/collectibles/index.d.ts +0 -5
- package/dist/react/queries/collectibles/index.js +0 -22
- package/dist/react/queries/collections/index.d.ts +0 -11
- package/dist/react/queries/collections/index.js +0 -20
- package/dist/react/queries/market/index.d.ts +0 -6
- package/dist/react/queries/market/index.js +0 -22
- package/dist/react/queries/orders/index.d.ts +0 -5
- package/dist/react/queries/orders/index.js +0 -13
- package/dist/react/queries/primary-sales/index.d.ts +0 -4
- package/dist/react/queries/primary-sales/index.js +0 -13
- package/dist/react/queries/tokens/index.d.ts +0 -5
- package/dist/react/queries/tokens/index.js +0 -13
- package/dist/react/queries/utils/index.d.ts +0 -4
- package/dist/react/queries/utils/index.js +0 -22
- package/dist/react/ssr/index.js.map +0 -1
- package/dist/react/ui/components/marketplace-collectible-card/components/footer/components/index.d.ts +0 -3
- package/dist/react/ui/components/marketplace-collectible-card/components/footer/components/index.js +0 -22
- package/dist/react/ui/components/marketplace-collectible-card/components/footer/index.d.ts +0 -51
- package/dist/react/ui/components/marketplace-collectible-card/components/footer/index.js +0 -39
- package/dist/react/ui/modals/_internal/components/actionModal/index.d.ts +0 -40
- package/dist/react/ui/modals/_internal/components/actionModal/index.js +0 -39
- package/dist/src.js.map +0 -1
- package/dist/tokenBalances.js +0 -56
- package/dist/tokenBalances.js.map +0 -1
- package/dist/tokenSupplies.d.ts +0 -261
- package/dist/tokens.js +0 -219
- package/dist/tokens.js.map +0 -1
- package/dist/utils3.js +0 -43
- package/dist/utils3.js.map +0 -1
- package/dist/waitForTransactionReceipt.js +0 -25
- package/dist/waitForTransactionReceipt.js.map +0 -1
- package/src/react/_internal/api/__mocks__/builder.msw.ts +0 -239
- package/src/react/_internal/api/__mocks__/indexer.msw.ts +0 -216
- package/src/react/_internal/api/__mocks__/marketplace.msw.ts +0 -402
- package/src/react/_internal/api/__mocks__/metadata.msw.ts +0 -195
- package/src/react/_internal/api/builder.gen.ts +0 -773
- package/src/react/_internal/api/marketplace.gen.ts +0 -2718
- package/src/react/_internal/api/query-keys.ts +0 -124
- package/src/react/hooks/data/collectibles/index.ts +0 -6
- package/src/react/hooks/data/collectibles/useListCollectibleActivities.test.tsx +0 -192
- package/src/react/hooks/data/collectibles/useListCollectibleActivities.tsx +0 -98
- package/src/react/hooks/data/collections/index.ts +0 -8
- package/src/react/hooks/data/collections/useCollectionActiveListingsCurrencies.test.tsx +0 -112
- package/src/react/hooks/data/collections/useCollectionActiveOffersCurrencies.test.tsx +0 -110
- package/src/react/hooks/data/collections/useCollectionDetails.test.tsx +0 -83
- package/src/react/hooks/data/collections/useCollectionDetails.ts +0 -69
- package/src/react/hooks/data/collections/useCollectionDetailsPolling.test.tsx +0 -137
- package/src/react/hooks/data/collections/useListCollectionActivities.test.tsx +0 -227
- package/src/react/hooks/data/collections/useListCollectionActivities.tsx +0 -93
- package/src/react/hooks/data/index.ts +0 -6
- package/src/react/hooks/data/inventory/index.ts +0 -1
- package/src/react/hooks/data/inventory/useInventory.tsx +0 -12
- package/src/react/hooks/data/market/index.ts +0 -3
- package/src/react/hooks/data/orders/index.ts +0 -11
- package/src/react/hooks/data/primary-sales/index.ts +0 -7
- package/src/react/hooks/data/primary-sales/useCountOfPrimarySaleItems.tsx +0 -13
- package/src/react/hooks/data/primary-sales/useGetCountOfPrimarySaleItems.tsx +0 -48
- package/src/react/hooks/data/tokens/index.ts +0 -5
- package/src/react/hooks/data/tokens/useListBalances.tsx +0 -29
- package/src/react/hooks/data/tokens/useTokenSupplies.ts +0 -69
- package/src/react/hooks/utils/useCheckoutOptions.test.tsx +0 -162
- package/src/react/hooks/utils/useCheckoutOptions.tsx +0 -98
- package/src/react/queries/collectibles/balanceOfCollectible.ts +0 -90
- package/src/react/queries/collectibles/collectible.ts +0 -81
- package/src/react/queries/collectibles/countOfCollectables.ts +0 -109
- package/src/react/queries/collectibles/index.ts +0 -7
- package/src/react/queries/collectibles/listCollectibleActivities.ts +0 -121
- package/src/react/queries/collectibles/listCollectibles.ts +0 -115
- package/src/react/queries/collectibles/listCollectiblesPaginated.ts +0 -104
- package/src/react/queries/collectibles/tokenBalances.ts +0 -89
- package/src/react/queries/collections/activeListingsCurrencies.ts +0 -84
- package/src/react/queries/collections/activeOffersCurrencies.ts +0 -84
- package/src/react/queries/collections/collection.ts +0 -69
- package/src/react/queries/collections/collectionBalanceDetails.ts +0 -107
- package/src/react/queries/collections/collectionDetails.ts +0 -79
- package/src/react/queries/collections/index.ts +0 -7
- package/src/react/queries/collections/listCollectionActivities.ts +0 -117
- package/src/react/queries/collections/listCollections.ts +0 -175
- package/src/react/queries/market/checkoutOptions.ts +0 -107
- package/src/react/queries/market/checkoutOptionsSalesContract.ts +0 -108
- package/src/react/queries/market/currency.ts +0 -92
- package/src/react/queries/market/filters.ts +0 -152
- package/src/react/queries/market/index.ts +0 -6
- package/src/react/queries/market/marketCurrencies.ts +0 -120
- package/src/react/queries/market/marketplaceConfig.ts +0 -117
- package/src/react/queries/orders/countItemsOrdersForCollection.ts +0 -86
- package/src/react/queries/orders/countListingsForCollectible.ts +0 -90
- package/src/react/queries/orders/countOffersForCollectible.ts +0 -90
- package/src/react/queries/orders/floorOrder.ts +0 -74
- package/src/react/queries/orders/getCountOfFilteredOrders.ts +0 -88
- package/src/react/queries/orders/highestOffer.ts +0 -78
- package/src/react/queries/orders/index.ts +0 -11
- package/src/react/queries/orders/listItemsOrdersForCollection.ts +0 -90
- package/src/react/queries/orders/listItemsOrdersForCollectionPaginated.ts +0 -90
- package/src/react/queries/orders/listListingsForCollectible.ts +0 -97
- package/src/react/queries/orders/listOffersForCollectible.ts +0 -116
- package/src/react/queries/orders/lowestListing.ts +0 -81
- package/src/react/queries/primary-sales/countOfPrimarySaleItems.ts +0 -62
- package/src/react/queries/primary-sales/index.ts +0 -4
- package/src/react/queries/primary-sales/primarySaleItem.ts +0 -80
- package/src/react/queries/primary-sales/primarySaleItems.ts +0 -94
- package/src/react/queries/primary-sales/primarySaleItemsCount.ts +0 -79
- package/src/react/queries/tokens/getTokenRanges.ts +0 -75
- package/src/react/queries/tokens/index.ts +0 -5
- package/src/react/queries/tokens/listBalances.ts +0 -71
- package/src/react/queries/tokens/listTokenMetadata.ts +0 -81
- package/src/react/queries/tokens/searchTokenMetadata.ts +0 -101
- package/src/react/queries/tokens/tokenSupplies.ts +0 -84
- package/src/react/queries/utils/comparePrices.ts +0 -132
- package/src/react/queries/utils/convertPriceToUSD.ts +0 -105
- package/src/react/queries/utils/index.ts +0 -2
- package/src/react/ui/components/marketplace-collectible-card/components/ActionButtonWrapper.tsx +0 -79
- package/src/react/ui/components/marketplace-collectible-card/components/BaseCard.tsx +0 -68
- package/src/react/ui/components/marketplace-collectible-card/components/footer/Footer.tsx +0 -165
- package/src/react/ui/components/marketplace-collectible-card/components/footer/components/FooterName.tsx +0 -103
- package/src/react/ui/components/marketplace-collectible-card/components/footer/components/PriceDisplay.tsx +0 -80
- package/src/react/ui/components/marketplace-collectible-card/components/footer/components/SaleDetailsPill.tsx +0 -29
- package/src/react/ui/components/marketplace-collectible-card/components/footer/components/TokenTypeBalancePill.tsx +0 -30
- package/src/react/ui/components/marketplace-collectible-card/components/footer/components/index.ts +0 -4
- package/src/react/ui/components/marketplace-collectible-card/components/footer/index.ts +0 -2
- package/src/react/ui/icons/CalendarIcon.tsx +0 -37
- package/src/react/ui/icons/CartIcon.tsx +0 -52
- package/src/react/ui/icons/InfoIcon.tsx +0 -44
- package/src/react/ui/modals/BuyModal/__tests__/BuyModalRouter.test.tsx +0 -557
- package/src/react/ui/modals/BuyModal/__tests__/ERC1155ShopModal.test.tsx +0 -409
- package/src/react/ui/modals/BuyModal/__tests__/ERC721ShopModal.test.tsx +0 -272
- package/src/react/ui/modals/BuyModal/__tests__/Modal.test.tsx.bak +0 -112
- package/src/react/ui/modals/BuyModal/__tests__/Modal1155.test.tsx +0 -251
- package/src/react/ui/modals/BuyModal/__tests__/store.test.ts +0 -105
- package/src/react/ui/modals/BuyModal/components/BuyModalRouter.tsx +0 -157
- package/src/react/ui/modals/BuyModal/components/ERC1155BuyModal.tsx +0 -198
- package/src/react/ui/modals/BuyModal/components/ERC1155ShopModal.tsx +0 -108
- package/src/react/ui/modals/BuyModal/components/ERC721BuyModal.tsx +0 -116
- package/src/react/ui/modals/BuyModal/components/ERC721ShopModal.tsx +0 -86
- package/src/react/ui/modals/BuyModal/hooks/__tests__/useCheckoutOptions.test.tsx +0 -115
- package/src/react/ui/modals/BuyModal/hooks/__tests__/useERC721SalePaymentParams.test.tsx +0 -283
- package/src/react/ui/modals/BuyModal/hooks/__tests__/useMarketPlatformFee.test.tsx +0 -145
- package/src/react/ui/modals/BuyModal/hooks/useCheckoutOptions.ts +0 -86
- package/src/react/ui/modals/BuyModal/hooks/useERC721SalePaymentParams.ts +0 -216
- package/src/react/ui/modals/BuyModal/hooks/useLoadData.ts +0 -120
- package/src/react/ui/modals/CreateListingModal/hooks/useCreateListing.tsx +0 -98
- package/src/react/ui/modals/CreateListingModal/hooks/useGetTokenApproval.ts +0 -87
- package/src/react/ui/modals/CreateListingModal/hooks/useTransactionSteps.tsx +0 -246
- package/src/react/ui/modals/CreateListingModal/store.ts +0 -99
- package/src/react/ui/modals/MakeOfferModal/hooks/useGetTokenApproval.tsx +0 -90
- package/src/react/ui/modals/MakeOfferModal/hooks/useMakeOffer.tsx +0 -71
- package/src/react/ui/modals/MakeOfferModal/hooks/useTransactionSteps.tsx +0 -241
- package/src/react/ui/modals/MakeOfferModal/store.ts +0 -94
- package/src/react/ui/modals/SellModal/__tests__/Modal.test.tsx +0 -85
- package/src/react/ui/modals/SellModal/hooks/useGetTokenApproval.tsx +0 -79
- package/src/react/ui/modals/SellModal/hooks/useSell.tsx +0 -77
- package/src/react/ui/modals/SellModal/hooks/useTransactionSteps.tsx +0 -242
- package/src/react/ui/modals/SellModal/store.ts +0 -62
- package/src/react/ui/modals/SellModal/utils.ts +0 -38
- package/src/react/ui/modals/SuccessfulPurchaseModal/__tests__/Modal.test.tsx +0 -157
- package/src/react/ui/modals/SuccessfulPurchaseModal/index.tsx +0 -154
- package/src/react/ui/modals/SuccessfulPurchaseModal/store.ts +0 -71
- package/src/react/ui/modals/TransferModal/__tests__/__snapshots__/store.test.ts.snap +0 -17
- package/src/react/ui/modals/TransferModal/_views/enterWalletAddress/__tests__/useHandleTransfer.test.tsx +0 -412
- package/src/react/ui/modals/TransferModal/_views/enterWalletAddress/_components/TransferButton.tsx +0 -66
- package/src/react/ui/modals/TransferModal/_views/enterWalletAddress/index.tsx +0 -137
- package/src/react/ui/modals/TransferModal/_views/enterWalletAddress/useHandleTransfer.tsx +0 -97
- package/src/react/ui/modals/TransferModal/_views/followWalletInstructions/index.tsx +0 -31
- package/src/react/ui/modals/TransferModal/messages.ts +0 -14
- package/src/react/ui/modals/TransferModal/store.ts +0 -122
- package/src/react/ui/modals/_internal/components/actionModal/ActionModal.test.tsx +0 -281
- package/src/react/ui/modals/_internal/components/actionModal/ActionModal.tsx +0 -113
- package/src/react/ui/modals/_internal/components/actionModal/ErrorModal.tsx +0 -35
- package/src/react/ui/modals/_internal/components/actionModal/LoadingModal.tsx +0 -32
- package/src/react/ui/modals/_internal/components/actionModal/index.ts +0 -1
- package/src/types/custom.d.ts +0 -1
- package/src/types/messages.ts +0 -43
- package/src/types/new-marketplace-types.ts +0 -95
- /package/src/react/ui/components/{_internals/action-button → marketplace-collectible-card/ActionButton}/types.ts +0 -0
- /package/src/react/ui/modals/_internal/hooks/{useSelectWaasFeeOptions.ts → useSelectWaasFeeOptions.tsx} +0 -0
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../src/types/types.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../src/types/transactions.ts","../src/types/types.ts"],"sourcesContent":["/**\n * Transaction modes for the buy modal\n * Used to distinguish between secondary market purchases and primary sales (minting)\n */\nexport enum TransactionType {\n\t/** Secondary market purchases from existing orders */\n\tMARKET_BUY = 'MARKET_BUY',\n\t/** Primary sales - direct from creator/contract (minting/shop) */\n\tPRIMARY_SALE = 'PRIMARY_SALE',\n}\n","import type {\n\tCurrency,\n\tFilterCondition,\n\tMarketCollection,\n\tMarketPage,\n\tMarketplaceCollection,\n\tMarketplaceSettings,\n\tMarketplaceWalletType,\n\tOpenIdProvider,\n\tShopCollection,\n\tShopPage,\n} from '@0xsequence/api-client';\n\n// Re-export collection types from API - these are the source of truth\nexport type {\n\tMarketCollection,\n\tMarketPage,\n\tMarketplaceCollection,\n\tShopCollection,\n\tShopPage,\n};\n\n// Marketplace Configuration\n\nexport type MarketplaceConfig = {\n\tprojectId: number;\n\tsettings: MarketplaceSettings;\n\tmarket: MarketPage;\n\tshop: ShopPage;\n};\n\n/**\n * Type guard to check if a collection is a ShopCollection\n * Shop collections are for primary sales\n */\nexport function isShopCollection(\n\tcollection: MarketplaceCollection,\n): collection is ShopCollection {\n\treturn collection.marketplaceCollectionType === 'shop';\n}\n\n/**\n * Type guard to check if a collection is a MarketCollection\n * Market collections are for secondary market trading\n */\nexport function isMarketCollection(\n\tcollection: MarketplaceCollection,\n): collection is MarketCollection {\n\treturn collection.marketplaceCollectionType === 'market';\n}\n\n// Wallet Configuration\n\nexport type EcosystemWalletSettings = {\n\twalletUrl: string;\n\twalletAppName: string;\n\tlogoLightUrl?: string;\n\tlogoDarkUrl?: string;\n};\n\nexport type MarketplaceWalletOptions = {\n\twalletType: MarketplaceWalletType;\n\toidcIssuers: { [key: string]: string };\n\tconnectors: Array<string>;\n\tincludeEIP6963Wallets: boolean;\n\tecosystem?: EcosystemWalletSettings;\n\twaas?: MarketplaceWalletWaasSettings;\n};\n\nexport type MarketplaceWalletWaasSettings = {\n\ttenantKey: string;\n\temailEnabled: boolean;\n\tproviders: Array<OpenIdProvider>;\n};\n\n// Filtering & Metadata\n\nexport type MetadataFilterRule = {\n\tkey: string;\n\tcondition: FilterCondition;\n\tvalue?: string;\n};\n\nexport type CollectionFilterSettings = {\n\tfilterOrder: Array<string>;\n\texclusions: Array<MetadataFilterRule>;\n};\n\n// UI Types\n\nexport type Price = {\n\tamountRaw: bigint;\n\tcurrency: Currency;\n};\n\n/**\n * Card type for UI rendering\n * Note: For collections, use type guards (isShopCollection/isMarketCollection) instead\n */\nexport type CardType = 'market' | 'shop' | 'inventory-non-tradable';\n\nexport enum CollectibleCardAction {\n\tBUY = 'Buy',\n\tSELL = 'Sell',\n\tLIST = 'Create listing',\n\tOFFER = 'Make an offer',\n\tTRANSFER = 'Transfer',\n}\n"],"mappings":";;;;;AAIA,IAAY,8DAAL;;AAEN;;AAEA;;;;;;;;;;AC2BD,SAAgB,iBACf,YAC+B;AAC/B,QAAO,WAAW,8BAA8B;;;;;;AAOjD,SAAgB,mBACf,YACiC;AACjC,QAAO,WAAW,8BAA8B;;AAqDjD,IAAY,0EAAL;AACN;AACA;AACA;AACA;AACA"}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { _ as PropertyType } from "./dist.js";
|
|
2
|
+
import { useMemo } from "react";
|
|
3
|
+
import { createSerializer, parseAsBoolean, parseAsJson, parseAsString, useQueryState } from "nuqs";
|
|
4
|
+
|
|
5
|
+
//#region src/react/hooks/ui/url-state/filter-state.tsx
|
|
6
|
+
const isPropertyFilter = (f) => {
|
|
7
|
+
if (typeof f !== "object" || f === null) return false;
|
|
8
|
+
const obj = f;
|
|
9
|
+
return typeof obj.name === "string" && Object.values(PropertyType).includes(obj.type);
|
|
10
|
+
};
|
|
11
|
+
const validateFilters = (value) => {
|
|
12
|
+
if (!Array.isArray(value)) return [];
|
|
13
|
+
return value.filter(isPropertyFilter);
|
|
14
|
+
};
|
|
15
|
+
const isUrlPriceFilter = (f) => {
|
|
16
|
+
if (typeof f !== "object" || f === null) return false;
|
|
17
|
+
const obj = f;
|
|
18
|
+
return typeof obj.contractAddress === "string" && (obj.min === void 0 || typeof obj.min === "string") && (obj.max === void 0 || typeof obj.max === "string");
|
|
19
|
+
};
|
|
20
|
+
const validatePriceFilters = (value) => {
|
|
21
|
+
if (!Array.isArray(value)) return [];
|
|
22
|
+
return value.filter(isUrlPriceFilter);
|
|
23
|
+
};
|
|
24
|
+
const filtersParser = parseAsJson(validateFilters).withDefault([]);
|
|
25
|
+
const searchParser = parseAsString.withDefault("");
|
|
26
|
+
const listedOnlyParser = parseAsBoolean.withDefault(false);
|
|
27
|
+
const priceFilterParser = parseAsBoolean.withDefault(false);
|
|
28
|
+
const priceFiltersParser = parseAsJson(validatePriceFilters).withDefault([]);
|
|
29
|
+
const serialize = createSerializer({
|
|
30
|
+
filters: filtersParser,
|
|
31
|
+
search: searchParser,
|
|
32
|
+
listedOnly: listedOnlyParser,
|
|
33
|
+
priceFilter: priceFilterParser,
|
|
34
|
+
priceFilters: priceFiltersParser
|
|
35
|
+
}, { urlKeys: {
|
|
36
|
+
filters: "f",
|
|
37
|
+
search: "q",
|
|
38
|
+
listedOnly: "l",
|
|
39
|
+
priceFilter: "p",
|
|
40
|
+
priceFilters: "pf"
|
|
41
|
+
} });
|
|
42
|
+
function useFilterState() {
|
|
43
|
+
const [filterOptions, setFilterOptions] = useQueryState("filters", filtersParser);
|
|
44
|
+
const [searchText, setSearchText] = useQueryState("search", searchParser);
|
|
45
|
+
const [showListedOnly, setShowListedOnly] = useQueryState("listedOnly", listedOnlyParser);
|
|
46
|
+
const [showPriceFilter, setShowPriceFilter] = useQueryState("priceFilter", priceFilterParser);
|
|
47
|
+
const [priceFilters, setPriceFilters] = useQueryState("priceFilters", priceFiltersParser);
|
|
48
|
+
return {
|
|
49
|
+
filterOptions,
|
|
50
|
+
searchText,
|
|
51
|
+
showListedOnly,
|
|
52
|
+
showPriceFilter,
|
|
53
|
+
priceFilters,
|
|
54
|
+
setFilterOptions,
|
|
55
|
+
setSearchText,
|
|
56
|
+
setShowListedOnly,
|
|
57
|
+
setShowPriceFilter,
|
|
58
|
+
setPriceFilters,
|
|
59
|
+
...useMemo(() => ({
|
|
60
|
+
getFilter: (name) => {
|
|
61
|
+
return filterOptions?.find((f) => f.name === name);
|
|
62
|
+
},
|
|
63
|
+
getFilterValues: (name) => {
|
|
64
|
+
const filter = filterOptions?.find((f) => f.name === name);
|
|
65
|
+
if (!filter) return void 0;
|
|
66
|
+
if (filter.type === PropertyType.INT) return {
|
|
67
|
+
type: PropertyType.INT,
|
|
68
|
+
min: filter.min ?? 0,
|
|
69
|
+
max: filter.max ?? 0
|
|
70
|
+
};
|
|
71
|
+
return {
|
|
72
|
+
type: PropertyType.STRING,
|
|
73
|
+
values: filter.values ?? []
|
|
74
|
+
};
|
|
75
|
+
},
|
|
76
|
+
isFilterActive: (name) => {
|
|
77
|
+
return !!filterOptions?.find((f) => f.name === name);
|
|
78
|
+
},
|
|
79
|
+
isStringValueSelected: (name, value) => {
|
|
80
|
+
const filter = filterOptions?.find((f) => f.name === name);
|
|
81
|
+
if (!filter || filter.type !== PropertyType.STRING) return false;
|
|
82
|
+
return filter.values?.includes(value) ?? false;
|
|
83
|
+
},
|
|
84
|
+
isIntFilterActive: (name) => {
|
|
85
|
+
const filter = filterOptions?.find((f) => f.name === name);
|
|
86
|
+
return !!filter && filter.type === PropertyType.INT;
|
|
87
|
+
},
|
|
88
|
+
getIntFilterRange: (name) => {
|
|
89
|
+
const filter = filterOptions?.find((f) => f.name === name);
|
|
90
|
+
if (!filter || filter.type !== PropertyType.INT) return void 0;
|
|
91
|
+
return [filter.min ?? 0, filter.max ?? 0];
|
|
92
|
+
},
|
|
93
|
+
deleteFilter: (name) => {
|
|
94
|
+
setFilterOptions(filterOptions?.filter((f) => !(f.name === name)) ?? []);
|
|
95
|
+
},
|
|
96
|
+
toggleStringFilterValue: (name, value) => {
|
|
97
|
+
const otherFilters = filterOptions?.filter((f) => !(f.name === name)) ?? [];
|
|
98
|
+
const filter = filterOptions?.find((f) => f.name === name);
|
|
99
|
+
const existingValues = filter?.type === PropertyType.STRING ? filter.values ?? [] : [];
|
|
100
|
+
if (existingValues.includes(value)) {
|
|
101
|
+
const newValues = existingValues.filter((v) => v !== value);
|
|
102
|
+
if (newValues.length === 0) {
|
|
103
|
+
setFilterOptions(otherFilters);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
setFilterOptions([...otherFilters, {
|
|
107
|
+
name,
|
|
108
|
+
type: PropertyType.STRING,
|
|
109
|
+
values: newValues
|
|
110
|
+
}]);
|
|
111
|
+
} else setFilterOptions([...otherFilters, {
|
|
112
|
+
name,
|
|
113
|
+
type: PropertyType.STRING,
|
|
114
|
+
values: [...existingValues, value]
|
|
115
|
+
}]);
|
|
116
|
+
},
|
|
117
|
+
setIntFilterValue: (name, min, max) => {
|
|
118
|
+
if (min === max && min === 0) {
|
|
119
|
+
setFilterOptions(filterOptions?.filter((f) => !(f.name === name)) ?? []);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
setFilterOptions([...filterOptions?.filter((f) => !(f.name === name)) ?? [], {
|
|
123
|
+
name,
|
|
124
|
+
type: PropertyType.INT,
|
|
125
|
+
min,
|
|
126
|
+
max
|
|
127
|
+
}]);
|
|
128
|
+
},
|
|
129
|
+
setPriceFilter: (contractAddress, min, max) => {
|
|
130
|
+
const otherPriceFilters = priceFilters?.filter((f) => f.contractAddress !== contractAddress) ?? [];
|
|
131
|
+
if (!min && !max) {
|
|
132
|
+
setPriceFilters(otherPriceFilters);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
const newPriceFilter = {
|
|
136
|
+
contractAddress,
|
|
137
|
+
...min && { min },
|
|
138
|
+
...max && { max }
|
|
139
|
+
};
|
|
140
|
+
setPriceFilters([...otherPriceFilters, newPriceFilter]);
|
|
141
|
+
},
|
|
142
|
+
getPriceFilter: (contractAddress) => {
|
|
143
|
+
return priceFilters?.find((f) => f.contractAddress === contractAddress);
|
|
144
|
+
},
|
|
145
|
+
clearPriceFilters: () => {
|
|
146
|
+
setPriceFilters([]);
|
|
147
|
+
},
|
|
148
|
+
clearAllFilters: () => {
|
|
149
|
+
setShowListedOnly(false);
|
|
150
|
+
setShowPriceFilter(false);
|
|
151
|
+
setFilterOptions([]);
|
|
152
|
+
setSearchText("");
|
|
153
|
+
setPriceFilters([]);
|
|
154
|
+
}
|
|
155
|
+
}), [
|
|
156
|
+
filterOptions,
|
|
157
|
+
setFilterOptions,
|
|
158
|
+
setShowListedOnly,
|
|
159
|
+
setSearchText,
|
|
160
|
+
setShowPriceFilter,
|
|
161
|
+
priceFilters,
|
|
162
|
+
setPriceFilters
|
|
163
|
+
]),
|
|
164
|
+
serialize
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
//#endregion
|
|
169
|
+
export { useFilterState as t };
|
|
170
|
+
//# sourceMappingURL=url-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"url-state.js","names":["newPriceFilter: UrlPriceFilter"],"sources":["../src/react/hooks/ui/url-state/filter-state.tsx"],"sourcesContent":["import {\n\tcreateSerializer,\n\tparseAsBoolean,\n\tparseAsJson,\n\tparseAsString,\n\tuseQueryState,\n} from 'nuqs';\nimport { useMemo } from 'react';\nimport { type PropertyFilter, PropertyType } from '../../../_internal';\n\n/**\n * URL-safe price filter type that uses strings instead of BigInt\n * to avoid JSON serialization issues with URL state management\n */\nexport interface UrlPriceFilter {\n\tcontractAddress: string;\n\tmin?: string;\n\tmax?: string;\n}\n\ninterface StringFilterValues {\n\ttype: PropertyType.STRING;\n\tvalues: string[];\n}\n\ninterface IntFilterValues {\n\ttype: PropertyType.INT;\n\tmin: number;\n\tmax: number;\n}\n\ntype FilterValues = StringFilterValues | IntFilterValues;\n\nconst isPropertyFilter = (f: unknown): f is PropertyFilter => {\n\tif (typeof f !== 'object' || f === null) return false;\n\tconst obj = f as Record<string, unknown>;\n\treturn (\n\t\ttypeof obj.name === 'string' &&\n\t\tObject.values(PropertyType).includes(obj.type as PropertyType)\n\t);\n};\n\nconst validateFilters = (value: unknown): PropertyFilter[] => {\n\tif (!Array.isArray(value)) return [];\n\treturn value.filter(isPropertyFilter);\n};\n\nconst isUrlPriceFilter = (f: unknown): f is UrlPriceFilter => {\n\tif (typeof f !== 'object' || f === null) return false;\n\tconst obj = f as Record<string, unknown>;\n\treturn (\n\t\ttypeof obj.contractAddress === 'string' &&\n\t\t(obj.min === undefined || typeof obj.min === 'string') &&\n\t\t(obj.max === undefined || typeof obj.max === 'string')\n\t);\n};\n\nconst validatePriceFilters = (value: unknown): UrlPriceFilter[] => {\n\tif (!Array.isArray(value)) return [];\n\treturn value.filter(isUrlPriceFilter);\n};\n\nconst filtersParser = parseAsJson(validateFilters).withDefault([]);\nconst searchParser = parseAsString.withDefault('');\nconst listedOnlyParser = parseAsBoolean.withDefault(false);\nconst priceFilterParser = parseAsBoolean.withDefault(false);\nconst priceFiltersParser = parseAsJson(validatePriceFilters).withDefault([]);\n\nconst serialize = createSerializer(\n\t{\n\t\tfilters: filtersParser,\n\t\tsearch: searchParser,\n\t\tlistedOnly: listedOnlyParser,\n\t\tpriceFilter: priceFilterParser,\n\t\tpriceFilters: priceFiltersParser,\n\t},\n\t{\n\t\turlKeys: {\n\t\t\tfilters: 'f',\n\t\t\tsearch: 'q',\n\t\t\tlistedOnly: 'l',\n\t\t\tpriceFilter: 'p',\n\t\t\tpriceFilters: 'pf',\n\t\t},\n\t},\n);\n\nexport function useFilterState() {\n\tconst [filterOptions, setFilterOptions] = useQueryState(\n\t\t'filters',\n\t\tfiltersParser,\n\t);\n\tconst [searchText, setSearchText] = useQueryState('search', searchParser);\n\tconst [showListedOnly, setShowListedOnly] = useQueryState(\n\t\t'listedOnly',\n\t\tlistedOnlyParser,\n\t);\n\tconst [showPriceFilter, setShowPriceFilter] = useQueryState(\n\t\t'priceFilter',\n\t\tpriceFilterParser,\n\t);\n\tconst [priceFilters, setPriceFilters] = useQueryState(\n\t\t'priceFilters',\n\t\tpriceFiltersParser,\n\t);\n\n\tconst helpers = useMemo(\n\t\t() => ({\n\t\t\tgetFilter: (name: string): PropertyFilter | undefined => {\n\t\t\t\treturn filterOptions?.find((f) => f.name === name);\n\t\t\t},\n\n\t\t\tgetFilterValues: (name: string): FilterValues | undefined => {\n\t\t\t\tconst filter = filterOptions?.find((f) => f.name === name);\n\t\t\t\tif (!filter) return undefined;\n\n\t\t\t\tif (filter.type === PropertyType.INT) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\ttype: PropertyType.INT,\n\t\t\t\t\t\tmin: filter.min ?? 0,\n\t\t\t\t\t\tmax: filter.max ?? 0,\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\ttype: PropertyType.STRING,\n\t\t\t\t\tvalues: (filter.values as string[]) ?? [],\n\t\t\t\t};\n\t\t\t},\n\n\t\t\tisFilterActive: (name: string): boolean => {\n\t\t\t\treturn !!filterOptions?.find((f) => f.name === name);\n\t\t\t},\n\n\t\t\tisStringValueSelected: (name: string, value: string): boolean => {\n\t\t\t\tconst filter = filterOptions?.find((f) => f.name === name);\n\t\t\t\tif (!filter || filter.type !== PropertyType.STRING) return false;\n\t\t\t\treturn (filter.values as string[])?.includes(value) ?? false;\n\t\t\t},\n\n\t\t\tisIntFilterActive: (name: string): boolean => {\n\t\t\t\tconst filter = filterOptions?.find((f) => f.name === name);\n\t\t\t\treturn !!filter && filter.type === PropertyType.INT;\n\t\t\t},\n\n\t\t\tgetIntFilterRange: (name: string): [number, number] | undefined => {\n\t\t\t\tconst filter = filterOptions?.find((f) => f.name === name);\n\t\t\t\tif (!filter || filter.type !== PropertyType.INT) return undefined;\n\t\t\t\treturn [filter.min ?? 0, filter.max ?? 0];\n\t\t\t},\n\n\t\t\tdeleteFilter: (name: string) => {\n\t\t\t\tconst otherFilters =\n\t\t\t\t\tfilterOptions?.filter((f) => !(f.name === name)) ?? [];\n\t\t\t\tsetFilterOptions(otherFilters);\n\t\t\t},\n\n\t\t\ttoggleStringFilterValue: (name: string, value: string) => {\n\t\t\t\tconst otherFilters =\n\t\t\t\t\tfilterOptions?.filter((f) => !(f.name === name)) ?? [];\n\t\t\t\tconst filter = filterOptions?.find((f) => f.name === name);\n\t\t\t\tconst existingValues =\n\t\t\t\t\tfilter?.type === PropertyType.STRING\n\t\t\t\t\t\t? ((filter.values as string[]) ?? [])\n\t\t\t\t\t\t: [];\n\n\t\t\t\tif (existingValues.includes(value)) {\n\t\t\t\t\tconst newValues = existingValues.filter((v) => v !== value);\n\t\t\t\t\tif (newValues.length === 0) {\n\t\t\t\t\t\tsetFilterOptions(otherFilters);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tsetFilterOptions([\n\t\t\t\t\t\t...otherFilters,\n\t\t\t\t\t\t{ name, type: PropertyType.STRING, values: newValues },\n\t\t\t\t\t]);\n\t\t\t\t} else {\n\t\t\t\t\tsetFilterOptions([\n\t\t\t\t\t\t...otherFilters,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\ttype: PropertyType.STRING,\n\t\t\t\t\t\t\tvalues: [...existingValues, value],\n\t\t\t\t\t\t},\n\t\t\t\t\t]);\n\t\t\t\t}\n\t\t\t},\n\n\t\t\tsetIntFilterValue: (name: string, min: number, max: number) => {\n\t\t\t\tif (min === max && min === 0) {\n\t\t\t\t\tconst otherFilters =\n\t\t\t\t\t\tfilterOptions?.filter((f) => !(f.name === name)) ?? [];\n\t\t\t\t\tsetFilterOptions(otherFilters);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst otherFilters =\n\t\t\t\t\tfilterOptions?.filter((f) => !(f.name === name)) ?? [];\n\t\t\t\tsetFilterOptions([\n\t\t\t\t\t...otherFilters,\n\t\t\t\t\t{ name, type: PropertyType.INT, min, max },\n\t\t\t\t]);\n\t\t\t},\n\n\t\t\tsetPriceFilter: (contractAddress: string, min?: string, max?: string) => {\n\t\t\t\tconst otherPriceFilters =\n\t\t\t\t\tpriceFilters?.filter((f) => f.contractAddress !== contractAddress) ??\n\t\t\t\t\t[];\n\n\t\t\t\tif (!min && !max) {\n\t\t\t\t\tsetPriceFilters(otherPriceFilters);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst newPriceFilter: UrlPriceFilter = {\n\t\t\t\t\tcontractAddress,\n\t\t\t\t\t...(min && { min }),\n\t\t\t\t\t...(max && { max }),\n\t\t\t\t};\n\n\t\t\t\tsetPriceFilters([...otherPriceFilters, newPriceFilter]);\n\t\t\t},\n\n\t\t\tgetPriceFilter: (contractAddress: string): UrlPriceFilter | undefined => {\n\t\t\t\treturn priceFilters?.find((f) => f.contractAddress === contractAddress);\n\t\t\t},\n\n\t\t\tclearPriceFilters: () => {\n\t\t\t\tsetPriceFilters([]);\n\t\t\t},\n\n\t\t\tclearAllFilters: () => {\n\t\t\t\tvoid setShowListedOnly(false);\n\t\t\t\tvoid setShowPriceFilter(false);\n\t\t\t\tvoid setFilterOptions([]);\n\t\t\t\tvoid setSearchText('');\n\t\t\t\tvoid setPriceFilters([]);\n\t\t\t},\n\t\t}),\n\t\t[\n\t\t\tfilterOptions,\n\t\t\tsetFilterOptions,\n\t\t\tsetShowListedOnly,\n\t\t\tsetSearchText,\n\t\t\tsetShowPriceFilter,\n\t\t\tpriceFilters,\n\t\t\tsetPriceFilters,\n\t\t],\n\t);\n\n\treturn {\n\t\tfilterOptions,\n\t\tsearchText,\n\t\tshowListedOnly,\n\t\tshowPriceFilter,\n\t\tpriceFilters,\n\t\tsetFilterOptions,\n\t\tsetSearchText,\n\t\tsetShowListedOnly,\n\t\tsetShowPriceFilter,\n\t\tsetPriceFilters,\n\t\t...helpers,\n\t\tserialize,\n\t};\n}\n"],"mappings":"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"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { n as
|
|
3
|
-
import {
|
|
4
|
-
import { i as
|
|
5
|
-
|
|
1
|
+
import "../../index2.js";
|
|
2
|
+
import { n as getMarketplaceABI, r as getSaleContractABI, t as MAIN_MODULE_ABI } from "../../index4.js";
|
|
3
|
+
import { n as SequenceMarketplaceV1_ABI, r as EIP2981_ABI, t as SequenceMarketplaceV2_ABI } from "../../index5.js";
|
|
4
|
+
import { i as ERC721_SALE_ABI_V0, n as ERC1155_SALES_CONTRACT_ABI_V0, r as ERC721_SALE_ABI_V1, t as ERC1155_SALES_CONTRACT_ABI_V1 } from "../../index6.js";
|
|
5
|
+
import { i as ERC20_ABI, n as ERC1155_ABI, r as ERC721_ABI, t as SEQUENCE_1155_ITEMS_ABI } from "../../index7.js";
|
|
6
|
+
export { EIP2981_ABI, ERC1155_ABI, ERC1155_SALES_CONTRACT_ABI_V0, ERC1155_SALES_CONTRACT_ABI_V1, ERC20_ABI, ERC721_ABI, ERC721_SALE_ABI_V0, ERC721_SALE_ABI_V1, MAIN_MODULE_ABI, SEQUENCE_1155_ITEMS_ABI, SequenceMarketplaceV1_ABI, SequenceMarketplaceV2_ABI, getMarketplaceABI, getSaleContractABI };
|
package/dist/utils/abi/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as MAIN_MODULE_ABI } from "../../abi.js";
|
|
2
1
|
import { n as SequenceMarketplaceV1_ABI, r as EIP2981_ABI, t as SequenceMarketplaceV2_ABI } from "../../marketplace.js";
|
|
3
2
|
import { i as ERC721_SALE_ABI_V0, n as ERC1155_SALES_CONTRACT_ABI_V0, r as ERC721_SALE_ABI_V1, t as ERC1155_SALES_CONTRACT_ABI_V1 } from "../../primary-sale.js";
|
|
3
|
+
import { n as getMarketplaceABI, r as getSaleContractABI, t as MAIN_MODULE_ABI } from "../../abi.js";
|
|
4
4
|
import { i as ERC20_ABI, n as ERC1155_ABI, r as ERC721_ABI, t as SEQUENCE_1155_ITEMS_ABI } from "../../token.js";
|
|
5
5
|
|
|
6
|
-
export { EIP2981_ABI, ERC1155_ABI, ERC1155_SALES_CONTRACT_ABI_V0, ERC1155_SALES_CONTRACT_ABI_V1, ERC20_ABI, ERC721_ABI, ERC721_SALE_ABI_V0, ERC721_SALE_ABI_V1, MAIN_MODULE_ABI, SEQUENCE_1155_ITEMS_ABI, SequenceMarketplaceV1_ABI, SequenceMarketplaceV2_ABI };
|
|
6
|
+
export { EIP2981_ABI, ERC1155_ABI, ERC1155_SALES_CONTRACT_ABI_V0, ERC1155_SALES_CONTRACT_ABI_V1, ERC20_ABI, ERC721_ABI, ERC721_SALE_ABI_V0, ERC721_SALE_ABI_V1, MAIN_MODULE_ABI, SEQUENCE_1155_ITEMS_ABI, SequenceMarketplaceV1_ABI, SequenceMarketplaceV2_ABI, getMarketplaceABI, getSaleContractABI };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as SequenceMarketplaceV1_ABI, r as EIP2981_ABI, t as SequenceMarketplaceV2_ABI } from "../../../
|
|
1
|
+
import { n as SequenceMarketplaceV1_ABI, r as EIP2981_ABI, t as SequenceMarketplaceV2_ABI } from "../../../index5.js";
|
|
2
2
|
export { EIP2981_ABI, SequenceMarketplaceV1_ABI, SequenceMarketplaceV2_ABI };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { i as ERC721_SALE_ABI_V0, n as ERC1155_SALES_CONTRACT_ABI_V0, r as ERC721_SALE_ABI_V1, t as ERC1155_SALES_CONTRACT_ABI_V1 } from "../../../
|
|
1
|
+
import { i as ERC721_SALE_ABI_V0, n as ERC1155_SALES_CONTRACT_ABI_V0, r as ERC721_SALE_ABI_V1, t as ERC1155_SALES_CONTRACT_ABI_V1 } from "../../../index6.js";
|
|
2
2
|
export { ERC1155_SALES_CONTRACT_ABI_V0, ERC1155_SALES_CONTRACT_ABI_V1, ERC721_SALE_ABI_V0, ERC721_SALE_ABI_V1 };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { i as ERC20_ABI, n as ERC1155_ABI, r as ERC721_ABI, t as SEQUENCE_1155_ITEMS_ABI } from "../../../
|
|
1
|
+
import { i as ERC20_ABI, n as ERC1155_ABI, r as ERC721_ABI, t as SEQUENCE_1155_ITEMS_ABI } from "../../../index7.js";
|
|
2
2
|
export { ERC1155_ABI, ERC20_ABI, ERC721_ABI, SEQUENCE_1155_ITEMS_ABI };
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import "../
|
|
2
|
-
import
|
|
3
|
-
import { n as
|
|
4
|
-
import {
|
|
5
|
-
import { i as
|
|
6
|
-
import {
|
|
7
|
-
|
|
1
|
+
import "../index2.js";
|
|
2
|
+
import "../index3.js";
|
|
3
|
+
import { n as getMarketplaceABI, r as getSaleContractABI, t as MAIN_MODULE_ABI } from "../index4.js";
|
|
4
|
+
import { n as SequenceMarketplaceV1_ABI, r as EIP2981_ABI, t as SequenceMarketplaceV2_ABI } from "../index5.js";
|
|
5
|
+
import { i as ERC721_SALE_ABI_V0, n as ERC1155_SALES_CONTRACT_ABI_V0, r as ERC721_SALE_ABI_V1, t as ERC1155_SALES_CONTRACT_ABI_V1 } from "../index6.js";
|
|
6
|
+
import { i as ERC20_ABI, n as ERC1155_ABI, r as ERC721_ABI, t as SEQUENCE_1155_ITEMS_ABI } from "../index7.js";
|
|
7
|
+
import { a as formatPriceWithFee, c as getNetwork, d as findMarketCollection, f as cn, h as truncateMiddle, i as formatPrice, l as getPresentableChainName, m as truncateEnd, n as calculatePriceDifferencePercentage, o as validateOpenseaOfferDecimals, p as compareAddress, r as calculateTotalOfferCost, s as networkToWagmiChain, t as calculateEarningsAfterFees, u as getMarketplaceDetails } from "../index8.js";
|
|
8
|
+
import "../index9.js";
|
|
9
|
+
export { EIP2981_ABI, ERC1155_ABI, ERC1155_SALES_CONTRACT_ABI_V0, ERC1155_SALES_CONTRACT_ABI_V1, ERC20_ABI, ERC721_ABI, ERC721_SALE_ABI_V0, ERC721_SALE_ABI_V1, MAIN_MODULE_ABI, SEQUENCE_1155_ITEMS_ABI, SequenceMarketplaceV1_ABI, SequenceMarketplaceV2_ABI, calculateEarningsAfterFees, calculatePriceDifferencePercentage, calculateTotalOfferCost, cn, compareAddress, findMarketCollection, formatPrice, formatPriceWithFee, getMarketplaceABI, getMarketplaceDetails, getNetwork, getPresentableChainName, getSaleContractABI, networkToWagmiChain, truncateEnd, truncateMiddle, validateOpenseaOfferDecimals };
|
package/dist/utils/index.js
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
import "../
|
|
1
|
+
import "../dist.js";
|
|
2
2
|
import { t as networkToWagmiChain } from "../networkconfigToWagmiChain.js";
|
|
3
|
-
import "../transaction.js";
|
|
4
|
-
import "../marketplace.gen.js";
|
|
5
|
-
import { n as getPresentableChainName, t as getNetwork } from "../network.js";
|
|
6
|
-
import "../types.js";
|
|
7
|
-
import { t as MAIN_MODULE_ABI } from "../abi.js";
|
|
8
3
|
import { n as SequenceMarketplaceV1_ABI, r as EIP2981_ABI, t as SequenceMarketplaceV2_ABI } from "../marketplace.js";
|
|
9
4
|
import { i as ERC721_SALE_ABI_V0, n as ERC1155_SALES_CONTRACT_ABI_V0, r as ERC721_SALE_ABI_V1, t as ERC1155_SALES_CONTRACT_ABI_V1 } from "../primary-sale.js";
|
|
5
|
+
import { n as getMarketplaceABI, r as getSaleContractABI, t as MAIN_MODULE_ABI } from "../abi.js";
|
|
10
6
|
import { i as ERC20_ABI, n as ERC1155_ABI, r as ERC721_ABI, t as SEQUENCE_1155_ITEMS_ABI } from "../token.js";
|
|
11
|
-
import { a as formatPriceWithFee, c as
|
|
12
|
-
import "../
|
|
7
|
+
import { a as formatPriceWithFee, c as findMarketCollection, d as truncateEnd, f as truncateMiddle, i as formatPrice, l as cn, n as calculatePriceDifferencePercentage, o as validateOpenseaOfferDecimals, r as calculateTotalOfferCost, s as getMarketplaceDetails, t as calculateEarningsAfterFees, u as compareAddress } from "../utils.js";
|
|
8
|
+
import { n as getPresentableChainName, t as getNetwork } from "../network.js";
|
|
13
9
|
|
|
14
|
-
export { EIP2981_ABI, ERC1155_ABI, ERC1155_SALES_CONTRACT_ABI_V0, ERC1155_SALES_CONTRACT_ABI_V1, ERC20_ABI, ERC721_ABI, ERC721_SALE_ABI_V0, ERC721_SALE_ABI_V1, MAIN_MODULE_ABI, SEQUENCE_1155_ITEMS_ABI, SequenceMarketplaceV1_ABI, SequenceMarketplaceV2_ABI, calculateEarningsAfterFees, calculatePriceDifferencePercentage, calculateTotalOfferCost, cn, compareAddress, formatPrice, formatPriceWithFee, getMarketplaceDetails, getNetwork, getPresentableChainName, networkToWagmiChain, truncateEnd, truncateMiddle, validateOpenseaOfferDecimals };
|
|
10
|
+
export { EIP2981_ABI, ERC1155_ABI, ERC1155_SALES_CONTRACT_ABI_V0, ERC1155_SALES_CONTRACT_ABI_V1, ERC20_ABI, ERC721_ABI, ERC721_SALE_ABI_V0, ERC721_SALE_ABI_V1, MAIN_MODULE_ABI, SEQUENCE_1155_ITEMS_ABI, SequenceMarketplaceV1_ABI, SequenceMarketplaceV2_ABI, calculateEarningsAfterFees, calculatePriceDifferencePercentage, calculateTotalOfferCost, cn, compareAddress, findMarketCollection, formatPrice, formatPriceWithFee, getMarketplaceABI, getMarketplaceDetails, getNetwork, getPresentableChainName, getSaleContractABI, networkToWagmiChain, truncateEnd, truncateMiddle, validateOpenseaOfferDecimals };
|
package/dist/utils.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { d as MarketplaceKind } from "./dist.js";
|
|
2
2
|
import { c as LooksRareLogo, d as MintifyLogo, g as SequenceLogo, i as BlurLogo, l as MagicEdenLogo, m as OpenSeaLogo, t as AlienSwapLogo, y as X2y2Logo } from "./marketplace-logos.js";
|
|
3
3
|
import { clsx } from "clsx";
|
|
4
4
|
import { twMerge } from "tailwind-merge";
|
|
@@ -26,6 +26,17 @@ function cn(...inputs) {
|
|
|
26
26
|
return twMerge(clsx(inputs));
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region src/utils/collection.ts
|
|
31
|
+
/**
|
|
32
|
+
* Finds a market collection matching both the collection address and chain ID.
|
|
33
|
+
* Always use this instead of manually searching market.collections to avoid
|
|
34
|
+
* multi-chain bugs where the same collection address exists on different chains.
|
|
35
|
+
*/
|
|
36
|
+
const findMarketCollection = (collections, collectionAddress, chainId) => {
|
|
37
|
+
return collections.find((collection) => compareAddress(collection.itemsAddress, collectionAddress) && Number(collection.chainId) === Number(chainId));
|
|
38
|
+
};
|
|
39
|
+
|
|
29
40
|
//#endregion
|
|
30
41
|
//#region src/utils/getMarketplaceDetails.ts
|
|
31
42
|
const MARKETPLACES = {
|
|
@@ -143,10 +154,10 @@ const formatPrice = (amount, decimals) => {
|
|
|
143
154
|
*/
|
|
144
155
|
const calculateEarningsAfterFees = (amount, decimals, fees) => {
|
|
145
156
|
try {
|
|
146
|
-
const decimalAmount =
|
|
147
|
-
let earnings = dn.from(decimalAmount
|
|
157
|
+
const decimalAmount = formatUnits(amount, decimals);
|
|
158
|
+
let earnings = dn.from(decimalAmount, decimals);
|
|
148
159
|
for (const fee of fees) if (fee > 0) {
|
|
149
|
-
const feeMultiplier = dn.from(
|
|
160
|
+
const feeMultiplier = dn.from(1 - fee / 100, decimals);
|
|
150
161
|
earnings = dn.multiply(earnings, feeMultiplier);
|
|
151
162
|
}
|
|
152
163
|
return dn.format(earnings, {
|
|
@@ -172,9 +183,9 @@ const calculateEarningsAfterFees = (amount, decimals, fees) => {
|
|
|
172
183
|
*/
|
|
173
184
|
const formatPriceWithFee = (amount, decimals, feePercentage) => {
|
|
174
185
|
try {
|
|
175
|
-
const decimalAmount =
|
|
176
|
-
const price = dn.from(decimalAmount
|
|
177
|
-
const feeMultiplier = dn.from(
|
|
186
|
+
const decimalAmount = formatUnits(amount, decimals);
|
|
187
|
+
const price = dn.from(decimalAmount, decimals);
|
|
188
|
+
const feeMultiplier = dn.from(1 + feePercentage / 100, decimals);
|
|
178
189
|
const totalPrice = dn.multiply(price, feeMultiplier);
|
|
179
190
|
return dn.format(totalPrice, {
|
|
180
191
|
digits: decimals,
|
|
@@ -191,7 +202,7 @@ const calculateTotalOfferCost = (offerAmountRaw, decimals, royaltyPercentage = 0
|
|
|
191
202
|
const dnumAmount = [offerAmountRaw, decimals];
|
|
192
203
|
let totalCost = dn.from(dnumAmount);
|
|
193
204
|
if (royaltyPercentage > 0) {
|
|
194
|
-
const royaltyFee = dn.multiply(totalCost, dn.from(
|
|
205
|
+
const royaltyFee = dn.multiply(totalCost, dn.from(royaltyPercentage / 100, decimals));
|
|
195
206
|
totalCost = dn.add(totalCost, royaltyFee);
|
|
196
207
|
}
|
|
197
208
|
const cleanAmount = dn.format(totalCost, {
|
|
@@ -226,5 +237,5 @@ const validateOpenseaOfferDecimals = (value) => {
|
|
|
226
237
|
};
|
|
227
238
|
|
|
228
239
|
//#endregion
|
|
229
|
-
export { formatPriceWithFee as a,
|
|
240
|
+
export { formatPriceWithFee as a, findMarketCollection as c, truncateEnd as d, truncateMiddle as f, formatPrice as i, cn as l, calculatePriceDifferencePercentage as n, validateOpenseaOfferDecimals as o, calculateTotalOfferCost as r, getMarketplaceDetails as s, calculateEarningsAfterFees as t, compareAddress as u };
|
|
230
241
|
//# sourceMappingURL=utils.js.map
|
package/dist/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":["MARKETPLACES: Record<string, Marketplace>","KIND_TO_MARKETPLACE: Partial<\n\tRecord<MarketplaceKind, keyof typeof MARKETPLACES>\n>"],"sources":["../src/utils/address.ts","../src/utils/cn.ts","../src/utils/getMarketplaceDetails.ts","../src/utils/price.ts"],"sourcesContent":["export const truncateMiddle = (\n\taddress: string,\n\tminPrefix = 20,\n\tminSuffix = 3,\n): string => {\n\tif (minPrefix + minSuffix >= 40) {\n\t\treturn address;\n\t}\n\treturn `${address.substring(0, 2 + minPrefix)}…${address.substring(address.length - minSuffix)}`;\n};\n\nexport const truncateEnd = (text: string | undefined, truncateAt: number) => {\n\tif (!text) return '';\n\n\tlet finalText = text;\n\n\tif (text.length >= truncateAt) {\n\t\tfinalText = `${text.slice(0, truncateAt)}...`;\n\t}\n\n\treturn finalText;\n};\n\nexport const compareAddress = (a = '', b = '') => {\n\treturn a.toLowerCase() === b.toLowerCase();\n};\n","import { type ClassValue, clsx } from 'clsx';\nimport { twMerge } from 'tailwind-merge';\n\nexport function cn(...inputs: ClassValue[]) {\n\treturn twMerge(clsx(inputs));\n}\n","import type { Image } from '@0xsequence/design-system';\nimport type { ComponentType } from 'react';\nimport {\n\tAlienSwapLogo,\n\tBlurLogo,\n\tLooksRareLogo,\n\tMagicEdenLogo,\n\tMintifyLogo,\n\tOpenSeaLogo,\n\tSequenceLogo,\n\tX2y2Logo,\n} from '../react/ui/components/marketplace-logos';\nimport { MarketplaceKind } from '../types';\n\ninterface Marketplace {\n\tlogo: ComponentType<React.ComponentProps<typeof Image>>;\n\tdisplayName: string;\n}\n\nconst MARKETPLACES: Record<string, Marketplace> = {\n\tsequence: {\n\t\tlogo: SequenceLogo,\n\t\tdisplayName: 'Sequence',\n\t},\n\topensea: {\n\t\tlogo: OpenSeaLogo,\n\t\tdisplayName: 'OpenSea',\n\t},\n\tmagiceden: {\n\t\tlogo: MagicEdenLogo,\n\t\tdisplayName: 'Magic Eden',\n\t},\n\tmintify: {\n\t\tlogo: MintifyLogo,\n\t\tdisplayName: 'Mintify',\n\t},\n\tlooksrare: {\n\t\tlogo: LooksRareLogo,\n\t\tdisplayName: 'Looks Rare',\n\t},\n\tx2y2: {\n\t\tlogo: X2y2Logo,\n\t\tdisplayName: 'X2Y2',\n\t},\n\tblur: {\n\t\tlogo: BlurLogo,\n\t\tdisplayName: 'Blur',\n\t},\n\talienswap: {\n\t\tlogo: AlienSwapLogo,\n\t\tdisplayName: 'AlienSwap',\n\t},\n} as const;\n\nconst KIND_TO_MARKETPLACE: Partial<\n\tRecord<MarketplaceKind, keyof typeof MARKETPLACES>\n> = {\n\t[MarketplaceKind.sequence_marketplace_v1]: 'sequence',\n\t[MarketplaceKind.sequence_marketplace_v2]: 'sequence',\n\t[MarketplaceKind.opensea]: 'opensea',\n\t[MarketplaceKind.mintify]: 'mintify',\n\t[MarketplaceKind.looks_rare]: 'looksrare',\n\t[MarketplaceKind.x2y2]: 'x2y2',\n\t[MarketplaceKind.blur]: 'blur',\n\t[MarketplaceKind.magic_eden]: 'magiceden',\n};\n\ntype MarketplaceDetailsProp = {\n\toriginName: string;\n\tkind: MarketplaceKind;\n};\n\n// TODO: add support for more marketplaces and improve detection of marketplace\nexport function getMarketplaceDetails({\n\toriginName,\n\tkind,\n}: MarketplaceDetailsProp) {\n\tif (\n\t\tkind === MarketplaceKind.sequence_marketplace_v1 ||\n\t\tkind === MarketplaceKind.sequence_marketplace_v2\n\t) {\n\t\treturn MARKETPLACES.sequence;\n\t}\n\n\tlet name = originName.toLowerCase();\n\n\ttry {\n\t\t//Check if the name can be parsed as a url\n\t\tnew URL(name);\n\t\t// if it can we are naively trying to extract the root domain\n\t\tname = getRootDomain(name) || name;\n\t} catch {}\n\n\tname = name.replace(/ /g, '');\n\n\tconst details = MARKETPLACES[name];\n\n\tif (details) {\n\t\treturn details;\n\t}\n\n\tif (KIND_TO_MARKETPLACE[kind]) {\n\t\treturn MARKETPLACES[KIND_TO_MARKETPLACE[kind]];\n\t}\n}\n\nfunction getRootDomain(url: string) {\n\tconst domain = url.replace(/^(https?:\\/\\/)?(www\\.)?/, '');\n\tconst parts = domain.split('.');\n\treturn parts[parts.length - 2] || parts[0];\n}\n","import * as dn from 'dnum';\nimport { formatUnits } from 'viem';\n\ntype CalculatePriceDifferencePercentageArgs = {\n\tinputPriceRaw: bigint;\n\tbasePriceRaw: bigint;\n\tdecimals: number;\n};\n\n/**\n * Calculates the percentage difference between two prices\n * @param args - Object containing input price, base price, and decimals\n * @returns The percentage difference as a string with 2 decimal places\n * @example\n * ```ts\n * const diff = calculatePriceDifferencePercentage({\n * inputPriceRaw: 1000000n,\n * basePriceRaw: 900000n,\n * decimals: 6\n * }); // Returns \"11.11\"\n * ```\n */\nexport const calculatePriceDifferencePercentage = ({\n\tinputPriceRaw,\n\tbasePriceRaw,\n\tdecimals,\n}: CalculatePriceDifferencePercentageArgs) => {\n\tconst inputPrice = Number(formatUnits(inputPriceRaw, decimals));\n\tconst basePrice = Number(formatUnits(basePriceRaw, decimals));\n\tconst difference = inputPrice - basePrice;\n\tconst percentageDifference = (difference / basePrice) * 100;\n\n\treturn percentageDifference.toFixed(2);\n};\n\n/**\n * Formats a raw price amount with the specified number of decimal places\n * @param amount - The raw price amount as a bigint\n * @param decimals - Number of decimal places to format to\n * @returns Formatted price string with proper decimal and thousands separators\n * @example\n * ```ts\n * const formatted = formatPrice(1000000n, 6); // Returns \"1.000000\"\n * ```\n */\nexport const formatPrice = (amount: bigint, decimals: number): string => {\n\tconst formattedUnits = Number(formatUnits(amount, decimals));\n\treturn formattedUnits.toLocaleString('en-US', {\n\t\tminimumFractionDigits: 0,\n\t\tmaximumFractionDigits: decimals,\n\t});\n};\n\n/**\n * Calculates the final earnings amount after applying multiple fee percentages\n * @param amount - The raw amount as a bigint (e.g., from a blockchain transaction)\n * @param decimals - The number of decimal places for the currency (e.g., 18 for ETH, 6 for USDC)\n * @param fees - Array of fee percentages to apply (e.g., [2.5, 1.0] for 2.5% and 1% fees)\n * @returns Formatted string representing the final earnings after all fees are applied\n * @throws Will return '0' if there's an error in calculation\n * @example\n * ```ts\n * const earnings = calculateEarningsAfterFees(\n * 1000000000000000000n, // 1 ETH\n * 18, // ETH decimals\n * [2.5, 1.0] // 2.5% and 1% fees\n * ); // Returns \"0.96525\" (1 ETH after 2.5% and 1% fees)\n * ```\n */\nexport const calculateEarningsAfterFees = (\n\tamount: bigint,\n\tdecimals: number,\n\tfees: number[],\n): string => {\n\ttry {\n\t\tconst decimalAmount = Number(formatUnits(amount, decimals));\n\t\tlet earnings = dn.from(decimalAmount.toString(), decimals);\n\n\t\tfor (const fee of fees) {\n\t\t\tif (fee > 0) {\n\t\t\t\tconst feeMultiplier = dn.from((1 - fee / 100).toString(), decimals);\n\t\t\t\tearnings = dn.multiply(earnings, feeMultiplier);\n\t\t\t}\n\t\t}\n\n\t\treturn dn.format(earnings, {\n\t\t\tdigits: decimals,\n\t\t\ttrailingZeros: false,\n\t\t\tlocale: 'en-US',\n\t\t});\n\t} catch (error) {\n\t\tconsole.error('Error calculating earnings after fees:', error);\n\t\treturn '0';\n\t}\n};\n\n/**\n * Formats a price amount with fee applied\n * @param amount - The raw price amount as a bigint\n * @param decimals - Number of decimal places for the currency\n * @param feePercentage - Fee percentage to apply (e.g., 3.5 for 3.5%)\n * @returns Formatted price string with fee applied and proper decimal/thousands separators\n * @example\n * ```ts\n * const priceWithFee = formatPriceWithFee(1000000n, 6, 3.5); // Returns \"1.035\"\n * ```\n */\nexport const formatPriceWithFee = (\n\tamount: bigint,\n\tdecimals: number,\n\tfeePercentage: number,\n): string => {\n\ttry {\n\t\tconst decimalAmount = Number(formatUnits(amount, decimals));\n\t\tconst price = dn.from(decimalAmount.toString(), decimals);\n\t\tconst feeMultiplier = dn.from(\n\t\t\t(1 + feePercentage / 100).toString(),\n\t\t\tdecimals,\n\t\t);\n\t\tconst totalPrice = dn.multiply(price, feeMultiplier);\n\n\t\treturn dn.format(totalPrice, {\n\t\t\tdigits: decimals,\n\t\t\ttrailingZeros: false,\n\t\t\tlocale: 'en-US',\n\t\t});\n\t} catch (error) {\n\t\tconsole.error('Error formatting price with fee:', error);\n\t\treturn '0';\n\t}\n};\n\nexport const calculateTotalOfferCost = (\n\tofferAmountRaw: bigint,\n\tdecimals: number,\n\troyaltyPercentage = 0,\n): bigint => {\n\ttry {\n\t\tconst dnumAmount = [offerAmountRaw, decimals] as dn.Dnum;\n\t\tlet totalCost = dn.from(dnumAmount);\n\n\t\tif (royaltyPercentage > 0) {\n\t\t\tconst royaltyFee = dn.multiply(\n\t\t\t\ttotalCost,\n\t\t\t\tdn.from((royaltyPercentage / 100).toString(), decimals),\n\t\t\t);\n\t\t\ttotalCost = dn.add(totalCost, royaltyFee);\n\t\t}\n\n\t\tconst totalCostString = dn.format(totalCost, {\n\t\t\tdigits: decimals,\n\t\t\ttrailingZeros: true,\n\t\t});\n\n\t\tconst cleanAmount = totalCostString.replace(/,/g, '');\n\n\t\treturn BigInt(Math.round(Number(cleanAmount) * 10 ** decimals));\n\t} catch (error) {\n\t\tconsole.error('Error calculating total offer cost:', error);\n\t\treturn offerAmountRaw;\n\t}\n};\n\n/**\n * Validates if a price value meets OpenSea's decimal constraints for offers\n * OpenSea allows maximum 4 decimal places for offers and minimum 0.0001\n * @param value - The price value as a string\n * @returns Object containing validation result and error message\n * @example\n * ```ts\n * const result = validateOpenseaOfferDecimals('0.12345');\n * // Returns { isValid: false, errorMessage: \"Offer amount must be at least 0.0001\" }\n * ```\n */\nexport const validateOpenseaOfferDecimals = (\n\tvalue: string,\n): { isValid: boolean; errorMessage?: string } => {\n\tif (!value || value === '0') return { isValid: true };\n\n\tconst [_, decimals = ''] = value.split('.');\n\tif (decimals.length > 4) {\n\t\treturn {\n\t\t\tisValid: false,\n\t\t\terrorMessage: 'Offer amount must be at least 0.0001',\n\t\t};\n\t}\n\n\treturn { isValid: true };\n};\n"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"utils.js","names":["MARKETPLACES: Record<string, Marketplace>","KIND_TO_MARKETPLACE: Partial<\n\tRecord<MarketplaceKind, keyof typeof MARKETPLACES>\n>"],"sources":["../src/utils/address.ts","../src/utils/cn.ts","../src/utils/collection.ts","../src/utils/getMarketplaceDetails.ts","../src/utils/price.ts"],"sourcesContent":["export const truncateMiddle = (\n\taddress: string,\n\tminPrefix = 20,\n\tminSuffix = 3,\n): string => {\n\tif (minPrefix + minSuffix >= 40) {\n\t\treturn address;\n\t}\n\treturn `${address.substring(0, 2 + minPrefix)}…${address.substring(address.length - minSuffix)}`;\n};\n\nexport const truncateEnd = (text: string | undefined, truncateAt: number) => {\n\tif (!text) return '';\n\n\tlet finalText = text;\n\n\tif (text.length >= truncateAt) {\n\t\tfinalText = `${text.slice(0, truncateAt)}...`;\n\t}\n\n\treturn finalText;\n};\n\nexport const compareAddress = (a = '', b = '') => {\n\treturn a.toLowerCase() === b.toLowerCase();\n};\n","import { type ClassValue, clsx } from 'clsx';\nimport { twMerge } from 'tailwind-merge';\n\nexport function cn(...inputs: ClassValue[]) {\n\treturn twMerge(clsx(inputs));\n}\n","import type { MarketCollection } from '@0xsequence/api-client';\nimport { compareAddress } from './address';\n\n/**\n * Finds a market collection matching both the collection address and chain ID.\n * Always use this instead of manually searching market.collections to avoid\n * multi-chain bugs where the same collection address exists on different chains.\n */\nexport const findMarketCollection = (\n\tcollections: MarketCollection[],\n\tcollectionAddress: string,\n\tchainId: string | number,\n): MarketCollection | undefined => {\n\treturn collections.find(\n\t\t(collection) =>\n\t\t\tcompareAddress(collection.itemsAddress, collectionAddress) &&\n\t\t\tNumber(collection.chainId) === Number(chainId),\n\t);\n};\n","import { MarketplaceKind } from '@0xsequence/api-client';\nimport type { Image } from '@0xsequence/design-system';\nimport type { ComponentType } from 'react';\nimport {\n\tAlienSwapLogo,\n\tBlurLogo,\n\tLooksRareLogo,\n\tMagicEdenLogo,\n\tMintifyLogo,\n\tOpenSeaLogo,\n\tSequenceLogo,\n\tX2y2Logo,\n} from '../react/ui/components/marketplace-logos';\n\ninterface Marketplace {\n\tlogo: ComponentType<React.ComponentProps<typeof Image>>;\n\tdisplayName: string;\n}\n\nconst MARKETPLACES: Record<string, Marketplace> = {\n\tsequence: {\n\t\tlogo: SequenceLogo,\n\t\tdisplayName: 'Sequence',\n\t},\n\topensea: {\n\t\tlogo: OpenSeaLogo,\n\t\tdisplayName: 'OpenSea',\n\t},\n\tmagiceden: {\n\t\tlogo: MagicEdenLogo,\n\t\tdisplayName: 'Magic Eden',\n\t},\n\tmintify: {\n\t\tlogo: MintifyLogo,\n\t\tdisplayName: 'Mintify',\n\t},\n\tlooksrare: {\n\t\tlogo: LooksRareLogo,\n\t\tdisplayName: 'Looks Rare',\n\t},\n\tx2y2: {\n\t\tlogo: X2y2Logo,\n\t\tdisplayName: 'X2Y2',\n\t},\n\tblur: {\n\t\tlogo: BlurLogo,\n\t\tdisplayName: 'Blur',\n\t},\n\talienswap: {\n\t\tlogo: AlienSwapLogo,\n\t\tdisplayName: 'AlienSwap',\n\t},\n} as const;\n\nconst KIND_TO_MARKETPLACE: Partial<\n\tRecord<MarketplaceKind, keyof typeof MARKETPLACES>\n> = {\n\t[MarketplaceKind.sequence_marketplace_v1]: 'sequence',\n\t[MarketplaceKind.sequence_marketplace_v2]: 'sequence',\n\t[MarketplaceKind.opensea]: 'opensea',\n\t[MarketplaceKind.mintify]: 'mintify',\n\t[MarketplaceKind.looks_rare]: 'looksrare',\n\t[MarketplaceKind.x2y2]: 'x2y2',\n\t[MarketplaceKind.blur]: 'blur',\n\t[MarketplaceKind.magic_eden]: 'magiceden',\n};\n\ntype MarketplaceDetailsProp = {\n\toriginName: string;\n\tkind: MarketplaceKind;\n};\n\n// TODO: add support for more marketplaces and improve detection of marketplace\nexport function getMarketplaceDetails({\n\toriginName,\n\tkind,\n}: MarketplaceDetailsProp) {\n\tif (\n\t\tkind === MarketplaceKind.sequence_marketplace_v1 ||\n\t\tkind === MarketplaceKind.sequence_marketplace_v2\n\t) {\n\t\treturn MARKETPLACES.sequence;\n\t}\n\n\tlet name = originName.toLowerCase();\n\n\ttry {\n\t\t//Check if the name can be parsed as a url\n\t\tnew URL(name);\n\t\t// if it can we are naively trying to extract the root domain\n\t\tname = getRootDomain(name) || name;\n\t} catch {}\n\n\tname = name.replace(/ /g, '');\n\n\tconst details = MARKETPLACES[name];\n\n\tif (details) {\n\t\treturn details;\n\t}\n\n\tif (KIND_TO_MARKETPLACE[kind]) {\n\t\treturn MARKETPLACES[KIND_TO_MARKETPLACE[kind]];\n\t}\n}\n\nfunction getRootDomain(url: string) {\n\tconst domain = url.replace(/^(https?:\\/\\/)?(www\\.)?/, '');\n\tconst parts = domain.split('.');\n\treturn parts[parts.length - 2] || parts[0];\n}\n","import * as dn from 'dnum';\nimport { formatUnits } from 'viem';\n\ntype CalculatePriceDifferencePercentageArgs = {\n\tinputPriceRaw: bigint;\n\tbasePriceRaw: bigint;\n\tdecimals: number;\n};\n\n/**\n * Calculates the percentage difference between two prices\n * @param args - Object containing input price, base price, and decimals\n * @returns The percentage difference as a string with 2 decimal places\n * @example\n * ```ts\n * const diff = calculatePriceDifferencePercentage({\n * inputPriceRaw: 1000000n,\n * basePriceRaw: 900000n,\n * decimals: 6\n * }); // Returns \"11.11\"\n * ```\n */\nexport const calculatePriceDifferencePercentage = ({\n\tinputPriceRaw,\n\tbasePriceRaw,\n\tdecimals,\n}: CalculatePriceDifferencePercentageArgs) => {\n\tconst inputPrice = Number(formatUnits(inputPriceRaw, decimals));\n\tconst basePrice = Number(formatUnits(basePriceRaw, decimals));\n\tconst difference = inputPrice - basePrice;\n\tconst percentageDifference = (difference / basePrice) * 100;\n\n\treturn percentageDifference.toFixed(2);\n};\n\n/**\n * Formats a raw price amount with the specified number of decimal places\n * @param amount - The raw price amount as a bigint\n * @param decimals - Number of decimal places to format to\n * @returns Formatted price string with proper decimal and thousands separators\n * @example\n * ```ts\n * const formatted = formatPrice(1000000n, 6); // Returns \"1.000000\"\n * ```\n */\nexport const formatPrice = (amount: bigint, decimals: number): string => {\n\tconst formattedUnits = Number(formatUnits(amount, decimals));\n\treturn formattedUnits.toLocaleString('en-US', {\n\t\tminimumFractionDigits: 0,\n\t\tmaximumFractionDigits: decimals,\n\t});\n};\n\n/**\n * Calculates the final earnings amount after applying multiple fee percentages\n * @param amount - The raw amount as a bigint (e.g., from a blockchain transaction)\n * @param decimals - The number of decimal places for the currency (e.g., 18 for ETH, 6 for USDC)\n * @param fees - Array of fee percentages to apply (e.g., [2.5, 1.0] for 2.5% and 1% fees)\n * @returns Formatted string representing the final earnings after all fees are applied\n * @throws Will return '0' if there's an error in calculation\n * @example\n * ```ts\n * const earnings = calculateEarningsAfterFees(\n * 1000000000000000000n, // 1 ETH\n * 18, // ETH decimals\n * [2.5, 1.0] // 2.5% and 1% fees\n * ); // Returns \"0.96525\" (1 ETH after 2.5% and 1% fees)\n * ```\n */\nexport const calculateEarningsAfterFees = (\n\tamount: bigint,\n\tdecimals: number,\n\tfees: number[],\n): string => {\n\ttry {\n\t\t// formatUnits already returns a string, no need for Number conversion\n\t\tconst decimalAmount = formatUnits(amount, decimals);\n\t\tlet earnings = dn.from(decimalAmount, decimals);\n\n\t\tfor (const fee of fees) {\n\t\t\tif (fee > 0) {\n\t\t\t\t// dnum accepts numbers directly via Numberish type\n\t\t\t\tconst feeMultiplier = dn.from(1 - fee / 100, decimals);\n\t\t\t\tearnings = dn.multiply(earnings, feeMultiplier);\n\t\t\t}\n\t\t}\n\n\t\treturn dn.format(earnings, {\n\t\t\tdigits: decimals,\n\t\t\ttrailingZeros: false,\n\t\t\tlocale: 'en-US',\n\t\t});\n\t} catch (error) {\n\t\tconsole.error('Error calculating earnings after fees:', error);\n\t\treturn '0';\n\t}\n};\n\n/**\n * Formats a price amount with fee applied\n * @param amount - The raw price amount as a bigint\n * @param decimals - Number of decimal places for the currency\n * @param feePercentage - Fee percentage to apply (e.g., 3.5 for 3.5%)\n * @returns Formatted price string with fee applied and proper decimal/thousands separators\n * @example\n * ```ts\n * const priceWithFee = formatPriceWithFee(1000000n, 6, 3.5); // Returns \"1.035\"\n * ```\n */\nexport const formatPriceWithFee = (\n\tamount: bigint,\n\tdecimals: number,\n\tfeePercentage: number,\n): string => {\n\ttry {\n\t\t// formatUnits already returns a string, no need for Number conversion\n\t\tconst decimalAmount = formatUnits(amount, decimals);\n\t\tconst price = dn.from(decimalAmount, decimals);\n\t\t// dnum accepts numbers directly via Numberish type\n\t\tconst feeMultiplier = dn.from(1 + feePercentage / 100, decimals);\n\t\tconst totalPrice = dn.multiply(price, feeMultiplier);\n\n\t\treturn dn.format(totalPrice, {\n\t\t\tdigits: decimals,\n\t\t\ttrailingZeros: false,\n\t\t\tlocale: 'en-US',\n\t\t});\n\t} catch (error) {\n\t\tconsole.error('Error formatting price with fee:', error);\n\t\treturn '0';\n\t}\n};\n\nexport const calculateTotalOfferCost = (\n\tofferAmountRaw: bigint,\n\tdecimals: number,\n\troyaltyPercentage = 0,\n): bigint => {\n\ttry {\n\t\tconst dnumAmount = [offerAmountRaw, decimals] as dn.Dnum;\n\t\tlet totalCost = dn.from(dnumAmount);\n\n\t\tif (royaltyPercentage > 0) {\n\t\t\t// dnum accepts numbers directly via Numberish type\n\t\t\tconst royaltyFee = dn.multiply(\n\t\t\t\ttotalCost,\n\t\t\t\tdn.from(royaltyPercentage / 100, decimals),\n\t\t\t);\n\t\t\ttotalCost = dn.add(totalCost, royaltyFee);\n\t\t}\n\n\t\tconst totalCostString = dn.format(totalCost, {\n\t\t\tdigits: decimals,\n\t\t\ttrailingZeros: true,\n\t\t});\n\n\t\tconst cleanAmount = totalCostString.replace(/,/g, '');\n\n\t\treturn BigInt(Math.round(Number(cleanAmount) * 10 ** decimals));\n\t} catch (error) {\n\t\tconsole.error('Error calculating total offer cost:', error);\n\t\treturn offerAmountRaw;\n\t}\n};\n\n/**\n * Validates if a price value meets OpenSea's decimal constraints for offers\n * OpenSea allows maximum 4 decimal places for offers and minimum 0.0001\n * @param value - The price value as a string\n * @returns Object containing validation result and error message\n * @example\n * ```ts\n * const result = validateOpenseaOfferDecimals('0.12345');\n * // Returns { isValid: false, errorMessage: \"Offer amount must be at least 0.0001\" }\n * ```\n */\nexport const validateOpenseaOfferDecimals = (\n\tvalue: string,\n): { isValid: boolean; errorMessage?: string } => {\n\tif (!value || value === '0') return { isValid: true };\n\n\tconst [_, decimals = ''] = value.split('.');\n\tif (decimals.length > 4) {\n\t\treturn {\n\t\t\tisValid: false,\n\t\t\terrorMessage: 'Offer amount must be at least 0.0001',\n\t\t};\n\t}\n\n\treturn { isValid: true };\n};\n"],"mappings":"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"}
|
package/dist/utils2.js
CHANGED
|
@@ -1,118 +1,76 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { queryOptions } from "@tanstack/react-query";
|
|
4
|
-
import * as dn from "dnum";
|
|
5
|
-
import { formatUnits } from "viem";
|
|
1
|
+
import { n as getIndexerClient } from "./api.js";
|
|
2
|
+
import { TransactionReceiptNotFoundError } from "viem";
|
|
6
3
|
|
|
7
|
-
//#region src/react/
|
|
4
|
+
//#region src/react/utils/normalize-attributes.ts
|
|
5
|
+
function isValidAttributePair(candidate) {
|
|
6
|
+
return (typeof candidate.name === "string" || typeof candidate.trait_type === "string") && (typeof candidate.value === "string" || typeof candidate.value === "number") && (candidate.display_type === void 0 || candidate.display_type === null || typeof candidate.display_type === "string");
|
|
7
|
+
}
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* Processes token metadata attributes into a standardized format
|
|
10
|
+
* Handles both array-based attributes (OpenSea standard) and object-based attributes
|
|
11
|
+
* @param attributes - Token attributes from metadata
|
|
12
|
+
* @returns Object with standardized attributes containing name, value, and optional display_type
|
|
10
13
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
chainId: params.chainId,
|
|
27
|
-
currencyAddress: params.currencyAddress,
|
|
28
|
-
amountRaw: params.amountRaw
|
|
29
|
-
};
|
|
30
|
-
return [
|
|
31
|
-
...currencyKeys.conversion,
|
|
32
|
-
"usd",
|
|
33
|
-
apiArgs
|
|
34
|
-
];
|
|
35
|
-
}
|
|
36
|
-
function convertPriceToUSDQueryOptions(params) {
|
|
37
|
-
const enabled = Boolean(params.chainId && params.currencyAddress && params.amountRaw && params.config && (params.query?.enabled ?? true));
|
|
38
|
-
return queryOptions({
|
|
39
|
-
queryKey: getConvertPriceToUSDQueryKey(params),
|
|
40
|
-
queryFn: () => fetchConvertPriceToUSD({
|
|
41
|
-
chainId: params.chainId,
|
|
42
|
-
currencyAddress: params.currencyAddress,
|
|
43
|
-
amountRaw: params.amountRaw,
|
|
44
|
-
config: params.config
|
|
45
|
-
}),
|
|
46
|
-
...params.query,
|
|
47
|
-
enabled
|
|
48
|
-
});
|
|
14
|
+
function processAttributes(attributes) {
|
|
15
|
+
if (Array.isArray(attributes)) return Object.fromEntries(attributes.filter((attr) => attr !== null && typeof attr === "object").filter(isValidAttributePair).map((attr) => {
|
|
16
|
+
const name = "name" in attr ? attr.name : attr.trait_type;
|
|
17
|
+
return [name, {
|
|
18
|
+
name,
|
|
19
|
+
value: String(attr.value),
|
|
20
|
+
display_type: attr.display_type
|
|
21
|
+
}];
|
|
22
|
+
}));
|
|
23
|
+
if (attributes && typeof attributes === "object") return Object.fromEntries(Object.entries(attributes).map(([key, value]) => [key, {
|
|
24
|
+
name: key,
|
|
25
|
+
value: typeof value === "object" && value !== null ? JSON.stringify(value) : String(value),
|
|
26
|
+
display_type: void 0
|
|
27
|
+
}]));
|
|
28
|
+
return {};
|
|
49
29
|
}
|
|
50
30
|
|
|
51
31
|
//#endregion
|
|
52
|
-
//#region src/react/
|
|
32
|
+
//#region src/react/utils/normalize-properties.ts
|
|
53
33
|
/**
|
|
54
|
-
*
|
|
34
|
+
* Processes token metadata properties into a standardized format
|
|
35
|
+
* @param properties - Token properties from metadata
|
|
36
|
+
* @returns Object with standardized properties containing name and value
|
|
55
37
|
*/
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
if (compareToPriceUSD.usdAmount === 0) throw new Error("Cannot compare to zero price");
|
|
71
|
-
const percentageDifference = difference / compareToPriceUSD.usdAmount * 100;
|
|
72
|
-
const isAbove = percentageDifference > 0;
|
|
73
|
-
const isSame = percentageDifference === 0;
|
|
74
|
-
const absPercentage = Math.abs(percentageDifference);
|
|
75
|
-
return {
|
|
76
|
-
percentageDifference,
|
|
77
|
-
percentageDifferenceFormatted: dn.format([BigInt(Math.round(absPercentage * 100)), 2], {
|
|
78
|
-
digits: 2,
|
|
79
|
-
trailingZeros: true,
|
|
80
|
-
locale: "en-US"
|
|
81
|
-
}),
|
|
82
|
-
status: isAbove ? "above" : isSame ? "same" : "below"
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
function getComparePricesQueryKey(params) {
|
|
86
|
-
const apiArgs = {
|
|
87
|
-
chainId: params.chainId,
|
|
88
|
-
priceAmountRaw: params.priceAmountRaw,
|
|
89
|
-
priceCurrencyAddress: params.priceCurrencyAddress,
|
|
90
|
-
compareToPriceAmountRaw: params.compareToPriceAmountRaw,
|
|
91
|
-
compareToPriceCurrencyAddress: params.compareToPriceCurrencyAddress
|
|
92
|
-
};
|
|
93
|
-
return [
|
|
94
|
-
...currencyKeys.conversion,
|
|
95
|
-
"compare",
|
|
96
|
-
apiArgs
|
|
97
|
-
];
|
|
98
|
-
}
|
|
99
|
-
function comparePricesQueryOptions(params) {
|
|
100
|
-
const enabled = Boolean(params.chainId && params.priceAmountRaw && params.priceCurrencyAddress && params.compareToPriceAmountRaw && params.compareToPriceCurrencyAddress && params.config && (params.query?.enabled ?? true));
|
|
101
|
-
return queryOptions({
|
|
102
|
-
queryKey: getComparePricesQueryKey(params),
|
|
103
|
-
queryFn: () => fetchComparePrices({
|
|
104
|
-
chainId: params.chainId,
|
|
105
|
-
priceAmountRaw: params.priceAmountRaw,
|
|
106
|
-
priceCurrencyAddress: params.priceCurrencyAddress,
|
|
107
|
-
compareToPriceAmountRaw: params.compareToPriceAmountRaw,
|
|
108
|
-
compareToPriceCurrencyAddress: params.compareToPriceCurrencyAddress,
|
|
109
|
-
config: params.config
|
|
110
|
-
}),
|
|
111
|
-
...params.query,
|
|
112
|
-
enabled
|
|
113
|
-
});
|
|
38
|
+
function processProperties(properties) {
|
|
39
|
+
if (!properties || typeof properties !== "object" || Array.isArray(properties) || Object.keys(properties).length === 0) return {};
|
|
40
|
+
return Object.fromEntries(Object.entries(properties).map(([key, value]) => [key, {
|
|
41
|
+
name: key,
|
|
42
|
+
value: typeof value === "object" && value !== null ? (() => {
|
|
43
|
+
const nestedValue = value.value;
|
|
44
|
+
if (nestedValue !== void 0) {
|
|
45
|
+
if (typeof nestedValue === "object" && nestedValue !== null) return JSON.stringify(nestedValue);
|
|
46
|
+
if (typeof nestedValue === "string" || typeof nestedValue === "number" || typeof nestedValue === "boolean") return String(nestedValue);
|
|
47
|
+
return JSON.stringify(nestedValue);
|
|
48
|
+
}
|
|
49
|
+
return JSON.stringify(value);
|
|
50
|
+
})() : value !== null && value !== void 0 ? String(value) : ""
|
|
51
|
+
}]));
|
|
114
52
|
}
|
|
115
53
|
|
|
116
54
|
//#endregion
|
|
117
|
-
|
|
55
|
+
//#region src/react/utils/waitForTransactionReceipt.ts
|
|
56
|
+
const MAX_RETRIES = 3;
|
|
57
|
+
const MAX_BLOCK_WAIT = 30;
|
|
58
|
+
const waitForTransactionReceipt = async ({ txHash, chainId, sdkConfig, maxBlockWait = MAX_BLOCK_WAIT }) => {
|
|
59
|
+
const indexer = getIndexerClient(chainId, sdkConfig);
|
|
60
|
+
let retries = 0;
|
|
61
|
+
while (retries < MAX_RETRIES) try {
|
|
62
|
+
return (await indexer.fetchTransactionReceipt({
|
|
63
|
+
txnHash: txHash,
|
|
64
|
+
maxBlockWait
|
|
65
|
+
})).receipt;
|
|
66
|
+
} catch (error) {
|
|
67
|
+
retries++;
|
|
68
|
+
console.error(`Failed to fetch transaction receipt (attempt ${retries}/${MAX_RETRIES}):`, error);
|
|
69
|
+
if (retries >= MAX_RETRIES) throw TransactionReceiptNotFoundError;
|
|
70
|
+
}
|
|
71
|
+
throw TransactionReceiptNotFoundError;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
//#endregion
|
|
75
|
+
export { processProperties as n, processAttributes as r, waitForTransactionReceipt as t };
|
|
118
76
|
//# sourceMappingURL=utils2.js.map
|