ghost-portal/packages/app-explorer/src/Events.tsx
Jaco Greeff 653c2a505f
Basic info display for 123-code (#641)
* Add withCalls

* withCalls operational

* Basic header display & cleanups

* Global account selector for app

* Remove errant debug log

* Simple transfer applet working

* Update Upgrade.tsx

* Update InputNumber.tsx

* Update Transfer.tsx

* Move TxButton back to 123code (for the time being)

* Good enough for a v1
2019-01-27 12:50:47 +01:00

89 lines
2.4 KiB
TypeScript

// Copyright 2017-2019 @polkadot/app-explorer 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 { I18nProps } from '@polkadot/ui-app/types';
import React from 'react';
import { EventRecord } from '@polkadot/types';
import { Event as EventDisplay } from '@polkadot/ui-app/index';
import { formatNumber } from '@polkadot/ui-app/util';
import translate from './translate';
type Props = I18nProps & {
value?: Array<EventRecord>,
emptyLabel?: React.ReactNode,
eventClassName?: string,
withoutIndex?: boolean
};
class Events extends React.PureComponent<Props> {
render () {
const { emptyLabel, eventClassName, value, t } = this.props;
if (!value || value.length === 0) {
return emptyLabel || t('no events available');
}
return value
.filter(({ event }) => event) // event.section !== 'system')
.map((event, index) => {
const rendered = this.renderEvent(event, index);
return eventClassName
? (
<div
className={eventClassName}
key={index}
>
{rendered}
</div>
)
: rendered;
});
}
private renderEvent = ({ event, phase }: EventRecord, index: number) => {
const { withoutIndex } = this.props;
const extIndex = !withoutIndex && phase.type === 'ApplyExtrinsic'
? phase.asApplyExtrinsic
: -1;
return (
<article
className={['explorer--Container', 'ui--hoverable'].join(' ')}
key={index}
>
<div className='header'>
<h3>
{event.section}.{event.method}&nbsp;{
extIndex !== -1
? `(#${formatNumber(extIndex)})`
: ''
}
</h3>
</div>
<div className='ui--hover'>
<div className='ui--hover-content'>
<div className='description'>
{
event.meta.documentation && event.meta.documentation.length
? event.meta.documentation.map((doc) => doc.toString()).join(' ')
: ''
}
</div>
<EventDisplay
className='details'
value={event}
/>
</div>
</div>
</article>
);
}
}
export default translate(Events);