Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert broken struct #1918

Merged
merged 2 commits into from
Nov 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/react-params/src/Param/Struct.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { TypeDef } from '@polkadot/types/types';
import { ParamDef, Props, RawParam } from '../types';

import React, { useEffect, useState } from 'react';
import { createType, getTypeDef } from '@polkadot/types';

import Params from '../';
import Base from './Base';
Expand All @@ -16,7 +17,10 @@ export default function StructParam (props: Props): React.ReactElement<Props> {
const [params, setParams] = useState<ParamDef[]>([]);

useEffect((): void => {
setParams((type.sub as TypeDef[]).map((subType): ParamDef => ({ name: subType.name, type: subType })));
const rawType = createType(type.type as any).toRawType();
const typeDef = getTypeDef(rawType);

setParams((typeDef.sub as TypeDef[]).map((type): ParamDef => ({ name: type.name, type })));
}, [type]);

if (isDisabled) {
Expand Down
8 changes: 2 additions & 6 deletions packages/react-params/src/Param/findComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { TypeDef, TypeDefInfo } from '@polkadot/types/types';
import { Props, ComponentMap } from '../types';

import BN from 'bn.js';
import { createType, getTypeDef, SPECIAL_TYPES } from '@polkadot/types';
import { createType, getTypeDef } from '@polkadot/types';

import Account from './Account';
import Amount from './Amount';
Expand Down Expand Up @@ -73,7 +73,7 @@ export default function findComponent (def: TypeDef, overrides: ComponentMap = {
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)) {
if (displayName) {
return displayName;
}

Expand All @@ -97,10 +97,6 @@ export default function findComponent (def: TypeDef, overrides: ComponentMap = {
return 'Tuple';

case TypeDefInfo.Vec:
if (type === 'Vec<u8>') {
return 'Bytes';
}

return ['Vec<KeyValue>'].includes(type)
? 'Vec<KeyValue>'
: 'Vec';
Expand Down
5 changes: 2 additions & 3 deletions packages/react-params/src/Param/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { BaseProps, Props as CProps, ComponentMap } from '../types';

import React, { useRef } from 'react';
import { classes } from '@polkadot/react-components/util';
import { displayType } from '@polkadot/types';
import { isUndefined } from '@polkadot/util';

import translate from '../translate';
Expand All @@ -28,8 +27,8 @@ function Param ({ className, defaultValue, isDisabled, isOptional, name, onChang
}

const label = isUndefined(name)
? displayType(type)
: `${name}: ${displayType(type)}`;
? (type.displayName || type.type)
: `${name}: ${type.displayName || type.type}`;

return isOptional
? (
Expand Down
Loading