Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
Hide raw transaction in a <details>
Browse files Browse the repository at this point in the history
- Start with details expanded
- Automatically collapse when the transaction decoding succeeds
- Respect user toggle actions as taking precedence over these defaults
  • Loading branch information
gnidan committed Mar 29, 2022
1 parent 73d08a9 commit c016d4b
Showing 1 changed file with 36 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export default function Transaction({
decoder
}: Props) {
const [decoding, setDecoding] = useState<Codec.CalldataDecoding | undefined>();
const [
showRawTransaction, setShowRawTransaction
] = useState<boolean | undefined>(undefined);

useEffect(() => {
if (!decoder) {
Expand All @@ -28,16 +31,15 @@ export default function Transaction({
from: transaction.from,
input: transaction.data,
value: transaction.value
})
.then(setDecoding);
}).then((decoding) => {
console.debug("decoding %o", decoding);
if (decoding.kind !== "unknown") {
setDecoding(decoding);
}
});
}, [transaction, decoder]);


console.debug("decoding %o", decoding);
if (decoding) {
console.log(inspect(new Codec.Export.CalldataDecodingInspector(decoding)));
}

const decodedTransaction = decoding && (
<pre>
{inspect(new Codec.Export.CalldataDecodingInspector(decoding))}
Expand All @@ -48,7 +50,33 @@ export default function Transaction({
return (
<div>
{decodedTransaction}
<ReactJson name="transaction" src={transaction} />
<details
open={
showRawTransaction === undefined
? !decoding
: showRawTransaction
}
onKeyDown={({ key }) => {
if ([" ", "return"].includes(key)) {
setShowRawTransaction(
showRawTransaction === undefined
? !!decoding
: !showRawTransaction
);
}
}}
onClick={() => {
setShowRawTransaction(
showRawTransaction === undefined
? !!decoding
: !showRawTransaction
);
}}
>
<summary>Raw transaction</summary>

<ReactJson name="transaction" src={transaction} />
</details>
</div>
);

Expand Down

0 comments on commit c016d4b

Please sign in to comment.