ghost-portal/packages/app-explorer/src/Events.tsx
Jaco Greeff fef9f61c65
Use ApiPromise instance, replace ApiObservable (#540)
* Expose ApiPromise, cleanup API props

* WIP

* First component via ApiPromise

* More items via ApiPromise

* More robust availability handling

* Disable routes based on API endpoint checks

* Handle promises

* Low-hanging fruit for call conversion

* Remove extra params

* Adjust rx components with children props

* Start pulling in derived values

* Additional derived

* Bump

* More derived values

* Add derive.balances.fees

* Additional account lookups

* derive lookup for Id -> Index mappings

* Cleanups, accountIdToIndex

* Rework for new API

* Update deps, all-ok after API bumps

* Add voting and validating balances

* Cleanup callback

* Democracy wrap-up

* 2019

* withApiPromise -> withApiCall

* Calculate referendum number

* Fix balances, withObservableBase -> withObservable

* Cleanup with actual interfaces

* withApiCall -> withCall

* Bumps

* api-observable types replaced

* Half-effort to adjust extrinsic creation

* No api-observable refs anymore

* Cleanup storage query app

* Cleanup call

* Voting works...

* Add Vote component

* Update API
2019-01-07 17:54:01 +01:00

113 lines
2.8 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.
// 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 { Event, EventRecord } from '@polkadot/types';
import { Event as EventDisplay } from '@polkadot/ui-app/index';
import { withCall, withMulti } from '@polkadot/ui-react-rx/with';
import { stringToU8a } from '@polkadot/util';
import { xxhashAsHex } from '@polkadot/util-crypto';
import { MAX_ITEMS } from './BlockHeaders';
import translate from './translate';
type Props = I18nProps & {
query_system_events?: Array<EventRecord>
};
type State = {
prevEventHash: string;
recentEvents: Array<Event>;
};
class EventsDisplay extends React.PureComponent<Props, State> {
constructor (props: Props) {
super(props);
this.state = {
prevEventHash: '',
recentEvents: []
};
}
static getDerivedStateFromProps ({ query_system_events = [] }: Props, prevState: State): State | null {
const prevEventHash = xxhashAsHex(stringToU8a(JSON.stringify(query_system_events)));
if (prevEventHash === prevState.prevEventHash) {
return null;
}
const recentEvents = query_system_events
.filter(({ event }) =>
event.section !== 'system'
)
.map(({ event }) =>
event
)
.concat(prevState.recentEvents)
.filter((_, index) =>
index < MAX_ITEMS
);
return {
prevEventHash,
recentEvents
};
}
render () {
const { t } = this.props;
const { recentEvents } = this.state;
if (recentEvents.length === 0) {
return (
<div>{t('events.none', {
defaultValue: 'no non-internal events available'
})}</div>
);
}
return (
<div>
{recentEvents.map(this.renderEvent)}
</div>
);
}
private renderEvent = (event: Event, index: number) => {
return (
<article
className='explorer--Container'
key={index}
>
<div className='header'>
<h3>
{event.section}.{event.method}
</h3>
<div className='description'>
{
event.meta.documentation && event.meta.documentation.length
? event.meta.documentation.map((doc) => doc.toString()).join(' ')
: ''
}
</div>
</div>
<EventDisplay value={event} />
</article>
);
}
}
export default withMulti(
EventsDisplay,
translate,
withCall('query.system.events')
);