Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

staging #201

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions apps/arkmarket/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ We try to keep this project as simple as possible, so you can start with just th
If you are not familiar with the different technologies used in this project, please refer to the respective docs. If you still are in the wind, please join our [Discord](https://t3.gg/discord) and ask for help.

- [Next.js](https://nextjs.org)
- [NextAuth.js](https://next-auth.js.org)
- [Drizzle](https://orm.drizzle.team)
- [Tailwind CSS](https://tailwindcss.com)
- [tRPC](https://trpc.io)

Expand Down
11 changes: 4 additions & 7 deletions apps/arkmarket/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,15 @@
},
"dependencies": {
"@ark-market/ui": "workspace:*",
"@ark-project/core": "^2.1.1",
"@ark-project/react": "^1.1.1",
"@ark-project/core": "3.0.0-beta.2",
"@ark-project/react": "2.0.0-beta.4",
"@hookform/error-message": "^2.0.1",
"@starknet-react/chains": "^0.1.7",
"@starknet-react/core": "^2.0.0",
"@t3-oss/env-nextjs": "^0.11.1",
"@tanstack/react-query": "catalog:",
"@tanstack/react-query": "5.55.4",
"@tanstack/react-table": "^8.15.3",
"@tanstack/react-virtual": "^3.5.0",
"@trpc/client": "catalog:",
"@trpc/react-query": "catalog:",
"@trpc/server": "catalog:",
"@vercel/speed-insights": "^1.0.10",
"blockies-ts": "^1.0.0",
"embla-carousel-wheel-gestures": "^8.0.1",
Expand Down Expand Up @@ -75,4 +72,4 @@
"vitest": "^2.1.2"
},
"prettier": "@ark-market/prettier-config"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,22 @@ export default function CollectionItemsBuyNow({
token,
}: CollectionItemsBuyNowProps) {
const [isOpen, setIsOpen] = useState(false);
const { fulfillListing, status } = useFulfillListing();
const { fulfillListingAsync, status } = useFulfillListing();
const { account, address } = useAccount();
const { data } = useBalance({ address, token: ETH });
const { toast } = useToast();
const isOwner = areAddressesEqual(token.owner, address);
const queryClient = useQueryClient();

const buy = async () => {
if (!account) {
toast({
variant: "canceled",
title: "Error",
description: "Please connect your wallet before Buying",
});
return;
}
let tokenMarketData: TokenMarketData | undefined;

try {
Expand Down Expand Up @@ -67,15 +75,20 @@ export default function CollectionItemsBuyNow({
return;
}

if (!tokenMarketData.listing.start_amount) {
sonner.error("Token is not for sale");
return;
}

setIsOpen(true);

await fulfillListing({
starknetAccount: account,
brokerId: env.NEXT_PUBLIC_BROKER_ID,
await fulfillListingAsync({
account: account,
brokerAddress: env.NEXT_PUBLIC_BROKER_ID,
tokenAddress: token.collection_address,
tokenId: token.token_id,
orderHash: tokenMarketData.listing.order_hash,
startAmount: tokenMarketData.listing.start_amount,
tokenId: BigInt(token.token_id),
orderHash: BigInt(tokenMarketData.listing.order_hash),
amount: BigInt(tokenMarketData.listing.start_amount),
});
};

Expand Down Expand Up @@ -137,17 +150,14 @@ export default function CollectionItemsBuyNow({
<Button
className="h-10 w-full rounded-none opacity-0 transition-opacity focus-visible:opacity-100 group-hover:opacity-100"
size="xl"
disabled={status === "loading"}
onClick={(e) => {
disabled={status === "pending"}
onClick={async (e) => {
e.preventDefault();
ensureConnect(e);

if (account) {
void buy();
}
await buy();
}}
>
{status === "loading" && (
{status === "pending" && (
<LoaderCircle className="absolute left-4 animate-spin" size={20} />
)}
Buy now
Expand Down
2 changes: 1 addition & 1 deletion apps/arkmarket/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ export default function RootLayout({ children }: PropsWithChildren) {
)}
>
<CustomFonts />
<SpeedInsights />
<Providers>
<div className="flex-col md:flex">
<SiteHeader />
{children}
<SpeedInsights />
</div>
{env.NEXT_PUBLIC_THEME === "unframed" ? (
<UnframedFooter />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ const AcceptOffer: React.FC<AcceptOfferProps> = ({
}) => {
const [isOpen, setIsOpen] = useState(false);
const { account } = useAccount();
const { fulfillOffer, status } = useFulfillOffer();
const { fulfill: fulfillAuction, status: statusAuction } =
const { fulfillOfferAsync, status } = useFulfillOffer();
const { fulfillAuctionAsync, status: statusAuction } =
useFulfillAuction();

const { toast } = useToast();
Expand All @@ -70,28 +70,36 @@ const AcceptOffer: React.FC<AcceptOfferProps> = ({
}, [status]);

const onConfirm = async () => {
if (!account) {
toast({
variant: "canceled",
title: "Error",
description: "Please connect your wallet before accepting an offer",
});
return;
}

if (isListed && listing.is_auction) {
await fulfillAuction({
brokerId: env.NEXT_PUBLIC_BROKER_ID,
orderHash: listing.order_hash,
relatedOrderHash: offerOrderHash,
starknetAccount: account,
startAmount: offerPrice,
await fulfillAuctionAsync({
brokerAddress: env.NEXT_PUBLIC_BROKER_ID,
orderHash: BigInt(listing.order_hash),
relatedOrderHash: BigInt(offerOrderHash),
account: account,
tokenAddress: collectionAddress,
tokenId: tokenId,
tokenId: BigInt(tokenId),
});
} else {
await fulfillOffer({
brokerId: env.NEXT_PUBLIC_BROKER_ID,
orderHash: offerOrderHash,
starknetAccount: account,
await fulfillOfferAsync({
brokerAddress: env.NEXT_PUBLIC_BROKER_ID,
orderHash: BigInt(offerOrderHash),
account: account,
tokenAddress: collectionAddress,
tokenId: tokenId,
tokenId: BigInt(tokenId),
});
}
};

const isLoading = status === "loading" || statusAuction === "loading";
const isLoading = status === "pending" || statusAuction === "pending";

useEffect(() => {
if (status === "error" || statusAuction === "error") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const CancelOffer = ({
tokenMetadata,
}: CancelOfferProps) => {
const { account } = useAccount();
const { cancel, status } = useCancel();
const { cancelAsync, status } = useCancel();
const { toast } = useToast();

useEffect(() => {
Expand Down Expand Up @@ -72,11 +72,16 @@ const CancelOffer = ({

const handleClick = async () => {
if (!account) {
toast({
variant: "canceled",
title: "Error",
description: "Please connect your wallet before canceling a listing"
});
return;
}

await cancel({
starknetAccount: account,
await cancelAsync({
account: account,
tokenAddress: collectionAddress,
tokenId: BigInt(tokenId),
orderHash: BigInt(offerOrderHash),
Expand All @@ -87,7 +92,7 @@ const CancelOffer = ({

return (
<Button size="sm" onClick={handleClick} disabled={isLoading}>
{status === "loading" ? (
{status === "pending" ? (
<ReloadIcon className="animate-spin" />
) : (
"Cancel"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ export default function TokenActionsAcceptBestOffer({
small,
}: TokenActionsAcceptBestOfferProps) {
const [isOpen, setIsOpen] = useState(false);
const { fulfill: fulfillAuction, status: statusAuction } =
useFulfillAuction();
const { fulfillOffer, status } = useFulfillOffer();
const { fulfillAuctionAsync, status: statusAuction } = useFulfillAuction();
const { fulfillOfferAsync, status } = useFulfillOffer();
const { address, account } = useAccount();
const { toast } = useToast();
const isOwner = areAddressesEqual(tokenMarketData.owner, address);
Expand Down Expand Up @@ -90,23 +89,31 @@ export default function TokenActionsAcceptBestOffer({
}, [status, statusAuction]);

const onConfirm = async () => {
if (!account) {
toast({
variant: "canceled",
title: "Error",
description: "Please connect your wallet before accepting an offer"
});
return;
}
try {
if (isAuction) {
await fulfillAuction({
brokerId: env.NEXT_PUBLIC_BROKER_ID,
orderHash: tokenMarketData.top_offer.order_hash,
relatedOrderHash: tokenMarketData.listing.order_hash,
starknetAccount: account,
await fulfillAuctionAsync({
brokerAddress: env.NEXT_PUBLIC_BROKER_ID,
orderHash: BigInt(tokenMarketData.top_offer.order_hash),
relatedOrderHash: BigInt(tokenMarketData.listing.order_hash),
account: account,
tokenAddress: token.collection_address,
tokenId: token.token_id,
tokenId: BigInt(token.token_id),
});
} else {
await fulfillOffer({
brokerId: env.NEXT_PUBLIC_BROKER_ID,
orderHash: tokenMarketData.top_offer.order_hash,
starknetAccount: account,
await fulfillOfferAsync({
brokerAddress: env.NEXT_PUBLIC_BROKER_ID,
orderHash: BigInt(tokenMarketData.top_offer.order_hash),
account: account,
tokenAddress: token.collection_address,
tokenId: token.token_id,
tokenId: BigInt(token.token_id),
});
}
} catch (error) {
Expand All @@ -118,7 +125,7 @@ export default function TokenActionsAcceptBestOffer({
return null;
}

const isLoading = status === "loading" || statusAuction === "loading";
const isLoading = status === "pending" || statusAuction === "pending";
const isDisabled = isLoading || tokenMarketData.buy_in_progress;

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function TokenActionsCancelListing({
small,
}: TokenActionsCancelListingProps) {
const { account, address } = useAccount();
const { cancel, status } = useCancel();
const { cancelAsync, status } = useCancel();
const isOwner = areAddressesEqual(tokenMarketData.owner, address);
const { toast } = useToast();

Expand Down Expand Up @@ -72,15 +72,15 @@ export default function TokenActionsCancelListing({
}

const handleClick = async () => {
await cancel({
starknetAccount: account,
await cancelAsync({
account: account,
orderHash: BigInt(tokenMarketData.listing.order_hash),
tokenAddress: token.collection_address,
tokenId: BigInt(token.token_id),
});
};

const isLoading = status === "loading" || status === "success";
const isLoading = status === "pending" || status === "success";
const isDisabled = isLoading || tokenMarketData.buy_in_progress;

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ export function TokenActionsCreateListing({
}),
refetchInterval: 5_000,
});
const { createListing, status } = useCreateListing();
const { create: createAuction, status: auctionStatus } = useCreateAuction();
const { createListingAsync, status } = useCreateListing();
const { createAuctionAsync, status: auctionStatus } = useCreateAuction();
const { toast } = useToast();
const { convertInUsd } = usePrices();

Expand Down Expand Up @@ -212,8 +212,11 @@ export function TokenActionsCreateListing({

async function onSubmit(values: z.infer<typeof formSchema>) {
if (!account) {
// TODO: Handle error with toast
console.error("Account is missing");
toast({
variant: "canceled",
title: "Error",
description: "Please connect your wallet before creating a listing"
});
return;
}

Expand All @@ -230,23 +233,23 @@ export function TokenActionsCreateListing({

try {
if (isAuction) {
await createAuction({
starknetAccount: account,
brokerId: env.NEXT_PUBLIC_BROKER_ID,
await createAuctionAsync({
account: account,
brokerAddress: env.NEXT_PUBLIC_BROKER_ID,
tokenAddress: token.collection_address,
tokenId: processedValues.tokenId,
endDate: processedValues.endDate,
startAmount: processedValues.startAmount,
endAmount: processedValues.endAmount,
});
} else {
await createListing({
starknetAccount: account,
brokerId: env.NEXT_PUBLIC_BROKER_ID,
await createListingAsync({
account: account,
brokerAddress: env.NEXT_PUBLIC_BROKER_ID,
tokenAddress: token.collection_address,
tokenId: processedValues.tokenId,
endDate: processedValues.endDate,
startAmount: processedValues.startAmount,
amount: processedValues.startAmount,
});
}
} catch (error) {
Expand All @@ -261,11 +264,11 @@ export function TokenActionsCreateListing({
const isDisabled =
!form.formState.isValid ||
form.formState.isSubmitting ||
status === "loading" ||
auctionStatus === "loading";
status === "pending" ||
auctionStatus === "pending";

const startAmountInUsd = convertInUsd({ amount: parseEther(startAmount) });
const isLoading = status === "loading" || auctionStatus === "loading";
const isLoading = status === "pending" || auctionStatus === "pending";
const isTriggerLoading = status === "success" || auctionStatus === "success";
const isTriggerDisabled =
isTriggerLoading || tokenMarketData?.buy_in_progress;
Expand Down
Loading