Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private _getTypeFromDataItem(dataItem: DataItem): Type {
const typeDocType = dataItem.components !== undefined ? TypeDocTypes.Reference : TypeDocTypes.Intrinsic;
let typeName: string;
if (typeDocType === TypeDocTypes.Reference) {
const nameIfExists = this._getNameFromDataItemIfExists(dataItem);
typeName = nameIfExists === undefined ? SolDoc._capitalize(dataItem.name) : nameIfExists;
} else {
typeName = dataItem.type;
}
const isArrayType = _.endsWith(dataItem.type, '[]');
let type: Type;
if (isArrayType) {
// tslint:disable-next-line:custom-no-magic-numbers
typeName = typeDocType === TypeDocTypes.Intrinsic ? typeName.slice(0, -2) : typeName;
type = {
elementType: { name: typeName, typeDocType },
typeDocType: TypeDocTypes.Array,
name: '',
};
} else {
type = { name: typeName, typeDocType };
}
return type;
}
private _overwriteStructNames(customTypes: CustomType[]): CustomType[] {
private _getTypeFromDataItem(dataItem: DataItem): Type {
const typeDocType = dataItem.components !== undefined ? TypeDocTypes.Reference : TypeDocTypes.Intrinsic;
let typeName: string;
if (typeDocType === TypeDocTypes.Reference) {
const nameIfExists = this._getNameFromDataItemIfExists(dataItem);
typeName = nameIfExists === undefined ? SolDoc._capitalize(dataItem.name) : nameIfExists;
} else {
typeName = dataItem.type;
}
const isArrayType = _.endsWith(dataItem.type, '[]');
let type: Type;
if (isArrayType) {
// tslint:disable-next-line:custom-no-magic-numbers
typeName = typeDocType === TypeDocTypes.Intrinsic ? typeName.slice(0, -2) : typeName;
type = {
elementType: { name: typeName, typeDocType },
typeDocType: TypeDocTypes.Array,
name: '',
typeDocType: TypeDocTypes.Tuple,
tupleElements: [],
};
for (const output of outputs) {
const tupleType = this._getTypeFromDataItem(output);
(type.tupleElements as Type[]).push(tupleType);
}
return type;
} else if (outputs.length === 1) {
const output = outputs[0];
type = this._getTypeFromDataItem(output);
} else {
type = {
name: 'void',
typeDocType: TypeDocTypes.Intrinsic,
};
}
return type;
}
private _getStructsAsCustomTypes(abiDefinition: AbiDefinition): CustomType[] {
export const Type: React.SFC = (props: TypeProps): any => {
const type = props.type;
const isReference = type.typeDocType === TypeDocTypes.Reference;
const isArray = type.typeDocType === TypeDocTypes.Array;
let typeNameColor = 'inherit';
let typeName: string | React.ReactNode;
let typeArgs: React.ReactNode[] = [];
switch (type.typeDocType) {
case TypeDocTypes.Intrinsic:
case TypeDocTypes.Unknown:
typeName = type.name;
typeNameColor = colors.orange;
break;
case TypeDocTypes.Reference:
typeName = type.name;
typeArgs = _.map(type.typeArguments, (arg: TypeDef) => {
if (arg.typeDocType === TypeDocTypes.Array) {
const key = `type-${arg.elementType.name}-${arg.elementType.typeDocType}`;
return (
<span>
</span>