ghost-portal/packages/apps/src/Content/index.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

82 lines
2.2 KiB
TypeScript

// Copyright 2017-2019 @polkadot/apps 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 { ApiProps } from '@polkadot/ui-api/types';
import { QueueProps } from '@polkadot/ui-app/Status/types';
import './Content.css';
import React from 'react';
import { withRouter } from 'react-router';
import { withCalls, withMulti } from '@polkadot/ui-api/index';
import { QueueConsumer } from '@polkadot/ui-app/Status/Context';
import Status from '../Status';
import routing from '../routing';
import translate from '../translate';
import NotFound from './NotFound';
type Props = I18nProps & ApiProps & {
location: Location
};
const unknown = {
isApiGated: false,
Component: NotFound,
name: ''
};
class Content extends React.Component<Props> {
render () {
const { isApiConnected, isApiReady, location, t } = this.props;
const app = location.pathname.slice(1) || '';
const { Component, isApiGated, name } = routing.routes.find((route) =>
!!(route && app.indexOf(route.name) === 0)
) || unknown;
if (isApiGated && (!isApiReady || !isApiConnected)) {
return (
<div className='apps--Content-body'>
<main>{t('Waiting for API to be connected and ready.')}</main>
</div>
);
}
return (
<div className='apps--Content'>
<QueueConsumer>
{({ queueAction, stqueue, txqueue }: QueueProps) => [
<Component
key='content-content'
basePath={`/${name}`}
onStatusChange={queueAction}
/>,
<Status
key='content-status'
queueAction={queueAction}
stqueue={stqueue}
txqueue={txqueue}
/>
]}
</QueueConsumer>
</div>
);
}
}
// React-router needs to be first, otherwise we have blocked updates
// These API queries are used in a number of places, warm them up as
// to avoid constant un/resubscriptions on these
export default withMulti(
Content,
withRouter,
translate,
withCalls<Props>(
'query.session.validators',
'derive.accounts.indexes',
'derive.balances.fees'
)
);