diff --git a/src/components/EvmEditors/EvmBatchTxEditor.tsx b/src/components/EvmEditors/EvmBatchTxEditor.tsx index 3fa6c48..288b1f6 100644 --- a/src/components/EvmEditors/EvmBatchTxEditor.tsx +++ b/src/components/EvmEditors/EvmBatchTxEditor.tsx @@ -8,7 +8,7 @@ import { Radio, RadioGroup, } from "@chakra-ui/react"; -import { AddIcon, CloseIcon } from "@chakra-ui/icons"; +import { AddIcon } from "@chakra-ui/icons"; import { ReactJSXElement } from "@emotion/react/types/jsx-namespace"; import type { EthereumTypes } from "@blocto/sdk"; import EvmTxForm from "./EvmTxForm"; @@ -20,17 +20,30 @@ interface EvmBatchTxEditorProps { account: string | null; } +const RevertOptionMap: Record = { + true: true, + false: false, + unset: undefined, +}; +const emptyTx = {}; + const EvmBatchTxEditor = ({ setRequestObject, account, }: EvmBatchTxEditorProps): ReactJSXElement => { const [revert, setRevert] = useState("true"); - const [txs, setTxs] = useState([{}]); + const [txs, setTxs] = useState([emptyTx]); + useEffect(() => { if (account) { setRequestObject({ method: "wallet_sendMultiCallTransaction", - params: [txs, revert === "true"], + params: [ + txs, + ...(RevertOptionMap[revert] !== undefined + ? [RevertOptionMap[revert]] + : []), + ], }); } }, [account, setRequestObject, revert, txs]); @@ -46,8 +59,11 @@ const EvmBatchTxEditor = ({ }} > - true - false + {Object.keys(RevertOptionMap).map((key) => ( + + {key} + + ))} @@ -61,7 +77,7 @@ const EvmBatchTxEditor = ({ size="xs" colorScheme="blue" onClick={() => { - setTxs((prev) => [...prev, ""]); + setTxs((prev) => [...prev, emptyTx]); }} />