diff --git a/examples/disassemble/src/xxx b/examples/disassemble/src/xxx deleted file mode 100644 index 3167918d..00000000 --- a/examples/disassemble/src/xxx +++ /dev/null @@ -1,253 +0,0 @@ -import * as React from 'react'; -import Box from '@mui/material/Box'; -import ExpandMoreIcon from '@mui/icons-material/ExpandMore'; -import ChevronRightIcon from '@mui/icons-material/ChevronRight'; -import TreeView from '@mui/lab/TreeView'; -import { isString } from 'lodash'; -import { WasmFs } from '@wasmer/wasmfs'; -import { Disassemble } from '@starcoin/move-js'; -import { Typography } from '@mui/material'; -import { useState } from 'react'; -import TreeItem, { - TreeItemProps, - useTreeItem, - TreeItemContentProps, -} from '@mui/lab/TreeItem'; -import clsx from 'clsx'; - -type Props = { - codes: any -} - - -function FunctionItem(props: Props) { - const { codes } = props; - return <>{codes.map((item: any, index: any) => { - - const prams = item.args.map((arg: any) => { - let type_tag; - if (isString(arg.type_tag)) { - type_tag = arg.type_tag; - } else { - type_tag = Object.keys(arg.type_tag).map((key) => { - return `${key}<${arg.type_tag[key]}>`; - }).join(', '); - } - return `${arg.name}: ${type_tag}`; - }).join(', '); - - return ; - })}; -} - - -function structField(fields: any) { - return fields.map((field: any) => { - let type_abi; - if (isString(field.type_abi)) { - type_abi = field.type_abi; - } else { - type_abi = structAbi(field.type_abi); - } - return `${field.name}: ${type_abi}`; - }).join(' , '); -} - -// @ts-ignore -function structAbi(type_abi: any) { - return Object.keys(type_abi).map((abi: any) => { - - let inner; - switch (abi) { - case 'Struct': - const innerStruct = structField(type_abi.Struct.fields); - inner = `${type_abi.Struct.name} { ${innerStruct} } `; - break; - case 'Vector': - if (isString(type_abi.Vector)) { - inner = `Vector<${type_abi.Vector}>`; - } else { - inner = structAbi(type_abi.Vector); - inner = `Vector<${inner}>`; - } - break; - default: - } - - return `${inner}`; - }).join(', \n'); -} - - -function StructItem(props: Props) { - const { codes } = props; - return <>{codes.map((item: any, index: any) => { - const fields = structField(item.fields); - return
-
; - })}; -} - - -// const CustomTreeItem = (props: TreeItemProps) => ( -// -// ); - - -export default function CodeContent(props: Props) { - const { codes } = props; - - const [expanded, setExpanded] = React.useState([]); - const [selected, setSelected] = useState([]); - - const CustomContent = React.forwardRef(function CustomContent( - props: TreeItemContentProps, - ref, - ) { - const { - classes, - className, - label, - nodeId, - icon: iconProp, - expansionIcon, - displayIcon, - } = props; - - const { - disabled, - expanded, - selected, - focused, - handleExpansion, - handleSelection, - preventSelection, - } = useTreeItem(nodeId); - - const icon = iconProp || expansionIcon || displayIcon; - - const handleMouseDown = (event: React.MouseEvent) => { - preventSelection(event); - }; - - const handleExpansionClick = ( - event: React.MouseEvent, - ) => { - handleExpansion(event); - }; - - const handleSelectionClick = ( - event: React.MouseEvent, - ) => { - handleSelection(event); - }; - - return ( - // eslint-disable-next-line jsx-a11y/no-static-element-interactions -
} - > - {/* eslint-disable-next-line jsx-a11y/click-events-have-key-events,jsx-a11y/no-static-element-interactions */} -
- {icon} -
- - {label} - -
- ); - }); - - if (codes.length === 0) { - return
no data
- } - - const handleToggle = (event: React.SyntheticEvent, nodeIds: string[]) => { - setExpanded(nodeIds); - }; - - const handleSelect = (event: React.SyntheticEvent, nodeIds: string[]) => { - setSelected(nodeIds); - }; - - const dis = () => { - const vfs = new WasmFs(); - - const mp = new Disassemble(vfs); - - mp.disassemble("test", "a11ceb0b040000000601000403040f051307071a60087a100c8a011800000001000200010000030001000104020100010c0002060c010e4163636f756e7453637269707473074163636f756e741964697361626c655f6175746f5f6163636570745f746f6b656e18656e61626c655f6175746f5f6163636570745f746f6b656e157365745f6175746f5f6163636570745f746f6b656e000000000000000000000000000000010002000001040e00091102020102000001040e000811020200", (ok: boolean, data: string) => { - console.log(ok) - console.log(data) - }) - - } - - dis(); - - console.log(expanded) - console.log(selected) - - return ( - - } - defaultExpandIcon={} - expanded={expanded} - selected={selected} - onNodeToggle={handleToggle} - onNodeSelect={handleSelect} - multiSelect - > - - {codes.map((item: any, index: any) => { - return - - { - item.code.script_functions.length > 0 ? - - - - : - } - - { - item.code.structs.length > 0 ? - - - - : - } - - ; - - })} - - - ); -} - -// { -// -// {/* */} -// -// {item.name} - -// -// { -// expanded.includes(item.name + index) ? : <> -// } -// -// } \ No newline at end of file