Skip to content

Commit

Permalink
chore: v1.0.10
Browse files Browse the repository at this point in the history
  • Loading branch information
joepegler committed Jun 7, 2024
1 parent eca3293 commit ed2a70d
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 67 deletions.
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"dependencies": {
"@biconomy/account": "^4.4.5",
"@biconomy/use-aa": "^1.0.8",
"@biconomy/use-aa": "^1.0.10",
"@emotion/react": "^11.10.6",
"@emotion/styled": "^11.10.6",
"@ethersproject/providers": "^5.7.2",
Expand Down
4 changes: 2 additions & 2 deletions src/components/AA/MintNft.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const MintNft: React.FC = () => {
isSuccess: waitIsSuccess,
error: waitError,
data: waitData,
} = useUserOpWait({ userOpResponse });
} = useUserOpWait(userOpResponse);

const getNftCount = useCallback(async () => {
if (!scwAddress || !publicClient) return;
Expand Down Expand Up @@ -61,7 +61,7 @@ const MintNft: React.FC = () => {

const mintNft = () =>
mutate({
manyOrOneTransactions: {
transactions: {
to: config.nft.address as Hex,
data: encodeFunctionData({
abi: config.nft.abi,
Expand Down
6 changes: 2 additions & 4 deletions src/components/Faucet/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,11 @@ const Faucet: React.FC = () => {
error: waitError,
isLoading: waitIsLoading,
data: waitData,
} = useUserOpWait({
userOpResponse,
});
} = useUserOpWait(userOpResponse);

const drip = () =>
mutate({
manyOrOneTransactions: {
transactions: {
to: config.faucet.address as Hex,
data: encodeFunctionData({
abi: config.faucet.abi,
Expand Down
76 changes: 30 additions & 46 deletions src/components/Forward/MintNft.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { makeStyles } from "@mui/styles";
import CircularProgress from "@mui/material/CircularProgress";
import { PaymasterFeeQuote, PaymasterMode } from "@biconomy/account";
import React, { useEffect, useState } from "react";
import React, { useEffect, useMemo, useState } from "react";

import Button from "../Button";
import {
Options,
mergeOptions,
useSendTransaction,
useSmartAccount,
useTokenFees,
useUserOpWait,
} from "@biconomy/use-aa";
import { configInfo as config, showSuccessMessage } from "../../utils";
Expand All @@ -18,54 +21,41 @@ import { polygonAmoy } from "viem/chains";
const MintNftForward: React.FC = () => {
const classes = useStyles();
const publicClient = usePublicClient();
const { smartAccountClient: smartAccount, smartAccountAddress: scwAddress } =
useSmartAccount();
const { smartAccountAddress } = useSmartAccount();
const [nftCount, setNftCount] = useState<number | null>(null);
const [isLoadingFee, setIsLoadingFee] = useState(false);

const [spender, setSpender] = useState("");
const [feeQuotesArr, setFeeQuotesArr] = useState<PaymasterFeeQuote[]>([]);
const [selectedQuote, setSelectedQuote] = useState<PaymasterFeeQuote>();

useEffect(() => {
const getNftCount = async () => {
if (!scwAddress || !publicClient) return;
if (!smartAccountAddress || !publicClient) return;
const nftContract = getContract({
address: config.nft.address as Hex,
abi: config.nft.abi,
client: publicClient,
});
const count = await nftContract.read.balanceOf([scwAddress as Hex]);
const count = await nftContract.read.balanceOf([
smartAccountAddress as Hex,
]);
console.log("count", Number(count));
setNftCount(Number(count));
};
getNftCount();
getFee();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [scwAddress, publicClient]);

const getFee = async () => {
if (!smartAccount || !scwAddress || !publicClient) return;
setIsLoadingFee(true);
}, [smartAccountAddress, publicClient]);

const tx = {
const transactions = useMemo(
() => ({
to: config.nft.address,
data: encodeFunctionData({
abi: config.nft.abi,
functionName: "safeMint",
args: [scwAddress as Hex],
args: [smartAccountAddress as Hex],
}),
};
}),
[smartAccountAddress]
);

const feeQuotesResponse = await smartAccount.getTokenFees([tx], {
paymasterServiceData: { mode: PaymasterMode.ERC20 },
});
setSpender(feeQuotesResponse.tokenPaymasterAddress || "");
const feeQuotes = feeQuotesResponse.feeQuotes as PaymasterFeeQuote[];
setFeeQuotesArr(feeQuotes);
console.log("getFeeQuotesForBatch", feeQuotes);
setIsLoadingFee(false);
};
const { data, isLoading: isLoadingFee } = useTokenFees({ transactions });

const {
mutate,
Expand All @@ -78,7 +68,7 @@ const MintNftForward: React.FC = () => {
isSuccess: waitIsSuccess,
error: waitError,
data: waitData,
} = useUserOpWait({ userOpResponse });
} = useUserOpWait(userOpResponse);

useEffect(() => {
waitIsSuccess &&
Expand All @@ -89,25 +79,19 @@ const MintNftForward: React.FC = () => {
}, [waitIsSuccess]);

const mintNft = () => {
const manyOrOneTransactions = {
to: config.nft.address,
data: encodeFunctionData({
abi: config.nft.abi,
functionName: "safeMint",
args: [scwAddress as Hex],
}),
};

mutate({
manyOrOneTransactions,
buildUseropDto: {
paymasterServiceData: {
feeQuote: selectedQuote,
mode: PaymasterMode.ERC20,
spender: spender as Hex,
maxApproval: false,
transactions,
options: mergeOptions([
Options.GasTokenPayment,
{
paymasterServiceData: {
mode: PaymasterMode.ERC20,
feeQuote: selectedQuote,
spender: data?.tokenPaymasterAddress,
maxApproval: false,
},
},
},
]),
});
};

Expand Down Expand Up @@ -164,7 +148,7 @@ const MintNftForward: React.FC = () => {
gap: 8,
}}
>
{feeQuotesArr.map((token, ind) => (
{(data?.feeQuotes ?? []).map((token, ind) => (
<div key={ind}>
<input
type="radio"
Expand Down
15 changes: 11 additions & 4 deletions src/components/Modules/CreateBatchSession.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import { makeStyles } from "@mui/styles";
import { useAccount } from "wagmi";
import Button from "../Button";
import {
Sponsored,
Options,
bigIntReplacer,
mergeOptions,
useCreateBatchSession,
useSmartAccount,
useUserOpWait,
Expand All @@ -14,14 +15,17 @@ import { polygonAmoy } from "viem/chains";
import { Hex } from "viem";
import UseBatchSession from "./UseBatchSession";
import { ErrorGuard } from "../../utils/ErrorGuard";
import { Policy as PolicyFromSDK } from "@biconomy/account";

export type Policy = Omit<PolicyFromSDK, "sessionKeyAddress">;

const CreateBatchSession: React.FC = () => {
const classes = useStyles();
const { address } = useAccount();
const { smartAccountAddress: scwAddress } = useSmartAccount();
const [hasSession, setHasSession] = useState<boolean>(false);

const policyLeaves = [
const policyLeaves: Policy[] = [
{
interval: {
validUntil: 0,
Expand Down Expand Up @@ -68,7 +72,7 @@ const CreateBatchSession: React.FC = () => {
isSuccess: waitIsSuccess,
error: waitError,
data: waitData,
} = useUserOpWait({ userOpResponse });
} = useUserOpWait(userOpResponse);

useEffect(() => {
if (waitIsSuccess) {
Expand All @@ -83,7 +87,10 @@ const CreateBatchSession: React.FC = () => {
const createSessionHandler = () =>
mutate({
policy: policyLeaves,
buildUseropDto: Sponsored,
options: mergeOptions([
Options.Sponsored,
Options.getIncreasedVerification(50),
]),
});

return (
Expand Down
6 changes: 3 additions & 3 deletions src/components/Modules/CreateSession.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "react-toastify/dist/ReactToastify.css";
import UseSession from "./UseSession";
import { useAccount } from "wagmi";
import {
Sponsored,
Options,
bigIntReplacer,
useCreateSession,
useSmartAccount,
Expand Down Expand Up @@ -57,7 +57,7 @@ const CreateSession: React.FC = () => {
isSuccess: waitIsSuccess,
error: waitError,
data: waitData,
} = useUserOpWait({ userOpResponse });
} = useUserOpWait(userOpResponse);

useEffect(() => {
if (waitIsSuccess) {
Expand All @@ -72,7 +72,7 @@ const CreateSession: React.FC = () => {
const createSessionHandler = () =>
mutate({
policy,
buildUseropDto: Sponsored,
options: Options.Sponsored,
});

return (
Expand Down
7 changes: 4 additions & 3 deletions src/components/Modules/UseBatchSession.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Hex, encodeFunctionData, parseAbi } from "viem";
import Button from "../Button";
import { configInfo, showSuccessMessage } from "../../utils";
import { polygonAmoy } from "viem/chains";
import { useBatchSession, useUserOpWait } from "@biconomy/use-aa";
import { useBatchSession, useUserOpWait, Options } from "@biconomy/use-aa";
import { ErrorGuard } from "../../utils/ErrorGuard";

interface props {
Expand All @@ -26,7 +26,7 @@ const UseBatchSession: React.FC<props> = ({ smartAccountAddress }) => {
isSuccess: waitIsSuccess,
error: waitError,
data: waitData,
} = useUserOpWait({ userOpResponse });
} = useUserOpWait(userOpResponse);

const nftMintTx: Transaction = {
to: configInfo.nft.address,
Expand All @@ -39,8 +39,9 @@ const UseBatchSession: React.FC<props> = ({ smartAccountAddress }) => {

const txTwice = () =>
mutate({
manyOrOneTx: [nftMintTx, nftMintTx],
transactions: [nftMintTx, nftMintTx],
correspondingIndexes: [0, 1],
options: Options.getIncreasedVerification(50),
});

useEffect(() => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/Modules/UseSession.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ const UseSession: React.FC<props> = ({ smartAccountAddress }) => {
isSuccess: waitIsSuccess,
error: waitError,
data: waitData,
} = useUserOpWait({ userOpResponse });
} = useUserOpWait(userOpResponse);

const mintTx = () =>
mutate({
manyOrOneTx: {
transactions: {
to: configInfo.nft.address,
data: encodeFunctionData({
abi: parseAbi(["function safeMint(address _to)"]),
Expand Down
8 changes: 6 additions & 2 deletions src/utils/ErrorGuard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ export const ErrorGuard = ({
errors,
}: {
children: ReactNode;
errors?: Error[];
errors?: (Error | null)[];
}) => {
if (errors?.some(Boolean)) {
return <div style={{ color: "red" }}>{errors?.[0]?.message ?? "Unknown Error"}</div>;
return (
<div style={{ color: "red" }}>
{errors?.[0]?.message ?? "Unknown Error"}
</div>
);
}
return children;
};

0 comments on commit ed2a70d

Please sign in to comment.