Skip to content

Commit

Permalink
remove duplicate logic
Browse files Browse the repository at this point in the history
  • Loading branch information
apoorvlathey committed Aug 9, 2021
1 parent af3ff28 commit 9541953
Showing 1 changed file with 12 additions and 32 deletions.
44 changes: 12 additions & 32 deletions src/components/Body/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,18 @@ function Body() {
const [disableAddressDecodeBtn, setDisableAddressDecodeBtn] = useState(true);

const decodeWithABI = () => {
abiDecoder.addABI(JSON.parse(abi));
_decodeWithABI(abi, calldata);
};

const _decodeWithABI = (_abi, _calldata) => {
abiDecoder.addABI(JSON.parse(_abi));
let decoded;
try {
decoded = JSON.stringify(abiDecoder.decodeMethod(calldata), undefined, 2);
decoded = JSON.stringify(
abiDecoder.decodeMethod(_calldata),
undefined,
2
);
} catch {
toast({
title: "Incorrect Calldata",
Expand Down Expand Up @@ -82,36 +90,8 @@ function Body() {
isClosable: true,
});
setTabIndex(0);
abiDecoder.addABI(JSON.parse(res_abi));
let decoded;
try {
decoded = JSON.stringify(
abiDecoder.decodeMethod(calldata),
undefined,
2
);
} catch {
toast({
title: "Incorrect Calldata",
status: "error",
isClosable: true,
});
return;
}
if (decoded) {
setOutput(decoded);
toast({
title: "Successfully Decoded",
status: "success",
isClosable: true,
});
} else {
toast({
title: "Can't Decode Calldata",
status: "error",
isClosable: true,
});
}

_decodeWithABI(res_abi, calldata);
} else {
toast({
title: "ABI Not found",
Expand Down

0 comments on commit 9541953

Please sign in to comment.