diff --git a/packages/ui-app/src/Params/Param/VoteThreshold.tsx b/packages/ui-app/src/Params/Param/VoteThreshold.tsx index 4ee52de910..5f6df4b664 100644 --- a/packages/ui-app/src/Params/Param/VoteThreshold.tsx +++ b/packages/ui-app/src/Params/Param/VoteThreshold.tsx @@ -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 { render () { const { className, defaultValue: { value }, isDisabled, isError, label, style, withLabel } = this.props; diff --git a/packages/ui-app/src/Params/valueToText.ts b/packages/ui-app/src/Params/valueToText.ts index bf59af5dcb..fae4fefea4 100644 --- a/packages/ui-app/src/Params/valueToText.ts +++ b/packages/ui-app/src/Params/valueToText.ts @@ -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, 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); } diff --git a/yarn.lock b/yarn.lock index 15b6c7c494..6376680635 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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: