From ed2a70db1f70de63e62fe33366c11d46d05099fd Mon Sep 17 00:00:00 2001 From: Joe Pegler Date: Fri, 7 Jun 2024 14:38:34 +0100 Subject: [PATCH] chore: v1.0.10 --- bun.lockb | Bin 802470 -> 802471 bytes package.json | 2 +- src/components/AA/MintNft.tsx | 4 +- src/components/Faucet/index.tsx | 6 +- src/components/Forward/MintNft.tsx | 76 +++++++----------- src/components/Modules/CreateBatchSession.tsx | 15 +++- src/components/Modules/CreateSession.tsx | 6 +- src/components/Modules/UseBatchSession.tsx | 7 +- src/components/Modules/UseSession.tsx | 4 +- src/utils/ErrorGuard.tsx | 8 +- 10 files changed, 61 insertions(+), 67 deletions(-) diff --git a/bun.lockb b/bun.lockb index 01129a6c918faa6e9c0cd4cedb70c6c1874e3316..1cb049cd5b7ea5f82dd41dd5ac8976be81c5fd0c 100755 GIT binary patch delta 1741 zcmY*ZZA?>F7(VAhfddFCgG%lssr=ZKK?*1rEP@zBGlnGK{!J!iK+15t; zl9@V=F_VaF!-O%y__)-KEsb+#D%ti&Cd-&^W5$euI1qy&?z!~d-mPi#JkR?+=Q+2h zJ?|&$=Kgi_`w6B;H>!SGH5!|Le0xD;G1g~Qv%e+fmF$=+Z%G;K-}|`AIGpcJYwxcV zNGKt8W0gRHf%UesRDxFq_daRd0}yHwChlkaqh;kO&x01D^x7cpLUIRTrxLEVUl5){Q`A zV?R~TpA?7@`ZiFhUj-_;LqH|>0uUS8ovN+_Mv*vTKMtZ8bAgdSNi~=@48*=k)lXfC z7Kz4nSS_7a3ze-FAtI1wx?0^9R*o;ZA4~mRSxpiffy#m+oTgHVnQ#*OASri*L%s`X zhV*mMn-aSMrL3eb$Hx*2#vvcxP)e^DD#xe#p^~BeIW0!a3}iYaae1(1)Cqwc-LQHb z603kp@u`bYdzFPQM>EzzWpDIoo5W&jyxTLE=Pij@p%T$ExIFhI!#7Y8Z#_yahHE(E zY%gWCcqlK;2R-bi98@*@tXE^}d|oT4Y8V7nm#u)l;!Vi1`KnIPBi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YEx zmA8Zej{=i`eolJB$Xp<4CUv%aWn>Hoo$n!OtP+&xqi#?NNW?heXp(YuFjn9kBn?LC>di~r+e0@y$mw) zrft-u{RzjM>y?4E*ppXofz0>H4oKNBrDkL6eBRxVvY`)Bp0)^CNGQeQhO<{(0k%jqM@g+AM9&>4-A? z;z3wMc;>2(w06#D#m*W3pvV4K{Rz3^FAhuuyx=FKlh%o;0C8d}Fk+H+^FIgKoAeBK}$-yk>}{P#r%r1bZ1@0O^%(GIws&@PN$c2^8K$ z{DDam&%VIk(<^Q0P~80e-wY!M1S*xo9U>*%eF616zGxmg%-ZRv{LC;j&^~@;n6>Da z@JiCfpPv5V^RpXAGc>5Z5nn=r`A(5V(-?jjL9g8VsHLUk((7p!)mOmJ!H}vnilj}S zRfzs!f@<*g5@HXD%)S3bf5SC(#KD)P+Dh}Wx-xrT_1}9>HT3i35$s`%7b57D=5;pD zT2`C=@+sB#fH%XCs&u>f)$3Ad+nr9;p!CD)%F|D8op71ek@fthR9k7FvmLg-JF_2M zQVpe?y08Ze*CXha2JHUhL~nTH=Eth9jTcJ>rDF%K%1Ria?Z2po0e-~AuF+|+@FF`# zX*@swJ&WddZwIUth40uVB_o!PvQmJE;cPz|+PdIocvgrD?jXk=9)6D*_>K+1Ozhea H?6>MazDVex diff --git a/package.json b/package.json index 5f2ba8d..eac57f5 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/components/AA/MintNft.tsx b/src/components/AA/MintNft.tsx index 1bc3fa6..f3099ce 100644 --- a/src/components/AA/MintNft.tsx +++ b/src/components/AA/MintNft.tsx @@ -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; @@ -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, diff --git a/src/components/Faucet/index.tsx b/src/components/Faucet/index.tsx index c279cf4..1c6d023 100644 --- a/src/components/Faucet/index.tsx +++ b/src/components/Faucet/index.tsx @@ -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, diff --git a/src/components/Forward/MintNft.tsx b/src/components/Forward/MintNft.tsx index a5c78d3..ec646d6 100644 --- a/src/components/Forward/MintNft.tsx +++ b/src/components/Forward/MintNft.tsx @@ -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"; @@ -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(null); - const [isLoadingFee, setIsLoadingFee] = useState(false); - - const [spender, setSpender] = useState(""); - const [feeQuotesArr, setFeeQuotesArr] = useState([]); const [selectedQuote, setSelectedQuote] = useState(); 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, @@ -78,7 +68,7 @@ const MintNftForward: React.FC = () => { isSuccess: waitIsSuccess, error: waitError, data: waitData, - } = useUserOpWait({ userOpResponse }); + } = useUserOpWait(userOpResponse); useEffect(() => { waitIsSuccess && @@ -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, + }, }, - }, + ]), }); }; @@ -164,7 +148,7 @@ const MintNftForward: React.FC = () => { gap: 8, }} > - {feeQuotesArr.map((token, ind) => ( + {(data?.feeQuotes ?? []).map((token, ind) => (
; const CreateBatchSession: React.FC = () => { const classes = useStyles(); @@ -21,7 +25,7 @@ const CreateBatchSession: React.FC = () => { const { smartAccountAddress: scwAddress } = useSmartAccount(); const [hasSession, setHasSession] = useState(false); - const policyLeaves = [ + const policyLeaves: Policy[] = [ { interval: { validUntil: 0, @@ -68,7 +72,7 @@ const CreateBatchSession: React.FC = () => { isSuccess: waitIsSuccess, error: waitError, data: waitData, - } = useUserOpWait({ userOpResponse }); + } = useUserOpWait(userOpResponse); useEffect(() => { if (waitIsSuccess) { @@ -83,7 +87,10 @@ const CreateBatchSession: React.FC = () => { const createSessionHandler = () => mutate({ policy: policyLeaves, - buildUseropDto: Sponsored, + options: mergeOptions([ + Options.Sponsored, + Options.getIncreasedVerification(50), + ]), }); return ( diff --git a/src/components/Modules/CreateSession.tsx b/src/components/Modules/CreateSession.tsx index 9538821..3f91ca6 100644 --- a/src/components/Modules/CreateSession.tsx +++ b/src/components/Modules/CreateSession.tsx @@ -4,7 +4,7 @@ import "react-toastify/dist/ReactToastify.css"; import UseSession from "./UseSession"; import { useAccount } from "wagmi"; import { - Sponsored, + Options, bigIntReplacer, useCreateSession, useSmartAccount, @@ -57,7 +57,7 @@ const CreateSession: React.FC = () => { isSuccess: waitIsSuccess, error: waitError, data: waitData, - } = useUserOpWait({ userOpResponse }); + } = useUserOpWait(userOpResponse); useEffect(() => { if (waitIsSuccess) { @@ -72,7 +72,7 @@ const CreateSession: React.FC = () => { const createSessionHandler = () => mutate({ policy, - buildUseropDto: Sponsored, + options: Options.Sponsored, }); return ( diff --git a/src/components/Modules/UseBatchSession.tsx b/src/components/Modules/UseBatchSession.tsx index 3c50b24..ed50a8f 100644 --- a/src/components/Modules/UseBatchSession.tsx +++ b/src/components/Modules/UseBatchSession.tsx @@ -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 { @@ -26,7 +26,7 @@ const UseBatchSession: React.FC = ({ smartAccountAddress }) => { isSuccess: waitIsSuccess, error: waitError, data: waitData, - } = useUserOpWait({ userOpResponse }); + } = useUserOpWait(userOpResponse); const nftMintTx: Transaction = { to: configInfo.nft.address, @@ -39,8 +39,9 @@ const UseBatchSession: React.FC = ({ smartAccountAddress }) => { const txTwice = () => mutate({ - manyOrOneTx: [nftMintTx, nftMintTx], + transactions: [nftMintTx, nftMintTx], correspondingIndexes: [0, 1], + options: Options.getIncreasedVerification(50), }); useEffect(() => { diff --git a/src/components/Modules/UseSession.tsx b/src/components/Modules/UseSession.tsx index 8a20a50..2db86ae 100644 --- a/src/components/Modules/UseSession.tsx +++ b/src/components/Modules/UseSession.tsx @@ -25,11 +25,11 @@ const UseSession: React.FC = ({ 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)"]), diff --git a/src/utils/ErrorGuard.tsx b/src/utils/ErrorGuard.tsx index 61bd321..60a401c 100644 --- a/src/utils/ErrorGuard.tsx +++ b/src/utils/ErrorGuard.tsx @@ -5,10 +5,14 @@ export const ErrorGuard = ({ errors, }: { children: ReactNode; - errors?: Error[]; + errors?: (Error | null)[]; }) => { if (errors?.some(Boolean)) { - return
{errors?.[0]?.message ?? "Unknown Error"}
; + return ( +
+ {errors?.[0]?.message ?? "Unknown Error"} +
+ ); } return children; };