@0xsequence/marketplace-sdk 0.9.0 → 0.10.0
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/main.ts +63 -0
- package/.storybook/preview.ts +24 -0
- package/.storybook/vitest.setup.ts +6 -0
- package/CHANGELOG.md +77 -8
- package/dist/{CalendarIcon-DbQ7Vxcw.js → CalendarIcon-CqsuAuCm.js} +4 -51
- package/dist/CalendarIcon-CqsuAuCm.js.map +1 -0
- package/dist/{CollectibleCard-C8Ae64Ab.d.ts → CollectibleCard-Dd-CG6dE.d.ts} +8 -7
- package/dist/InfoIcon-v0w_Lu7t.js +53 -0
- package/dist/InfoIcon-v0w_Lu7t.js.map +1 -0
- package/dist/{_internal-BgWcRIak.js → _internal-C75gOSNo.js} +2 -10
- package/dist/_internal-C75gOSNo.js.map +1 -0
- package/dist/actionModal-CMUeVsFX.js +116 -0
- package/dist/actionModal-CMUeVsFX.js.map +1 -0
- package/dist/{alien_swap-B_76IMma.js → alien_swap-CYv6YlOF.js} +1 -1
- package/dist/{alien_swap-B_76IMma.js.map → alien_swap-CYv6YlOF.js.map} +1 -1
- package/dist/{api-DTIan01C.js → api-BiMGqWdz.js} +17 -34
- package/dist/api-BiMGqWdz.js.map +1 -0
- package/dist/{aqua-xyz-CMN_TFY5.js → aqua-xyz-Bzn5baeH.js} +1 -1
- package/dist/{aqua-xyz-CMN_TFY5.js.map → aqua-xyz-Bzn5baeH.js.map} +1 -1
- package/dist/{aura-Cye_TuHj.js → aura-DzIWh8WT.js} +1 -1
- package/dist/{aura-Cye_TuHj.js.map → aura-DzIWh8WT.js.map} +1 -1
- package/dist/base-DqaJPvfN.js +22 -0
- package/dist/base-DqaJPvfN.js.map +1 -0
- package/dist/{blur-DWDMyMpK.js → blur-DSH-Cbpj.js} +1 -1
- package/dist/{blur-DWDMyMpK.js.map → blur-DSH-Cbpj.js.map} +1 -1
- package/dist/{coinbase-ByA_XRB0.js → coinbase-Df8URNxq.js} +1 -1
- package/dist/{coinbase-ByA_XRB0.js.map → coinbase-Df8URNxq.js.map} +1 -1
- package/dist/{new-marketplace-types-Bfis0U4J.d.ts → create-config-DKJ-F0jc.d.ts} +402 -41
- package/dist/{wagmi-CDzEQbfk.js → create-config-fQ-jbJD1.js} +20 -10
- package/dist/create-config-fQ-jbJD1.js.map +1 -0
- package/dist/{element-b77CyXIZ.js → element-Cx6uJu5N.js} +1 -1
- package/dist/{element-b77CyXIZ.js.map → element-Cx6uJu5N.js.map} +1 -1
- package/dist/{foundation-DbOrKP9Y.js → foundation-D6U4aRLN.js} +1 -1
- package/dist/{foundation-DbOrKP9Y.js.map → foundation-D6U4aRLN.js.map} +1 -1
- package/dist/get-provider-CYYHfrlg.js +10 -0
- package/dist/get-provider-CYYHfrlg.js.map +1 -0
- package/dist/get-query-client-D19vvfJo.js +23 -0
- package/dist/get-query-client-D19vvfJo.js.map +1 -0
- package/dist/hooks-4pxIbLbM.js +4044 -0
- package/dist/hooks-4pxIbLbM.js.map +1 -0
- package/dist/{index-BL9RUSEK.d.ts → index-136YrWDH.d.ts} +1 -1
- package/dist/{index-D5v5iluA.d.ts → index-BAhaEfqY.d.ts} +1 -1
- package/dist/index-BKBin-rq.d.ts +979 -0
- package/dist/{index-BQsgAvtX.d.ts → index-BUWB_RXp.d.ts} +776 -570
- package/dist/{index-21LE7OhL.d.ts → index-BhVFc2rX.d.ts} +6 -3
- package/dist/{index-DXMfTZ1F.d.ts → index-C5aqo8xu.d.ts} +1 -1
- package/dist/{index-ByznONYE.d.ts → index-CKrYP7ot.d.ts} +20 -48
- package/dist/{index-DaE5ZNHb.d.ts → index-CUwMH7Ht.d.ts} +5 -5
- package/dist/{index-CLy8y5hm.d.ts → index-Cu70Lw-w.d.ts} +1 -1
- package/dist/index.css +414 -1
- package/dist/index.d.ts +8 -10
- package/dist/index.js +13 -9
- package/dist/{looks-rare-C1VqNcSM.js → looks-rare-ChBRBY-p.js} +1 -1
- package/dist/{looks-rare-C1VqNcSM.js.map → looks-rare-ChBRBY-p.js.map} +1 -1
- package/dist/{magic-eden-ea_AGCZr.js → magic-eden-D5U7N1xL.js} +1 -1
- package/dist/{magic-eden-ea_AGCZr.js.map → magic-eden-D5U7N1xL.js.map} +1 -1
- package/dist/{manifold-8y8J2sjT.js → manifold-CtLF52zU.js} +1 -1
- package/dist/{manifold-8y8J2sjT.js.map → manifold-CtLF52zU.js.map} +1 -1
- package/dist/{marketplace-nwnZv9Cb.js → marketplace-DmFiyBoS.js} +1 -1
- package/dist/{marketplace-nwnZv9Cb.js.map → marketplace-DmFiyBoS.js.map} +1 -1
- package/dist/{marketplace-logos-CSeGcPW4.js → marketplace-logos-Cd6W-qOq.js} +21 -21
- package/dist/{marketplace-logos-CSeGcPW4.js.map → marketplace-logos-Cd6W-qOq.js.map} +1 -1
- package/dist/{marketplace.gen-BSDIX7NZ.js → marketplace.gen-HpnpL5xU.js} +3 -3
- package/dist/marketplace.gen-HpnpL5xU.js.map +1 -0
- package/dist/{marketplaceConfig-C6X1SUik.js → marketplaceConfig-GQTTmihy.js} +3 -3
- package/dist/marketplaceConfig-GQTTmihy.js.map +1 -0
- package/dist/{mintify-LA68TzWg.js → mintify-Bi3Bce68.js} +1 -1
- package/dist/{mintify-LA68TzWg.js.map → mintify-Bi3Bce68.js.map} +1 -1
- package/dist/network-CGD0oKtS.js +15 -0
- package/dist/network-CGD0oKtS.js.map +1 -0
- package/dist/{nftx-D3Tc8nzd.js → nftx-BDQZjtkX.js} +1 -1
- package/dist/{nftx-D3Tc8nzd.js.map → nftx-BDQZjtkX.js.map} +1 -1
- package/dist/{okx-hbqg6oIJ.js → okx-D4meadLe.js} +1 -1
- package/dist/{okx-hbqg6oIJ.js.map → okx-D4meadLe.js.map} +1 -1
- package/dist/{open-sea-BccuK8-t.js → open-sea-DN0hgfVw.js} +1 -1
- package/dist/{open-sea-BccuK8-t.js.map → open-sea-DN0hgfVw.js.map} +1 -1
- package/dist/{primary-sale-C55ALnfQ.js → primary-sale-CmWxSfFQ.js} +1 -1
- package/dist/{primary-sale-C55ALnfQ.js.map → primary-sale-CmWxSfFQ.js.map} +1 -1
- package/dist/provider-DPGUA10G.js +125 -0
- package/dist/provider-DPGUA10G.js.map +1 -0
- package/dist/{queries-CUU65uYZ.js → queries-Ce_2othB.js} +165 -7
- package/dist/queries-Ce_2othB.js.map +1 -0
- package/dist/{rarible-BgTwwj9g.js → rarible-B0xlD88A.js} +1 -1
- package/dist/{rarible-BgTwwj9g.js.map → rarible-B0xlD88A.js.map} +1 -1
- package/dist/react/_internal/api/index.d.ts +2 -4
- package/dist/react/_internal/api/index.js +7 -4
- package/dist/react/_internal/databeat/index.d.ts +2 -73
- package/dist/react/_internal/databeat/index.js +4 -21
- package/dist/react/_internal/index.d.ts +2 -7
- package/dist/react/_internal/index.js +11 -6
- package/dist/react/_internal/wagmi/index.d.ts +2 -4
- package/dist/react/_internal/wagmi/index.js +5 -3
- package/dist/react/hooks/index.d.ts +12 -17
- package/dist/react/hooks/index.js +23 -19
- package/dist/react/hooks/options/index.d.ts +2 -3
- package/dist/react/hooks/options/index.js +12 -7
- package/dist/react/index.d.ts +12 -17
- package/dist/react/index.js +28 -19
- package/dist/react/queries/index.d.ts +9 -8
- package/dist/react/queries/index.js +20 -15
- package/dist/react/ssr/index.d.ts +7 -9
- package/dist/react/ssr/index.js +11 -6
- package/dist/react/ssr/index.js.map +1 -1
- package/dist/react/ui/components/marketplace-collectible-card/index.d.ts +3 -8
- package/dist/react/ui/components/marketplace-collectible-card/index.js +27 -18
- package/dist/react/ui/components/marketplace-collectible-card/utils/index.d.ts +2 -7
- package/dist/react/ui/components/marketplace-collectible-card/utils/index.js +11 -6
- package/dist/react/ui/components/marketplace-logos/index.d.ts +21 -21
- package/dist/react/ui/components/marketplace-logos/index.js +1 -1
- package/dist/react/ui/icons/index.js +13 -9
- package/dist/react/ui/index.d.ts +3 -8
- package/dist/react/ui/index.js +27 -18
- package/dist/react/ui/modals/_internal/components/actionModal/index.d.ts +2 -2
- package/dist/react/ui/modals/_internal/components/actionModal/index.js +23 -18
- package/dist/{react-DAIicQPT.js → react-DP0M2Wfm.js} +799 -4306
- package/dist/react-DP0M2Wfm.js.map +1 -0
- package/dist/{react-BbHBl6gg.css → react-DeDyTgo7.css} +1 -1
- package/dist/{react-BbHBl6gg.css.map → react-DeDyTgo7.css.map} +1 -1
- package/dist/{sequence-Do3kzb4J.js → sequence-BIrOVRXO.js} +1 -1
- package/dist/{sequence-Do3kzb4J.js.map → sequence-BIrOVRXO.js.map} +1 -1
- package/dist/{sudo-swap-B6vPKxBz.js → sudo-swap-BPMon-M5.js} +1 -1
- package/dist/{sudo-swap-B6vPKxBz.js.map → sudo-swap-BPMon-M5.js.map} +1 -1
- package/dist/{super-rare-eCm1SE6O.js → super-rare-kPN6Ua8i.js} +1 -1
- package/dist/{super-rare-eCm1SE6O.js.map → super-rare-kPN6Ua8i.js.map} +1 -1
- package/dist/{token-Da4TdyUk.js → token-CHSBPYVG.js} +1 -1
- package/dist/{token-Da4TdyUk.js.map → token-CHSBPYVG.js.map} +1 -1
- package/dist/{transaction-CcVViHEL.js → transaction-CnctdNzS.js} +3 -21
- package/dist/transaction-CnctdNzS.js.map +1 -0
- package/dist/types/index.d.ts +2 -3
- package/dist/types/index.js +2 -2
- package/dist/{types-DwWE6xOF.js → types-Yw2ywj6j.js} +1 -1
- package/dist/{types-DwWE6xOF.js.map → types-Yw2ywj6j.js.map} +1 -1
- package/dist/utils/abi/index.d.ts +4 -4
- package/dist/utils/abi/index.js +4 -4
- package/dist/utils/abi/marketplace/index.d.ts +1 -1
- package/dist/utils/abi/marketplace/index.js +1 -1
- package/dist/utils/abi/primary-sale/index.d.ts +1 -1
- package/dist/utils/abi/primary-sale/index.js +1 -1
- package/dist/utils/abi/token/index.d.ts +1 -1
- package/dist/utils/abi/token/index.js +1 -1
- package/dist/utils/index.d.ts +7 -8
- package/dist/utils/index.js +12 -9
- package/dist/{utils-CW2NA5KG.js → utils-9RXDgcBl.js} +4 -11
- package/dist/utils-9RXDgcBl.js.map +1 -0
- package/dist/{utils-BPYfgDSL.js → utils-DjVJ9tov.js} +5 -6
- package/dist/utils-DjVJ9tov.js.map +1 -0
- package/dist/wagmi-Do_KW5ke.js +0 -0
- package/dist/{x2y2-DD17tT91.js → x2y2-BLz-_Q2O.js} +1 -1
- package/dist/{x2y2-DD17tT91.js.map → x2y2-BLz-_Q2O.js.map} +1 -1
- package/dist/{zora-BpSG9UzS.js → zora-UGhKs-aL.js} +1 -1
- package/dist/{zora-BpSG9UzS.js.map → zora-UGhKs-aL.js.map} +1 -1
- package/eslint.config.mjs +4 -0
- package/package.json +27 -14
- package/postcss.config.mjs +6 -0
- package/src/index.css +5 -4
- package/src/index.ts +1 -0
- package/src/react/__tests__/provider.test.tsx +4 -3
- package/src/react/_internal/api/__mocks__/indexer.msw.ts +16 -0
- package/src/react/_internal/api/__mocks__/laos.msw.ts +387 -0
- package/src/react/_internal/api/__mocks__/marketplace.msw.ts +2 -0
- package/src/react/_internal/api/__tests__/laos-api.test.ts +756 -0
- package/src/react/_internal/api/laos-api.ts +3 -0
- package/src/react/_internal/api/marketplace.gen.ts +5 -3
- package/src/react/_internal/api/query-keys.ts +12 -4
- package/src/react/_internal/api/services.ts +2 -14
- package/src/react/_internal/databeat/index.ts +15 -14
- package/src/react/_internal/databeat/types.ts +22 -0
- package/src/react/_internal/databeat/utils.ts +26 -0
- package/src/react/_internal/utils.ts +4 -4
- package/src/react/_internal/wagmi/create-config.ts +28 -13
- package/src/react/_internal/wallet/wallet.ts +4 -4
- package/src/react/hooks/__tests__/useBalanceOfCollectible.laos.test.tsx +367 -0
- package/src/react/hooks/__tests__/useCheckoutOptions.test.tsx +158 -0
- package/src/react/hooks/__tests__/useCheckoutOptionsSalesContract.test.tsx +42 -65
- package/src/react/hooks/__tests__/useCollectionBalanceDetails.test.tsx +17 -0
- package/src/react/hooks/__tests__/useCollectionDetailsPolling.test.tsx +11 -3
- package/src/react/hooks/__tests__/useConvertPriceToUSD.test.tsx +3 -3
- package/src/react/hooks/__tests__/useCurrencyBalance.test.tsx +7 -3
- package/src/react/hooks/__tests__/useFilters.test.tsx +2 -2
- package/src/react/hooks/__tests__/useGetTokenRanges.test.tsx +111 -0
- package/src/react/hooks/__tests__/useListTokenMetadata.test.tsx +83 -57
- package/src/react/hooks/__tests__/useTransferTokens.test.tsx +469 -0
- package/src/react/hooks/index.ts +3 -1
- package/src/react/hooks/useCheckoutOptions.tsx +96 -0
- package/src/react/hooks/useCheckoutOptionsSalesContract.tsx +98 -57
- package/src/react/hooks/useCollectionBalanceDetails.tsx +95 -68
- package/src/react/hooks/useCollectionDetailsPolling.tsx +3 -7
- package/src/react/hooks/useComparePrices.tsx +90 -82
- package/src/react/hooks/useConvertPriceToUSD.tsx +85 -71
- package/src/react/hooks/useCurrencyBalance.tsx +132 -46
- package/src/react/hooks/useERC721SaleMintedTokens.tsx +8 -5
- package/src/react/hooks/useFilters.tsx +154 -111
- package/src/react/hooks/useGetCountOfPrimarySaleItems.tsx +48 -0
- package/src/react/hooks/useGetTokenRanges.tsx +83 -22
- package/src/react/hooks/useList1155ShopCardData.tsx +2 -0
- package/src/react/hooks/useList721ShopCardData.tsx +12 -7
- package/src/react/hooks/useListCollections.tsx +25 -25
- package/src/react/hooks/useListMarketCardData.tsx +2 -1
- package/src/react/hooks/useListPrimarySaleItems.tsx +66 -0
- package/src/react/hooks/useListTokenMetadata.ts +71 -0
- package/src/react/hooks/useOpenConnectModal.tsx +9 -0
- package/src/react/hooks/useTokenSaleDetailsBatch.tsx +3 -7
- package/src/react/hooks/useTokenSupplies.ts +81 -0
- package/src/react/hooks/useTransferTokens.tsx +2 -2
- package/src/react/provider.tsx +73 -9
- package/src/react/queries/__tests__/balanceOfCollectible.laos.test.ts +123 -0
- package/src/react/queries/__tests__/inventory.laos.test.ts +496 -0
- package/src/react/queries/balanceOfCollectible.ts +7 -4
- package/src/react/queries/checkoutOptions.ts +85 -0
- package/src/react/queries/checkoutOptionsSalesContract.ts +89 -0
- package/src/react/queries/collectionBalanceDetails.ts +92 -0
- package/src/react/queries/comparePrices.ts +108 -0
- package/src/react/queries/convertPriceToUSD.ts +92 -0
- package/src/react/queries/filters.ts +138 -0
- package/src/react/queries/getTokenRanges.ts +62 -0
- package/src/react/queries/index.ts +3 -0
- package/src/react/queries/inventory.ts +6 -0
- package/src/react/queries/listBalances.ts +4 -3
- package/src/react/queries/listCollections.ts +7 -3
- package/src/react/queries/listTokenMetadata.ts +2 -2
- package/src/react/queries/marketplaceConfig.ts +1 -1
- package/src/react/queries/primarySaleItems.ts +85 -0
- package/src/react/queries/primarySaleItemsCount.ts +64 -0
- package/src/react/queries/tokenSupplies.ts +93 -0
- package/src/react/ui/components/_internals/action-button/ActionButton.tsx +66 -66
- package/src/react/ui/components/_internals/action-button/__tests__/ActionButtonBody.test.tsx +22 -4
- package/src/react/ui/components/_internals/action-button/components/ActionButtonBody.tsx +5 -4
- package/src/react/ui/components/_internals/action-button/components/NonOwnerActions.tsx +3 -0
- package/src/react/ui/components/_internals/action-button/components/OwnerActions.tsx +4 -4
- package/src/react/ui/components/_internals/action-button/hooks/useActionButtonLogic.ts +13 -8
- package/src/react/ui/components/_internals/action-button/store.ts +44 -34
- package/src/react/ui/components/_internals/custom-select/CustomSelect.stories.tsx +582 -0
- package/src/react/ui/components/_internals/pill/Pill.stories.tsx +83 -0
- package/src/react/ui/components/marketplace-collectible-card/Footer.tsx +11 -4
- package/src/react/ui/components/marketplace-collectible-card/components/ActionButtonWrapper.tsx +7 -4
- package/src/react/ui/components/marketplace-collectible-card/types.ts +4 -3
- package/src/react/ui/components/marketplace-collectible-card/utils/supplyStatus.ts +4 -7
- package/src/react/ui/components/marketplace-collectible-card/variants/ShopCard.tsx +5 -1
- package/src/react/ui/components/marketplace-logos/marketplace-logos.stories.tsx +199 -0
- package/src/react/ui/components/media/Media.stories.tsx +642 -0
- package/src/react/ui/components/media/Media.tsx +24 -19
- package/src/react/ui/components/media/types.ts +6 -0
- package/src/react/ui/modals/BuyModal/__tests__/BuyModalRouter.test.tsx +15 -0
- package/src/react/ui/modals/BuyModal/__tests__/ERC1155ShopModal.test.tsx +6 -0
- package/src/react/ui/modals/BuyModal/__tests__/Modal1155.test.tsx +7 -1
- package/src/react/ui/modals/BuyModal/__tests__/store.test.ts +9 -1
- package/src/react/ui/modals/BuyModal/components/ERC1155QuantityModal.tsx +15 -8
- package/src/react/ui/modals/BuyModal/components/ERC1155ShopModal.tsx +3 -0
- package/src/react/ui/modals/BuyModal/hooks/__tests__/useERC1155Checkout.test.tsx +30 -27
- package/src/react/ui/modals/BuyModal/hooks/useCheckoutOptions.ts +2 -2
- package/src/react/ui/modals/BuyModal/hooks/useERC1155Checkout.ts +11 -2
- package/src/react/ui/modals/BuyModal/hooks/useERC721SalePaymentParams.ts +1 -1
- package/src/react/ui/modals/BuyModal/hooks/usePaymentModalParams.ts +7 -0
- package/src/react/ui/modals/BuyModal/index.tsx +9 -1
- package/src/react/ui/modals/BuyModal/store.ts +26 -0
- package/src/react/ui/modals/CreateListingModal/Modal.tsx +28 -11
- package/src/react/ui/modals/CreateListingModal/store.ts +3 -3
- package/src/react/ui/modals/MakeOfferModal/Modal.tsx +30 -13
- package/src/react/ui/modals/MakeOfferModal/store.ts +3 -3
- package/src/react/ui/modals/SellModal/Modal.tsx +11 -8
- package/src/react/ui/modals/SellModal/store.ts +3 -3
- package/src/react/ui/modals/TransferModal/__tests__/__snapshots__/store.test.ts.snap +17 -0
- package/src/react/ui/modals/TransferModal/__tests__/store.test.ts +366 -0
- package/src/react/ui/modals/TransferModal/_views/enterWalletAddress/__tests__/useHandleTransfer.test.tsx +402 -0
- package/src/react/ui/modals/TransferModal/_views/enterWalletAddress/_components/TokenQuantityInput.tsx +51 -48
- package/src/react/ui/modals/TransferModal/_views/enterWalletAddress/_components/TransferButton.tsx +39 -47
- package/src/react/ui/modals/TransferModal/_views/enterWalletAddress/_components/WalletAddressInput.tsx +9 -8
- package/src/react/ui/modals/TransferModal/_views/enterWalletAddress/index.tsx +31 -35
- package/src/react/ui/modals/TransferModal/_views/enterWalletAddress/useHandleTransfer.tsx +19 -10
- package/src/react/ui/modals/TransferModal/index.tsx +28 -31
- package/src/react/ui/modals/TransferModal/messages.ts +1 -1
- package/src/react/ui/modals/TransferModal/store.ts +122 -0
- package/src/react/ui/modals/_internal/components/calendar/index.tsx +0 -1
- package/src/react/ui/modals/_internal/components/currencyImage/index.tsx +10 -14
- package/src/react/ui/modals/_internal/components/currencyOptionsSelect/__tests__/index.test.tsx +5 -2
- package/src/react/ui/modals/_internal/components/currencyOptionsSelect/index.tsx +23 -17
- package/src/react/ui/modals/_internal/components/expirationDateSelect/index.tsx +10 -10
- package/src/react/ui/modals/_internal/components/floorPriceText/__tests__/FloorPriceText.test.tsx +6 -6
- package/src/react/ui/modals/_internal/components/priceInput/__tests__/PriceInput.test.tsx +13 -5
- package/src/react/ui/modals/_internal/components/priceInput/index.tsx +41 -26
- package/src/react/ui/modals/_internal/components/quantityInput/__tests__/index.test.tsx +68 -59
- package/src/react/ui/modals/_internal/components/quantityInput/index.tsx +155 -20
- package/src/react/ui/modals/_internal/components/selectWaasFeeOptions/__tests__/SelectWaasFeeOptions.test.tsx +339 -40
- package/src/react/ui/modals/_internal/components/selectWaasFeeOptions/index.tsx +95 -101
- package/src/react/ui/modals/_internal/components/selectWaasFeeOptions/store.ts +72 -14
- package/src/react/ui/modals/_internal/components/selectWaasFeeOptions/useWaasFeeOptionManager.tsx +29 -13
- package/src/react/ui/modals/_internal/components/tokenPreview/index.tsx +2 -2
- package/src/react/ui/modals/_internal/components/transactionDetails/index.tsx +2 -2
- package/src/react/ui/modals/_internal/components/transactionPreview/index.tsx +88 -89
- package/src/react/ui/modals/_internal/components/transactionStatusModal/__tests__/TransactionStatusModal.test.tsx +36 -10
- package/src/react/ui/modals/_internal/components/transactionStatusModal/index.tsx +32 -20
- package/src/react/ui/modals/_internal/components/transactionStatusModal/store.ts +91 -62
- package/src/react/ui/modals/_internal/components/waasFeeOptionsSelect/WaasFeeOptionsSelect.tsx +43 -44
- package/src/react/ui/modals/_internal/types.ts +2 -2
- package/src/types/sdk-config.ts +6 -1
- package/src/utils/network.ts +15 -0
- package/test/test-utils.tsx +2 -0
- package/vitest.shims.d.ts +2 -0
- package/vitest.storybook.config.js +33 -0
- package/dist/CalendarIcon-DbQ7Vxcw.js.map +0 -1
- package/dist/_internal-BgWcRIak.js.map +0 -1
- package/dist/api-DTIan01C.js.map +0 -1
- package/dist/builder-api-C_zj5mr3.d.ts +0 -12
- package/dist/index-BUVWziLP.d.ts +0 -60
- package/dist/index-COt10OgI.d.ts +0 -24
- package/dist/index-DPNWNa7t.d.ts +0 -414
- package/dist/index-DsfCs3-x.d.ts +0 -122
- package/dist/index-dUb6wb4Y.d.ts +0 -22
- package/dist/marketplace.gen-BSDIX7NZ.js.map +0 -1
- package/dist/marketplaceConfig-C6X1SUik.js.map +0 -1
- package/dist/queries-CUU65uYZ.js.map +0 -1
- package/dist/react-DAIicQPT.js.map +0 -1
- package/dist/transaction-CcVViHEL.js.map +0 -1
- package/dist/utils-BPYfgDSL.js.map +0 -1
- package/dist/utils-CW2NA5KG.js.map +0 -1
- package/dist/wagmi-CDzEQbfk.js.map +0 -1
- package/src/react/hooks/__tests__/useGetTokenSuppliesMap.test.tsx +0 -104
- package/src/react/hooks/useGetTokenSuppliesMap.tsx +0 -73
- package/src/react/hooks/useListPrimarySaleItems.ts +0 -102
- package/src/react/queries/getTokenSuppliesMap.ts +0 -77
- package/src/react/ui/modals/TransferModal/_store.ts +0 -66
- package/src/react/ui/modals/_internal/components/quantityInput/QuantityInputBase.tsx +0 -166
- package/src/react/ui/modals/_internal/stores/accountModal.ts +0 -3
- /package/dist/{abi-BKyRjVcZ.js → abi-BMvgNbKQ.js} +0 -0
- /package/dist/{index-C39K_8SG.d.ts → index-CD2bj_xW.d.ts} +0 -0
- /package/dist/{options-B4QN7Xou.js → options-BBBR8u_4.js} +0 -0
|
@@ -1,67 +1,108 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { skipToken, useQuery } from '@tanstack/react-query';
|
|
4
|
+
import type { Address } from 'viem';
|
|
3
5
|
import { useAccount } from 'wagmi';
|
|
4
|
-
import type {
|
|
6
|
+
import type { CheckoutOptionsItem, Optional } from '../_internal';
|
|
5
7
|
import {
|
|
6
|
-
type
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
type CheckoutOptionsSalesContractQueryOptions,
|
|
9
|
+
checkoutOptionsSalesContractQueryOptions,
|
|
10
|
+
type FetchCheckoutOptionsSalesContractParams,
|
|
11
|
+
type fetchCheckoutOptionsSalesContract,
|
|
12
|
+
} from '../queries/checkoutOptionsSalesContract';
|
|
9
13
|
import { useConfig } from './useConfig';
|
|
10
14
|
|
|
11
|
-
type
|
|
12
|
-
|
|
13
|
-
'
|
|
14
|
-
|
|
15
|
+
export type UseCheckoutOptionsSalesContractParams = Optional<
|
|
16
|
+
CheckoutOptionsSalesContractQueryOptions,
|
|
17
|
+
'config' | 'walletAddress'
|
|
18
|
+
>;
|
|
15
19
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Hook to fetch checkout options for sales contract items
|
|
22
|
+
*
|
|
23
|
+
* Retrieves checkout options including available payment methods, fees, and transaction details
|
|
24
|
+
* for items from a sales contract. Requires a connected wallet to calculate wallet-specific options.
|
|
25
|
+
*
|
|
26
|
+
* @param params - Configuration parameters or skipToken to skip the query
|
|
27
|
+
* @param params.chainId - The chain ID (must be number, e.g., 1 for Ethereum, 137 for Polygon)
|
|
28
|
+
* @param params.contractAddress - The sales contract address
|
|
29
|
+
* @param params.collectionAddress - The collection contract address
|
|
30
|
+
* @param params.items - Array of items to purchase with tokenId and quantity
|
|
31
|
+
* @param params.query - Optional React Query configuration
|
|
32
|
+
*
|
|
33
|
+
* @returns Query result containing checkout options with payment methods and fees
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* Basic usage:
|
|
37
|
+
* ```typescript
|
|
38
|
+
* const { data: checkoutOptions, isLoading } = useCheckoutOptionsSalesContract({
|
|
39
|
+
* chainId: 137,
|
|
40
|
+
* contractAddress: '0x1234...',
|
|
41
|
+
* collectionAddress: '0x5678...',
|
|
42
|
+
* items: [{
|
|
43
|
+
* tokenId: '1',
|
|
44
|
+
* quantity: '1'
|
|
45
|
+
* }]
|
|
46
|
+
* })
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* With skipToken to conditionally skip:
|
|
51
|
+
* ```typescript
|
|
52
|
+
* const { data: checkoutOptions } = useCheckoutOptionsSalesContract(
|
|
53
|
+
* items.length > 0 ? {
|
|
54
|
+
* chainId: 1,
|
|
55
|
+
* contractAddress: contractAddress,
|
|
56
|
+
* collectionAddress: collectionAddress,
|
|
57
|
+
* items: items
|
|
58
|
+
* } : skipToken
|
|
59
|
+
* )
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export function useCheckoutOptionsSalesContract(
|
|
63
|
+
params: UseCheckoutOptionsSalesContractParams | typeof skipToken,
|
|
64
|
+
) {
|
|
65
|
+
const { address } = useAccount();
|
|
66
|
+
const defaultConfig = useConfig();
|
|
67
|
+
|
|
68
|
+
const queryOptions = checkoutOptionsSalesContractQueryOptions(
|
|
69
|
+
params === skipToken
|
|
70
|
+
? {
|
|
71
|
+
config: defaultConfig,
|
|
72
|
+
walletAddress: address as Address,
|
|
73
|
+
chainId: 0,
|
|
74
|
+
contractAddress: '',
|
|
75
|
+
collectionAddress: '',
|
|
76
|
+
items: [],
|
|
77
|
+
query: { enabled: false },
|
|
78
|
+
}
|
|
79
|
+
: {
|
|
80
|
+
config: defaultConfig,
|
|
81
|
+
walletAddress: address as Address,
|
|
82
|
+
...params,
|
|
83
|
+
},
|
|
84
|
+
);
|
|
29
85
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
| (UseCheckoutOptionsSalesContractArgs & { wallet?: Hex })
|
|
33
|
-
| typeof skipToken,
|
|
34
|
-
config: SdkConfig,
|
|
35
|
-
) => {
|
|
36
|
-
return queryOptions({
|
|
37
|
-
queryKey: ['checkoutOptionsSalesContract', args],
|
|
38
|
-
queryFn:
|
|
39
|
-
skipToken === args
|
|
40
|
-
? skipToken
|
|
41
|
-
: () =>
|
|
42
|
-
fetchCheckoutOptionsSalesContract(
|
|
43
|
-
{
|
|
44
|
-
chainId: String(args.chainId),
|
|
45
|
-
// biome-ignore lint/style/noNonNullAssertion: wallet is guaranteed to exist when not skipToken
|
|
46
|
-
wallet: args.wallet!,
|
|
47
|
-
contractAddress: args.contractAddress,
|
|
48
|
-
collectionAddress: args.collectionAddress,
|
|
49
|
-
items: args.items,
|
|
50
|
-
},
|
|
51
|
-
config,
|
|
52
|
-
),
|
|
86
|
+
return useQuery({
|
|
87
|
+
...queryOptions,
|
|
53
88
|
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export { checkoutOptionsSalesContractQueryOptions };
|
|
92
|
+
|
|
93
|
+
export type {
|
|
94
|
+
FetchCheckoutOptionsSalesContractParams,
|
|
95
|
+
CheckoutOptionsSalesContractQueryOptions,
|
|
54
96
|
};
|
|
55
97
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
checkoutOptionsSalesContractOptions(
|
|
63
|
-
skipToken === args ? skipToken : { ...args, wallet: address },
|
|
64
|
-
config,
|
|
65
|
-
),
|
|
66
|
-
);
|
|
98
|
+
// Legacy exports for backward compatibility
|
|
99
|
+
export type UseCheckoutOptionsSalesContractArgs = {
|
|
100
|
+
chainId: number;
|
|
101
|
+
contractAddress: string;
|
|
102
|
+
collectionAddress: string;
|
|
103
|
+
items: Array<CheckoutOptionsItem>;
|
|
67
104
|
};
|
|
105
|
+
|
|
106
|
+
export type UseCheckoutOptionsSalesContractReturn = Awaited<
|
|
107
|
+
ReturnType<typeof fetchCheckoutOptionsSalesContract>
|
|
108
|
+
>;
|
|
@@ -1,79 +1,106 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
import type {
|
|
5
|
-
import
|
|
6
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useQuery } from '@tanstack/react-query';
|
|
4
|
+
import type { Optional } from '../_internal';
|
|
5
|
+
import {
|
|
6
|
+
type CollectionBalanceDetailsQueryOptions,
|
|
7
|
+
type CollectionBalanceFilter,
|
|
8
|
+
collectionBalanceDetailsQueryOptions,
|
|
9
|
+
type FetchCollectionBalanceDetailsParams,
|
|
10
|
+
type fetchCollectionBalanceDetails,
|
|
11
|
+
} from '../queries/collectionBalanceDetails';
|
|
7
12
|
import { useConfig } from './useConfig';
|
|
8
13
|
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
+
export type UseCollectionBalanceDetailsParams = Optional<
|
|
15
|
+
CollectionBalanceDetailsQueryOptions,
|
|
16
|
+
'config'
|
|
17
|
+
>;
|
|
14
18
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Hook to fetch detailed balance information for multiple accounts
|
|
21
|
+
*
|
|
22
|
+
* Retrieves token balances and native balances for multiple account addresses,
|
|
23
|
+
* with support for contract whitelisting and optional native balance exclusion.
|
|
24
|
+
* Aggregates results from multiple account addresses into a single response.
|
|
25
|
+
*
|
|
26
|
+
* @param params - Configuration parameters
|
|
27
|
+
* @param params.chainId - The chain ID (must be number, e.g., 1 for Ethereum, 137 for Polygon)
|
|
28
|
+
* @param params.filter - Filter configuration for balance queries
|
|
29
|
+
* @param params.filter.accountAddresses - Array of account addresses to query balances for
|
|
30
|
+
* @param params.filter.contractWhitelist - Optional array of contract addresses to filter by
|
|
31
|
+
* @param params.filter.omitNativeBalances - Whether to exclude native token balances
|
|
32
|
+
* @param params.query - Optional React Query configuration
|
|
33
|
+
*
|
|
34
|
+
* @returns Query result containing aggregated balance details for all accounts
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* Basic usage:
|
|
38
|
+
* ```typescript
|
|
39
|
+
* const { data: balanceDetails, isLoading } = useCollectionBalanceDetails({
|
|
40
|
+
* chainId: 137,
|
|
41
|
+
* filter: {
|
|
42
|
+
* accountAddresses: ['0x1234...', '0x5678...'],
|
|
43
|
+
* omitNativeBalances: false
|
|
44
|
+
* }
|
|
45
|
+
* })
|
|
46
|
+
*
|
|
47
|
+
* if (data) {
|
|
48
|
+
* console.log(`Found ${data.balances.length} token balances`);
|
|
49
|
+
* console.log(`Found ${data.nativeBalances.length} native balances`);
|
|
50
|
+
* }
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* With contract whitelist:
|
|
55
|
+
* ```typescript
|
|
56
|
+
* const { data: balanceDetails } = useCollectionBalanceDetails({
|
|
57
|
+
* chainId: 1,
|
|
58
|
+
* filter: {
|
|
59
|
+
* accountAddresses: [userAddress],
|
|
60
|
+
* contractWhitelist: ['0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'], // USDC only
|
|
61
|
+
* omitNativeBalances: true
|
|
62
|
+
* },
|
|
63
|
+
* query: {
|
|
64
|
+
* enabled: Boolean(userAddress),
|
|
65
|
+
* refetchInterval: 60000 // Refresh every minute
|
|
66
|
+
* }
|
|
67
|
+
* })
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export function useCollectionBalanceDetails(
|
|
71
|
+
params: UseCollectionBalanceDetailsParams,
|
|
72
|
+
) {
|
|
73
|
+
const defaultConfig = useConfig();
|
|
34
74
|
|
|
35
|
-
const
|
|
36
|
-
const mergedResponse = responses.reduce<GetTokenBalancesDetailsReturn>(
|
|
37
|
-
(
|
|
38
|
-
acc: GetTokenBalancesDetailsReturn,
|
|
39
|
-
curr: GetTokenBalancesDetailsReturn | null,
|
|
40
|
-
) => {
|
|
41
|
-
if (!curr) return acc;
|
|
42
|
-
return {
|
|
43
|
-
page: curr.page,
|
|
44
|
-
nativeBalances: [
|
|
45
|
-
...(acc.nativeBalances || []),
|
|
46
|
-
...(curr.nativeBalances || []),
|
|
47
|
-
],
|
|
48
|
-
balances: [...(acc.balances || []), ...(curr.balances || [])],
|
|
49
|
-
};
|
|
50
|
-
},
|
|
51
|
-
{ page: {}, nativeBalances: [], balances: [] },
|
|
52
|
-
);
|
|
75
|
+
const { config = defaultConfig, ...rest } = params;
|
|
53
76
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
77
|
+
const queryOptions = collectionBalanceDetailsQueryOptions({
|
|
78
|
+
config,
|
|
79
|
+
...rest,
|
|
80
|
+
});
|
|
57
81
|
|
|
58
|
-
return
|
|
59
|
-
|
|
82
|
+
return useQuery({
|
|
83
|
+
...queryOptions,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
60
86
|
|
|
61
|
-
export
|
|
62
|
-
args: UseCollectionBalanceDetailsArgs,
|
|
63
|
-
config: SdkConfig,
|
|
64
|
-
) => {
|
|
65
|
-
const indexerClient = getIndexerClient(args.chainId, config);
|
|
87
|
+
export { collectionBalanceDetailsQueryOptions };
|
|
66
88
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
});
|
|
89
|
+
export type {
|
|
90
|
+
FetchCollectionBalanceDetailsParams,
|
|
91
|
+
CollectionBalanceDetailsQueryOptions,
|
|
92
|
+
CollectionBalanceFilter,
|
|
72
93
|
};
|
|
73
94
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
95
|
+
// Legacy exports for backward compatibility
|
|
96
|
+
export type UseCollectionBalanceDetailsArgs = {
|
|
97
|
+
chainId: number;
|
|
98
|
+
filter: CollectionBalanceFilter;
|
|
99
|
+
query?: {
|
|
100
|
+
enabled?: boolean;
|
|
101
|
+
};
|
|
79
102
|
};
|
|
103
|
+
|
|
104
|
+
export type UseCollectionBalanceDetailsReturn = Awaited<
|
|
105
|
+
ReturnType<typeof fetchCollectionBalanceDetails>
|
|
106
|
+
>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { queryOptions, useQuery } from '@tanstack/react-query';
|
|
2
2
|
import type { SdkConfig } from '../../types';
|
|
3
|
-
import { CollectionStatus } from '../_internal
|
|
4
|
-
import { collectionDetailsQueryOptions } from '
|
|
3
|
+
import { CollectionStatus } from '../_internal';
|
|
4
|
+
import { collectionDetailsQueryOptions } from './useCollectionDetails';
|
|
5
5
|
import { useConfig } from './useConfig';
|
|
6
6
|
|
|
7
7
|
type UseCollectionDetailsPolling = {
|
|
@@ -30,11 +30,7 @@ export const collectionDetailsPollingOptions = (
|
|
|
30
30
|
config: SdkConfig,
|
|
31
31
|
) => {
|
|
32
32
|
return queryOptions({
|
|
33
|
-
...collectionDetailsQueryOptions({
|
|
34
|
-
collectionAddress: args.collectionAddress,
|
|
35
|
-
chainId: args.chainId,
|
|
36
|
-
config,
|
|
37
|
-
}),
|
|
33
|
+
...collectionDetailsQueryOptions({ ...args, config }),
|
|
38
34
|
refetchInterval: (query) => {
|
|
39
35
|
const data = query.state.data;
|
|
40
36
|
if (data && isTerminalState(data.status)) {
|
|
@@ -1,96 +1,104 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useQuery } from '@tanstack/react-query';
|
|
2
4
|
import type { Address } from 'viem';
|
|
3
|
-
import type {
|
|
4
|
-
import {
|
|
5
|
+
import type { Optional } from '../_internal';
|
|
6
|
+
import {
|
|
7
|
+
type ComparePricesQueryOptions,
|
|
8
|
+
comparePricesQueryOptions,
|
|
9
|
+
type FetchComparePricesParams,
|
|
10
|
+
} from '../queries/comparePrices';
|
|
5
11
|
import { useConfig } from './useConfig';
|
|
6
|
-
import { convertPriceToUSD } from './useConvertPriceToUSD';
|
|
7
12
|
|
|
8
|
-
export
|
|
13
|
+
export type UseComparePricesParams = Optional<
|
|
14
|
+
ComparePricesQueryOptions,
|
|
15
|
+
'config'
|
|
16
|
+
>;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Hook to compare prices between different currencies by converting both to USD
|
|
20
|
+
*
|
|
21
|
+
* Compares two prices by converting both to USD using real-time exchange rates
|
|
22
|
+
* and returns the percentage difference with comparison status.
|
|
23
|
+
*
|
|
24
|
+
* @param params - Configuration parameters
|
|
25
|
+
* @param params.chainId - The chain ID (must be number, e.g., 1 for Ethereum, 137 for Polygon)
|
|
26
|
+
* @param params.priceAmountRaw - The raw amount of the first price (wei format)
|
|
27
|
+
* @param params.priceCurrencyAddress - The currency address of the first price
|
|
28
|
+
* @param params.compareToPriceAmountRaw - The raw amount of the second price to compare against (wei format)
|
|
29
|
+
* @param params.compareToPriceCurrencyAddress - The currency address of the second price
|
|
30
|
+
* @param params.query - Optional React Query configuration
|
|
31
|
+
*
|
|
32
|
+
* @returns Query result containing percentage difference and comparison status
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* Basic usage:
|
|
36
|
+
* ```typescript
|
|
37
|
+
* const { data: comparison, isLoading } = useComparePrices({
|
|
38
|
+
* chainId: 1,
|
|
39
|
+
* priceAmountRaw: '1000000000000000000', // 1 ETH in wei
|
|
40
|
+
* priceCurrencyAddress: '0x0000000000000000000000000000000000000000', // ETH
|
|
41
|
+
* compareToPriceAmountRaw: '2000000000', // 2000 USDC in wei (6 decimals)
|
|
42
|
+
* compareToPriceCurrencyAddress: '0xA0b86a33E6B8DbF5E71Eaa9bfD3F6fD8e8Be3F69' // USDC
|
|
43
|
+
* })
|
|
44
|
+
*
|
|
45
|
+
* if (data) {
|
|
46
|
+
* console.log(`${data.percentageDifferenceFormatted}% ${data.status}`);
|
|
47
|
+
* // e.g., "25.50% above" or "10.25% below"
|
|
48
|
+
* }
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* With custom query options:
|
|
53
|
+
* ```typescript
|
|
54
|
+
* const { data: comparison } = useComparePrices({
|
|
55
|
+
* chainId: 137,
|
|
56
|
+
* priceAmountRaw: price1,
|
|
57
|
+
* priceCurrencyAddress: currency1Address,
|
|
58
|
+
* compareToPriceAmountRaw: price2,
|
|
59
|
+
* compareToPriceCurrencyAddress: currency2Address,
|
|
60
|
+
* query: {
|
|
61
|
+
* enabled: Boolean(price1 && price2),
|
|
62
|
+
* refetchInterval: 30000 // Refresh every 30 seconds
|
|
63
|
+
* }
|
|
64
|
+
* })
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
export function useComparePrices(params: UseComparePricesParams) {
|
|
68
|
+
const defaultConfig = useConfig();
|
|
69
|
+
|
|
70
|
+
const { config = defaultConfig, ...rest } = params;
|
|
71
|
+
|
|
72
|
+
const queryOptions = comparePricesQueryOptions({
|
|
73
|
+
config,
|
|
74
|
+
...rest,
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
return useQuery({
|
|
78
|
+
...queryOptions,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export { comparePricesQueryOptions };
|
|
83
|
+
|
|
84
|
+
export type { FetchComparePricesParams, ComparePricesQueryOptions };
|
|
85
|
+
|
|
86
|
+
// Legacy exports for backward compatibility
|
|
87
|
+
export type UseComparePricesArgs = {
|
|
9
88
|
chainId: number;
|
|
10
|
-
// First price details
|
|
11
89
|
priceAmountRaw: string;
|
|
12
90
|
priceCurrencyAddress: Address;
|
|
13
|
-
// Second price details (to compare against)
|
|
14
91
|
compareToPriceAmountRaw: string;
|
|
15
92
|
compareToPriceCurrencyAddress: Address;
|
|
16
|
-
query
|
|
17
|
-
|
|
93
|
+
query?: {
|
|
94
|
+
enabled?: boolean;
|
|
95
|
+
};
|
|
96
|
+
};
|
|
18
97
|
|
|
19
|
-
export
|
|
98
|
+
export type UseComparePricesReturn = {
|
|
20
99
|
percentageDifference: number;
|
|
21
100
|
percentageDifferenceFormatted: string;
|
|
22
101
|
status: 'above' | 'same' | 'below';
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const comparePrices = async (
|
|
26
|
-
args: UseComparePricesArgs,
|
|
27
|
-
config: SdkConfig,
|
|
28
|
-
): Promise<UseComparePricesReturn> => {
|
|
29
|
-
const [priceUSD, compareToPriceUSD] = await Promise.all([
|
|
30
|
-
convertPriceToUSD(
|
|
31
|
-
{
|
|
32
|
-
chainId: args.chainId,
|
|
33
|
-
currencyAddress: args.priceCurrencyAddress,
|
|
34
|
-
amountRaw: args.priceAmountRaw,
|
|
35
|
-
query: {},
|
|
36
|
-
},
|
|
37
|
-
config,
|
|
38
|
-
),
|
|
39
|
-
convertPriceToUSD(
|
|
40
|
-
{
|
|
41
|
-
chainId: args.chainId,
|
|
42
|
-
currencyAddress: args.compareToPriceCurrencyAddress,
|
|
43
|
-
amountRaw: args.compareToPriceAmountRaw,
|
|
44
|
-
query: {},
|
|
45
|
-
},
|
|
46
|
-
config,
|
|
47
|
-
),
|
|
48
|
-
]);
|
|
49
|
-
const difference = priceUSD.usdAmount - compareToPriceUSD.usdAmount;
|
|
50
|
-
|
|
51
|
-
if (compareToPriceUSD.usdAmount === 0) {
|
|
52
|
-
throw new Error('Cannot compare to zero price');
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const percentageDifference = (difference / compareToPriceUSD.usdAmount) * 100;
|
|
56
|
-
const isAbove = percentageDifference > 0;
|
|
57
|
-
const isSame = percentageDifference === 0;
|
|
58
|
-
|
|
59
|
-
return {
|
|
60
|
-
percentageDifference,
|
|
61
|
-
percentageDifferenceFormatted: Math.abs(percentageDifference).toFixed(2),
|
|
62
|
-
status: isAbove ? 'above' : isSame ? 'same' : 'below',
|
|
63
|
-
};
|
|
64
102
|
};
|
|
65
103
|
|
|
66
|
-
export
|
|
67
|
-
args: UseComparePricesArgs,
|
|
68
|
-
config: SdkConfig,
|
|
69
|
-
) => {
|
|
70
|
-
return queryOptions({
|
|
71
|
-
...args.query,
|
|
72
|
-
queryKey: [...currencyKeys.conversion, 'compare', args],
|
|
73
|
-
queryFn: () => comparePrices(args, config),
|
|
74
|
-
});
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* Hook to compare prices between different currencies by converting both to USD
|
|
79
|
-
* @param args - The arguments for the hook
|
|
80
|
-
* @returns The percentage difference between the two prices
|
|
81
|
-
* @example
|
|
82
|
-
* ```ts
|
|
83
|
-
* const { data } = useComparePrices({
|
|
84
|
-
* chainId: 1,
|
|
85
|
-
* priceAmountRaw: "1000000000000000000",
|
|
86
|
-
* priceCurrencyAddress: "0x0000000000000000000000000000000000000000",
|
|
87
|
-
* });
|
|
88
|
-
*
|
|
89
|
-
* console.log(data);
|
|
90
|
-
* // { percentageDifference: 10, percentageDifferenceFormatted: "10.00", isAbove: true, isSame: false, isBelow: false }
|
|
91
|
-
* ```
|
|
92
|
-
*/
|
|
93
|
-
export const useComparePrices = (args: UseComparePricesArgs) => {
|
|
94
|
-
const config = useConfig();
|
|
95
|
-
return useQuery(comparePricesOptions(args, config));
|
|
96
|
-
};
|
|
104
|
+
export type ComparePricesReturn = UseComparePricesReturn;
|