Reformat toHuman outputs (#2319)

This commit is contained in:
Jaco Greeff 2020-03-01 22:41:26 +01:00 committed by GitHub
parent 7e921debbe
commit c69154e06c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 5 deletions

View File

@ -67,7 +67,8 @@ function createComponent (type: string, Component: React.ComponentType<any>, def
// In order to modify the parameters which are used to render the default component, we can use this method
refresh: (swallowErrors: boolean, contentShorten: boolean): React.ComponentType<any> =>
renderHelper(
(value: any): React.ReactNode => valueToText(type, value, swallowErrors, contentShorten),
(value: any): React.ReactNode =>
<pre>{valueToText(type, value, swallowErrors, contentShorten)}</pre>,
defaultProps
)
};
@ -115,7 +116,8 @@ function getCachedComponent (query: QueryTypes): CacheInstance {
const defaultProps = { className: 'ui--output' };
const Component = renderHelper(
// By default we render a simple div node component with the query results in it
(value: any): React.ReactNode => valueToText(type, value, true, true),
(value: any): React.ReactNode =>
<pre>{valueToText(type, value, true, true)}</pre>,
defaultProps
);
@ -228,4 +230,8 @@ export default styled(Query)`
margin: -10px 0;
vertical-align: middle;
}
pre {
margin: 0;
}
`;

View File

@ -34,7 +34,7 @@ export default function Results ({ queue = [] }: Props): React.ReactElement<Prop
value={
error
? error.message
: <pre>{JSON.stringify(result.toHuman(), null, 2)}</pre>
: <pre>{JSON.stringify(result.toHuman(), null, 2).replace(/"/g, '')}</pre>
}
/>
))}

View File

@ -46,13 +46,13 @@ export default function valueToText (type: string, value: any, swallowError = tr
// HACK Handle Keys as hex-only (this should go away once the node value is
// consistently swapped to `Bytes`)
: type === 'Vec<(ValidatorId,Keys)>'
? JSON.stringify(formatKeys(value as [ValidatorId, Keys][]))
? JSON.stringify(formatKeys(value as [ValidatorId, Keys][]), null, 2).replace(/"/g, '')
: value instanceof Raw
? value.isEmpty
? '<empty>'
: value.toString()
: (value instanceof Option) && value.isNone
? '<none>'
: JSON.stringify(value.toHuman())
: JSON.stringify(value.toHuman(), null, 2).replace(/"/g, '')
);
}