Skip to content

Commit

Permalink
fix revert when meta transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
yu23ki14 committed Nov 30, 2023
1 parent 23180bf commit 12cd450
Show file tree
Hide file tree
Showing 3 changed files with 1,209 additions and 18 deletions.
48 changes: 31 additions & 17 deletions frontend/src/hooks/useDropNFTs.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import { useForwarderContract, useMintNFTContract } from "./useMintNFT";
import { ContractEvent, useContractEvents, useContractWrite, useSDK, useSigner, TransactionError } from "@thirdweb-dev/react";
import {
ContractEvent,
useContractEvents,
useContractWrite,
useSDK,
useSigner,
TransactionError,
} from "@thirdweb-dev/react";
import { useCallback, useEffect, useMemo, useState } from "react";
import { Event } from "types/Event";
import { signMetaTxRequest } from "utils/signer";
import axios from "axios";
import { useCurrentBlock } from "./useBlockChain";

export const useDropNFTs = (
event: Event.EventRecord,
address: string,
) => {
export const useDropNFTs = (event: Event.EventRecord, address: string) => {
const { mintNFTContract } = useMintNFTContract();
const { forwarderContract } = useForwarderContract();
const signer = useSigner();
Expand Down Expand Up @@ -44,7 +48,6 @@ export const useDropNFTs = (
subscribe: true,
});


const error: any = useMemo(() => {
return dropStatus.error || dropError;
}, [dropError, dropStatus]);
Expand Down Expand Up @@ -75,7 +78,7 @@ export const useDropNFTs = (
args: [event.eventRecordId, addresses],
});
} catch (error) {
console.log('dropNFTs error', error);
console.log("dropNFTs error", error);
}
},
[event, mutateAsync]
Expand All @@ -87,18 +90,30 @@ export const useDropNFTs = (
setDroppedComplete(false);
setDropStatus({ isLoading: true, status: "loading", error: null });
try {
await (
mintNFTContract as any
).contractWrapper.writeContract.callStatic.dropNFTs(
event?.eventRecordId,
addresses
);

const to = mintNFTContract?.getAddress();
const from = address;
const data = mintNFTContract?.encoder.encode("dropNFTs", [
event?.eventRecordId,
addresses
addresses,
]);
const request = await signMetaTxRequest(sdk.wallet, forwarderContract, {
from,
to,
data,
});
const { data: response } = await axios.post("/api/autotask", {
const request = await signMetaTxRequest(
sdk.wallet,
forwarderContract,
{
from,
to,
data,
},
addresses.length
);
const { data: response } = await axios.post("/api/mtx/relay", {
request: request.request,
signature: request.signature.signature,
});
Expand All @@ -112,13 +127,12 @@ export const useDropNFTs = (
[event, forwarderContract, signer]
);


return {
dropNFTs,
dropNFTsMTX,
isLoading,
error,
status,
isDroppedComplete
isDroppedComplete,
};
};
};
2 changes: 1 addition & 1 deletion frontend/utils/signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const buildRequest = async (
// get nonce from forwarder contract
// this nonce is used to prevent replay attack
const nonce = (await forwarder.call("getNonce", [input.from])).toString();
const gas: number = numberOfMint > 1 ? 5e5 * numberOfMint : 2e6;
const gas: number = numberOfMint > 1 ? 8e5 * numberOfMint : 2e6;
return { value: 0, gas: gas, nonce, ...input };
};

Expand Down
Loading

0 comments on commit 12cd450

Please sign in to comment.