* [app-js] fixed copyright * [app-js] css fixes * [app-js] Add api to window object * Make CSS columns resizable (FF & Chrome) * Window Interface export * formatting * Make columns responsive, added Dropdown * Added code snippets * Strip down output to functional component * removed component state, removed onEdit, update on select * Editor styling * Added snippets and local storage * output formatting * Example dummies * Cleanup & examples * Added util & keyring @polkadot modules to window object * Moved intro to component to make it translatable * Added more RPC examples * small fix * WIP exaples * Styles for resizer, fixed flex overflow misbehaviour * remove code from snippets for options, * Added labels to dropdown * Examples * More examples and removed deprecated examples * Added labels to dropdown -> missing type decl. * correst link to ui-keyring package * Make tslint happy * Pull api clone/disconnect into sd-668 (#686) * JS playground & console (start something...) * It runs... * WIP * Use codeflask * Highlights * Small updates, console v0.1 is ok to play with * Bump * Only shadow, no border (article) * Allow API to be disposed of between runs * Clone and disconnect API * Move id generation (no need for constructor) * Small updates * Small type adjustments * smaller fixes after code review * updated yarn.lock * move options calculation out of return * Remove exposure of api to window object * Expand JS console logging (#691) * Expand JS console logging * Log extrinsics directly * switch to getDerivedStateFromProps() * roll back ts versions * react-i18next rollback to 9.0.2 * Lock react-i18next to 9.0.2
52 lines
1.5 KiB
TypeScript
52 lines
1.5 KiB
TypeScript
// Copyright 2017-2019 @polkadot/app-js 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 { BareProps } from '@polkadot/ui-app/types';
|
|
import { Log } from './types';
|
|
|
|
import React from 'react';
|
|
import { isError, isNull, isUndefined } from '@polkadot/util';
|
|
|
|
type Props = BareProps & {
|
|
children?: React.ReactNode,
|
|
logs: Array<Log>
|
|
};
|
|
|
|
const format = (value: any): string => {
|
|
if (isError(value)) {
|
|
return value.stack ? value.stack : value.toString();
|
|
} else if (isUndefined(value)) {
|
|
return 'undefined';
|
|
} else if (isNull(value)) {
|
|
return 'null';
|
|
} else if (Array.isArray(value)) {
|
|
return `[${value.map((value) => format(value)).join(', ')}]`;
|
|
} else if (value instanceof Map) {
|
|
return `{${[...value.entries()].map(([key, value]) => key + ': ' + format(value)).join(', ')}}`;
|
|
}
|
|
|
|
return value.toString();
|
|
};
|
|
|
|
const renderEntry = ({ args, type }: Log, index: number): React.ReactNode => (
|
|
<div className={`js--Log ${type}`} key={index}>
|
|
{args.map((arg) => format(arg)).join(' ')}
|
|
</div>
|
|
);
|
|
|
|
export default (props: Props) => {
|
|
return (
|
|
<article className='container js--Output'>
|
|
<div className='logs-wrapper'>
|
|
<div className='logs-container'>
|
|
<div className='logs-content'>
|
|
{props.logs.map(renderEntry)}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{props.children}
|
|
</article>
|
|
);
|
|
};
|