Skip to content
Open
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
42 changes: 0 additions & 42 deletions app/api/smartwallet/sendUserOperation/route.ts

This file was deleted.

56 changes: 12 additions & 44 deletions hooks/useZoraMintComment.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,16 @@
import { useEffect, useState } from "react";
import { useAccount } from "wagmi";
import { zoraCreator1155ImplABI } from "@zoralabs/protocol-deployments";
import { zoraCreatorFixedPriceSaleStrategyAddress } from "@/lib/protocolSdk/constants";
import { CHAIN } from "@/lib/consts";
import { Address, encodeAbiParameters, parseAbiParameters } from "viem";
import { Address } from "viem";
import { useTokenProvider } from "@/providers/TokenProvider";
import { useUserProvider } from "@/providers/UserProvider";
import { useCrossmintCheckout } from "@crossmint/client-sdk-react-ui";
import useConnectedWallet from "./useConnectedWallet";
import { useFrameProvider } from "@/providers/FrameProvider";
import { toast } from "sonner";
import { MintType } from "@/types/zora";
import useUsdcMint from "./useUsdcMint";
import useNativeMint from "./useNativeMint";

const mintOnSmartWallet = async (parameters: any) => {
const response = await fetch(`/api/smartwallet/sendUserOperation`, {
method: "POST",
headers: {
"content-type": "application/json",
accept: "application/json",
},
body: JSON.stringify({
parameters,
}),
});

const data = await response.json();

return data.transactionHash;
};
import mintOnSmartWallet from "@/lib/smartwallets/mintOnSmartWallet";

const useZoraMintComment = () => {
const [isOpenCrossmint, setIsOpenCrossmint] = useState(false);
const { connectedWallet } = useConnectedWallet();
const { address } = useAccount();
const { context } = useFrameProvider();
const [isLoading, setIsLoading] = useState(false);
const {
token,
Expand All @@ -47,7 +22,8 @@ const useZoraMintComment = () => {
setCollected,
mintCount,
} = useTokenProvider();
const { isPrepared } = useUserProvider();
const { isPrepared, externalWallet, connectedAddress } = useUserProvider();
const account = externalWallet || connectedAddress;
const { order } = useCrossmintCheckout();
const { mintWithUsdc } = useUsdcMint();
const { mintWithNativeToken } = useNativeMint();
Expand All @@ -62,24 +38,16 @@ const useZoraMintComment = () => {
if (!isPrepared()) return;
if (!saleConfig) return;
setIsLoading(true);
const account = context ? address : connectedWallet;
const minterArguments = encodeAbiParameters(parseAbiParameters("address, string"), [
account as Address,
comment,
]);

if (saleConfig.pricePerToken === BigInt(0)) {
await mintOnSmartWallet({
address: token.tokenContractAddress,
abi: zoraCreator1155ImplABI,
functionName: "mint",
args: [
zoraCreatorFixedPriceSaleStrategyAddress[CHAIN.id],
token.tokenId,
mintCount,
[],
minterArguments,
],
token: {
tokenId: Number(token.tokenId),
tokenContractAddress: token.tokenContractAddress,
},
account: connectedAddress as Address,
to: (externalWallet || connectedAddress) as Address,
comment,
amount: mintCount,
});
} else {
let receipt = null;
Expand Down
34 changes: 34 additions & 0 deletions lib/smartwallets/mintOnSmartWallet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Address } from "viem";

interface mintCommentInput {
token: {
tokenId: number;
tokenContractAddress: Address;
};
account: Address;
to: Address;
comment: string;
amount: number;
}
const mintOnSmartWallet = async ({ token, account, comment, amount, to }: mintCommentInput) => {
const response = await fetch(`/api/smartwallet/comment`, {
method: "POST",
headers: {
"content-type": "application/json",
accept: "application/json",
},
body: JSON.stringify({
account,
to,
token,
comment,
amount,
}),
});

const data = await response.json();

return data.transactionHash;
};

export default mintOnSmartWallet;