@0xsequence/marketplace-sdk 0.0.1 → 0.2.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/.ctirc +32 -0
- package/dist/{chunk-TZGLKJRF.js → chunk-4E34HVSA.js} +2 -2
- package/dist/chunk-5EOVZAKT.js +1325 -0
- package/dist/chunk-5EOVZAKT.js.map +1 -0
- package/dist/{chunk-RNUHUVLC.js → chunk-6JWGELXL.js} +1 -1
- package/dist/chunk-6JWGELXL.js.map +1 -0
- package/dist/{chunk-4PFMUVE4.js → chunk-CSN7YD5Q.js} +2 -2
- package/dist/chunk-CSN7YD5Q.js.map +1 -0
- package/dist/{chunk-G3D572BT.js → chunk-FCQCNLFZ.js} +24 -1
- package/dist/chunk-FCQCNLFZ.js.map +1 -0
- package/dist/{chunk-HGBEC3WX.js → chunk-GZIA25G4.js} +1 -1
- package/dist/chunk-GZIA25G4.js.map +1 -0
- package/dist/{chunk-QOJXWHRZ.js → chunk-LFQB477Y.js} +3 -1
- package/dist/chunk-LFQB477Y.js.map +1 -0
- package/dist/{chunk-SM7V6ZWI.js → chunk-MD4JHPMH.js} +493 -418
- package/dist/chunk-MD4JHPMH.js.map +1 -0
- package/dist/{chunk-EDTC7UES.js → chunk-NII6JJGH.js} +9 -4
- package/dist/chunk-NII6JJGH.js.map +1 -0
- package/dist/{chunk-BBB3XUB4.js → chunk-PE2LLUTJ.js} +1 -1
- package/dist/chunk-PE2LLUTJ.js.map +1 -0
- package/dist/chunk-Q2BVDQ3G.js +41 -0
- package/dist/chunk-Q2BVDQ3G.js.map +1 -0
- package/dist/{chunk-3TYUQEFM.js → chunk-VEX7FDL6.js} +2 -2
- package/dist/chunk-VEX7FDL6.js.map +1 -0
- package/dist/{create-config-Dz0gCiQ0.d.ts → create-config-CgtmCzvb.d.ts} +2 -2
- package/dist/index.css +4 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +4 -4
- package/dist/{marketplace-config-DZbtyrma.d.ts → marketplace-config-Bbxl-uKX.d.ts} +2 -1
- package/dist/react/_internal/api/index.d.ts +1 -1
- package/dist/react/_internal/api/index.js +1 -1
- package/dist/react/_internal/index.d.ts +5 -4
- package/dist/react/_internal/index.js +16 -8
- 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 +1691 -103
- package/dist/react/hooks/index.js +34 -22
- package/dist/react/index.css +4 -1
- package/dist/react/index.css.map +1 -1
- package/dist/react/index.d.ts +7 -6
- package/dist/react/index.js +43 -31
- package/dist/react/ssr/index.d.ts +26 -25
- package/dist/react/ssr/index.js +34 -4
- package/dist/react/ssr/index.js.map +1 -1
- package/dist/react/ui/icons/index.js +2 -2
- package/dist/react/ui/index.css +4 -1
- package/dist/react/ui/index.css.map +1 -1
- package/dist/react/ui/index.d.ts +47 -42
- package/dist/react/ui/index.js +10 -10
- package/dist/react/ui/modals/_internal/components/actionModal/index.js +4 -4
- package/dist/{services-BIwQ1C1c.d.ts → services-Dei25J6_.d.ts} +1 -1
- package/dist/styles/index.css +4 -1
- package/dist/styles/index.css.map +1 -1
- package/dist/styles/index.d.ts +2 -1
- package/dist/styles/index.js +4 -4973
- package/dist/styles/index.js.map +1 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/types/index.js +3 -3
- package/dist/types-BzZVURNL.d.ts +19 -0
- package/dist/utils/abi/clients/index.js +1 -1
- package/dist/utils/index.d.ts +2 -1
- package/dist/utils/index.js +2 -2
- package/package.json +19 -25
- package/src/react/_internal/api/marketplace.gen.ts +4 -1
- package/src/react/_internal/api/zod-schema.ts +636 -0
- package/src/react/_internal/types.ts +33 -9
- package/src/react/_internal/wagmi/create-config.ts +9 -3
- package/src/react/_internal/wagmi/embedded.ts +1 -1
- package/src/react/_internal/wagmi/universal.ts +1 -1
- package/src/react/hooks/index.ts +3 -0
- package/src/react/hooks/options/marketplaceConfigOptions.ts +2 -2
- package/src/react/hooks/useBalanceOfCollectible.tsx +47 -21
- package/src/react/hooks/useCheckoutOptions.tsx +63 -0
- package/src/react/hooks/useCollectible.tsx +20 -14
- package/src/react/hooks/useCollection.tsx +18 -12
- package/src/react/hooks/useCountOfCollectables.tsx +77 -0
- package/src/react/hooks/useCurrencies.tsx +67 -56
- package/src/react/hooks/useFilters.tsx +18 -12
- package/src/react/hooks/useFloorOrder.tsx +24 -9
- package/src/react/hooks/useGenerateListingTransaction.tsx +8 -7
- package/src/react/hooks/useGenerateOfferTransaction.tsx +5 -5
- package/src/react/hooks/useGenerateSellTransaction.tsx +19 -12
- package/src/react/hooks/useHighestOffer.tsx +26 -16
- package/src/react/hooks/useListBalances.tsx +60 -29
- package/src/react/hooks/useListCollectibles.tsx +28 -15
- package/src/react/hooks/useListOffersForCollectible.tsx +17 -8
- package/src/react/hooks/useLowestListing.tsx +26 -17
- package/src/react/hooks/useRoyaltyPercentage.tsx +18 -8
- package/src/react/hooks/useTransferTokens.tsx +3 -3
- package/src/react/provider.tsx +1 -1
- package/src/react/ssr/create-ssr-client.ts +1 -1
- package/src/react/ui/modals/CreateListingModal/_store.ts +39 -40
- package/src/react/ui/modals/CreateListingModal/index.tsx +152 -130
- package/src/react/ui/modals/MakeOfferModal/_store.ts +38 -43
- package/src/react/ui/modals/MakeOfferModal/index.tsx +39 -28
- package/src/react/ui/modals/SellModal/_store.ts +59 -57
- package/src/react/ui/modals/SellModal/index.tsx +34 -12
- package/src/react/ui/modals/SuccessfulPurchaseModal/_store.ts +1 -1
- package/src/react/ui/modals/SuccessfulPurchaseModal/index.tsx +14 -14
- package/src/react/ui/modals/TransferModal/_store.ts +11 -11
- package/src/react/ui/modals/TransferModal/_views/enterWalletAddress/index.tsx +92 -89
- package/src/react/ui/modals/TransferModal/_views/enterWalletAddress/useHandleTransfer.tsx +114 -0
- package/src/react/ui/modals/TransferModal/_views/followWalletInstructions/index.tsx +0 -96
- package/src/react/ui/modals/TransferModal/index.tsx +24 -3
- package/src/react/ui/modals/_internal/components/actionModal/ActionModal.tsx +1 -1
- package/src/react/ui/modals/_internal/components/currencyOptionsSelect/index.tsx +4 -4
- package/src/react/ui/modals/_internal/components/floorPriceText/index.tsx +4 -3
- package/src/react/ui/modals/_internal/components/priceInput/index.tsx +55 -12
- package/src/react/ui/modals/_internal/components/priceInput/styles.css.ts +4 -0
- package/src/react/ui/modals/_internal/components/quantityInput/index.tsx +3 -2
- package/src/react/ui/modals/_internal/components/switchChainModal/index.tsx +4 -4
- package/src/react/ui/modals/_internal/components/switchChainModal/store.ts +4 -4
- package/src/react/ui/modals/_internal/components/tokenPreview/index.tsx +3 -2
- package/src/react/ui/modals/_internal/components/transactionDetails/index.tsx +7 -5
- package/src/react/ui/modals/_internal/components/transactionPreview/index.tsx +6 -6
- package/src/react/ui/modals/_internal/components/transactionStatusModal/index.tsx +47 -14
- package/src/react/ui/modals/_internal/components/transactionStatusModal/store.ts +14 -6
- package/src/types/api-types.ts +2 -2
- package/src/types/callbacks.ts +51 -0
- package/src/types/marketplace-config.ts +2 -1
- package/src/types/types.ts +1 -1
- package/src/utils/get-public-rpc-client.ts +1 -1
- package/tsconfig.json +24 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/tsup.config.ts +35 -0
- package/README.md +0 -8
- package/dist/chunk-3TYUQEFM.js.map +0 -1
- package/dist/chunk-4PFMUVE4.js.map +0 -1
- package/dist/chunk-BBB3XUB4.js.map +0 -1
- package/dist/chunk-EDTC7UES.js.map +0 -1
- package/dist/chunk-G3D572BT.js.map +0 -1
- package/dist/chunk-HGBEC3WX.js.map +0 -1
- package/dist/chunk-QOJXWHRZ.js.map +0 -1
- package/dist/chunk-RNUHUVLC.js.map +0 -1
- package/dist/chunk-SM7V6ZWI.js.map +0 -1
- package/dist/chunk-STO74F2I.js +0 -14
- package/dist/chunk-STO74F2I.js.map +0 -1
- package/dist/chunk-VPGWEMWL.js +0 -162
- package/dist/chunk-VPGWEMWL.js.map +0 -1
- package/dist/chunk-ZE2LNX65.js +0 -394
- package/dist/chunk-ZE2LNX65.js.map +0 -1
- package/dist/types-BrAQ8-w4.d.ts +0 -12
- package/src/react/hooks/useCollectionCounts.tsx +0 -61
- /package/dist/{chunk-TZGLKJRF.js.map → chunk-4E34HVSA.js.map} +0 -0
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import { useMutation } from '@tanstack/react-query';
|
|
2
|
+
import type { SdkConfig } from '../../types';
|
|
1
3
|
import {
|
|
2
4
|
type ChainId,
|
|
5
|
+
type CreateReq,
|
|
3
6
|
type GenerateOfferTransactionArgs,
|
|
7
|
+
type Step,
|
|
4
8
|
getMarketplaceClient,
|
|
5
|
-
} from '
|
|
6
|
-
import { useMutation } from '@tanstack/react-query';
|
|
7
|
-
import type { SdkConfig, Step } from '@types';
|
|
9
|
+
} from '../_internal';
|
|
8
10
|
import { useConfig } from './useConfig';
|
|
9
11
|
|
|
10
12
|
export type UseGenerateOfferTransactionArgs = {
|
|
@@ -12,8 +14,6 @@ export type UseGenerateOfferTransactionArgs = {
|
|
|
12
14
|
onSuccess?: (data?: Step[]) => void;
|
|
13
15
|
};
|
|
14
16
|
|
|
15
|
-
import type { CreateReq } from '@types';
|
|
16
|
-
|
|
17
17
|
type CreateReqWithDateExpiry = Omit<CreateReq, 'expiry'> & {
|
|
18
18
|
expiry: Date;
|
|
19
19
|
};
|
|
@@ -1,27 +1,34 @@
|
|
|
1
|
+
import { useMutation } from '@tanstack/react-query';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import type { SdkConfig } from '../../types';
|
|
1
4
|
import {
|
|
2
5
|
type ChainId,
|
|
6
|
+
ChainIdSchema,
|
|
3
7
|
type GenerateSellTransactionArgs,
|
|
4
8
|
getMarketplaceClient,
|
|
5
|
-
} from '
|
|
6
|
-
import {
|
|
7
|
-
import type { SdkConfig } from '@types';
|
|
9
|
+
} from '../_internal';
|
|
10
|
+
import { stepSchema } from '../_internal/api/zod-schema';
|
|
8
11
|
import { useConfig } from './useConfig';
|
|
9
12
|
|
|
10
|
-
|
|
11
|
-
chainId:
|
|
12
|
-
onSuccess
|
|
13
|
-
};
|
|
13
|
+
const UserGeneratSellTransactionArgsSchema = z.object({
|
|
14
|
+
chainId: ChainIdSchema.pipe(z.coerce.string()),
|
|
15
|
+
onSuccess: z.function().args(stepSchema.array().optional()).optional(),
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
type UseGenerateSellTransactionArgs = z.infer<
|
|
19
|
+
typeof UserGeneratSellTransactionArgsSchema
|
|
20
|
+
>;
|
|
14
21
|
|
|
15
22
|
export const generateSellTransaction = async (
|
|
16
23
|
args: GenerateSellTransactionArgs,
|
|
17
24
|
config: SdkConfig,
|
|
18
25
|
chainId: ChainId,
|
|
19
26
|
) => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
27
|
+
const parsedChainId = ChainIdSchema.pipe(z.coerce.string()).parse(chainId);
|
|
28
|
+
const marketplaceClient = getMarketplaceClient(parsedChainId, config);
|
|
29
|
+
return marketplaceClient
|
|
30
|
+
.generateSellTransaction(args)
|
|
31
|
+
.then((data) => data.steps);
|
|
25
32
|
};
|
|
26
33
|
|
|
27
34
|
export const useGenerateSellTransaction = (
|
|
@@ -1,31 +1,41 @@
|
|
|
1
|
+
import { queryOptions, useQuery } from '@tanstack/react-query';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import type { SdkConfig } from '../../types';
|
|
1
4
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
5
|
+
AddressSchema,
|
|
6
|
+
ChainIdSchema,
|
|
7
|
+
QueryArgSchema,
|
|
4
8
|
collectableKeys,
|
|
5
9
|
getMarketplaceClient,
|
|
6
|
-
} from '
|
|
7
|
-
import {
|
|
8
|
-
import type { SdkConfig } from '@types';
|
|
10
|
+
} from '../_internal';
|
|
11
|
+
import { getCollectibleHighestOfferArgsSchema } from '../_internal/api/zod-schema';
|
|
9
12
|
import { useConfig } from './useConfig';
|
|
10
13
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
const UseHighestOfferArgsSchema = getCollectibleHighestOfferArgsSchema
|
|
15
|
+
.omit({
|
|
16
|
+
contractAddress: true,
|
|
17
|
+
})
|
|
18
|
+
.extend({
|
|
19
|
+
collectionAddress: AddressSchema,
|
|
20
|
+
chainId: ChainIdSchema.pipe(z.coerce.string()),
|
|
21
|
+
query: QueryArgSchema,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
export type UseHighestOfferArgs = z.infer<typeof UseHighestOfferArgsSchema>;
|
|
18
25
|
|
|
19
|
-
export type UseHighestOfferReturn =
|
|
26
|
+
export type UseHighestOfferReturn = Awaited<
|
|
27
|
+
ReturnType<typeof fetchHighestOffer>
|
|
28
|
+
>;
|
|
20
29
|
|
|
21
30
|
const fetchHighestOffer = async (
|
|
22
31
|
args: UseHighestOfferArgs,
|
|
23
32
|
config: SdkConfig,
|
|
24
33
|
) => {
|
|
25
|
-
const
|
|
34
|
+
const parsedArgs = UseHighestOfferArgsSchema.parse(args);
|
|
35
|
+
const marketplaceClient = getMarketplaceClient(parsedArgs.chainId, config);
|
|
26
36
|
return marketplaceClient.getCollectibleHighestOffer({
|
|
27
|
-
...
|
|
28
|
-
contractAddress:
|
|
37
|
+
...parsedArgs,
|
|
38
|
+
contractAddress: parsedArgs.collectionAddress,
|
|
29
39
|
});
|
|
30
40
|
};
|
|
31
41
|
|
|
@@ -1,56 +1,87 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { type Page, SortOrder } from '@0xsequence/indexer';
|
|
2
|
+
import { infiniteQueryOptions, useInfiniteQuery } from '@tanstack/react-query';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import type { SdkConfig } from '../../types';
|
|
2
5
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
6
|
+
AddressSchema,
|
|
7
|
+
ChainIdSchema,
|
|
8
|
+
QueryArgSchema,
|
|
5
9
|
balanceQueries,
|
|
6
10
|
getIndexerClient,
|
|
7
|
-
} from '
|
|
8
|
-
import { infiniteQueryOptions, useInfiniteQuery } from '@tanstack/react-query';
|
|
9
|
-
import type { SdkConfig } from '@types';
|
|
11
|
+
} from '../_internal';
|
|
10
12
|
import { useConfig } from './useConfig';
|
|
11
13
|
|
|
12
|
-
export
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
|
|
14
|
+
export const metadataOptionsSchema = z.object({
|
|
15
|
+
verifiedOnly: z.boolean().optional(),
|
|
16
|
+
unverifiedOnly: z.boolean().optional(),
|
|
17
|
+
includeContracts: z.array(z.string()).optional(),
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
const sortOrderSchema = z.nativeEnum(SortOrder);
|
|
21
|
+
|
|
22
|
+
const sortBySchema = z.object({
|
|
23
|
+
column: z.string(),
|
|
24
|
+
order: sortOrderSchema,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const pageSchema = z.object({
|
|
28
|
+
page: z.number().optional(),
|
|
29
|
+
column: z.string().optional(),
|
|
30
|
+
before: z.any().optional(),
|
|
31
|
+
after: z.any().optional(),
|
|
32
|
+
sort: z.array(sortBySchema).optional(),
|
|
33
|
+
pageSize: z.number().optional(),
|
|
34
|
+
more: z.boolean().optional(),
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const useListBalancesArgsSchema = z.object({
|
|
38
|
+
chainId: ChainIdSchema.pipe(z.coerce.number()),
|
|
39
|
+
accountAddress: AddressSchema.optional(),
|
|
40
|
+
contractAddress: AddressSchema.optional(),
|
|
41
|
+
tokenId: z.string().optional(),
|
|
42
|
+
includeMetadata: z.boolean().optional(),
|
|
43
|
+
metadataOptions: metadataOptionsSchema.optional(),
|
|
44
|
+
includeCollectionTokens: z.boolean().optional(),
|
|
45
|
+
page: pageSchema.optional(),
|
|
46
|
+
query: QueryArgSchema,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
export type UseFetchTokenBalancesReturn = Awaited<
|
|
50
|
+
ReturnType<typeof fetchBalances>
|
|
51
|
+
>;
|
|
52
|
+
|
|
53
|
+
export type UseListBalancesArgs = z.input<typeof useListBalancesArgsSchema>;
|
|
54
|
+
|
|
55
|
+
const fetchBalances = async (
|
|
56
|
+
args: UseListBalancesArgs,
|
|
27
57
|
page: Page,
|
|
28
58
|
config: SdkConfig,
|
|
29
59
|
) => {
|
|
30
|
-
const
|
|
60
|
+
const parsedArgs = useListBalancesArgsSchema.parse(args);
|
|
61
|
+
const indexerClient = getIndexerClient(parsedArgs.chainId, config);
|
|
31
62
|
|
|
32
63
|
return indexerClient.getTokenBalances({
|
|
33
|
-
...
|
|
34
|
-
tokenID:
|
|
64
|
+
...parsedArgs,
|
|
65
|
+
tokenID: parsedArgs.tokenId,
|
|
35
66
|
page: page,
|
|
36
67
|
});
|
|
37
68
|
};
|
|
38
69
|
|
|
39
|
-
export const
|
|
40
|
-
args:
|
|
70
|
+
export const listBalancesOptions = (
|
|
71
|
+
args: UseListBalancesArgs,
|
|
41
72
|
config: SdkConfig,
|
|
42
73
|
) => {
|
|
43
74
|
return infiniteQueryOptions({
|
|
44
75
|
...args.query,
|
|
45
76
|
queryKey: [...balanceQueries.lists, args, config],
|
|
46
77
|
queryFn: ({ pageParam }: { pageParam: Page }) =>
|
|
47
|
-
|
|
78
|
+
fetchBalances(args, pageParam, config),
|
|
48
79
|
initialPageParam: { page: 1, pageSize: 30 } as Page,
|
|
49
80
|
getNextPageParam: (lastPage) => lastPage.page.after,
|
|
50
81
|
});
|
|
51
82
|
};
|
|
52
83
|
|
|
53
|
-
export const
|
|
84
|
+
export const useListBalances = (args: UseListBalancesArgs) => {
|
|
54
85
|
const config = useConfig();
|
|
55
|
-
return useInfiniteQuery(
|
|
86
|
+
return useInfiniteQuery(listBalancesOptions(args, config));
|
|
56
87
|
};
|
|
@@ -1,32 +1,45 @@
|
|
|
1
|
+
import { infiniteQueryOptions, useInfiniteQuery } from '@tanstack/react-query';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import type { SdkConfig } from '../../types';
|
|
1
4
|
import {
|
|
2
|
-
|
|
5
|
+
AddressSchema,
|
|
6
|
+
ChainIdSchema,
|
|
3
7
|
type ListCollectiblesArgs,
|
|
4
8
|
type Page,
|
|
9
|
+
QueryArgSchema,
|
|
5
10
|
collectableKeys,
|
|
6
11
|
getMarketplaceClient,
|
|
7
|
-
} from '
|
|
8
|
-
import {
|
|
9
|
-
import type { SdkConfig } from '@types';
|
|
12
|
+
} from '../_internal';
|
|
13
|
+
import { listCollectiblesArgsSchema } from '../_internal/api/zod-schema';
|
|
10
14
|
import { useConfig } from './useConfig';
|
|
11
15
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
const UseListCollectiblesArgsSchema = listCollectiblesArgsSchema
|
|
17
|
+
.omit({
|
|
18
|
+
contractAddress: true,
|
|
19
|
+
})
|
|
20
|
+
.extend({
|
|
21
|
+
collectionAddress: AddressSchema,
|
|
22
|
+
chainId: ChainIdSchema.pipe(z.coerce.string()),
|
|
23
|
+
query: QueryArgSchema,
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export type UseListCollectiblesArgs = z.infer<
|
|
27
|
+
typeof UseListCollectiblesArgsSchema
|
|
28
|
+
>;
|
|
19
29
|
|
|
20
|
-
export type UseListCollectiblesReturn =
|
|
30
|
+
export type UseListCollectiblesReturn = Awaited<
|
|
31
|
+
ReturnType<typeof fetchCollectibles>
|
|
32
|
+
>;
|
|
21
33
|
|
|
22
34
|
const fetchCollectibles = async (
|
|
23
35
|
args: UseListCollectiblesArgs,
|
|
24
36
|
page: Page,
|
|
25
|
-
marketplaceClient: ReturnType<typeof getMarketplaceClient
|
|
37
|
+
marketplaceClient: Awaited<ReturnType<typeof getMarketplaceClient>>,
|
|
26
38
|
) => {
|
|
39
|
+
const parsedArgs = UseListCollectiblesArgsSchema.parse(args);
|
|
27
40
|
const arg = {
|
|
28
|
-
...
|
|
29
|
-
contractAddress:
|
|
41
|
+
...parsedArgs,
|
|
42
|
+
contractAddress: parsedArgs.collectionAddress,
|
|
30
43
|
page,
|
|
31
44
|
} satisfies ListCollectiblesArgs;
|
|
32
45
|
|
|
@@ -1,18 +1,27 @@
|
|
|
1
|
+
import { infiniteQueryOptions, useInfiniteQuery } from '@tanstack/react-query';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import type { SdkConfig } from '../../types';
|
|
1
4
|
import {
|
|
5
|
+
ChainIdSchema,
|
|
2
6
|
type ListOffersForCollectibleArgs,
|
|
7
|
+
type Page,
|
|
3
8
|
collectableKeys,
|
|
4
9
|
getMarketplaceClient,
|
|
5
|
-
} from '
|
|
6
|
-
import {
|
|
7
|
-
import type { Page, SdkConfig } from '@types';
|
|
10
|
+
} from '../_internal';
|
|
11
|
+
import { listOffersForCollectibleArgsSchema } from '../_internal/api/zod-schema';
|
|
8
12
|
import { useConfig } from './useConfig';
|
|
9
13
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
14
|
+
const UseListOffersForCollectibleArgsSchema =
|
|
15
|
+
listOffersForCollectibleArgsSchema.extend({
|
|
16
|
+
chainId: ChainIdSchema.pipe(z.coerce.string()),
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
type UseListOffersForCollectibleArgs = z.infer<
|
|
20
|
+
typeof UseListOffersForCollectibleArgsSchema
|
|
21
|
+
>;
|
|
13
22
|
|
|
14
|
-
export type
|
|
15
|
-
typeof fetchListOffersForCollectible
|
|
23
|
+
export type UseListOffersForCollectibleReturn = Awaited<
|
|
24
|
+
ReturnType<typeof fetchListOffersForCollectible>
|
|
16
25
|
>;
|
|
17
26
|
|
|
18
27
|
const fetchListOffersForCollectible = async (
|
|
@@ -1,32 +1,41 @@
|
|
|
1
|
+
import { queryOptions, useQuery } from '@tanstack/react-query';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import type { SdkConfig } from '../../types';
|
|
1
4
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
+
AddressSchema,
|
|
6
|
+
ChainIdSchema,
|
|
7
|
+
QueryArgSchema,
|
|
5
8
|
collectableKeys,
|
|
6
9
|
getMarketplaceClient,
|
|
7
|
-
} from '
|
|
8
|
-
import {
|
|
9
|
-
import type { SdkConfig } from '@types';
|
|
10
|
+
} from '../_internal';
|
|
11
|
+
import { getCollectibleLowestListingArgsSchema } from '../_internal/api/zod-schema';
|
|
10
12
|
import { useConfig } from './useConfig';
|
|
11
13
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
const UseLowestListingSchema = getCollectibleLowestListingArgsSchema
|
|
15
|
+
.omit({
|
|
16
|
+
contractAddress: true,
|
|
17
|
+
})
|
|
18
|
+
.extend({
|
|
19
|
+
collectionAddress: AddressSchema,
|
|
20
|
+
chainId: ChainIdSchema.pipe(z.coerce.string()),
|
|
21
|
+
query: QueryArgSchema,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
export type UseLowestListingArgs = z.infer<typeof UseLowestListingSchema>;
|
|
19
25
|
|
|
20
|
-
export type UseLowestListingReturn =
|
|
26
|
+
export type UseLowestListingReturn = Awaited<
|
|
27
|
+
ReturnType<typeof fetchLowestListing>
|
|
28
|
+
>;
|
|
21
29
|
|
|
22
30
|
const fetchLowestListing = async (
|
|
23
31
|
args: UseLowestListingArgs,
|
|
24
32
|
config: SdkConfig,
|
|
25
33
|
) => {
|
|
26
|
-
const
|
|
34
|
+
const parsedArgs = UseLowestListingSchema.parse(args);
|
|
35
|
+
const marketplaceClient = getMarketplaceClient(parsedArgs.chainId, config);
|
|
27
36
|
return marketplaceClient.getCollectibleLowestListing({
|
|
28
|
-
...
|
|
29
|
-
contractAddress:
|
|
37
|
+
...parsedArgs,
|
|
38
|
+
contractAddress: parsedArgs.collectionAddress,
|
|
30
39
|
});
|
|
31
40
|
};
|
|
32
41
|
|
|
@@ -1,21 +1,31 @@
|
|
|
1
|
-
import { type ChainId, type QueryArg, collectableKeys } from '@internal';
|
|
2
1
|
import { queryOptions, useQuery } from '@tanstack/react-query';
|
|
3
2
|
import type { Hex } from 'viem';
|
|
4
3
|
import { getContract } from 'viem';
|
|
4
|
+
import { z } from 'zod';
|
|
5
5
|
import { EIP2981_ABI } from '../../utils/abi/abi/standard/EIP2981';
|
|
6
6
|
import { getPublicRpcClient } from '../../utils/get-public-rpc-client';
|
|
7
|
+
import {
|
|
8
|
+
AddressSchema,
|
|
9
|
+
ChainIdSchema,
|
|
10
|
+
QueryArgSchema,
|
|
11
|
+
collectableKeys,
|
|
12
|
+
} from '../_internal';
|
|
7
13
|
|
|
8
|
-
|
|
9
|
-
chainId:
|
|
10
|
-
collectionAddress:
|
|
11
|
-
collectibleId: string
|
|
12
|
-
|
|
14
|
+
const UseRoyaletyPercentageSchema = z.object({
|
|
15
|
+
chainId: ChainIdSchema.pipe(z.coerce.string()),
|
|
16
|
+
collectionAddress: AddressSchema,
|
|
17
|
+
collectibleId: z.string(),
|
|
18
|
+
query: QueryArgSchema,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
type UseRoyaletyPercentageArgs = z.infer<typeof UseRoyaletyPercentageSchema>;
|
|
13
22
|
|
|
14
23
|
const fetchRoyaletyPercentage = async (args: UseRoyaletyPercentageArgs) => {
|
|
15
|
-
const
|
|
24
|
+
const parsedArgs = UseRoyaletyPercentageSchema.parse(args);
|
|
25
|
+
const publicClient = getPublicRpcClient(parsedArgs.chainId);
|
|
16
26
|
|
|
17
27
|
const contract = getContract({
|
|
18
|
-
address:
|
|
28
|
+
address: parsedArgs.collectionAddress as Hex,
|
|
19
29
|
abi: EIP2981_ABI,
|
|
20
30
|
client: publicClient,
|
|
21
31
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { ERC1155_ABI } from '../../utils';
|
|
3
|
-
import { type Abi, erc721Abi, type Address, type Hex } from 'viem';
|
|
1
|
+
import { type Abi, type Address, type Hex, erc721Abi } from 'viem';
|
|
4
2
|
import { useAccount, useWriteContract } from 'wagmi';
|
|
3
|
+
import { ERC1155_ABI } from '../../utils';
|
|
4
|
+
import type { ChainId, ContractType } from '../_internal';
|
|
5
5
|
|
|
6
6
|
interface BaseTransferParams {
|
|
7
7
|
chainId: ChainId;
|
package/src/react/provider.tsx
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { createContext } from 'react';
|
|
4
4
|
import '@0xsequence/design-system/styles.css';
|
|
5
|
-
import type { SdkConfig } from '
|
|
5
|
+
import type { SdkConfig } from '../types';
|
|
6
6
|
import { PROVIDER_ID } from './_internal/get-provider';
|
|
7
7
|
|
|
8
8
|
export const MarketplaceSdkContext = createContext({} as SdkConfig);
|
|
@@ -2,7 +2,7 @@ import { type State, cookieToInitialState } from 'wagmi';
|
|
|
2
2
|
import type { SdkConfig } from '../../types/sdk-config';
|
|
3
3
|
import { getQueryClient } from '../_internal/api/get-query-client';
|
|
4
4
|
import { createWagmiConfig } from '../_internal/wagmi/create-config';
|
|
5
|
-
import { marketplaceConfigOptions } from '../hooks/options/marketplaceConfigOptions
|
|
5
|
+
import { marketplaceConfigOptions } from '../hooks/options/marketplaceConfigOptions';
|
|
6
6
|
|
|
7
7
|
type InitSSRClientArgs = {
|
|
8
8
|
cookie: string;
|
|
@@ -1,27 +1,34 @@
|
|
|
1
1
|
import { observable, when } from '@legendapp/state';
|
|
2
2
|
import { useMount, useSelector } from '@legendapp/state/react';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import type { QueryKey } from '@tanstack/react-query';
|
|
4
|
+
import { addDays } from 'date-fns/addDays';
|
|
5
|
+
import type { Hex } from 'viem';
|
|
6
|
+
import { useAccount, useSendTransaction } from 'wagmi';
|
|
7
|
+
import type { ShowCreateListingModalArgs } from '.';
|
|
8
|
+
import type { Price } from '../../../../types';
|
|
9
|
+
import type {
|
|
10
|
+
CreateListingErrorCallbacks,
|
|
11
|
+
CreateListingSuccessCallbacks,
|
|
12
|
+
} from '../../../../types/callbacks';
|
|
5
13
|
import {
|
|
14
|
+
type CollectionType,
|
|
6
15
|
type Currency,
|
|
7
16
|
OrderbookKind,
|
|
8
|
-
type Price,
|
|
9
17
|
type Step,
|
|
10
18
|
StepType,
|
|
11
19
|
type WalletKind,
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
import
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
20
|
+
collectableKeys,
|
|
21
|
+
} from '../../../_internal';
|
|
22
|
+
import {
|
|
23
|
+
useCollectible,
|
|
24
|
+
useCollection,
|
|
25
|
+
useGenerateListingTransaction,
|
|
26
|
+
} from '../../../hooks';
|
|
18
27
|
import { useTransactionStatusModal } from '../_internal/components/transactionStatusModal';
|
|
19
28
|
import {
|
|
20
29
|
getCreateListingTransactionMessage,
|
|
21
30
|
getCreateListingTransactionTitle,
|
|
22
31
|
} from './_utils/getCreateListingTransactionTitleMessage';
|
|
23
|
-
import { useCollectible } from '@react-hooks/useCollectible';
|
|
24
|
-
import type { CollectionType } from '@internal';
|
|
25
32
|
|
|
26
33
|
export interface CreateListingModalState {
|
|
27
34
|
isOpen: boolean;
|
|
@@ -32,11 +39,12 @@ export interface CreateListingModalState {
|
|
|
32
39
|
collectionType: CollectionType | undefined;
|
|
33
40
|
listingPrice: Price;
|
|
34
41
|
quantity: string;
|
|
35
|
-
collectionAddress:
|
|
42
|
+
collectionAddress: Hex;
|
|
36
43
|
chainId: string;
|
|
37
44
|
collectibleId: string;
|
|
38
45
|
expiry: Date;
|
|
39
|
-
|
|
46
|
+
errorCallbacks?: CreateListingErrorCallbacks;
|
|
47
|
+
successCallbacks?: CreateListingSuccessCallbacks;
|
|
40
48
|
};
|
|
41
49
|
steps: {
|
|
42
50
|
isLoading: () => boolean;
|
|
@@ -62,14 +70,12 @@ export const initialState: CreateListingModalState = {
|
|
|
62
70
|
collectionAddress,
|
|
63
71
|
chainId,
|
|
64
72
|
collectibleId,
|
|
65
|
-
messages,
|
|
66
73
|
}: ShowCreateListingModalArgs) => {
|
|
67
74
|
createListingModal$.state.set({
|
|
68
75
|
...createListingModal$.state.get(),
|
|
69
76
|
collectionAddress,
|
|
70
77
|
chainId,
|
|
71
78
|
collectibleId,
|
|
72
|
-
messages,
|
|
73
79
|
});
|
|
74
80
|
createListingModal$.isOpen.set(true);
|
|
75
81
|
},
|
|
@@ -85,7 +91,7 @@ export const initialState: CreateListingModalState = {
|
|
|
85
91
|
quantity: '1',
|
|
86
92
|
expiry: new Date(addDays(new Date(), 7).toJSON()),
|
|
87
93
|
collectionType: undefined,
|
|
88
|
-
collectionAddress: '',
|
|
94
|
+
collectionAddress: '' as Hex,
|
|
89
95
|
chainId: '',
|
|
90
96
|
collectibleId: '',
|
|
91
97
|
},
|
|
@@ -165,11 +171,10 @@ export const useHydrate = () => {
|
|
|
165
171
|
|
|
166
172
|
const useTokenApprovalHandler = (chainId: string) => {
|
|
167
173
|
const { sendTransactionAsync, isPending, isSuccess } = useSendTransaction();
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
createListingModal$.state.get().messages?.approveToken || {};
|
|
174
|
+
const onError =
|
|
175
|
+
createListingModal$.state.get().errorCallbacks?.onApproveTokenError;
|
|
176
|
+
const onSuccess: (() => void) | undefined =
|
|
177
|
+
createListingModal$.state.get().successCallbacks?.onApproveTokenSuccess;
|
|
173
178
|
|
|
174
179
|
createListingModal$.steps.tokenApproval.set({
|
|
175
180
|
isNeeded: () => !!createListingModal$.steps.tokenApproval.getStep(),
|
|
@@ -180,13 +185,13 @@ const useTokenApprovalHandler = (chainId: string) => {
|
|
|
180
185
|
pending:
|
|
181
186
|
createListingModal$.steps._currentStep.get() === 'tokenApproval' &&
|
|
182
187
|
isPending,
|
|
183
|
-
execute: () => {
|
|
188
|
+
execute: async () => {
|
|
184
189
|
const step = createListingModal$.steps.tokenApproval.getStep();
|
|
185
190
|
if (!step) return;
|
|
186
191
|
createListingModal$.steps._currentStep.set('tokenApproval');
|
|
187
192
|
|
|
188
193
|
try {
|
|
189
|
-
sendTransactionAsync({
|
|
194
|
+
await sendTransactionAsync({
|
|
190
195
|
to: step.to as Hex,
|
|
191
196
|
chainId: Number(chainId),
|
|
192
197
|
data: step.data as Hex,
|
|
@@ -195,7 +200,7 @@ const useTokenApprovalHandler = (chainId: string) => {
|
|
|
195
200
|
|
|
196
201
|
onSuccess && onSuccess();
|
|
197
202
|
} catch (error) {
|
|
198
|
-
|
|
203
|
+
onError && onError(error);
|
|
199
204
|
}
|
|
200
205
|
},
|
|
201
206
|
});
|
|
@@ -209,23 +214,18 @@ const useTokenApprovalHandler = (chainId: string) => {
|
|
|
209
214
|
};
|
|
210
215
|
|
|
211
216
|
const useCreateListingHandler = (chainId: string) => {
|
|
212
|
-
const { collectibleId, collectionAddress } =
|
|
217
|
+
const { collectibleId, collectionAddress, errorCallbacks, successCallbacks } =
|
|
218
|
+
createListingModal$.state.get();
|
|
213
219
|
const { connector, address } = useAccount();
|
|
214
220
|
const {
|
|
215
221
|
generateListingTransactionAsync,
|
|
216
222
|
isPending: generateListingTransactionPending,
|
|
217
|
-
error: generateListingTransactionError,
|
|
218
223
|
} = useGenerateListingTransaction({ chainId });
|
|
219
224
|
const { data: collectible } = useCollectible({
|
|
220
225
|
chainId,
|
|
221
226
|
collectionAddress,
|
|
222
227
|
collectibleId,
|
|
223
228
|
});
|
|
224
|
-
const {
|
|
225
|
-
onUnknownError,
|
|
226
|
-
onSuccess,
|
|
227
|
-
}: { onUnknownError?: Function; onSuccess?: Function } =
|
|
228
|
-
createListingModal$.state.get().messages?.sellCollectible || {};
|
|
229
229
|
|
|
230
230
|
const { sendTransactionAsync, isPending: sendTransactionPending } =
|
|
231
231
|
useSendTransaction();
|
|
@@ -268,6 +268,8 @@ const useCreateListingHandler = (chainId: string) => {
|
|
|
268
268
|
|
|
269
269
|
createListingModal$.steps._currentStep.set(null);
|
|
270
270
|
|
|
271
|
+
createListingModal$.close();
|
|
272
|
+
|
|
271
273
|
showTransactionStatusModal({
|
|
272
274
|
hash: hash!,
|
|
273
275
|
price: createListingModal$.state.listingPrice.get(),
|
|
@@ -281,21 +283,18 @@ const useCreateListingHandler = (chainId: string) => {
|
|
|
281
283
|
collectible?.name || '',
|
|
282
284
|
),
|
|
283
285
|
type: 'transfer',
|
|
286
|
+
callbacks: {
|
|
287
|
+
onSuccess: successCallbacks?.onCreateListingSuccess,
|
|
288
|
+
onUnknownError: errorCallbacks?.onCreateListingError,
|
|
289
|
+
},
|
|
290
|
+
queriesToInvalidate: collectableKeys.all as unknown as QueryKey[],
|
|
284
291
|
});
|
|
285
|
-
|
|
286
|
-
createListingModal$.close();
|
|
287
|
-
|
|
288
|
-
onSuccess && onSuccess();
|
|
289
292
|
})
|
|
290
293
|
.catch((error) => {
|
|
291
|
-
|
|
294
|
+
errorCallbacks?.onCreateListingError?.(error);
|
|
292
295
|
});
|
|
293
296
|
},
|
|
294
297
|
});
|
|
295
|
-
|
|
296
|
-
if (generateListingTransactionError) {
|
|
297
|
-
onUnknownError && onUnknownError(generateListingTransactionError);
|
|
298
|
-
}
|
|
299
298
|
};
|
|
300
299
|
|
|
301
300
|
const useShowTransactionStatusModal = () => {
|