Skip to content

Commit

Permalink
Merge pull request #103 from blocto/feat/add-swap-template
Browse files Browse the repository at this point in the history
feat: add swap template
  • Loading branch information
sanyu1225 authored Apr 12, 2024
2 parents 1994883 + fb546d8 commit f0c0e21
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/components/EvmEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ const EvmEditor = (): ReactJSXElement => {
<EvmBatchTxEditor
setRequestObject={setRequestObject}
account={account}
chainId={chainId}
/>
</TabPanel>
</TabPanels>
Expand Down
26 changes: 23 additions & 3 deletions src/components/EvmEditors/EvmBatchTxEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ interface EvmBatchTxEditorProps {
SetStateAction<EthereumTypes.EIP1193RequestPayload | undefined>
>;
account: string | null;
chainId: string | null;
}

const RevertOptionMap: Record<string, any> = {
Expand All @@ -32,6 +33,7 @@ const RevertOptionMap: Record<string, any> = {
const EvmBatchTxEditor = ({
setRequestObject,
account,
chainId,
}: EvmBatchTxEditorProps): ReactJSXElement => {
const [revert, setRevert] = useState<string>("false");
const [txs, setTxs] = useState<any[]>();
Expand Down Expand Up @@ -75,6 +77,17 @@ const EvmBatchTxEditor = ({
});
};

const SwapToken = () => {
const obj = {
from: account,
to: "0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD",
data: "0x3593564c000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000066053af000000000000000000000000000000000000000000000000000000000000000020b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000038d7ea4c680000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000038d7ea4c680000000000000000000000000000000000000000000000000000000b99e289c676500000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002bfff9976782d46cc05630d1f6ebab18b2324d6b140001f41f9840a85d5af5bf1d1762f925bdaddc4201f984000000000000000000000000000000000000000000",
};
setTxs((state) => {
return [...(state || []), obj];
});
};

const removeTransfer = (index: number) => {
setTxs((state) => {
if (Array.isArray(state) && state.length === 1) {
Expand Down Expand Up @@ -113,9 +126,16 @@ const EvmBatchTxEditor = ({
<Button w="110px" onClick={addTransfer}>
Transfer
</Button>
<Button w="110px" onClick={mintNFT}>
Mint NFT
</Button>
{chainId === "0x8274f" && (
<Button w="110px" onClick={mintNFT}>
Mint NFT
</Button>
)}
{chainId === "0xaa36a7" && (
<Button w="110px" onClick={SwapToken}>
Swap
</Button>
)}
</Grid>
<Flex flexDir="column" mt={2} pl={4}>
{Array.isArray(txs) &&
Expand Down

0 comments on commit f0c0e21

Please sign in to comment.