@0xsequence/marketplace-sdk 0.0.1 → 0.1.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/dist/chunk-7CL54NCX.js +41 -0
- package/dist/chunk-7CL54NCX.js.map +1 -0
- package/dist/{chunk-G3D572BT.js → chunk-G3YU4NQ2.js} +24 -1
- package/dist/chunk-G3YU4NQ2.js.map +1 -0
- package/dist/{chunk-SM7V6ZWI.js → chunk-GNB736ZE.js} +226 -208
- package/dist/chunk-GNB736ZE.js.map +1 -0
- package/dist/chunk-ITJEOCDV.js +1006 -0
- package/dist/chunk-ITJEOCDV.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-VPGWEMWL.js → chunk-M4MXVMAM.js} +134 -25
- package/dist/chunk-M4MXVMAM.js.map +1 -0
- package/dist/{chunk-4PFMUVE4.js → chunk-SNOEEUPZ.js} +2 -2
- package/dist/{create-config-Dz0gCiQ0.d.ts → create-config-Cto2ehcz.d.ts} +1 -1
- package/dist/index.css +4 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.js +1 -1
- package/dist/{marketplace-config-DZbtyrma.d.ts → marketplace-config-Bbxl-uKX.d.ts} +2 -1
- package/dist/react/_internal/index.d.ts +4 -3
- package/dist/react/_internal/index.js +9 -1
- package/dist/react/_internal/wagmi/index.d.ts +2 -2
- package/dist/react/hooks/index.d.ts +1363 -101
- package/dist/react/hooks/index.js +13 -7
- package/dist/react/index.css +4 -1
- package/dist/react/index.css.map +1 -1
- package/dist/react/index.d.ts +6 -5
- package/dist/react/index.js +28 -22
- package/dist/react/ssr/index.d.ts +2 -1
- package/dist/react/ssr/index.js +23 -0
- package/dist/react/ssr/index.js.map +1 -1
- package/dist/react/ui/index.css +4 -1
- package/dist/react/ui/index.css.map +1 -1
- package/dist/react/ui/index.d.ts +4 -4
- package/dist/react/ui/index.js +5 -5
- package/dist/react/ui/modals/_internal/components/actionModal/index.js +2 -2
- 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 +3 -4972
- package/dist/styles/index.js.map +1 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/types/index.js +1 -1
- package/dist/types-BzZVURNL.d.ts +19 -0
- package/dist/utils/index.d.ts +2 -1
- package/dist/utils/index.js +1 -1
- package/package.json +3 -2
- package/src/react/_internal/api/zod-schema.ts +636 -0
- package/src/react/_internal/types.ts +32 -8
- package/src/react/hooks/index.ts +1 -0
- package/src/react/hooks/useBalanceOfCollectible.tsx +43 -18
- package/src/react/hooks/useCollectible.tsx +17 -11
- package/src/react/hooks/useCollection.tsx +35 -29
- package/src/react/hooks/useCountOfCollectables.tsx +77 -0
- package/src/react/hooks/useCurrencies.tsx +23 -12
- package/src/react/hooks/useFilters.tsx +15 -9
- package/src/react/hooks/useFloorOrder.tsx +23 -8
- package/src/react/hooks/useGenerateSellTransaction.tsx +16 -9
- package/src/react/hooks/useHighestOffer.tsx +23 -13
- package/src/react/hooks/useListBalances.tsx +57 -26
- package/src/react/hooks/useListCollectibles.tsx +25 -12
- package/src/react/hooks/useListOffersForCollectible.tsx +13 -5
- package/src/react/hooks/useLowestListing.tsx +23 -14
- package/src/react/hooks/useRoyaltyPercentage.tsx +18 -8
- package/src/react/hooks/useTransferTokens.tsx +3 -3
- package/src/react/ui/modals/CreateListingModal/_store.ts +5 -5
- package/src/react/ui/modals/CreateListingModal/index.tsx +5 -4
- package/src/react/ui/modals/MakeOfferModal/_store.ts +6 -9
- package/src/react/ui/modals/MakeOfferModal/index.tsx +15 -25
- package/src/react/ui/modals/SellModal/_store.ts +28 -23
- package/src/react/ui/modals/SellModal/index.tsx +11 -10
- package/src/react/ui/modals/TransferModal/_views/enterWalletAddress/index.tsx +8 -7
- package/src/react/ui/modals/_internal/components/currencyOptionsSelect/index.tsx +2 -1
- package/src/react/ui/modals/_internal/components/floorPriceText/index.tsx +3 -2
- 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 +2 -1
- package/src/react/ui/modals/_internal/components/tokenPreview/index.tsx +2 -1
- package/src/react/ui/modals/_internal/components/transactionDetails/index.tsx +2 -2
- package/src/react/ui/modals/_internal/components/transactionPreview/index.tsx +4 -4
- package/src/react/ui/modals/_internal/components/transactionStatusModal/index.tsx +14 -14
- package/src/react/ui/modals/_internal/components/transactionStatusModal/store.ts +5 -5
- package/src/types/marketplace-config.ts +2 -1
- package/dist/chunk-G3D572BT.js.map +0 -1
- package/dist/chunk-QOJXWHRZ.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.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-4PFMUVE4.js.map → chunk-SNOEEUPZ.js.map} +0 -0
|
@@ -1,13 +1,37 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ChainId as NetworkChainId } from '@0xsequence/network';
|
|
2
2
|
import type { ContractType } from '@types';
|
|
3
|
+
import type { Address } from 'viem';
|
|
4
|
+
import { z } from 'zod';
|
|
3
5
|
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
enabled
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
};
|
|
6
|
+
export const QueryArgSchema = z
|
|
7
|
+
.object({
|
|
8
|
+
enabled: z.boolean().optional(),
|
|
9
|
+
})
|
|
10
|
+
.optional();
|
|
10
11
|
|
|
11
|
-
export type
|
|
12
|
+
export type QueryArg = z.infer<typeof QueryArgSchema>;
|
|
13
|
+
|
|
14
|
+
export const CollectableIdSchema = z.string().or(z.number());
|
|
15
|
+
|
|
16
|
+
export const ChainIdSchema = z.union([
|
|
17
|
+
z.string(),
|
|
18
|
+
z.number(),
|
|
19
|
+
z.nativeEnum(NetworkChainId),
|
|
20
|
+
]);
|
|
21
|
+
|
|
22
|
+
export const AddressSchema = z.string().transform((val, ctx) => {
|
|
23
|
+
const regex = /^0x[a-fA-F0-9]{40}$/;
|
|
24
|
+
|
|
25
|
+
if (!regex.test(val)) {
|
|
26
|
+
ctx.addIssue({
|
|
27
|
+
code: z.ZodIssueCode.custom,
|
|
28
|
+
message: `Invalid Address ${val}`,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return val as Address;
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
export type ChainId = z.infer<typeof ChainIdSchema>;
|
|
12
36
|
|
|
13
37
|
export type CollectionType = ContractType.ERC1155 | ContractType.ERC721;
|
package/src/react/hooks/index.ts
CHANGED
|
@@ -1,51 +1,76 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
AddressSchema,
|
|
3
|
+
ChainIdSchema,
|
|
4
|
+
CollectableIdSchema,
|
|
5
|
+
type QueryArgSchema,
|
|
4
6
|
collectableKeys,
|
|
5
7
|
getIndexerClient,
|
|
6
8
|
} from '@internal';
|
|
7
|
-
import { queryOptions, useQuery } from '@tanstack/react-query';
|
|
9
|
+
import { queryOptions, skipToken, useQuery } from '@tanstack/react-query';
|
|
8
10
|
import type { SdkConfig } from '@types';
|
|
11
|
+
import type { Hex } from 'viem';
|
|
12
|
+
import { z } from 'zod';
|
|
9
13
|
import { useConfig } from './useConfig';
|
|
10
14
|
|
|
11
|
-
|
|
12
|
-
collectionAddress:
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
chainId:
|
|
16
|
-
}
|
|
15
|
+
const fetchBalanceOfCollectibleSchema = z.object({
|
|
16
|
+
collectionAddress: AddressSchema,
|
|
17
|
+
collectableId: CollectableIdSchema.pipe(z.coerce.string()),
|
|
18
|
+
userAddress: AddressSchema,
|
|
19
|
+
chainId: ChainIdSchema.pipe(z.coerce.number()),
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
type FetchBalanceOfCollectibleArgs = z.input<
|
|
23
|
+
typeof fetchBalanceOfCollectibleSchema
|
|
24
|
+
>;
|
|
17
25
|
|
|
18
26
|
const fetchBalanceOfCollectible = async (
|
|
19
|
-
args:
|
|
27
|
+
args: FetchBalanceOfCollectibleArgs,
|
|
20
28
|
config: SdkConfig,
|
|
21
29
|
) => {
|
|
22
|
-
const
|
|
30
|
+
const parsedArgs = fetchBalanceOfCollectibleSchema.parse(args);
|
|
31
|
+
const indexerClient = getIndexerClient(parsedArgs.chainId, config);
|
|
23
32
|
return indexerClient
|
|
24
33
|
.getTokenBalances({
|
|
25
|
-
accountAddress:
|
|
26
|
-
contractAddress:
|
|
27
|
-
tokenID:
|
|
34
|
+
accountAddress: parsedArgs.userAddress,
|
|
35
|
+
contractAddress: parsedArgs.collectionAddress,
|
|
36
|
+
tokenID: parsedArgs.collectableId,
|
|
28
37
|
includeMetadata: false,
|
|
29
38
|
metadataOptions: {
|
|
30
39
|
verifiedOnly: true,
|
|
31
|
-
includeContracts: [
|
|
40
|
+
includeContracts: [parsedArgs.collectionAddress],
|
|
32
41
|
},
|
|
33
42
|
})
|
|
34
43
|
.then((res) => res.balances[0] || null);
|
|
35
44
|
};
|
|
36
45
|
|
|
46
|
+
interface BalanceOfCollectibleOptions
|
|
47
|
+
extends Omit<FetchBalanceOfCollectibleArgs, 'userAddress'> {
|
|
48
|
+
userAddress?: Hex;
|
|
49
|
+
query?: z.infer<typeof QueryArgSchema>;
|
|
50
|
+
}
|
|
37
51
|
export const balanceOfCollectibleOptions = (
|
|
38
|
-
args:
|
|
52
|
+
args: BalanceOfCollectibleOptions,
|
|
39
53
|
config: SdkConfig,
|
|
40
54
|
) => {
|
|
41
55
|
return queryOptions({
|
|
42
56
|
...args.query,
|
|
43
57
|
queryKey: [...collectableKeys.userBalances, args, config],
|
|
44
|
-
queryFn:
|
|
58
|
+
queryFn: args.userAddress
|
|
59
|
+
? () =>
|
|
60
|
+
fetchBalanceOfCollectible(
|
|
61
|
+
{
|
|
62
|
+
...args,
|
|
63
|
+
// biome-ignore lint/style/noNonNullAssertion: this is guaranteed by the userAddress check above
|
|
64
|
+
userAddress: args.userAddress!,
|
|
65
|
+
},
|
|
66
|
+
config,
|
|
67
|
+
)
|
|
68
|
+
: skipToken,
|
|
69
|
+
enabled: !!args.userAddress || args.query?.enabled,
|
|
45
70
|
});
|
|
46
71
|
};
|
|
47
72
|
|
|
48
|
-
export const useBalanceOfCollectible = (args:
|
|
73
|
+
export const useBalanceOfCollectible = (args: BalanceOfCollectibleOptions) => {
|
|
49
74
|
const config = useConfig();
|
|
50
75
|
return useQuery(balanceOfCollectibleOptions(args, config));
|
|
51
76
|
};
|
|
@@ -1,31 +1,37 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
AddressSchema,
|
|
3
|
+
ChainIdSchema,
|
|
4
|
+
QueryArgSchema,
|
|
4
5
|
collectableKeys,
|
|
5
6
|
getMetadataClient,
|
|
6
7
|
} from '@internal';
|
|
7
8
|
import { queryOptions, useQuery } from '@tanstack/react-query';
|
|
8
9
|
import type { SdkConfig } from '@types';
|
|
10
|
+
import { z } from 'zod';
|
|
9
11
|
import { useConfig } from './useConfig';
|
|
10
12
|
|
|
11
|
-
|
|
12
|
-
chainId:
|
|
13
|
-
collectionAddress:
|
|
14
|
-
collectibleId: string
|
|
15
|
-
|
|
13
|
+
const UseCollectibleSchema = z.object({
|
|
14
|
+
chainId: ChainIdSchema.pipe(z.coerce.string()),
|
|
15
|
+
collectionAddress: AddressSchema,
|
|
16
|
+
collectibleId: z.string(),
|
|
17
|
+
query: QueryArgSchema,
|
|
18
|
+
});
|
|
16
19
|
|
|
17
|
-
export type
|
|
20
|
+
export type UseCollectibleArgs = z.infer<typeof UseCollectibleSchema>;
|
|
21
|
+
|
|
22
|
+
export type UseCollectibleReturn = Awaited<ReturnType<typeof fetchCollectible>>;
|
|
18
23
|
|
|
19
24
|
const fetchCollectible = async (
|
|
20
25
|
args: UseCollectibleArgs,
|
|
21
26
|
config: SdkConfig,
|
|
22
27
|
) => {
|
|
28
|
+
const parsedArgs = UseCollectibleSchema.parse(args);
|
|
23
29
|
const metadataClient = getMetadataClient(config);
|
|
24
30
|
return metadataClient
|
|
25
31
|
.getTokenMetadata({
|
|
26
|
-
chainID:
|
|
27
|
-
contractAddress:
|
|
28
|
-
tokenIDs: [
|
|
32
|
+
chainID: parsedArgs.chainId,
|
|
33
|
+
contractAddress: parsedArgs.collectionAddress,
|
|
34
|
+
tokenIDs: [parsedArgs.collectibleId],
|
|
29
35
|
})
|
|
30
36
|
.then((resp) => resp.tokenMetadata[0]);
|
|
31
37
|
};
|
|
@@ -1,42 +1,48 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
2
|
+
AddressSchema,
|
|
3
|
+
ChainIdSchema,
|
|
4
|
+
QueryArgSchema,
|
|
5
|
+
collectionKeys,
|
|
6
|
+
getMetadataClient,
|
|
7
|
+
} from "@internal";
|
|
8
|
+
import { queryOptions, useQuery } from "@tanstack/react-query";
|
|
9
|
+
import type { SdkConfig } from "@types";
|
|
10
|
+
import { z } from "zod";
|
|
11
|
+
import { useConfig } from "./useConfig";
|
|
10
12
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
const UseCollectionSchema = z.object({
|
|
14
|
+
chainId: ChainIdSchema.pipe(z.coerce.string()),
|
|
15
|
+
collectionAddress: AddressSchema,
|
|
16
|
+
query: QueryArgSchema,
|
|
17
|
+
});
|
|
15
18
|
|
|
16
|
-
export type
|
|
19
|
+
export type UseCollectionArgs = z.input<typeof UseCollectionSchema>;
|
|
20
|
+
|
|
21
|
+
export type UseCollectionReturn = Awaited<ReturnType<typeof fetchCollection>>;
|
|
17
22
|
|
|
18
23
|
const fetchCollection = async (args: UseCollectionArgs, config: SdkConfig) => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
const parsedArgs = UseCollectionSchema.parse(args);
|
|
25
|
+
const metadataClient = getMetadataClient(config);
|
|
26
|
+
return metadataClient
|
|
27
|
+
.getContractInfo({
|
|
28
|
+
chainID: parsedArgs.chainId,
|
|
29
|
+
contractAddress: parsedArgs.collectionAddress,
|
|
30
|
+
})
|
|
31
|
+
.then((resp) => resp.contractInfo);
|
|
26
32
|
};
|
|
27
33
|
|
|
28
34
|
export const collectionOptions = (
|
|
29
|
-
|
|
30
|
-
|
|
35
|
+
args: UseCollectionArgs,
|
|
36
|
+
config: SdkConfig
|
|
31
37
|
) => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
38
|
+
return queryOptions({
|
|
39
|
+
...args.query,
|
|
40
|
+
queryKey: [...collectionKeys.detail, args, config],
|
|
41
|
+
queryFn: () => fetchCollection(args, config),
|
|
42
|
+
});
|
|
37
43
|
};
|
|
38
44
|
|
|
39
45
|
export const useCollection = (args: UseCollectionArgs) => {
|
|
40
|
-
|
|
41
|
-
|
|
46
|
+
const config = useConfig();
|
|
47
|
+
return useQuery(collectionOptions(args, config));
|
|
42
48
|
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AddressSchema,
|
|
3
|
+
ChainIdSchema,
|
|
4
|
+
OrderSide,
|
|
5
|
+
QueryArgSchema,
|
|
6
|
+
collectableKeys,
|
|
7
|
+
getMarketplaceClient,
|
|
8
|
+
} from '@internal';
|
|
9
|
+
import { queryOptions, useQuery } from '@tanstack/react-query';
|
|
10
|
+
import type { SdkConfig } from '@types';
|
|
11
|
+
import { z } from 'zod';
|
|
12
|
+
import { collectiblesFilterSchema } from '../_internal/api/zod-schema';
|
|
13
|
+
import { useConfig } from './useConfig';
|
|
14
|
+
|
|
15
|
+
const BaseSchema = z.object({
|
|
16
|
+
chainId: ChainIdSchema.pipe(z.coerce.string()),
|
|
17
|
+
collectionAddress: AddressSchema,
|
|
18
|
+
query: QueryArgSchema,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const UseCountOfCollectableSchema = BaseSchema.extend({
|
|
22
|
+
filter: collectiblesFilterSchema,
|
|
23
|
+
side: z.nativeEnum(OrderSide),
|
|
24
|
+
}).or(
|
|
25
|
+
BaseSchema.extend({
|
|
26
|
+
filter: z.undefined(),
|
|
27
|
+
side: z.undefined(),
|
|
28
|
+
}),
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
export type UseCountOfCollectablesArgs = z.infer<
|
|
32
|
+
typeof UseCountOfCollectableSchema
|
|
33
|
+
>;
|
|
34
|
+
|
|
35
|
+
export type UseContOfCollectableReturn = Awaited<
|
|
36
|
+
ReturnType<typeof fetchCountOfCollectables>
|
|
37
|
+
>;
|
|
38
|
+
|
|
39
|
+
const fetchCountOfCollectables = async (
|
|
40
|
+
args: UseCountOfCollectablesArgs,
|
|
41
|
+
config: SdkConfig,
|
|
42
|
+
) => {
|
|
43
|
+
const parsedArgs = UseCountOfCollectableSchema.parse(args);
|
|
44
|
+
const marketplaceClient = getMarketplaceClient(parsedArgs.chainId, config);
|
|
45
|
+
if (parsedArgs.filter) {
|
|
46
|
+
return marketplaceClient
|
|
47
|
+
.getCountOfFilteredCollectibles({
|
|
48
|
+
...parsedArgs,
|
|
49
|
+
contractAddress: parsedArgs.collectionAddress,
|
|
50
|
+
// biome-ignore lint/style/noNonNullAssertion: safe to assert here, as it's validated
|
|
51
|
+
side: parsedArgs.side!,
|
|
52
|
+
})
|
|
53
|
+
.then((resp) => resp.count);
|
|
54
|
+
}
|
|
55
|
+
return marketplaceClient
|
|
56
|
+
.getCountOfAllCollectibles({
|
|
57
|
+
...parsedArgs,
|
|
58
|
+
contractAddress: parsedArgs.collectionAddress,
|
|
59
|
+
})
|
|
60
|
+
.then((resp) => resp.count);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export const countOfCollectablesOptions = (
|
|
64
|
+
args: UseCountOfCollectablesArgs,
|
|
65
|
+
config: SdkConfig,
|
|
66
|
+
) => {
|
|
67
|
+
return queryOptions({
|
|
68
|
+
...args.query,
|
|
69
|
+
queryKey: [...collectableKeys.counts, args],
|
|
70
|
+
queryFn: () => fetchCountOfCollectables(args, config),
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export const useCountOfCollectables = (args: UseCountOfCollectablesArgs) => {
|
|
75
|
+
const config = useConfig();
|
|
76
|
+
return useQuery(countOfCollectablesOptions(args, config));
|
|
77
|
+
};
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
+
AddressSchema,
|
|
2
3
|
type ChainId,
|
|
4
|
+
ChainIdSchema,
|
|
3
5
|
type Currency,
|
|
4
|
-
|
|
6
|
+
QueryArgSchema,
|
|
5
7
|
configKeys,
|
|
6
8
|
currencyKeys,
|
|
7
9
|
getMarketplaceClient,
|
|
@@ -9,31 +11,40 @@ import {
|
|
|
9
11
|
} from '@internal';
|
|
10
12
|
import { queryOptions, useQuery } from '@tanstack/react-query';
|
|
11
13
|
import type { MarketplaceConfig, SdkConfig } from '@types';
|
|
14
|
+
import { z } from 'zod';
|
|
12
15
|
import { useConfig } from './useConfig';
|
|
13
16
|
|
|
14
|
-
|
|
15
|
-
chainId: ChainId;
|
|
16
|
-
collectionAddress?: string;
|
|
17
|
-
includeNativeCurrency?: boolean;
|
|
18
|
-
} & QueryArg;
|
|
17
|
+
const ChainIdCoerce = ChainIdSchema.transform((val) => val.toString());
|
|
19
18
|
|
|
20
|
-
|
|
19
|
+
const UseCurrenciesArgsSchema = z.object({
|
|
20
|
+
chainId: ChainIdCoerce,
|
|
21
|
+
collectionAddress: AddressSchema.optional(),
|
|
22
|
+
includeNativeCurrency: z.boolean().optional(),
|
|
23
|
+
query: QueryArgSchema,
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
type UseCurrenciesArgs = z.input<typeof UseCurrenciesArgsSchema>;
|
|
27
|
+
|
|
28
|
+
export type UseCurrenciesReturn = Awaited<ReturnType<typeof fetchCurrencies>>;
|
|
21
29
|
|
|
22
30
|
const fetchCurrencies = async (chainId: ChainId, config: SdkConfig) => {
|
|
23
|
-
const
|
|
31
|
+
const parsedChainId = ChainIdCoerce.parse(chainId);
|
|
32
|
+
const marketplaceClient = getMarketplaceClient(parsedChainId, config);
|
|
24
33
|
return marketplaceClient.listCurrencies().then((resp) => resp.currencies);
|
|
25
34
|
};
|
|
26
35
|
|
|
27
36
|
const selectCurrencies = (data: Currency[], args: UseCurrenciesArgs) => {
|
|
37
|
+
const argsParsed = UseCurrenciesArgsSchema.parse(args);
|
|
28
38
|
// if collectionAddress is passed, filter currencies based on collection currency options
|
|
29
|
-
if (
|
|
39
|
+
if (argsParsed.collectionAddress) {
|
|
30
40
|
const queryClient = getQueryClient();
|
|
31
41
|
const marketplaceConfigCache = queryClient.getQueriesData({
|
|
32
42
|
queryKey: configKeys.marketplace,
|
|
33
43
|
})[0][1] as MarketplaceConfig;
|
|
34
44
|
|
|
35
45
|
const collection = marketplaceConfigCache?.collections.find(
|
|
36
|
-
(collection) =>
|
|
46
|
+
(collection) =>
|
|
47
|
+
collection.collectionAddress === argsParsed.collectionAddress,
|
|
37
48
|
);
|
|
38
49
|
|
|
39
50
|
if (!collection) {
|
|
@@ -44,12 +55,12 @@ const selectCurrencies = (data: Currency[], args: UseCurrenciesArgs) => {
|
|
|
44
55
|
(currency) =>
|
|
45
56
|
collection.currencyOptions?.includes(currency.contractAddress) ||
|
|
46
57
|
// biome-ignore lint/suspicious/noDoubleEquals: <explanation>
|
|
47
|
-
currency.nativeCurrency ==
|
|
58
|
+
currency.nativeCurrency == argsParsed.includeNativeCurrency ||
|
|
48
59
|
currency.defaultChainCurrency,
|
|
49
60
|
);
|
|
50
61
|
}
|
|
51
62
|
// if includeNativeCurrency is true, return all currencies
|
|
52
|
-
if (
|
|
63
|
+
if (argsParsed.includeNativeCurrency) {
|
|
53
64
|
return data;
|
|
54
65
|
}
|
|
55
66
|
|
|
@@ -1,26 +1,32 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
AddressSchema,
|
|
3
|
+
ChainIdSchema,
|
|
4
|
+
QueryArgSchema,
|
|
4
5
|
collectableKeys,
|
|
5
6
|
getMetadataClient,
|
|
6
7
|
} from '@internal';
|
|
7
8
|
import { queryOptions, useQuery } from '@tanstack/react-query';
|
|
8
9
|
import type { SdkConfig } from '@types';
|
|
10
|
+
import { z } from 'zod';
|
|
9
11
|
import { useConfig } from './useConfig';
|
|
10
12
|
|
|
11
|
-
|
|
12
|
-
chainId:
|
|
13
|
-
collectionAddress:
|
|
14
|
-
|
|
13
|
+
const UseFiltersSchema = z.object({
|
|
14
|
+
chainId: ChainIdSchema.pipe(z.coerce.string()),
|
|
15
|
+
collectionAddress: AddressSchema,
|
|
16
|
+
query: QueryArgSchema,
|
|
17
|
+
});
|
|
15
18
|
|
|
16
|
-
export type
|
|
19
|
+
export type UseFiltersArgs = z.infer<typeof UseFiltersSchema>;
|
|
20
|
+
|
|
21
|
+
export type UseFilterReturn = Awaited<ReturnType<typeof fetchFilters>>;
|
|
17
22
|
|
|
18
23
|
export const fetchFilters = async (args: UseFiltersArgs, config: SdkConfig) => {
|
|
24
|
+
const parsedArgs = UseFiltersSchema.parse(args);
|
|
19
25
|
const metadataClient = getMetadataClient(config);
|
|
20
26
|
return metadataClient
|
|
21
27
|
.tokenCollectionFilters({
|
|
22
|
-
chainID:
|
|
23
|
-
contractAddress:
|
|
28
|
+
chainID: parsedArgs.chainId,
|
|
29
|
+
contractAddress: parsedArgs.collectionAddress,
|
|
24
30
|
})
|
|
25
31
|
.then((resp) => resp.filters);
|
|
26
32
|
};
|
|
@@ -1,28 +1,43 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
AddressSchema,
|
|
3
|
+
ChainIdSchema,
|
|
4
|
+
QueryArgSchema,
|
|
5
|
+
collectableKeys,
|
|
6
|
+
getMarketplaceClient,
|
|
7
|
+
} from '@internal';
|
|
2
8
|
import { queryOptions, useQuery } from '@tanstack/react-query';
|
|
3
9
|
import type { SdkConfig } from '@types';
|
|
10
|
+
import { z } from 'zod';
|
|
4
11
|
import { useConfig } from './useConfig';
|
|
5
12
|
|
|
6
|
-
|
|
7
|
-
chainId: string
|
|
8
|
-
collectionAddress:
|
|
9
|
-
|
|
13
|
+
const UseFloorOrderSchema = z.object({
|
|
14
|
+
chainId: ChainIdSchema.pipe(z.coerce.string()),
|
|
15
|
+
collectionAddress: AddressSchema,
|
|
16
|
+
query: QueryArgSchema,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export type UseFloorOrderArgs = z.infer<typeof UseFloorOrderSchema>;
|
|
20
|
+
|
|
21
|
+
export type UseFloorOrderReturn = Awaited<ReturnType<typeof fetchFloorOrder>>;
|
|
10
22
|
|
|
11
|
-
const fetchFloorOrder = async (args:
|
|
23
|
+
const fetchFloorOrder = async (args: UseFloorOrderArgs, config: SdkConfig) => {
|
|
12
24
|
const marketplaceClient = getMarketplaceClient(args.chainId, config);
|
|
13
25
|
return marketplaceClient
|
|
14
26
|
.getFloorOrder({ contractAddress: args.collectionAddress })
|
|
15
27
|
.then((data) => data.collectible);
|
|
16
28
|
};
|
|
17
29
|
|
|
18
|
-
export const floorOrderOptions = (
|
|
30
|
+
export const floorOrderOptions = (
|
|
31
|
+
args: UseFloorOrderArgs,
|
|
32
|
+
config: SdkConfig,
|
|
33
|
+
) => {
|
|
19
34
|
return queryOptions({
|
|
20
35
|
queryKey: [...collectableKeys.floorOrders, args, config],
|
|
21
36
|
queryFn: () => fetchFloorOrder(args, config),
|
|
22
37
|
});
|
|
23
38
|
};
|
|
24
39
|
|
|
25
|
-
export const useFloorOrder = (args:
|
|
40
|
+
export const useFloorOrder = (args: UseFloorOrderArgs) => {
|
|
26
41
|
const config = useConfig();
|
|
27
42
|
return useQuery(floorOrderOptions(args, config));
|
|
28
43
|
};
|
|
@@ -1,27 +1,34 @@
|
|
|
1
1
|
import {
|
|
2
2
|
type ChainId,
|
|
3
|
+
ChainIdSchema,
|
|
3
4
|
type GenerateSellTransactionArgs,
|
|
4
5
|
getMarketplaceClient,
|
|
5
6
|
} from '@internal';
|
|
6
7
|
import { useMutation } from '@tanstack/react-query';
|
|
7
8
|
import type { SdkConfig } from '@types';
|
|
9
|
+
import { z } from 'zod';
|
|
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
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
AddressSchema,
|
|
3
|
+
ChainIdSchema,
|
|
4
|
+
QueryArgSchema,
|
|
4
5
|
collectableKeys,
|
|
5
6
|
getMarketplaceClient,
|
|
6
7
|
} from '@internal';
|
|
7
8
|
import { queryOptions, useQuery } from '@tanstack/react-query';
|
|
8
9
|
import type { SdkConfig } from '@types';
|
|
10
|
+
import { z } from 'zod';
|
|
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
|
|