2021-04-14 16:22:40 -07:00
|
|
|
import React from "react";
|
|
|
|
import { ConfirmedSignatureInfo } from "@solana/web3.js";
|
|
|
|
import {
|
|
|
|
getTokenProgramInstructionName,
|
|
|
|
InstructionType,
|
|
|
|
} from "utils/instruction";
|
|
|
|
|
|
|
|
export function InstructionDetails({
|
|
|
|
instructionType,
|
|
|
|
tx,
|
|
|
|
}: {
|
|
|
|
instructionType: InstructionType;
|
|
|
|
tx: ConfirmedSignatureInfo;
|
|
|
|
}) {
|
|
|
|
const [expanded, setExpanded] = React.useState(false);
|
|
|
|
|
|
|
|
let instructionTypes = instructionType.innerInstructions
|
|
|
|
.map((ix) => {
|
|
|
|
if ("parsed" in ix && ix.program === "spl-token") {
|
|
|
|
return getTokenProgramInstructionName(ix, tx);
|
|
|
|
}
|
|
|
|
return undefined;
|
|
|
|
})
|
|
|
|
.filter((type) => type !== undefined);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<p className="tree">
|
|
|
|
{instructionTypes.length > 0 && (
|
|
|
|
<span
|
|
|
|
onClick={(e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
setExpanded(!expanded);
|
|
|
|
}}
|
2021-11-28 14:49:22 -06:00
|
|
|
className={`c-pointer fe me-2 ${
|
2021-04-14 16:22:40 -07:00
|
|
|
expanded ? "fe-minus-square" : "fe-plus-square"
|
|
|
|
}`}
|
|
|
|
></span>
|
|
|
|
)}
|
|
|
|
{instructionType.name}
|
|
|
|
</p>
|
|
|
|
{expanded && (
|
|
|
|
<ul className="tree">
|
|
|
|
{instructionTypes.map((type, index) => {
|
|
|
|
return <li key={index}>{type}</li>;
|
|
|
|
})}
|
|
|
|
</ul>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|