Split tuple for wrapped components (#2988)

This commit is contained in:
Jaco Greeff 2020-06-19 13:36:25 +02:00 committed by GitHub
parent 192e2831a8
commit 8804961af5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 40 deletions

View File

@ -55,8 +55,8 @@ export default React.memo(styled(Option)`
position: relative;
.ui--Param-Option-toggle {
bottom: 1.375rem;
position: absolute;
right: 3.5rem;
top: 0.5rem;
}
`);

View File

@ -50,4 +50,8 @@ export default React.memo(styled(StaticParam)`
overflow: hidden;
text-overflow: ellipsis;
}
.ui--Static {
margin-bottom: 0 !important;
}
`);

View File

@ -76,47 +76,49 @@ const components: ComponentMap = componentDef.reduce((components, { c, t }): Com
const warnList: string[] = [];
function fromDef ({ displayName, info, sub, type }: TypeDef): string {
if (displayName && SPECIAL_TYPES.includes(displayName)) {
return displayName;
}
switch (info) {
case TypeDefInfo.Compact:
return (sub as TypeDef).type;
case TypeDefInfo.Option:
return 'Option';
case TypeDefInfo.Enum:
return 'Enum';
case TypeDefInfo.Struct:
return 'Struct';
case TypeDefInfo.Tuple:
if (components[type] === Account) {
return type;
}
return 'Tuple';
case TypeDefInfo.Vec:
if (type === 'Vec<u8>') {
return 'Bytes';
}
return ['Vec<KeyValue>'].includes(type)
? 'Vec<KeyValue>'
: 'Vec';
default:
return type;
}
}
export default function findComponent (def: TypeDef, overrides: ComponentMap = {}): React.ComponentType<Props> {
const findOne = (type: string): React.ComponentType<Props> | null =>
overrides[type] || components[type];
const type = (({ displayName, info, sub, type }: TypeDef): string => {
if (displayName && SPECIAL_TYPES.includes(displayName)) {
return displayName;
}
switch (info) {
case TypeDefInfo.Compact:
return (sub as TypeDef).type;
case TypeDefInfo.Option:
return 'Option';
case TypeDefInfo.Enum:
return 'Enum';
case TypeDefInfo.Struct:
return 'Struct';
case TypeDefInfo.Tuple:
if (components[type] === Account) {
return type;
}
return 'Tuple';
case TypeDefInfo.Vec:
if (type === 'Vec<u8>') {
return 'Bytes';
}
return ['Vec<KeyValue>'].includes(type)
? 'Vec<KeyValue>'
: 'Vec';
default:
return type;
}
})(def);
const type = fromDef(def);
let Component = findOne(type);
@ -131,7 +133,7 @@ export default function findComponent (def: TypeDef, overrides: ComponentMap = {
return Component;
} else if (isBn(instance)) {
return Amount;
} else if ([TypeDefInfo.Enum, TypeDefInfo.Struct].includes(raw.info)) {
} else if ([TypeDefInfo.Enum, TypeDefInfo.Struct, TypeDefInfo.Tuple].includes(raw.info)) {
return findComponent(raw, overrides);
}
} catch (error) {