Skip to content

Commit

Permalink
enhance: optional revert and improve empty tx express
Browse files Browse the repository at this point in the history
  • Loading branch information
q20274982 committed Jan 9, 2024
1 parent a7f45f6 commit 035e585
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions src/components/EvmEditors/EvmBatchTxEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -20,17 +20,30 @@ interface EvmBatchTxEditorProps {
account: string | null;
}

const RevertOptionMap: Record<string, any> = {
true: true,
false: false,
unset: undefined,
};
const emptyTx = {};

const EvmBatchTxEditor = ({
setRequestObject,
account,
}: EvmBatchTxEditorProps): ReactJSXElement => {
const [revert, setRevert] = useState<string>("true");
const [txs, setTxs] = useState<any[]>([{}]);
const [txs, setTxs] = useState<any[]>([emptyTx]);

useEffect(() => {
if (account) {
setRequestObject({
method: "wallet_sendMultiCallTransaction",
params: [txs, revert === "true"],
params: [
txs,
...(RevertOptionMap[revert] !== undefined
? [RevertOptionMap[revert]]
: []),
],
});
}
}, [account, setRequestObject, revert, txs]);
Expand All @@ -46,8 +59,11 @@ const EvmBatchTxEditor = ({
}}
>
<Flex gap="15px">
<Radio value="true">true</Radio>
<Radio value="false">false</Radio>
{Object.keys(RevertOptionMap).map((key) => (
<Radio key={key} value={key}>
{key}
</Radio>
))}
</Flex>
</RadioGroup>

Expand All @@ -61,7 +77,7 @@ const EvmBatchTxEditor = ({
size="xs"
colorScheme="blue"
onClick={() => {
setTxs((prev) => [...prev, ""]);
setTxs((prev) => [...prev, emptyTx]);
}}
/>
</Flex>
Expand Down

0 comments on commit 035e585

Please sign in to comment.