@0xsequence/marketplace-sdk 0.5.3 → 0.5.4
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/{builder-types-wOwfTJpd.d.ts → builder-types-Jl3Ymws8.d.ts} +1 -1
- package/dist/{chunk-BZD2LDJJ.js → chunk-7C7ADZ2H.js} +2 -2
- package/dist/{chunk-H5YWG6WN.js → chunk-JWNONWD6.js} +136 -90
- package/dist/chunk-JWNONWD6.js.map +1 -0
- package/dist/{chunk-Y7YTLAO2.js → chunk-TLNRD4BQ.js} +3 -3
- package/dist/chunk-WGGZEQHL.js +56 -0
- package/dist/chunk-WGGZEQHL.js.map +1 -0
- package/dist/{chunk-MWDG7UTB.js → chunk-ZBLU3Q22.js} +1 -1
- package/dist/{chunk-BVXIRVEC.js → chunk-ZGVCOQ4I.js} +137 -47
- package/dist/chunk-ZGVCOQ4I.js.map +1 -0
- package/dist/{create-config-Bltg8Enl.d.ts → create-config-DOUq8Day.d.ts} +2 -2
- package/dist/index.d.ts +4 -3
- package/dist/index.js +2 -2
- package/dist/{sdk-config-B32_2bG3.d.ts → marketplace.gen-D0ADxbfH.d.ts} +1 -24
- package/dist/react/_internal/api/index.d.ts +3 -2
- package/dist/react/_internal/databeat/index.css +82 -0
- package/dist/react/_internal/databeat/index.css.map +1 -0
- package/dist/react/_internal/databeat/index.d.ts +68 -0
- package/dist/react/_internal/databeat/index.js +26 -0
- package/dist/react/_internal/databeat/index.js.map +1 -0
- package/dist/react/_internal/index.d.ts +6 -5
- package/dist/react/_internal/wagmi/index.d.ts +4 -3
- package/dist/react/hooks/index.d.ts +298 -5
- package/dist/react/hooks/index.js +7 -3
- package/dist/react/index.d.ts +7 -6
- package/dist/react/index.js +10 -5
- package/dist/react/ui/components/collectible-card/index.d.ts +4 -3
- package/dist/react/ui/components/collectible-card/index.js +6 -5
- package/dist/react/ui/components/marketplace-logos/index.js +1 -1
- package/dist/react/ui/index.d.ts +4 -3
- package/dist/react/ui/index.js +6 -5
- package/dist/react/ui/modals/_internal/components/actionModal/index.d.ts +4 -3
- package/dist/react/ui/modals/_internal/components/actionModal/index.js +4 -4
- package/dist/sdk-config-xWkdBdrL.d.ts +24 -0
- package/dist/{services-BRBVE0mm.d.ts → services-Dd2MoBTM.d.ts} +2 -1
- package/dist/types/index.d.ts +4 -3
- package/dist/{types-BY3husBh.d.ts → types-vOfhbBkR.d.ts} +3 -2
- package/dist/utils/index.d.ts +4 -3
- package/dist/utils/index.js +2 -2
- package/package.json +2 -1
- package/src/react/_internal/databeat/index.ts +63 -0
- package/src/react/_internal/databeat/types.ts +70 -0
- package/src/react/hooks/__tests__/useListCollectiblesPaginated.test.tsx +217 -0
- package/src/react/hooks/index.ts +1 -0
- package/src/react/hooks/useFilters.tsx +9 -3
- package/src/react/hooks/useListCollectiblesPaginated.tsx +78 -0
- package/src/react/ui/modals/CreateListingModal/hooks/useTransactionSteps.tsx +40 -4
- package/src/react/ui/modals/MakeOfferModal/hooks/useTransactionSteps.tsx +26 -2
- package/src/react/ui/modals/SellModal/Modal.tsx +3 -1
- package/src/react/ui/modals/SellModal/hooks/useSell.tsx +10 -7
- package/src/react/ui/modals/SellModal/hooks/useTransactionSteps.tsx +51 -13
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/chunk-BVXIRVEC.js.map +0 -1
- package/dist/chunk-H5YWG6WN.js.map +0 -1
- /package/dist/{chunk-BZD2LDJJ.js.map → chunk-7C7ADZ2H.js.map} +0 -0
- /package/dist/{chunk-Y7YTLAO2.js.map → chunk-TLNRD4BQ.js.map} +0 -0
- /package/dist/{chunk-MWDG7UTB.js.map → chunk-ZBLU3Q22.js.map} +0 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { SequenceIndexer } from '@0xsequence/indexer';
|
|
2
2
|
import { SequenceMetadata } from '@0xsequence/metadata';
|
|
3
|
-
import {
|
|
3
|
+
import { E as Env, S as SdkConfig } from './sdk-config-xWkdBdrL.js';
|
|
4
|
+
import { an as Marketplace } from './marketplace.gen-D0ADxbfH.js';
|
|
4
5
|
|
|
5
6
|
declare class SequenceMarketplace extends Marketplace {
|
|
6
7
|
projectAccessKey: string;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export {
|
|
1
|
+
export { E as Env, S as SdkConfig } from '../sdk-config-xWkdBdrL.js';
|
|
2
|
+
import { w as Currency } from '../marketplace.gen-D0ADxbfH.js';
|
|
3
|
+
export { q as Activity, y as AdditionalFee, A as Asset, L as CheckoutOptions, K as CheckoutOptionsItem, J as CheckoutOptionsMarketplaceOrder, v as Collectible, o as CollectibleOrder, f as CollectibleStatus, l as CollectiblesFilter, r as Collection, s as CollectionConfig, t as CollectionLastSynced, d as CollectionStatus, C as ContractType, D as CreateReq, I as Domain, E as ExecuteType, n as FeeBreakdown, F as Filter, G as GetOrdersInput, M as MarketplaceKind, m as Order, x as OrderData, p as OrderFilter, b as OrderSide, c as OrderStatus, O as OrderbookKind, i as Page, B as PostRequest, u as Project, e as ProjectStatus, k as PropertyFilter, P as PropertyType, H as Signature, j as SortBy, S as SortOrder, a as SourceKind, z as Step, g as StepType, h as TokenMetadata, T as TransactionCrypto, W as WalletKind } from '../marketplace.gen-D0ADxbfH.js';
|
|
4
|
+
export { C as CollectionFilterSettings, F as FilterCondition, d as MarketplaceCollection, g as MarketplaceConfig, f as MarketplaceSettings, e as MarketplaceSocials, a as MarketplaceType, M as MarketplaceWallet, b as MarketplaceWalletOptions, c as MetadataFilterRule } from '../builder-types-Jl3Ymws8.js';
|
|
4
5
|
|
|
5
6
|
type Price = {
|
|
6
7
|
amountRaw: string;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { ChainId as ChainId$1 } from '@0xsequence/network';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { Chain } from 'viem';
|
|
4
|
-
import { C as ContractType,
|
|
5
|
-
import {
|
|
4
|
+
import { C as ContractType, O as OrderbookKind, M as MarketplaceKind, D as CreateReq } from './marketplace.gen-D0ADxbfH.js';
|
|
5
|
+
import { S as SdkConfig } from './sdk-config-xWkdBdrL.js';
|
|
6
|
+
import { g as MarketplaceConfig } from './builder-types-Jl3Ymws8.js';
|
|
6
7
|
|
|
7
8
|
declare const QueryArgSchema: z.ZodOptional<z.ZodObject<{
|
|
8
9
|
enabled: z.ZodOptional<z.ZodBoolean>;
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
export { EIP2981_ABI, SequenceMarketplaceV1_ABI, SequenceMarketplaceV2_ABI } from './abi/marketplace/index.js';
|
|
2
2
|
export { ERC1155_ABI, ERC20_ABI, ERC721_ABI } from './abi/token/index.js';
|
|
3
3
|
import { PublicClient } from 'viem';
|
|
4
|
-
import { c as ChainId } from '../types-
|
|
5
|
-
import { M as MarketplaceKind } from '../
|
|
4
|
+
import { c as ChainId } from '../types-vOfhbBkR.js';
|
|
5
|
+
import { M as MarketplaceKind } from '../marketplace.gen-D0ADxbfH.js';
|
|
6
6
|
import { ComponentType } from 'react';
|
|
7
7
|
import { Image } from '@0xsequence/design-system';
|
|
8
8
|
import '@0xsequence/network';
|
|
9
9
|
import 'zod';
|
|
10
|
-
import '../
|
|
10
|
+
import '../sdk-config-xWkdBdrL.js';
|
|
11
|
+
import '../builder-types-Jl3Ymws8.js';
|
|
11
12
|
|
|
12
13
|
declare const truncateMiddle: (address: string, minPrefix?: number, minSuffix?: number) => string;
|
|
13
14
|
declare const truncateEnd: (text: string | undefined, truncateAt: number) => string;
|
package/dist/utils/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@0xsequence/marketplace-sdk",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.5.
|
|
4
|
+
"version": "0.5.4",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": [
|
|
7
7
|
"**/*.css"
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
}
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
+
"@databeat/tracker": "^0.9.3",
|
|
36
37
|
"@legendapp/state": "^3.0.0-beta.26",
|
|
37
38
|
"@radix-ui/react-dialog": "^1.1.6",
|
|
38
39
|
"@radix-ui/react-popover": "^1.1.6",
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { Event as DatabeatEvent } from '@databeat/tracker';
|
|
2
|
+
import { Databeat } from '@databeat/tracker';
|
|
3
|
+
|
|
4
|
+
import { useConfig } from '../../hooks';
|
|
5
|
+
import type {
|
|
6
|
+
EventType,
|
|
7
|
+
TrackCreateListing,
|
|
8
|
+
TrackCreateOffer,
|
|
9
|
+
TrackSellItems,
|
|
10
|
+
TrackTransactionFailed,
|
|
11
|
+
} from './types';
|
|
12
|
+
|
|
13
|
+
export type EventTypes = keyof typeof EventType;
|
|
14
|
+
export type Event = DatabeatEvent<EventTypes>;
|
|
15
|
+
|
|
16
|
+
export class DatabeatAnalytics extends Databeat<Extract<EventTypes, string>> {
|
|
17
|
+
// Currently handled by kit-checkout
|
|
18
|
+
// trackBuyItems(args: TrackBuyItems) {
|
|
19
|
+
// this.track({
|
|
20
|
+
// event: 'BUY_ITEMS',
|
|
21
|
+
// props: args.props,
|
|
22
|
+
// nums: args.nums
|
|
23
|
+
// })
|
|
24
|
+
// }
|
|
25
|
+
|
|
26
|
+
trackSellItems(args: TrackSellItems) {
|
|
27
|
+
this.track({
|
|
28
|
+
event: 'SELL_ITEMS',
|
|
29
|
+
props: args.props,
|
|
30
|
+
nums: args.nums,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
trackCreateListing(args: TrackCreateListing) {
|
|
35
|
+
this.track({
|
|
36
|
+
event: 'CREATE_LISTING',
|
|
37
|
+
props: args.props,
|
|
38
|
+
nums: args.nums,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
trackCreateOffer(args: TrackCreateOffer) {
|
|
43
|
+
this.track({
|
|
44
|
+
event: 'CREATE_OFFER',
|
|
45
|
+
props: args.props,
|
|
46
|
+
nums: args.nums,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
trackTransactionFailed(args: TrackTransactionFailed) {
|
|
51
|
+
this.track({
|
|
52
|
+
event: 'TRANSACTION_FAILED',
|
|
53
|
+
props: args,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export const useAnalytics = () => {
|
|
59
|
+
const config = useConfig();
|
|
60
|
+
return new DatabeatAnalytics('https://databeat.sequence.app', {
|
|
61
|
+
jwt: config.projectAccessKey,
|
|
62
|
+
});
|
|
63
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { MarketplaceKind, OrderbookKind } from '../api';
|
|
2
|
+
|
|
3
|
+
export enum EventType {
|
|
4
|
+
BUY_ITEMS = 0,
|
|
5
|
+
SELL_ITEMS = 1,
|
|
6
|
+
CREATE_LISTING = 2,
|
|
7
|
+
CREATE_OFFER = 3,
|
|
8
|
+
CANCEL_LISTING = 4,
|
|
9
|
+
CANCEL_OFFER = 5,
|
|
10
|
+
TRANSACTION_FAILED = 6,
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface PropsEvent {
|
|
14
|
+
[key: string]: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface NumsEvent {
|
|
18
|
+
[key: string]: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
interface Transaction extends PropsEvent {
|
|
22
|
+
chainId: string;
|
|
23
|
+
txnHash: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface TradeItemsInfo extends PropsEvent {
|
|
27
|
+
marketplaceKind: MarketplaceKind;
|
|
28
|
+
collectionAddress: string;
|
|
29
|
+
currencyAddress: string;
|
|
30
|
+
currencySymbol: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
interface TradeItemsValues extends NumsEvent {
|
|
34
|
+
currencyValueDecimal: number;
|
|
35
|
+
currencyValueRaw: number;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface TrackBuyItems {
|
|
39
|
+
props: TradeItemsInfo & Transaction;
|
|
40
|
+
nums: TradeItemsValues;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface TrackSellItems {
|
|
44
|
+
props: TradeItemsInfo & Transaction;
|
|
45
|
+
nums: TradeItemsValues;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
interface ListOfferItemsInfo extends PropsEvent {
|
|
49
|
+
orderbookKind: OrderbookKind;
|
|
50
|
+
collectionAddress: string;
|
|
51
|
+
currencyAddress: string;
|
|
52
|
+
currencySymbol: string;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
interface ListOfferItemsValues extends NumsEvent {
|
|
56
|
+
currencyValueDecimal: number;
|
|
57
|
+
currencyValueRaw: number;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface TrackCreateListing {
|
|
61
|
+
props: ListOfferItemsInfo & Transaction;
|
|
62
|
+
nums: ListOfferItemsValues;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface TrackCreateOffer {
|
|
66
|
+
props: ListOfferItemsInfo & Transaction;
|
|
67
|
+
nums: ListOfferItemsValues;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface TrackTransactionFailed extends Transaction, PropsEvent {}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { waitFor } from '@testing-library/react';
|
|
2
|
+
import { http, HttpResponse } from 'msw';
|
|
3
|
+
import { zeroAddress } from 'viem';
|
|
4
|
+
import { describe, expect, it } from 'vitest';
|
|
5
|
+
import {
|
|
6
|
+
mockCollectibleOrder,
|
|
7
|
+
mockMarketplaceEndpoint,
|
|
8
|
+
} from '../../_internal/api/__mocks__/marketplace.msw';
|
|
9
|
+
import { OrderSide } from '../../_internal/api/marketplace.gen';
|
|
10
|
+
import { renderHook } from '../../_internal/test-utils';
|
|
11
|
+
import { server } from '../../_internal/test/setup';
|
|
12
|
+
import { useListCollectiblesPaginated } from '../useListCollectiblesPaginated';
|
|
13
|
+
import type { UseListCollectiblesPaginatedArgs } from '../useListCollectiblesPaginated';
|
|
14
|
+
|
|
15
|
+
describe('useListCollectiblesPaginated', () => {
|
|
16
|
+
const defaultArgs: UseListCollectiblesPaginatedArgs = {
|
|
17
|
+
chainId: '1',
|
|
18
|
+
collectionAddress: zeroAddress,
|
|
19
|
+
side: OrderSide.listing,
|
|
20
|
+
query: {
|
|
21
|
+
enabled: true,
|
|
22
|
+
page: 1,
|
|
23
|
+
pageSize: 30,
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
it('should fetch collectibles successfully', async () => {
|
|
28
|
+
// Set up mock response
|
|
29
|
+
server.use(
|
|
30
|
+
http.post(mockMarketplaceEndpoint('ListCollectibles'), () => {
|
|
31
|
+
return HttpResponse.json({
|
|
32
|
+
collectibles: [mockCollectibleOrder],
|
|
33
|
+
page: { page: 1, pageSize: 30, more: false },
|
|
34
|
+
});
|
|
35
|
+
}),
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
const { result } = renderHook(() =>
|
|
39
|
+
useListCollectiblesPaginated(defaultArgs),
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
// Wait for the query to complete
|
|
43
|
+
await waitFor(() => {
|
|
44
|
+
expect(result.current.isSuccess).toBe(true);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// Verify the data
|
|
48
|
+
expect(result.current.data?.collectibles).toEqual([mockCollectibleOrder]);
|
|
49
|
+
expect(result.current.data?.page).toEqual({
|
|
50
|
+
page: 1,
|
|
51
|
+
pageSize: 30,
|
|
52
|
+
more: false,
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('should handle error states', async () => {
|
|
57
|
+
// Override the handler to return an error
|
|
58
|
+
server.use(
|
|
59
|
+
http.post(mockMarketplaceEndpoint('ListCollectibles'), () => {
|
|
60
|
+
return HttpResponse.json(
|
|
61
|
+
{ error: { message: 'Failed to fetch collectibles' } },
|
|
62
|
+
{ status: 500 },
|
|
63
|
+
);
|
|
64
|
+
}),
|
|
65
|
+
);
|
|
66
|
+
|
|
67
|
+
const { result } = renderHook(() =>
|
|
68
|
+
useListCollectiblesPaginated(defaultArgs),
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
// Wait for the error state
|
|
72
|
+
await waitFor(() => {
|
|
73
|
+
expect(result.current.isError).toBe(true);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
expect(result.current.error).toBeDefined();
|
|
77
|
+
expect(result.current.data).toBeUndefined();
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('should handle pagination correctly', async () => {
|
|
81
|
+
// Set up mock response for page 2
|
|
82
|
+
const modifiedCollectibleOrder = {
|
|
83
|
+
...mockCollectibleOrder,
|
|
84
|
+
metadata: {
|
|
85
|
+
...mockCollectibleOrder.metadata,
|
|
86
|
+
tokenId: '2',
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
server.use(
|
|
91
|
+
http.post(mockMarketplaceEndpoint('ListCollectibles'), () => {
|
|
92
|
+
return HttpResponse.json({
|
|
93
|
+
collectibles: [modifiedCollectibleOrder],
|
|
94
|
+
page: { page: 2, pageSize: 20, more: false },
|
|
95
|
+
});
|
|
96
|
+
}),
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
const paginatedArgs: UseListCollectiblesPaginatedArgs = {
|
|
100
|
+
...defaultArgs,
|
|
101
|
+
query: {
|
|
102
|
+
enabled: true,
|
|
103
|
+
page: 2,
|
|
104
|
+
pageSize: 20,
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const { result } = renderHook(() =>
|
|
109
|
+
useListCollectiblesPaginated(paginatedArgs),
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
// Wait for the query to complete
|
|
113
|
+
await waitFor(() => {
|
|
114
|
+
expect(result.current.isSuccess).toBe(true);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
// Verify the data for page 2
|
|
118
|
+
expect(result.current.data?.collectibles[0].metadata.tokenId).toBe('2');
|
|
119
|
+
expect(result.current.data?.page).toEqual({
|
|
120
|
+
page: 2,
|
|
121
|
+
pageSize: 20,
|
|
122
|
+
more: false,
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('should refetch when args change', async () => {
|
|
127
|
+
// Set up initial mock response
|
|
128
|
+
server.use(
|
|
129
|
+
http.post(mockMarketplaceEndpoint('ListCollectibles'), () => {
|
|
130
|
+
return HttpResponse.json({
|
|
131
|
+
collectibles: [mockCollectibleOrder],
|
|
132
|
+
page: { page: 1, pageSize: 30, more: true },
|
|
133
|
+
});
|
|
134
|
+
}),
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
let currentArgs = defaultArgs;
|
|
138
|
+
const { result, rerender } = renderHook(() =>
|
|
139
|
+
useListCollectiblesPaginated(currentArgs),
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
// Wait for initial data
|
|
143
|
+
await waitFor(() => {
|
|
144
|
+
expect(result.current.isSuccess).toBe(true);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
// Change args and rerender
|
|
148
|
+
currentArgs = {
|
|
149
|
+
...defaultArgs,
|
|
150
|
+
query: {
|
|
151
|
+
...defaultArgs.query,
|
|
152
|
+
page: 2,
|
|
153
|
+
},
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
// Set up mock response for page 2
|
|
157
|
+
const modifiedCollectibleOrder = {
|
|
158
|
+
...mockCollectibleOrder,
|
|
159
|
+
metadata: {
|
|
160
|
+
...mockCollectibleOrder.metadata,
|
|
161
|
+
tokenId: '2',
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
server.use(
|
|
166
|
+
http.post(mockMarketplaceEndpoint('ListCollectibles'), () => {
|
|
167
|
+
return HttpResponse.json({
|
|
168
|
+
collectibles: [modifiedCollectibleOrder],
|
|
169
|
+
page: { page: 2, pageSize: 30, more: false },
|
|
170
|
+
});
|
|
171
|
+
}),
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
rerender();
|
|
175
|
+
|
|
176
|
+
// Wait for new data
|
|
177
|
+
await waitFor(() => {
|
|
178
|
+
expect(result.current.data?.page?.page).toBe(2);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
// Verify new data
|
|
182
|
+
expect(result.current.data?.collectibles[0].metadata.tokenId).toBe('2');
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it('should not fetch when enabled is false', async () => {
|
|
186
|
+
// Set up a mock handler to ensure no requests are made
|
|
187
|
+
let requestMade = false;
|
|
188
|
+
server.use(
|
|
189
|
+
http.post(mockMarketplaceEndpoint('ListCollectibles'), () => {
|
|
190
|
+
requestMade = true;
|
|
191
|
+
return HttpResponse.json({
|
|
192
|
+
collectibles: [mockCollectibleOrder],
|
|
193
|
+
page: { page: 1, pageSize: 30, more: false },
|
|
194
|
+
});
|
|
195
|
+
}),
|
|
196
|
+
);
|
|
197
|
+
|
|
198
|
+
const disabledArgs: UseListCollectiblesPaginatedArgs = {
|
|
199
|
+
...defaultArgs,
|
|
200
|
+
query: {
|
|
201
|
+
enabled: false,
|
|
202
|
+
page: 1,
|
|
203
|
+
pageSize: 30,
|
|
204
|
+
},
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
const { result } = renderHook(() =>
|
|
208
|
+
useListCollectiblesPaginated(disabledArgs),
|
|
209
|
+
);
|
|
210
|
+
|
|
211
|
+
// For disabled queries, we expect no loading state and no data
|
|
212
|
+
expect(result.current.isLoading).toBe(false);
|
|
213
|
+
expect(result.current.data).toBeUndefined();
|
|
214
|
+
expect(result.current.error).toBeNull();
|
|
215
|
+
expect(requestMade).toBe(false);
|
|
216
|
+
});
|
|
217
|
+
});
|
package/src/react/hooks/index.ts
CHANGED
|
@@ -13,6 +13,7 @@ export * from './useHighestOffer';
|
|
|
13
13
|
export * from './useListBalances';
|
|
14
14
|
export * from './useListCollectibleActivities';
|
|
15
15
|
export * from './useListCollectibles';
|
|
16
|
+
export * from './useListCollectiblesPaginated';
|
|
16
17
|
export * from './useListCollectionActivities';
|
|
17
18
|
export * from './useListOffersForCollectible';
|
|
18
19
|
export * from './useCountOffersForCollectible';
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import type { PropertyFilter } from '@0xsequence/metadata';
|
|
1
2
|
import { queryOptions, useQuery } from '@tanstack/react-query';
|
|
2
3
|
import { z } from 'zod';
|
|
3
4
|
import { FilterCondition, type SdkConfig } from '../../types';
|
|
5
|
+
import { compareAddress } from '../../utils';
|
|
4
6
|
import {
|
|
5
7
|
AddressSchema,
|
|
6
8
|
ChainIdSchema,
|
|
@@ -11,8 +13,6 @@ import {
|
|
|
11
13
|
} from '../_internal';
|
|
12
14
|
import { useConfig } from './useConfig';
|
|
13
15
|
import { marketplaceConfigOptions } from './useMarketplaceConfig';
|
|
14
|
-
import { compareAddress } from '../../utils';
|
|
15
|
-
import type { PropertyFilter } from '@0xsequence/metadata';
|
|
16
16
|
|
|
17
17
|
const UseFiltersSchema = z.object({
|
|
18
18
|
chainId: ChainIdSchema.pipe(z.coerce.string()),
|
|
@@ -45,7 +45,13 @@ export const fetchFilters = async (args: UseFiltersArgs, config: SdkConfig) => {
|
|
|
45
45
|
compareAddress(c.address, parsedArgs.collectionAddress),
|
|
46
46
|
)?.filterSettings;
|
|
47
47
|
|
|
48
|
-
if (
|
|
48
|
+
if (
|
|
49
|
+
!collectionFilters?.exclusions ||
|
|
50
|
+
collectionFilters.exclusions.length === 0 ||
|
|
51
|
+
!collectionFilters.filterOrder ||
|
|
52
|
+
collectionFilters.filterOrder.length === 0
|
|
53
|
+
)
|
|
54
|
+
return filters;
|
|
49
55
|
|
|
50
56
|
const { filterOrder, exclusions } = collectionFilters;
|
|
51
57
|
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { queryOptions, useQuery } from '@tanstack/react-query';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import type { Page, SdkConfig } from '../../types';
|
|
4
|
+
import {
|
|
5
|
+
AddressSchema,
|
|
6
|
+
ChainIdSchema,
|
|
7
|
+
type ListCollectiblesArgs,
|
|
8
|
+
collectableKeys,
|
|
9
|
+
getMarketplaceClient,
|
|
10
|
+
} from '../_internal';
|
|
11
|
+
import { listCollectiblesArgsSchema } from '../_internal/api/zod-schema';
|
|
12
|
+
import { useConfig } from './useConfig';
|
|
13
|
+
|
|
14
|
+
const UseListCollectiblesPaginatedArgsSchema = listCollectiblesArgsSchema
|
|
15
|
+
.omit({
|
|
16
|
+
contractAddress: true,
|
|
17
|
+
})
|
|
18
|
+
.extend({
|
|
19
|
+
collectionAddress: AddressSchema,
|
|
20
|
+
chainId: ChainIdSchema.pipe(z.coerce.string()),
|
|
21
|
+
query: z
|
|
22
|
+
.object({
|
|
23
|
+
enabled: z.boolean().optional(),
|
|
24
|
+
page: z.number().optional().default(1),
|
|
25
|
+
pageSize: z.number().optional().default(30),
|
|
26
|
+
})
|
|
27
|
+
.optional()
|
|
28
|
+
.default({}),
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export type UseListCollectiblesPaginatedArgs = z.infer<
|
|
32
|
+
typeof UseListCollectiblesPaginatedArgsSchema
|
|
33
|
+
>;
|
|
34
|
+
|
|
35
|
+
export type UseListCollectiblesPaginatedReturn = Awaited<
|
|
36
|
+
ReturnType<typeof fetchCollectiblesPaginated>
|
|
37
|
+
>;
|
|
38
|
+
|
|
39
|
+
const fetchCollectiblesPaginated = async (
|
|
40
|
+
args: UseListCollectiblesPaginatedArgs,
|
|
41
|
+
marketplaceClient: Awaited<ReturnType<typeof getMarketplaceClient>>,
|
|
42
|
+
) => {
|
|
43
|
+
const parsedArgs = UseListCollectiblesPaginatedArgsSchema.parse(args);
|
|
44
|
+
const page: Page = {
|
|
45
|
+
page: parsedArgs.query?.page ?? 1,
|
|
46
|
+
pageSize: parsedArgs.query?.pageSize ?? 30,
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const arg = {
|
|
50
|
+
...parsedArgs,
|
|
51
|
+
contractAddress: parsedArgs.collectionAddress,
|
|
52
|
+
page,
|
|
53
|
+
} as ListCollectiblesArgs;
|
|
54
|
+
|
|
55
|
+
return marketplaceClient.listCollectibles(arg);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const listCollectiblesPaginatedOptions = (
|
|
59
|
+
args: UseListCollectiblesPaginatedArgs,
|
|
60
|
+
config: SdkConfig,
|
|
61
|
+
) => {
|
|
62
|
+
const marketplaceClient = getMarketplaceClient(
|
|
63
|
+
args.chainId as string,
|
|
64
|
+
config,
|
|
65
|
+
);
|
|
66
|
+
return queryOptions({
|
|
67
|
+
queryKey: [...collectableKeys.lists, 'paginated', args],
|
|
68
|
+
queryFn: () => fetchCollectiblesPaginated(args, marketplaceClient),
|
|
69
|
+
enabled: args.query?.enabled ?? true,
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export const useListCollectiblesPaginated = (
|
|
74
|
+
args: UseListCollectiblesPaginatedArgs,
|
|
75
|
+
) => {
|
|
76
|
+
const config = useConfig();
|
|
77
|
+
return useQuery(listCollectiblesPaginatedOptions(args, config));
|
|
78
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Observable } from '@legendapp/state';
|
|
2
|
-
import type
|
|
2
|
+
import { type Address, type Hex, formatUnits } from 'viem';
|
|
3
3
|
import type { OrderbookKind } from '../../../../../types';
|
|
4
4
|
import {
|
|
5
5
|
ExecuteType,
|
|
@@ -10,17 +10,21 @@ import {
|
|
|
10
10
|
collectableKeys,
|
|
11
11
|
getMarketplaceClient,
|
|
12
12
|
} from '../../../../_internal';
|
|
13
|
+
import { useAnalytics } from '../../../../_internal/databeat';
|
|
13
14
|
import { TransactionType } from '../../../../_internal/types';
|
|
14
15
|
import type { ListingInput } from '../../../../_internal/types';
|
|
15
|
-
import { useWallet } from '../../../../_internal/wallet/useWallet';
|
|
16
16
|
import type {
|
|
17
17
|
SignatureStep,
|
|
18
18
|
TransactionStep as WalletTransactionStep,
|
|
19
19
|
} from '../../../../_internal/utils';
|
|
20
|
-
import {
|
|
20
|
+
import { useWallet } from '../../../../_internal/wallet/useWallet';
|
|
21
|
+
import {
|
|
22
|
+
useConfig,
|
|
23
|
+
useCurrencies,
|
|
24
|
+
useGenerateListingTransaction,
|
|
25
|
+
} from '../../../../hooks';
|
|
21
26
|
import { useTransactionStatusModal } from '../../_internal/components/transactionStatusModal';
|
|
22
27
|
import type { ModalCallbacks } from '../../_internal/types';
|
|
23
|
-
|
|
24
28
|
interface UseTransactionStepsArgs {
|
|
25
29
|
listingInput: ListingInput;
|
|
26
30
|
chainId: string;
|
|
@@ -44,7 +48,11 @@ export const useTransactionSteps = ({
|
|
|
44
48
|
const expiry = new Date(Number(listingInput.listing.expiry) * 1000);
|
|
45
49
|
const { show: showTransactionStatusModal } = useTransactionStatusModal();
|
|
46
50
|
const sdkConfig = useConfig();
|
|
51
|
+
const { data: currencies } = useCurrencies({
|
|
52
|
+
chainId: Number(chainId),
|
|
53
|
+
});
|
|
47
54
|
const marketplaceClient = getMarketplaceClient(chainId, sdkConfig);
|
|
55
|
+
const analytics = useAnalytics();
|
|
48
56
|
const { generateListingTransactionAsync, isPending: generatingSteps } =
|
|
49
57
|
useGenerateListingTransaction({
|
|
50
58
|
chainId,
|
|
@@ -164,6 +172,34 @@ export const useTransactionSteps = ({
|
|
|
164
172
|
steps$.transaction.isExecuting.set(false);
|
|
165
173
|
steps$.transaction.exist.set(false);
|
|
166
174
|
}
|
|
175
|
+
|
|
176
|
+
if (hash || orderId) {
|
|
177
|
+
const currencyDecimal =
|
|
178
|
+
currencies?.find(
|
|
179
|
+
(currency) =>
|
|
180
|
+
currency.contractAddress === listingInput.listing.currencyAddress,
|
|
181
|
+
)?.decimals || 0;
|
|
182
|
+
|
|
183
|
+
const currencyValueRaw = Number(listingInput.listing.pricePerToken);
|
|
184
|
+
const currencyValueDecimal = Number(
|
|
185
|
+
formatUnits(BigInt(currencyValueRaw), currencyDecimal),
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
analytics.trackCreateListing({
|
|
189
|
+
props: {
|
|
190
|
+
orderbookKind,
|
|
191
|
+
collectionAddress,
|
|
192
|
+
currencyAddress: listingInput.listing.currencyAddress,
|
|
193
|
+
currencySymbol: '',
|
|
194
|
+
chainId,
|
|
195
|
+
txnHash: hash || '',
|
|
196
|
+
},
|
|
197
|
+
nums: {
|
|
198
|
+
currencyValueDecimal,
|
|
199
|
+
currencyValueRaw,
|
|
200
|
+
},
|
|
201
|
+
});
|
|
202
|
+
}
|
|
167
203
|
} catch (error) {
|
|
168
204
|
steps$.transaction.isExecuting.set(false);
|
|
169
205
|
steps$.transaction.exist.set(false);
|