Fix static params display (#1404)

* Fix statis params display

* Remove stray log
This commit is contained in:
Jaco Greeff 2019-07-15 08:53:23 +02:00 committed by GitHub
parent 83babcdae5
commit 4632c304cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 18 deletions

View File

@ -2,12 +2,12 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { IExtrinsic, IMethod } from '@polkadot/types/types';
import { Codec, IExtrinsic, IMethod } from '@polkadot/types/types';
import { BareProps, I18nProps } from './types';
import React from 'react';
import styled from 'styled-components';
import { Method, getTypeDef } from '@polkadot/types';
import { Method, getTypeDef, TypeDef } from '@polkadot/types';
import Params from '@polkadot/ui-params';
import Static from './Static';
@ -15,10 +15,10 @@ import { classes } from './util';
import translate from './translate';
export type Props = I18nProps & BareProps & {
children?: React.ReactNode,
value: IExtrinsic | IMethod,
withHash?: boolean,
mortality?: string
children?: React.ReactNode;
value: IExtrinsic | IMethod;
withHash?: boolean;
mortality?: string;
};
const Wrapper = styled.div`
@ -33,11 +33,11 @@ const Wrapper = styled.div`
class Call extends React.PureComponent<Props> {
public render (): React.ReactNode {
const { children, className, style, mortality, value, withHash, t } = this.props;
const params = Method.filterOrigin(value.meta).map(({ name, type }) => ({
const params = Method.filterOrigin(value.meta).map(({ name, type }): { name: string; type: TypeDef } => ({
name: name.toString(),
type: getTypeDef(type)
}));
const values = value.args.map((value) => ({
const values = value.args.map((value): { isValid: boolean; value: Codec } => ({
isValid: true,
value
}));

View File

@ -30,10 +30,10 @@ interface Props extends I18nProps {
}
interface State {
handlers: RawParamOnChange[];
handlers?: RawParamOnChange[];
onChangeParam: (at: number, next: RawParamOnChangeValue) => void;
params: Param[];
values: RawParams;
params?: Param[];
values?: RawParams;
}
class Params extends React.PureComponent<Props, State> {
@ -43,10 +43,7 @@ class Params extends React.PureComponent<Props, State> {
super(props);
this.state = {
handlers: [],
onChangeParam: this.onChangeParam,
params: [],
values: []
onChangeParam: this.onChangeParam
};
}
@ -84,7 +81,7 @@ class Params extends React.PureComponent<Props, State> {
const { values } = this.state;
if (!isDisabled && prevState.values !== values) {
onChange && onChange(values);
onChange && onChange(values || []);
}
}
@ -130,7 +127,7 @@ class Params extends React.PureComponent<Props, State> {
this.setState(
(prevState: State): State => ({
values: prevState.values.map((prev, index): RawParam =>
values: (prevState.values || []).map((prev, index): RawParam =>
index !== at
? prev
: {
@ -147,7 +144,7 @@ class Params extends React.PureComponent<Props, State> {
const { values } = this.state;
const { onChange, isDisabled } = this.props;
if (isDisabled) {
if (isDisabled || !values) {
return;
}