* Some initial cleanups * Make it lint * Small s/type/interface/ additions * Small minor s/type/interface/ * More type -> interface * Add lint:new rule * Some small updates * Cleanup dangling tslint issues * Small updates * ui-signer cleanups * ui-reactive updated * Make lint:new run * Mini ui-params cleanups * Some additions * Tiny... and done for now. * 1950 problems (1241 errors, 709 warnings) * 1829 problems (1181 errors, 648 warnings) * 1674 problems (1181 errors, 493 warnings) (no any... for now) * Small additions. * Array<T> -> T[] (all)
56 lines
1.5 KiB
TypeScript
56 lines
1.5 KiB
TypeScript
// Copyright 2017-2019 @polkadot/ui-app authors & contributors
|
|
// This software may be modified and distributed under the terms
|
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
|
|
|
import './Params.css';
|
|
|
|
import React from 'react';
|
|
import { classes } from '@polkadot/ui-app/util';
|
|
import { isNull, isUndefined, u8aToHex } from '@polkadot/util';
|
|
import { Option, U8a } from '@polkadot/types';
|
|
|
|
interface DivProps {
|
|
className?: string;
|
|
key?: any;
|
|
}
|
|
|
|
function div ({ key, className }: DivProps, ...values: React.ReactNode[]): React.ReactNode {
|
|
return (
|
|
<div
|
|
className={classes('ui--Param-text', className)}
|
|
key={key}
|
|
>
|
|
{values}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
const unknown = div({}, '<unknown>');
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
function valueToText (type: string, value: any, swallowError: boolean = true, contentShorten: boolean = true): React.ReactNode {
|
|
// dont' even ask, nested ?: ... really?
|
|
return isNull(value) || isUndefined(value)
|
|
? unknown
|
|
: div(
|
|
{},
|
|
['Bytes', 'Data'].includes(type)
|
|
? u8aToHex(value.toU8a(true), contentShorten ? 512 : -1)
|
|
: (
|
|
value instanceof U8a
|
|
? (
|
|
value.isEmpty
|
|
? '<empty>'
|
|
: value.toString()
|
|
)
|
|
: (
|
|
(value instanceof Option) && value.isNone
|
|
? '<empty>'
|
|
: value.toString()
|
|
)
|
|
)
|
|
);
|
|
}
|
|
|
|
export default valueToText;
|