Files
js/@3rdweb-sdk/react/hooks/useMarketplace.ts
T
Jonas Daniels d1d01d3d7c new marketplace sdk things (#77)
* new marketplace sdk things

* fix transfer logic bug

* show reason why transfer cell is disabled
2022-04-22 15:59:43 -07:00

75 lines
2.0 KiB
TypeScript

import { useMutationWithInvalidate } from "./query/useQueryWithNetwork";
import { getAllQueryKey, getTotalCountQueryKey } from "./useGetAll";
import { useMarketplace } from "@thirdweb-dev/react";
import {
ListingType,
NewAuctionListing,
NewDirectListing,
} from "@thirdweb-dev/sdk";
export function useMarketplaceDirectListMutation(contractAddress?: string) {
const marketplace = useMarketplace(contractAddress);
return useMutationWithInvalidate(
async (data: NewDirectListing) => {
return await marketplace?.direct.createListing({
...data,
});
},
{
onSuccess: (_data, _variables, _options, invalidate) => {
return invalidate([
getAllQueryKey(marketplace),
getTotalCountQueryKey(marketplace),
]);
},
},
);
}
export function useMarketplaceAuctionListMutation(contractAddress?: string) {
const marketplace = useMarketplace(contractAddress);
return useMutationWithInvalidate(
async (data: NewAuctionListing) => {
return await marketplace?.auction.createListing({
...data,
});
},
{
onSuccess: (_data, _variables, _options, invalidate) => {
return invalidate([
getAllQueryKey(marketplace),
getTotalCountQueryKey(marketplace),
]);
},
},
);
}
interface CancelListingProps {
listingId: string;
listingType: ListingType;
}
export function useMarketplaceCancelMutation(contractAddress?: string) {
const marketplace = useMarketplace(contractAddress);
return useMutationWithInvalidate(
async (data: CancelListingProps) => {
const { listingId, listingType } = data;
if (listingType === ListingType.Auction) {
return await marketplace?.auction.cancelListing(listingId);
} else {
return await marketplace?.direct.cancelListing(listingId);
}
},
{
onSuccess: (_data, _variables, _options, invalidate) => {
return invalidate([
getAllQueryKey(marketplace),
getTotalCountQueryKey(marketplace),
]);
},
},
);
}