Update Referendum text display (#145)

This commit is contained in:
Jaco Greeff 2018-07-13 11:26:56 +02:00 committed by GitHub
parent 02aefa60e1
commit 67691af8c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 3 deletions

View File

@ -9,12 +9,20 @@ import React from 'react';
import Dropdown from '../../Dropdown';
import Bare from './Bare';
type TextMap = { [index: number]: string };
const options = [
{ text: 'Super majority approval', value: 0 },
{ text: 'Super majority rejection', value: 1 },
{ text: 'Simple majority', value: 2 }
];
export const textMap = options.reduce((textMap, { text, value }) => {
textMap[value] = text;
return textMap;
}, {} as TextMap);
export default class VoteThreshold extends React.PureComponent<Props> {
render () {
const { className, defaultValue: { value }, isDisabled, isError, label, style, withLabel } = this.props;

View File

@ -9,6 +9,9 @@ import addressEncode from '@polkadot/util-keyring/address/encode';
import u8aToHex from '@polkadot/util/u8a/toHex';
import isBn from '@polkadot/util/is/bn';
import isU8a from '@polkadot/util/is/u8a';
import isUndefined from '@polkadot/util/is/undefined';
import { textMap as thresholdTextMap } from './Param/VoteThreshold';
function proposalToText ({ extrinsic, params }: ExtrinsicDecoded): string {
if (!extrinsic) {
@ -32,7 +35,6 @@ function arrayToText (type: Param$Type$Array, value: Array<any>, withBound: bool
return `${value.length}`;
}
console.error('value.length', value);
return value.map((value) =>
valueToText(type[0], value, false)
).join(', ');
@ -51,7 +53,7 @@ function valueToText (type: Param$Types, value: any, swallowError: boolean = tru
return value ? 'Yes' : 'No';
}
if (!value) {
if (isUndefined(value)) {
return 'unknown';
}
@ -69,6 +71,10 @@ function valueToText (type: Param$Types, value: any, swallowError: boolean = tru
return proposalToText(value as ExtrinsicDecoded);
}
if (type === 'VoteThreshold') {
return thresholdTextMap[value];
}
if (isU8a(value)) {
return u8aToHex(value, 256);
}

View File

@ -2294,7 +2294,7 @@ babel-preset-es2015@^6.9.0:
babel-plugin-transform-es2015-unicode-regex "^6.24.1"
babel-plugin-transform-regenerator "^6.24.1"
babel-preset-jest@^23.2.0:
babel-preset-jest@^23.0.1, babel-preset-jest@^23.2.0:
version "23.2.0"
resolved "https://registry.yarnpkg.com/babel-preset-jest/-/babel-preset-jest-23.2.0.tgz#8ec7a03a138f001a1a8fb1e8113652bf1a55da46"
dependencies: