Adjust valueToText formatting (no trailing ,) (#6330)
This commit is contained in:
parent
8c47eaf011
commit
067240185e
@ -10,6 +10,7 @@ import styled from 'styled-components';
|
||||
import { Static } from '@polkadot/react-components';
|
||||
|
||||
import { useTranslation } from '../translate';
|
||||
import { toHumanJson } from '../valueToText';
|
||||
import Bare from './Bare';
|
||||
|
||||
interface Props {
|
||||
@ -27,12 +28,11 @@ function StaticParam ({ asHex, children, childrenPre, className = '', defaultVal
|
||||
const value = defaultValue && (defaultValue.value as string) && (
|
||||
asHex
|
||||
? (defaultValue.value as Codec).toHex()
|
||||
: JSON.stringify(
|
||||
: toHumanJson(
|
||||
(defaultValue.value as { toHuman?: () => unknown }).toHuman
|
||||
? (defaultValue.value as Codec).toHuman()
|
||||
: defaultValue.value,
|
||||
null, 2
|
||||
).replace(/"/g, '').replace(/\\/g, '').replace(/\],\[/g, '],\n[')
|
||||
: defaultValue.value
|
||||
)
|
||||
);
|
||||
|
||||
return (
|
||||
|
||||
@ -7,7 +7,7 @@ import type { Codec } from '@polkadot/types/types';
|
||||
import React from 'react';
|
||||
|
||||
import { Option, Raw } from '@polkadot/types';
|
||||
import { isFunction, isNull, isUndefined, u8aToHex } from '@polkadot/util';
|
||||
import { isFunction, isNull, isUndefined, stringify, u8aToHex } from '@polkadot/util';
|
||||
|
||||
interface DivProps {
|
||||
className?: string;
|
||||
@ -41,9 +41,9 @@ function toHuman (value: Codec | Codec[]): unknown {
|
||||
: value.toString();
|
||||
}
|
||||
|
||||
function toString (value: any): string {
|
||||
return JSON
|
||||
.stringify(value, null, 2)
|
||||
export function toHumanJson (value: any): string {
|
||||
return stringify(value, 2)
|
||||
.replace(/,\n/g, '\n')
|
||||
.replace(/"/g, '')
|
||||
.replace(/\\/g, '')
|
||||
.replace(/\],\[/g, '],\n[');
|
||||
@ -61,13 +61,13 @@ export default function valueToText (type: string, value: Codec | undefined | nu
|
||||
// HACK Handle Keys as hex-only (this should go away once the node value is
|
||||
// consistently swapped to `Bytes`)
|
||||
: type === 'Vec<(ValidatorId,Keys)>'
|
||||
? toString(formatKeys(value as unknown as [ValidatorId, Keys][]))
|
||||
? toHumanJson(formatKeys(value as unknown as [ValidatorId, Keys][]))
|
||||
: value instanceof Raw
|
||||
? value.isEmpty
|
||||
? '<empty>'
|
||||
: value.toString()
|
||||
: (value instanceof Option) && value.isNone
|
||||
? '<none>'
|
||||
: toString(toHuman(value))
|
||||
: toHumanJson(toHuman(value))
|
||||
);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user