parent
2ac2af11ee
commit
0a1363f2eb
@ -0,0 +1,44 @@ |
|||||||
|
import React from 'react' |
||||||
|
import DropdownPanel from './dropdown-panel' |
||||||
|
import { extractData } from '../../utils/solidityTypeFormatter' |
||||||
|
import { ExtractData } from '../../types' |
||||||
|
|
||||||
|
export const SolidityLocals = () => { |
||||||
|
|
||||||
|
const formatSelf = (key: string, data: ExtractData) => { |
||||||
|
let color = 'var(--primary)' |
||||||
|
if (data.isArray || data.isStruct || data.isMapping) { |
||||||
|
color = 'var(--info)' |
||||||
|
} else if ( |
||||||
|
data.type.indexOf('uint') === 0 || |
||||||
|
data.type.indexOf('int') === 0 || |
||||||
|
data.type.indexOf('bool') === 0 || |
||||||
|
data.type.indexOf('enum') === 0 |
||||||
|
) { |
||||||
|
color = 'var(--green)' |
||||||
|
} else if (data.type === 'string') { |
||||||
|
color = 'var(--teal)' |
||||||
|
} else if (data.self == 0x0) { // eslint-disable-line
|
||||||
|
color = 'var(--gray)' |
||||||
|
} |
||||||
|
return ( |
||||||
|
<label className='mb-0' style={{ color: data.isProperty ? 'var(--info)' : '', whiteSpace: 'pre-wrap' }}> |
||||||
|
{' ' + key}: |
||||||
|
<label className='mb-0' style={{ color }}> |
||||||
|
{' ' + data.self} |
||||||
|
</label> |
||||||
|
<label style={{ fontStyle: 'italic' }}> |
||||||
|
{data.isProperty || !data.type ? '' : ' ' + data.type} |
||||||
|
</label> |
||||||
|
</label> |
||||||
|
) |
||||||
|
} |
||||||
|
|
||||||
|
return ( |
||||||
|
<div id='soliditylocals' data-id="solidityLocals"> |
||||||
|
<DropdownPanel dropdownName='Solidity Locals' opts={{ json: true }} extractFunc={extractData} formatSelfFunc={formatSelf} /> |
||||||
|
</div> |
||||||
|
) |
||||||
|
} |
||||||
|
|
||||||
|
export default SolidityLocals |
@ -1,11 +1,44 @@ |
|||||||
import React from 'react' |
import React from 'react' |
||||||
import DropdownPanel from './dropdown-panel' |
import DropdownPanel from './dropdown-panel' |
||||||
|
import { extractData } from '../../utils/solidityTypeFormatter' |
||||||
|
import { ExtractData } from '../../types' |
||||||
|
|
||||||
export const SolidityState = () => { |
export const SolidityState = () => { |
||||||
|
const formatSelf = (key: string, data: ExtractData) => { |
||||||
|
let color = 'var(--primary)' |
||||||
|
if (data.isArray || data.isStruct || data.isMapping) { |
||||||
|
color = 'var(--info)' |
||||||
|
} else if ( |
||||||
|
data.type.indexOf('uint') === 0 || |
||||||
|
data.type.indexOf('int') === 0 || |
||||||
|
data.type.indexOf('bool') === 0 || |
||||||
|
data.type.indexOf('enum') === 0 |
||||||
|
) { |
||||||
|
color = 'var(--green)' |
||||||
|
} else if (data.type === 'string') { |
||||||
|
color = 'var(--teal)' |
||||||
|
} else if (data.self == 0x0) { // eslint-disable-line
|
||||||
|
color = 'var(--gray)' |
||||||
|
} |
||||||
|
return ( |
||||||
|
<label className='mb-0' style={{ color: data.isProperty ? 'var(--info)' : '', whiteSpace: 'pre-wrap' }}> |
||||||
|
{' ' + key}: |
||||||
|
<label className='mb-0' style={{ color }}> |
||||||
|
{' ' + data.self} |
||||||
|
</label> |
||||||
|
<label style={{ fontStyle: 'italic' }}> |
||||||
|
{data.isProperty || !data.type ? '' : ' ' + data.type} |
||||||
|
</label> |
||||||
|
</label> |
||||||
|
) |
||||||
|
} |
||||||
|
|
||||||
return ( |
return ( |
||||||
<DropdownPanel dropdownName='Solidity State' opts={{
|
<div id='soliditylocals' data-id='solidityLocals'> |
||||||
|
{ |
||||||
}} /> |
<DropdownPanel dropdownName='Solidity State' opts={{ json: true }} formatSelfFunc={formatSelf} extractFunc={extractData} /> |
||||||
|
} |
||||||
|
</div> |
||||||
) |
) |
||||||
} |
} |
||||||
|
|
||||||
|
@ -0,0 +1,42 @@ |
|||||||
|
import { BN } from 'ethereumjs-util' |
||||||
|
import { ExtractData } from '../types' |
||||||
|
|
||||||
|
export function extractData (item, parent): ExtractData { |
||||||
|
const ret: ExtractData = {} |
||||||
|
|
||||||
|
if (item.isProperty) { |
||||||
|
return item |
||||||
|
} |
||||||
|
if (item.type.lastIndexOf(']') === item.type.length - 1) { |
||||||
|
ret.children = (item.value || []).map(function (item, index) { |
||||||
|
return {key: index, value: item} |
||||||
|
}) |
||||||
|
ret.children.unshift({ |
||||||
|
key: 'length', |
||||||
|
value: { |
||||||
|
self: (new BN(item.length.replace('0x', ''), 16)).toString(10), |
||||||
|
type: 'uint', |
||||||
|
isProperty: true |
||||||
|
} |
||||||
|
}) |
||||||
|
ret.isArray = true |
||||||
|
ret.self = parent.isArray ? '' : item.type |
||||||
|
} else if (item.type.indexOf('struct') === 0) { |
||||||
|
ret.children = Object.keys((item.value || {})).map(function (key) { |
||||||
|
return {key: key, value: item.value[key]} |
||||||
|
}) |
||||||
|
ret.self = item.type |
||||||
|
ret.isStruct = true |
||||||
|
} else if (item.type.indexOf('mapping') === 0) { |
||||||
|
ret.children = Object.keys((item.value || {})).map(function (key) { |
||||||
|
return {key: key, value: item.value[key]} |
||||||
|
}) |
||||||
|
ret.isMapping = true |
||||||
|
ret.self = item.type |
||||||
|
} else { |
||||||
|
ret.children = null |
||||||
|
ret.self = item.value |
||||||
|
ret.type = item.type |
||||||
|
} |
||||||
|
return ret |
||||||
|
} |
@ -1,4 +1,10 @@ |
|||||||
export interface TreeViewProps { |
export interface TreeViewProps { |
||||||
children?: React.ReactNode, |
children?: React.ReactNode, |
||||||
key: string |
key: string |
||||||
|
} |
||||||
|
|
||||||
|
export interface TreeViewItemProps { |
||||||
|
children?: React.ReactNode, |
||||||
|
key: string, |
||||||
|
label: string | number | React.ReactNode |
||||||
} |
} |
Loading…
Reference in new issue