@0xsequence/marketplace-sdk 0.4.6 → 0.4.8
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/dist/alien_swap-4GAIV7PA.png +0 -0
- package/dist/alien_swap-IZONL4XB.js +8 -0
- package/dist/alien_swap-PMYKGY6A.js +8 -0
- package/dist/aqua-xyz-HLNZIFE2.js +8 -0
- package/dist/aqua-xyz-HLNZIFE2.js.map +1 -0
- package/dist/aqua-xyz-JY5QCI5L.js +8 -0
- package/dist/aqua-xyz-JY5QCI5L.js.map +1 -0
- package/dist/aqua-xyz-WU4JVU2K.png +0 -0
- package/dist/aura-CYKEACX2.js +8 -0
- package/dist/aura-CYKEACX2.js.map +1 -0
- package/dist/aura-HLMWKNSP.js +8 -0
- package/dist/aura-HLMWKNSP.js.map +1 -0
- package/dist/aura-RITZV42R.png +0 -0
- package/dist/blur-2ABQMPTL.png +0 -0
- package/dist/blur-MIPRQYJL.js +8 -0
- package/dist/blur-MIPRQYJL.js.map +1 -0
- package/dist/blur-XDIGHYB7.js +8 -0
- package/dist/blur-XDIGHYB7.js.map +1 -0
- package/dist/{chunk-QVOUL555.js → chunk-6R4G7J6Q.js} +86 -26
- package/dist/chunk-6R4G7J6Q.js.map +1 -0
- package/dist/{chunk-2FOUCP2R.js → chunk-7WCZP6FN.js} +743 -744
- package/dist/chunk-7WCZP6FN.js.map +1 -0
- package/dist/{chunk-RD7HPANB.js → chunk-AQT3BQ67.js} +9 -9
- package/dist/chunk-AQT3BQ67.js.map +1 -0
- package/dist/{chunk-ZEH4JI2U.js → chunk-FCF57DZI.js} +7 -2
- package/dist/chunk-FCF57DZI.js.map +1 -0
- package/dist/{chunk-3C2MT5TM.js → chunk-FWN2MCLI.js} +12 -6
- package/dist/chunk-FWN2MCLI.js.map +1 -0
- package/dist/{chunk-5D3ARFFZ.js → chunk-JEOUQFT3.js} +17 -129
- package/dist/chunk-JEOUQFT3.js.map +1 -0
- package/dist/chunk-MWDG7UTB.js +132 -0
- package/dist/chunk-MWDG7UTB.js.map +1 -0
- package/dist/chunk-RK6KYMZM.js +18 -0
- package/dist/chunk-RK6KYMZM.js.map +1 -0
- package/dist/{chunk-36NGHJH5.js → chunk-WRMJ5FZM.js} +140 -37
- package/dist/chunk-WRMJ5FZM.js.map +1 -0
- package/dist/{chunk-LTHX6RXH.js → chunk-XP3WY5AX.js} +90 -2
- package/dist/chunk-XP3WY5AX.js.map +1 -0
- package/dist/{chunk-DNVERQ5J.js → chunk-YOKGP2EQ.js} +1 -1
- package/dist/chunk-YOKGP2EQ.js.map +1 -0
- package/dist/chunk-ZUEQGPLO.js +302 -0
- package/dist/chunk-ZUEQGPLO.js.map +1 -0
- package/dist/coinbase-MIJPE653.js +8 -0
- package/dist/coinbase-MIJPE653.js.map +1 -0
- package/dist/coinbase-MZUBBEC4.png +0 -0
- package/dist/coinbase-T24XHLQL.js +8 -0
- package/dist/coinbase-T24XHLQL.js.map +1 -0
- package/dist/{create-config-BBTTSJyp.d.ts → create-config-D5WqfUft.d.ts} +2 -2
- package/dist/element-GHIPFSB6.png +0 -0
- package/dist/element-MWATR3ON.js +8 -0
- package/dist/element-MWATR3ON.js.map +1 -0
- package/dist/element-X45NH4D7.js +8 -0
- package/dist/element-X45NH4D7.js.map +1 -0
- package/dist/foundation-BDJUT6CK.js +8 -0
- package/dist/foundation-BDJUT6CK.js.map +1 -0
- package/dist/foundation-FJKIXLS5.png +0 -0
- package/dist/foundation-Z6D6U74V.js +8 -0
- package/dist/foundation-Z6D6U74V.js.map +1 -0
- package/dist/index.d.ts +6 -4
- package/dist/index.js +11 -5
- package/dist/looks-rare-B6G3OQAP.png +0 -0
- package/dist/looks-rare-LBHT6EXZ.js +8 -0
- package/dist/looks-rare-LBHT6EXZ.js.map +1 -0
- package/dist/looks-rare-STS6IKI4.js +8 -0
- package/dist/looks-rare-STS6IKI4.js.map +1 -0
- package/dist/magic-eden-HA3X3P2O.png +0 -0
- package/dist/magic-eden-RMZ24554.js +8 -0
- package/dist/magic-eden-RMZ24554.js.map +1 -0
- package/dist/magic-eden-YMTLPKLE.js +8 -0
- package/dist/magic-eden-YMTLPKLE.js.map +1 -0
- package/dist/manifold-I4NT4V5L.png +0 -0
- package/dist/manifold-L7FLFDRO.js +8 -0
- package/dist/manifold-L7FLFDRO.js.map +1 -0
- package/dist/manifold-YIUSABCZ.js +8 -0
- package/dist/manifold-YIUSABCZ.js.map +1 -0
- package/dist/{marketplace-config-vioKvBQe.d.ts → marketplace-config-C_fDWzz0.d.ts} +2 -2
- package/dist/marketplace.gen-B8S8fflj.d.ts +390 -0
- package/dist/mintify-ARDASD5Z.js +8 -0
- package/dist/mintify-ARDASD5Z.js.map +1 -0
- package/dist/mintify-OLOGFTWQ.png +0 -0
- package/dist/mintify-TSZA3SQT.js +8 -0
- package/dist/mintify-TSZA3SQT.js.map +1 -0
- package/dist/nftx-67RX7ZV6.js +8 -0
- package/dist/nftx-67RX7ZV6.js.map +1 -0
- package/dist/nftx-DJIV3PYG.png +0 -0
- package/dist/nftx-KVJ3T3G2.js +8 -0
- package/dist/nftx-KVJ3T3G2.js.map +1 -0
- package/dist/okx-MOA2EFVR.js +8 -0
- package/dist/okx-MOA2EFVR.js.map +1 -0
- package/dist/okx-WNQRV3WE.png +0 -0
- package/dist/okx-WQA7H7EM.js +8 -0
- package/dist/okx-WQA7H7EM.js.map +1 -0
- package/dist/open-sea-2HWFM4P6.js +8 -0
- package/dist/open-sea-2HWFM4P6.js.map +1 -0
- package/dist/open-sea-C57XWTAR.png +0 -0
- package/dist/open-sea-GESD6S2M.js +8 -0
- package/dist/open-sea-GESD6S2M.js.map +1 -0
- package/dist/rarible-GHMFCPBT.js +8 -0
- package/dist/rarible-GHMFCPBT.js.map +1 -0
- package/dist/rarible-QNNAZZQC.js +8 -0
- package/dist/rarible-QNNAZZQC.js.map +1 -0
- package/dist/rarible-ZCE7U3I5.png +0 -0
- package/dist/react/_internal/api/index.d.ts +4 -2
- package/dist/react/_internal/api/index.js +5 -1
- package/dist/react/_internal/index.d.ts +5 -5
- package/dist/react/_internal/index.js +7 -3
- package/dist/react/_internal/wagmi/index.d.ts +3 -3
- package/dist/react/_internal/wagmi/index.js +1 -1
- package/dist/react/hooks/index.d.ts +668 -5
- package/dist/react/hooks/index.js +16 -6
- package/dist/react/index.d.ts +7 -7
- package/dist/react/index.js +18 -9
- package/dist/react/ssr/index.js +14 -31
- package/dist/react/ssr/index.js.map +1 -1
- package/dist/react/ui/components/collectible-card/index.css.map +1 -0
- package/dist/react/ui/components/{index.d.ts → collectible-card/index.d.ts} +3 -3
- package/dist/react/ui/components/collectible-card/index.js +29 -0
- package/dist/react/ui/components/collectible-card/index.js.map +1 -0
- package/dist/react/ui/components/marketplace-logos/index.d.ts +26 -0
- package/dist/react/ui/components/marketplace-logos/index.js +46 -0
- package/dist/react/ui/components/marketplace-logos/index.js.map +1 -0
- package/dist/react/ui/icons/index.js +0 -8
- package/dist/react/ui/icons/index.js.map +1 -1
- package/dist/react/ui/index.d.ts +4 -4
- package/dist/react/ui/index.js +10 -9
- package/dist/react/ui/modals/_internal/components/actionModal/index.d.ts +4 -3
- package/dist/react/ui/modals/_internal/components/actionModal/index.js +8 -6
- package/dist/{sdk-config-CasNGLz4.d.ts → sdk-config-BXVH8PS2.d.ts} +68 -16
- package/dist/sequence-JAFBEQNI.png +0 -0
- package/dist/sequence-OIPVNE5P.js +8 -0
- package/dist/sequence-OIPVNE5P.js.map +1 -0
- package/dist/sequence-QNNBU34G.js +8 -0
- package/dist/sequence-QNNBU34G.js.map +1 -0
- package/dist/{services-CbsurKYr.d.ts → services-CdXAIjt1.d.ts} +1 -1
- package/dist/sudo-swap-D3FAP7W4.js +8 -0
- package/dist/sudo-swap-D3FAP7W4.js.map +1 -0
- package/dist/sudo-swap-XNJ3BIUD.js +8 -0
- package/dist/sudo-swap-XNJ3BIUD.js.map +1 -0
- package/dist/sudo-swap-Y6GICQTL.png +0 -0
- package/dist/super-rare-VIUS3P6B.js +8 -0
- package/dist/super-rare-VIUS3P6B.js.map +1 -0
- package/dist/super-rare-WWXZ3MQL.png +0 -0
- package/dist/super-rare-YPU3Y7EF.js +8 -0
- package/dist/super-rare-YPU3Y7EF.js.map +1 -0
- package/dist/types/index.d.ts +3 -3
- package/dist/types/index.js +8 -5
- package/dist/{types-rupsBCjv.d.ts → types-eX4P9xju.d.ts} +2 -2
- package/dist/utils/index.d.ts +16 -4
- package/dist/utils/index.js +8 -1
- package/dist/x2y2-CXOXXZKS.png +0 -0
- package/dist/x2y2-G2SXS5VR.js +8 -0
- package/dist/x2y2-G2SXS5VR.js.map +1 -0
- package/dist/x2y2-GKWTQTPB.js +8 -0
- package/dist/x2y2-GKWTQTPB.js.map +1 -0
- package/dist/zora-3DPG4KAY.png +0 -0
- package/dist/zora-JUDT67NX.js +8 -0
- package/dist/zora-JUDT67NX.js.map +1 -0
- package/dist/zora-Z5VR477F.js +8 -0
- package/dist/zora-Z5VR477F.js.map +1 -0
- package/package.json +34 -19
- package/src/react/__tests__/provider.test.tsx +75 -0
- package/src/react/_internal/api/__mocks__/marketplace.msw.ts +218 -0
- package/src/react/_internal/api/marketplace.gen.ts +125 -42
- package/src/react/_internal/api/query-keys.ts +8 -0
- package/src/react/_internal/api/zod-schema.ts +33 -0
- package/src/react/_internal/test-utils.tsx +68 -0
- package/src/react/_internal/types.ts +3 -3
- package/src/react/_internal/wagmi/__tests__/create-config.test.ts +196 -0
- package/src/react/_internal/wagmi/create-config.ts +9 -1
- package/src/react/hooks/index.ts +2 -0
- package/src/react/hooks/options/__mocks__/marketplaceConfig.msw.ts +77 -0
- package/src/react/hooks/options/__tests__/marketplaceConfigOptions.test.tsx +144 -0
- package/src/react/hooks/useCancelOrder.tsx +1 -1
- package/src/react/hooks/useCancelTransactionSteps.tsx +6 -6
- package/src/react/hooks/useCurrencies.tsx +2 -5
- package/src/react/hooks/useCurrency.tsx +10 -1
- package/src/react/hooks/useCurrencyBalance.tsx +38 -36
- package/src/react/hooks/useGetReceiptFromHash.tsx +1 -1
- package/src/react/hooks/useListCollectibleActivities.tsx +57 -0
- package/src/react/hooks/useListCollectionActivities.tsx +57 -0
- package/src/react/provider.tsx +5 -0
- package/src/react/ssr/create-ssr-client.ts +1 -1
- package/src/react/ui/components/_internals/custom-select/__tests__/CustomSelect.test.tsx +89 -0
- package/src/react/ui/components/collectible-card/CollectibleCard.tsx +9 -8
- package/src/react/ui/components/collectible-card/Footer.tsx +4 -1
- package/src/react/ui/components/collectible-card/index.ts +1 -0
- package/src/react/ui/components/marketplace-logos/index.ts +23 -0
- package/src/react/ui/components/marketplace-logos/marketplace-logos.tsx +111 -0
- package/src/react/ui/images/marketplaces/alien_swap.png +0 -0
- package/src/react/ui/images/marketplaces/aqua-xyz.png +0 -0
- package/src/react/ui/images/marketplaces/aura.png +0 -0
- package/src/react/ui/images/marketplaces/blur.png +0 -0
- package/src/react/ui/images/marketplaces/coinbase.png +0 -0
- package/src/react/ui/images/marketplaces/element.png +0 -0
- package/src/react/ui/images/marketplaces/foundation.png +0 -0
- package/src/react/ui/images/marketplaces/looks-rare.png +0 -0
- package/src/react/ui/images/marketplaces/magic-eden.png +0 -0
- package/src/react/ui/images/marketplaces/manifold.png +0 -0
- package/src/react/ui/images/marketplaces/mintify.png +0 -0
- package/src/react/ui/images/marketplaces/nftx.png +0 -0
- package/src/react/ui/images/marketplaces/okx.png +0 -0
- package/src/react/ui/images/marketplaces/open-sea.png +0 -0
- package/src/react/ui/images/marketplaces/rarible.png +0 -0
- package/src/react/ui/images/marketplaces/sequence.png +0 -0
- package/src/react/ui/images/marketplaces/sudo-swap.png +0 -0
- package/src/react/ui/images/marketplaces/super-rare.png +0 -0
- package/src/react/ui/images/marketplaces/x2y2.png +0 -0
- package/src/react/ui/images/marketplaces/zora.png +0 -0
- package/src/react/ui/modals/BuyModal/Modal.tsx +14 -3
- package/src/react/ui/modals/BuyModal/hooks/useBuyCollectable.ts +1 -0
- package/src/react/ui/modals/BuyModal/modals/CheckoutModal.tsx +7 -0
- package/src/react/ui/modals/CreateListingModal/Modal.tsx +2 -1
- package/src/react/ui/modals/CreateListingModal/__tests__/Modal.test.tsx +208 -0
- package/src/react/ui/modals/CreateListingModal/store.ts +26 -16
- package/src/react/ui/modals/MakeOfferModal/Modal.tsx +2 -2
- package/src/react/ui/modals/MakeOfferModal/__tests__/Modal.test.tsx +199 -0
- package/src/react/ui/modals/MakeOfferModal/store.ts +27 -16
- package/src/react/ui/modals/SellModal/Modal.tsx +1 -0
- package/src/react/ui/modals/SellModal/__tests__/Modal.test.tsx +192 -0
- package/src/react/ui/modals/SellModal/hooks/useGetTokenApproval.tsx +3 -3
- package/src/react/ui/modals/SellModal/hooks/useSell.tsx +3 -3
- package/src/react/ui/modals/SellModal/hooks/useTransactionSteps.tsx +8 -8
- package/src/react/ui/modals/SuccessfulPurchaseModal/__tests__/Modal.test.tsx +145 -0
- package/src/react/ui/modals/_internal/components/actionModal/ActionModal.tsx +2 -0
- package/src/react/ui/modals/_internal/components/actionModal/ErrorModal.tsx +7 -1
- package/src/react/ui/modals/_internal/components/actionModal/LoadingModal.tsx +7 -1
- package/src/react/ui/modals/_internal/components/currencyOptionsSelect/__tests__/index.test.tsx +159 -0
- package/src/react/ui/modals/_internal/components/currencyOptionsSelect/index.tsx +4 -5
- package/src/react/ui/modals/_internal/components/priceInput/__tests__/index.test.tsx +124 -0
- package/src/react/ui/modals/_internal/components/priceInput/index.tsx +48 -45
- package/src/react/ui/modals/_internal/components/switchChainModal/__tests__/SwitchChainModal.test.tsx +221 -0
- package/src/react/ui/modals/_internal/components/switchChainModal/index.tsx +24 -5
- package/src/react/ui/modals/_internal/components/switchChainModal/store.ts +2 -2
- package/src/react/ui/modals/_internal/components/transactionPreview/index.tsx +16 -2
- package/src/react/ui/modals/_internal/components/transactionStatusModal/__tests__/TransactionStatusModal.test.tsx +147 -0
- package/src/react/ui/modals/_internal/components/transactionStatusModal/__tests__/utils.test.ts +218 -0
- package/src/react/ui/modals/_internal/components/transactionStatusModal/index.tsx +27 -10
- package/src/react/ui/modals/_internal/components/transactionStatusModal/util/getMessage.ts +1 -1
- package/src/react/ui/modals/modal-provider.tsx +0 -2
- package/src/types/marketplace-config.ts +1 -1
- package/src/utils/__tests__/address.test.ts +65 -0
- package/src/utils/__tests__/date.test.ts +31 -0
- package/src/utils/__tests__/get-public-rpc-client.test.ts +109 -0
- package/src/utils/__tests__/getMarketplaceDetails.test.ts +134 -0
- package/src/utils/__tests__/price.test.ts +42 -0
- package/src/utils/_internal/error/config.ts +16 -0
- package/src/utils/get-public-rpc-client.ts +6 -0
- package/src/utils/getMarketplaceDetails.ts +110 -0
- package/src/utils/index.ts +1 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/vitest.config.js +10 -0
- package/dist/chunk-2FOUCP2R.js.map +0 -1
- package/dist/chunk-36NGHJH5.js.map +0 -1
- package/dist/chunk-3C2MT5TM.js.map +0 -1
- package/dist/chunk-5D3ARFFZ.js.map +0 -1
- package/dist/chunk-6WB4GCCJ.js +0 -38
- package/dist/chunk-6WB4GCCJ.js.map +0 -1
- package/dist/chunk-CP2IVRMX.js +0 -85
- package/dist/chunk-CP2IVRMX.js.map +0 -1
- package/dist/chunk-DNVERQ5J.js.map +0 -1
- package/dist/chunk-LTHX6RXH.js.map +0 -1
- package/dist/chunk-MJ4YU7RW.js +0 -2
- package/dist/chunk-QVOUL555.js.map +0 -1
- package/dist/chunk-RD7HPANB.js.map +0 -1
- package/dist/chunk-ZEH4JI2U.js.map +0 -1
- package/dist/react/ui/components/index.css.map +0 -1
- package/dist/react/ui/components/index.js +0 -28
- package/src/react/ui/components/index.ts +0 -1
- package/src/react/ui/modals/Account/index.tsx +0 -29
- package/src/react/ui/modals/_internal/components/priceInput/hooks/useBalanceCheck.ts +0 -67
- package/src/react/ui/modals/_internal/components/priceInput/hooks/usePriceInput.ts +0 -54
- /package/dist/{chunk-MJ4YU7RW.js.map → alien_swap-IZONL4XB.js.map} +0 -0
- /package/dist/{react/ui/components/index.js.map → alien_swap-PMYKGY6A.js.map} +0 -0
- /package/dist/react/ui/components/{index.css → collectible-card/index.css} +0 -0
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach } from 'vitest';
|
|
2
|
+
import { createWagmiConfig } from '../create-config';
|
|
3
|
+
import { getWaasConnectors } from '../embedded';
|
|
4
|
+
import type { MarketplaceConfig, SdkConfig } from '../../../../types';
|
|
5
|
+
import { WalletOptions } from '../../../../types';
|
|
6
|
+
import { polygon } from 'viem/chains';
|
|
7
|
+
import { MissingConfigError } from '../../../../utils/_internal/error/transaction';
|
|
8
|
+
import { cookieStorage, type Config } from 'wagmi';
|
|
9
|
+
|
|
10
|
+
describe('createWagmiConfig', () => {
|
|
11
|
+
let baseMarketplaceConfig: MarketplaceConfig;
|
|
12
|
+
let baseSdkConfig: SdkConfig;
|
|
13
|
+
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
baseMarketplaceConfig = {
|
|
16
|
+
projectId: 1,
|
|
17
|
+
publisherId: 'test-publisher',
|
|
18
|
+
title: 'Test Marketplace',
|
|
19
|
+
shortDescription: 'Test Description',
|
|
20
|
+
faviconUrl: 'https://test.com/favicon.ico',
|
|
21
|
+
landingBannerUrl: 'https://test.com/banner.jpg',
|
|
22
|
+
titleTemplate: '%s | Test',
|
|
23
|
+
walletOptions: [WalletOptions.Sequence],
|
|
24
|
+
collections: [
|
|
25
|
+
{
|
|
26
|
+
collectionAddress: '0x1234567890123456789012345678901234567890',
|
|
27
|
+
chainId: polygon.id,
|
|
28
|
+
marketplaceFeePercentage: 2.5,
|
|
29
|
+
marketplaceType: 'orderbook',
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
landingPageLayout: 'default',
|
|
33
|
+
cssString: '',
|
|
34
|
+
manifestUrl: 'https://test.com/manifest.json',
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
baseSdkConfig = {
|
|
38
|
+
projectAccessKey: 'test-access-key',
|
|
39
|
+
projectId: '1',
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
describe('successful cases', () => {
|
|
44
|
+
it('should create config with empty collections', () => {
|
|
45
|
+
const configWithEmptyCollections = createWagmiConfig(
|
|
46
|
+
{
|
|
47
|
+
...baseMarketplaceConfig,
|
|
48
|
+
collections: [],
|
|
49
|
+
},
|
|
50
|
+
baseSdkConfig,
|
|
51
|
+
);
|
|
52
|
+
expect(configWithEmptyCollections.chains).toBeDefined();
|
|
53
|
+
expect(Array.isArray(configWithEmptyCollections.chains)).toBe(true);
|
|
54
|
+
expect(configWithEmptyCollections.chains).toHaveLength(1);
|
|
55
|
+
// Default chain is polygon if no collections are specified
|
|
56
|
+
expect(configWithEmptyCollections.chains[0].id).toBe(polygon.id);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('should create config with universal wallet setup', () => {
|
|
60
|
+
const marketplaceConfig: MarketplaceConfig = {
|
|
61
|
+
...baseMarketplaceConfig,
|
|
62
|
+
walletOptionsNew: {
|
|
63
|
+
connectors: ['walletconnect', 'coinbase'],
|
|
64
|
+
includeEIP6963Wallets: true,
|
|
65
|
+
walletType: 'universal',
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const sdkConfig: SdkConfig = {
|
|
70
|
+
...baseSdkConfig,
|
|
71
|
+
wallet: {
|
|
72
|
+
walletConnectProjectId: 'test-wc-project-id',
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const config = createWagmiConfig(marketplaceConfig, sdkConfig);
|
|
77
|
+
expect(config.connectors).toBeDefined();
|
|
78
|
+
expect(config.chains).toHaveLength(1);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('should create config with embedded wallet setup', () => {
|
|
82
|
+
const marketplaceConfig: MarketplaceConfig = {
|
|
83
|
+
...baseMarketplaceConfig,
|
|
84
|
+
walletOptionsNew: {
|
|
85
|
+
connectors: ['walletconnect'],
|
|
86
|
+
includeEIP6963Wallets: false,
|
|
87
|
+
walletType: 'embedded',
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const sdkConfig: SdkConfig = {
|
|
92
|
+
...baseSdkConfig,
|
|
93
|
+
wallet: {
|
|
94
|
+
embedded: {
|
|
95
|
+
waasConfigKey:
|
|
96
|
+
'eyJwcm9qZWN0SWQiOjEzNjM5LCJycGNTZXJ2ZXIiOiJodHRwczovL3dhYXMuc2VxdWVuY2UuYXBwIn0',
|
|
97
|
+
googleClientId: 'test-google-id',
|
|
98
|
+
appleClientId: 'test-apple-id',
|
|
99
|
+
appleRedirectURI: 'https://test.com/redirect',
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const config = createWagmiConfig(marketplaceConfig, sdkConfig);
|
|
105
|
+
expect(config.connectors).toBeDefined();
|
|
106
|
+
expect(config.chains).toHaveLength(1);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('should respect EIP6963 wallet inclusion setting', () => {
|
|
110
|
+
const marketplaceConfig: MarketplaceConfig = {
|
|
111
|
+
...baseMarketplaceConfig,
|
|
112
|
+
walletOptionsNew: {
|
|
113
|
+
connectors: ['walletconnect'],
|
|
114
|
+
includeEIP6963Wallets: false,
|
|
115
|
+
walletType: 'universal',
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const config = createWagmiConfig(marketplaceConfig, baseSdkConfig);
|
|
120
|
+
expect(config.connectors).toBeDefined();
|
|
121
|
+
expect(config.chains).toHaveLength(1);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('should create SSR compatible config when ssr flag is true', async () => {
|
|
125
|
+
const config = createWagmiConfig(
|
|
126
|
+
baseMarketplaceConfig,
|
|
127
|
+
baseSdkConfig,
|
|
128
|
+
true,
|
|
129
|
+
) as Config;
|
|
130
|
+
|
|
131
|
+
expect(config.storage).toBeInstanceOf(cookieStorage.constructor);
|
|
132
|
+
|
|
133
|
+
const testKey = 'wagmi.test';
|
|
134
|
+
const testValue = { data: 'test-value' };
|
|
135
|
+
|
|
136
|
+
config.storage?.setItem(testKey, JSON.stringify(testValue));
|
|
137
|
+
|
|
138
|
+
const storedValue = await config.storage?.getItem(testKey);
|
|
139
|
+
expect(storedValue).toBeDefined();
|
|
140
|
+
expect(JSON.parse(storedValue as string)).toEqual(testValue);
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
describe('failure cases', () => {
|
|
145
|
+
it('should throw error when trying to use embedded wallet without waasConfigKey', () => {
|
|
146
|
+
const marketplaceConfig: MarketplaceConfig = {
|
|
147
|
+
...baseMarketplaceConfig,
|
|
148
|
+
walletOptionsNew: {
|
|
149
|
+
connectors: ['walletconnect'],
|
|
150
|
+
includeEIP6963Wallets: false,
|
|
151
|
+
walletType: 'embedded',
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
const sdkConfig: SdkConfig = {
|
|
156
|
+
...baseSdkConfig,
|
|
157
|
+
wallet: {
|
|
158
|
+
embedded: {
|
|
159
|
+
waasConfigKey: '',
|
|
160
|
+
googleClientId: 'test-google-id',
|
|
161
|
+
appleClientId: 'test-apple-id',
|
|
162
|
+
appleRedirectURI: 'https://test.com/redirect',
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
expect(() =>
|
|
168
|
+
getWaasConnectors(marketplaceConfig, {
|
|
169
|
+
...sdkConfig,
|
|
170
|
+
wallet: {
|
|
171
|
+
...sdkConfig.wallet,
|
|
172
|
+
embedded: {
|
|
173
|
+
...sdkConfig.wallet?.embedded,
|
|
174
|
+
waasConfigKey: '', // Empty waasConfigKey should trigger the error
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
}),
|
|
178
|
+
).toThrow(MissingConfigError);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it('should still create config when walletConnectProjectId is missing', () => {
|
|
182
|
+
const marketplaceConfig: MarketplaceConfig = {
|
|
183
|
+
...baseMarketplaceConfig,
|
|
184
|
+
walletOptionsNew: {
|
|
185
|
+
connectors: ['walletconnect'],
|
|
186
|
+
includeEIP6963Wallets: true,
|
|
187
|
+
walletType: 'universal',
|
|
188
|
+
},
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
const config = createWagmiConfig(marketplaceConfig, baseSdkConfig);
|
|
192
|
+
expect(config.connectors).toBeDefined();
|
|
193
|
+
expect(config.chains).toHaveLength(1);
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getDefaultChains } from '@0xsequence/kit';
|
|
2
2
|
import { allNetworks, findNetworkConfig } from '@0xsequence/network';
|
|
3
3
|
import type { Chain, Transport } from 'viem';
|
|
4
|
+
import { polygon } from 'viem/chains';
|
|
4
5
|
import { http, cookieStorage, createConfig, createStorage } from 'wagmi';
|
|
5
6
|
import type { MarketplaceConfig, SdkConfig } from '../../../types';
|
|
6
7
|
import { getWaasConnectors } from './embedded';
|
|
@@ -45,7 +46,14 @@ function getChainConfigs(marketConfig: MarketplaceConfig): [Chain, ...Chain[]] {
|
|
|
45
46
|
const supportedChainIds = new Set(
|
|
46
47
|
marketConfig.collections.map((c) => c.chainId),
|
|
47
48
|
);
|
|
48
|
-
|
|
49
|
+
|
|
50
|
+
// Marketplace config does not specify any chains, use polygon as default
|
|
51
|
+
if (supportedChainIds.size === 0) {
|
|
52
|
+
supportedChainIds.add(polygon.id); // Mainnet chain ID
|
|
53
|
+
}
|
|
54
|
+
const chains = getDefaultChains([...supportedChainIds]);
|
|
55
|
+
|
|
56
|
+
return chains;
|
|
49
57
|
}
|
|
50
58
|
|
|
51
59
|
function getTransportConfigs(
|
package/src/react/hooks/index.ts
CHANGED
|
@@ -10,7 +10,9 @@ export * from './useFilters';
|
|
|
10
10
|
export * from './useFloorOrder';
|
|
11
11
|
export * from './useHighestOffer';
|
|
12
12
|
export * from './useListBalances';
|
|
13
|
+
export * from './useListCollectibleActivities';
|
|
13
14
|
export * from './useListCollectibles';
|
|
15
|
+
export * from './useListCollectionActivities';
|
|
14
16
|
export * from './useListOffersForCollectible';
|
|
15
17
|
export * from './useCountOffersForCollectible';
|
|
16
18
|
export * from './useListListingsForCollectible';
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { http, HttpResponse } from 'msw';
|
|
2
|
+
import { WalletOptions, type MarketplaceConfig } from '../../../../types';
|
|
3
|
+
|
|
4
|
+
// Mock data
|
|
5
|
+
export const mockConfig: MarketplaceConfig = {
|
|
6
|
+
projectId: 123,
|
|
7
|
+
publisherId: 'test-publisher',
|
|
8
|
+
title: 'Test Marketplace',
|
|
9
|
+
shortDescription: 'A test marketplace',
|
|
10
|
+
faviconUrl: 'https://example.com/favicon.png',
|
|
11
|
+
landingBannerUrl: 'https://example.com/banner.png',
|
|
12
|
+
logoUrl: 'https://example.com/logo.png',
|
|
13
|
+
titleTemplate: '%s | Test Marketplace',
|
|
14
|
+
walletOptions: [WalletOptions.Sequence],
|
|
15
|
+
collections: [],
|
|
16
|
+
landingPageLayout: 'default',
|
|
17
|
+
cssString: '',
|
|
18
|
+
manifestUrl: '',
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const mockStyles = `
|
|
22
|
+
.marketplace-theme {
|
|
23
|
+
--primary-color: #000000;
|
|
24
|
+
}
|
|
25
|
+
`;
|
|
26
|
+
|
|
27
|
+
// Debug configuration
|
|
28
|
+
export let isDebugEnabled = false;
|
|
29
|
+
export const enableDebug = () => {
|
|
30
|
+
isDebugEnabled = true;
|
|
31
|
+
};
|
|
32
|
+
export const disableDebug = () => {
|
|
33
|
+
isDebugEnabled = false;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
// Debug logger function
|
|
37
|
+
const debugLog = (endpoint: string, request: Request, response: Response) => {
|
|
38
|
+
if (isDebugEnabled) {
|
|
39
|
+
console.log(`[MSW Debug] ${endpoint}:`, {
|
|
40
|
+
request,
|
|
41
|
+
response,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
// MSW handlers
|
|
47
|
+
export const createConfigHandler = (config = mockConfig) =>
|
|
48
|
+
http.get('*/marketplace/*/config.json', ({ request }) => {
|
|
49
|
+
const response = HttpResponse.json(config);
|
|
50
|
+
debugLog('config.json', request, response);
|
|
51
|
+
return response;
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
export const createStylesHandler = (styles = mockStyles) =>
|
|
55
|
+
http.get('*/marketplace/*/styles.css', ({ request }) => {
|
|
56
|
+
const response = new HttpResponse(styles, {
|
|
57
|
+
headers: { 'Content-Type': 'text/css' },
|
|
58
|
+
});
|
|
59
|
+
debugLog('styles.css', request, response);
|
|
60
|
+
return response;
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
export const createErrorHandler = () =>
|
|
64
|
+
http.get('*/marketplace/*/config.json', () => {
|
|
65
|
+
return HttpResponse.json(
|
|
66
|
+
{ code: 3000, msg: 'Project not found' },
|
|
67
|
+
{ status: 404 },
|
|
68
|
+
);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
export const createStylesErrorHandler = () =>
|
|
72
|
+
http.get('*/marketplace/*/styles.css', () => {
|
|
73
|
+
return new HttpResponse('', { status: 500 });
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// Default handlers
|
|
77
|
+
export const handlers = [createConfigHandler(), createStylesHandler()];
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { describe, it, expect, beforeAll, afterAll, afterEach } from 'vitest';
|
|
2
|
+
import { setupServer } from 'msw/node';
|
|
3
|
+
import { marketplaceConfigOptions } from '../marketplaceConfigOptions';
|
|
4
|
+
import { renderHook, waitFor } from '../../../_internal/test-utils';
|
|
5
|
+
import type { QueryFunctionContext } from '@tanstack/react-query';
|
|
6
|
+
import {
|
|
7
|
+
handlers,
|
|
8
|
+
createErrorHandler,
|
|
9
|
+
createStylesErrorHandler,
|
|
10
|
+
mockConfig,
|
|
11
|
+
mockStyles,
|
|
12
|
+
} from '../__mocks__/marketplaceConfig.msw';
|
|
13
|
+
|
|
14
|
+
type MarketplaceConfigQueryKey = ['configs', 'marketplace', string, string];
|
|
15
|
+
type MarketplaceConfigContext = QueryFunctionContext<MarketplaceConfigQueryKey>;
|
|
16
|
+
|
|
17
|
+
// Create MSW server with default handlers
|
|
18
|
+
const server = setupServer(...handlers);
|
|
19
|
+
|
|
20
|
+
// Setup test environment
|
|
21
|
+
beforeAll(() => server.listen());
|
|
22
|
+
afterEach(() => server.resetHandlers());
|
|
23
|
+
afterAll(() => server.close());
|
|
24
|
+
|
|
25
|
+
describe('marketplaceConfigOptions', () => {
|
|
26
|
+
it('should fetch marketplace config and styles successfully', async () => {
|
|
27
|
+
const { result } = renderHook(() =>
|
|
28
|
+
marketplaceConfigOptions({
|
|
29
|
+
projectId: 'test-project',
|
|
30
|
+
}),
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
await waitFor(() => {
|
|
34
|
+
expect(result.current.queryKey).toEqual([
|
|
35
|
+
'configs',
|
|
36
|
+
'marketplace',
|
|
37
|
+
'production',
|
|
38
|
+
'test-project',
|
|
39
|
+
]);
|
|
40
|
+
expect(result.current.queryFn).toBeDefined();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const data = await result.current.queryFn?.({
|
|
44
|
+
queryKey: ['configs', 'marketplace', 'production', 'test-project'],
|
|
45
|
+
} as MarketplaceConfigContext);
|
|
46
|
+
expect(data).toEqual({
|
|
47
|
+
...mockConfig,
|
|
48
|
+
cssString: mockStyles.replaceAll(/['"]/g, ''),
|
|
49
|
+
manifestUrl: expect.stringContaining('/manifest.json'),
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('should use custom environment and dev access key when provided', async () => {
|
|
54
|
+
const { result } = renderHook(() =>
|
|
55
|
+
marketplaceConfigOptions({
|
|
56
|
+
projectId: 'test-project',
|
|
57
|
+
_internal: {
|
|
58
|
+
builderEnv: 'development',
|
|
59
|
+
devAccessKey: 'test-dev-access-key',
|
|
60
|
+
},
|
|
61
|
+
}),
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
await waitFor(() => {
|
|
65
|
+
expect(result.current.queryKey).toEqual([
|
|
66
|
+
'configs',
|
|
67
|
+
'marketplace',
|
|
68
|
+
'development',
|
|
69
|
+
'test-project',
|
|
70
|
+
]);
|
|
71
|
+
expect(result.current.queryFn).toBeDefined();
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const data = await result.current.queryFn?.({
|
|
75
|
+
queryKey: ['configs', 'marketplace', 'development', 'test-project'],
|
|
76
|
+
} as MarketplaceConfigContext);
|
|
77
|
+
expect(data).toEqual({
|
|
78
|
+
...mockConfig,
|
|
79
|
+
cssString: mockStyles.replaceAll(/['"]/g, ''),
|
|
80
|
+
manifestUrl: expect.stringContaining('/manifest.json'),
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('should handle error responses', async () => {
|
|
85
|
+
// Override handler to return an error
|
|
86
|
+
server.use(createErrorHandler());
|
|
87
|
+
|
|
88
|
+
const { result } = renderHook(() =>
|
|
89
|
+
marketplaceConfigOptions({
|
|
90
|
+
projectId: 'non-existent-project',
|
|
91
|
+
}),
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
await waitFor(() => {
|
|
95
|
+
expect(result.current.queryKey).toEqual([
|
|
96
|
+
'configs',
|
|
97
|
+
'marketplace',
|
|
98
|
+
'production',
|
|
99
|
+
'non-existent-project',
|
|
100
|
+
]);
|
|
101
|
+
expect(result.current.queryFn).toBeDefined();
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
await expect(
|
|
105
|
+
result.current.queryFn?.({
|
|
106
|
+
queryKey: [
|
|
107
|
+
'configs',
|
|
108
|
+
'marketplace',
|
|
109
|
+
'production',
|
|
110
|
+
'non-existent-project',
|
|
111
|
+
],
|
|
112
|
+
} as MarketplaceConfigContext),
|
|
113
|
+
).rejects.toThrow('Project not found');
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('should handle network errors when fetching styles', async () => {
|
|
117
|
+
server.use(createStylesErrorHandler());
|
|
118
|
+
|
|
119
|
+
const { result } = renderHook(() =>
|
|
120
|
+
marketplaceConfigOptions({
|
|
121
|
+
projectId: 'test-project',
|
|
122
|
+
}),
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
await waitFor(() => {
|
|
126
|
+
expect(result.current.queryKey).toEqual([
|
|
127
|
+
'configs',
|
|
128
|
+
'marketplace',
|
|
129
|
+
'production',
|
|
130
|
+
'test-project',
|
|
131
|
+
]);
|
|
132
|
+
expect(result.current.queryFn).toBeDefined();
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
const data = await result.current.queryFn?.({
|
|
136
|
+
queryKey: ['configs', 'marketplace', 'production', 'test-project'],
|
|
137
|
+
} as MarketplaceConfigContext);
|
|
138
|
+
expect(data).toEqual({
|
|
139
|
+
...mockConfig,
|
|
140
|
+
cssString: '',
|
|
141
|
+
manifestUrl: expect.stringContaining('/manifest.json'),
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useState } from 'react';
|
|
2
2
|
import { useCancelTransactionSteps } from './useCancelTransactionSteps';
|
|
3
|
-
import { MarketplaceKind } from '../../types';
|
|
3
|
+
import type { MarketplaceKind } from '../../types';
|
|
4
4
|
|
|
5
5
|
interface UseCancelOrderArgs {
|
|
6
6
|
collectionAddress: string;
|
|
@@ -2,17 +2,17 @@ import {
|
|
|
2
2
|
ExecuteType,
|
|
3
3
|
getMarketplaceClient,
|
|
4
4
|
getQueryClient,
|
|
5
|
-
MarketplaceKind,
|
|
6
|
-
Step,
|
|
5
|
+
type MarketplaceKind,
|
|
6
|
+
type Step,
|
|
7
7
|
StepType,
|
|
8
8
|
} from '../_internal';
|
|
9
9
|
import { useWallet } from '../_internal/wallet/useWallet';
|
|
10
|
-
import { ModalCallbacks } from '../ui/modals/_internal/types';
|
|
10
|
+
import type { ModalCallbacks } from '../ui/modals/_internal/types';
|
|
11
11
|
import { useConfig } from './useConfig';
|
|
12
12
|
import { useGenerateCancelTransaction } from './useGenerateCancelTransaction';
|
|
13
|
-
import { TransactionStep } from './useCancelOrder';
|
|
14
|
-
import { SignatureStep } from '../_internal/utils';
|
|
15
|
-
import { Hex } from 'viem';
|
|
13
|
+
import type { TransactionStep } from './useCancelOrder';
|
|
14
|
+
import type { SignatureStep } from '../_internal/utils';
|
|
15
|
+
import type { Hex } from 'viem';
|
|
16
16
|
import { useSwitchChainModal } from '../ui/modals/_internal/components/switchChainModal';
|
|
17
17
|
import {
|
|
18
18
|
ChainSwitchUserRejectedError,
|
|
@@ -52,11 +52,8 @@ const selectCurrencies = (data: Currency[], args: UseCurrenciesArgs) => {
|
|
|
52
52
|
option.toLowerCase(),
|
|
53
53
|
);
|
|
54
54
|
|
|
55
|
-
filteredData = filteredData.filter(
|
|
56
|
-
(currency)
|
|
57
|
-
lowerCaseCurrencyOptions.includes(
|
|
58
|
-
currency.contractAddress.toLowerCase(),
|
|
59
|
-
)
|
|
55
|
+
filteredData = filteredData.filter((currency) =>
|
|
56
|
+
lowerCaseCurrencyOptions.includes(currency.contractAddress.toLowerCase()),
|
|
60
57
|
);
|
|
61
58
|
}
|
|
62
59
|
return filteredData;
|
|
@@ -44,10 +44,19 @@ const fetchCurrency = async (
|
|
|
44
44
|
.then((resp) => resp.currencies);
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
if (!currencies?.length) {
|
|
48
|
+
throw new Error('No currencies returned');
|
|
49
|
+
}
|
|
50
|
+
const currency = currencies.find(
|
|
48
51
|
(currency) =>
|
|
49
52
|
currency.contractAddress.toLowerCase() === currencyAddress.toLowerCase(),
|
|
50
53
|
);
|
|
54
|
+
|
|
55
|
+
if (!currency) {
|
|
56
|
+
throw new Error('Currency not found');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return currency;
|
|
51
60
|
};
|
|
52
61
|
|
|
53
62
|
export const currencyOptions = (args: UseCurrencyArgs, config: SdkConfig) => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useQuery } from '@tanstack/react-query';
|
|
1
|
+
import { skipToken, useQuery } from '@tanstack/react-query';
|
|
2
2
|
import { type Address, erc20Abi, formatUnits, zeroAddress } from 'viem';
|
|
3
3
|
import { getPublicRpcClient } from '../../utils';
|
|
4
4
|
|
|
@@ -7,46 +7,48 @@ export function useCurrencyBalance({
|
|
|
7
7
|
chainId,
|
|
8
8
|
userAddress,
|
|
9
9
|
}: {
|
|
10
|
-
currencyAddress: Address;
|
|
11
|
-
chainId: number;
|
|
12
|
-
userAddress: Address;
|
|
10
|
+
currencyAddress: Address | undefined;
|
|
11
|
+
chainId: number | undefined;
|
|
12
|
+
userAddress: Address | undefined;
|
|
13
13
|
}) {
|
|
14
|
-
const publicClient = getPublicRpcClient(chainId);
|
|
15
|
-
|
|
16
14
|
return useQuery({
|
|
17
15
|
queryKey: ['balance', currencyAddress, chainId, userAddress],
|
|
18
|
-
queryFn:
|
|
19
|
-
|
|
16
|
+
queryFn:
|
|
17
|
+
!!userAddress && !!chainId && !!currencyAddress
|
|
18
|
+
? async () => {
|
|
19
|
+
if (!userAddress) return null;
|
|
20
|
+
|
|
21
|
+
const publicClient = getPublicRpcClient(chainId);
|
|
20
22
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
if (currencyAddress === zeroAddress) {
|
|
24
|
+
const balance = await publicClient.getBalance({
|
|
25
|
+
address: userAddress,
|
|
26
|
+
});
|
|
27
|
+
return {
|
|
28
|
+
value: balance,
|
|
29
|
+
formatted: formatUnits(balance, 18),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
30
32
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
33
|
+
const [balance, decimals] = await Promise.all([
|
|
34
|
+
publicClient.readContract({
|
|
35
|
+
address: currencyAddress,
|
|
36
|
+
abi: erc20Abi,
|
|
37
|
+
functionName: 'balanceOf',
|
|
38
|
+
args: [userAddress],
|
|
39
|
+
}),
|
|
40
|
+
publicClient.readContract({
|
|
41
|
+
address: currencyAddress,
|
|
42
|
+
abi: erc20Abi,
|
|
43
|
+
functionName: 'decimals',
|
|
44
|
+
}),
|
|
45
|
+
]);
|
|
44
46
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
return {
|
|
48
|
+
value: balance,
|
|
49
|
+
formatted: formatUnits(balance, decimals),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
: skipToken,
|
|
51
53
|
});
|
|
52
54
|
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { queryOptions, useQuery } from '@tanstack/react-query';
|
|
2
|
+
import type { z } from 'zod';
|
|
3
|
+
import type { SdkConfig } from '../../types';
|
|
4
|
+
import { collectableKeys, getMarketplaceClient } from '../_internal';
|
|
5
|
+
import { useConfig } from './useConfig';
|
|
6
|
+
import type {
|
|
7
|
+
getListCollectibleActivitiesArgsSchema,
|
|
8
|
+
getListCollectibleActivitiesReturnSchema,
|
|
9
|
+
} from '../_internal/api/zod-schema';
|
|
10
|
+
|
|
11
|
+
export type UseListCollectibleActivitiesArgs = z.infer<
|
|
12
|
+
typeof getListCollectibleActivitiesArgsSchema
|
|
13
|
+
>;
|
|
14
|
+
|
|
15
|
+
export type UseListCollectibleActivitiesReturn = z.infer<
|
|
16
|
+
typeof getListCollectibleActivitiesReturnSchema
|
|
17
|
+
>;
|
|
18
|
+
|
|
19
|
+
const fetchCollectibleActivities = async (
|
|
20
|
+
args: UseListCollectibleActivitiesArgs,
|
|
21
|
+
config: SdkConfig,
|
|
22
|
+
) => {
|
|
23
|
+
const marketplaceClient = getMarketplaceClient(args.chainId, config);
|
|
24
|
+
return marketplaceClient
|
|
25
|
+
.listCollectibleActivities({
|
|
26
|
+
contractAddress: args.collectionAddress,
|
|
27
|
+
tokenId: args.tokenId,
|
|
28
|
+
page: args.query?.enabled
|
|
29
|
+
? {
|
|
30
|
+
page: args.query.page ?? 1,
|
|
31
|
+
pageSize: args.query.pageSize ?? 10,
|
|
32
|
+
sort: args.query.sort,
|
|
33
|
+
}
|
|
34
|
+
: undefined,
|
|
35
|
+
})
|
|
36
|
+
.then((data) => ({
|
|
37
|
+
activities: data.activities,
|
|
38
|
+
page: data.page,
|
|
39
|
+
}));
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export const listCollectibleActivitiesOptions = (
|
|
43
|
+
args: UseListCollectibleActivitiesArgs,
|
|
44
|
+
config: SdkConfig,
|
|
45
|
+
) => {
|
|
46
|
+
return queryOptions({
|
|
47
|
+
queryKey: [...collectableKeys.collectibleActivities, args, config],
|
|
48
|
+
queryFn: () => fetchCollectibleActivities(args, config),
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const useListCollectibleActivities = (
|
|
53
|
+
args: UseListCollectibleActivitiesArgs,
|
|
54
|
+
) => {
|
|
55
|
+
const config = useConfig();
|
|
56
|
+
return useQuery(listCollectibleActivitiesOptions(args, config));
|
|
57
|
+
};
|