ghost-portal/packages/app-toolbox/src/index.js
Jaco Greeff 397dd0c983
Update jsonrpc dependency tree (#54)
* Use tyopeToString from @polkadot/params

* Upgrades... before checks

* Cleanups... WIP.

* more WIP.

* Expand defaultValue & handlers

* Cleanups

* CodeClimate cleanups

* Additional CodeClimate cleanups

* Base for app-rpc

* Initial split into ui-signer

* Signer operational (extrinsics)

* Decode extrinsic method

* RPC progress...

* RPC class works again

* @flow cleanups
2018-05-23 18:01:42 +02:00

104 lines
2.3 KiB
JavaScript

// Copyright 2017-2018 Jaco Greeff
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
// @flow
import type { I18nProps } from '@polkadot/ui-app/types';
import './index.css';
import React from 'react';
import Button from '@polkadot/ui-app/Button';
import classes from '@polkadot/ui-app/util/classes';
import Hash from './Hash';
import Sign from './Sign';
import Verify from './Verify';
import translate from './translate';
type Actions = 'hash' | 'sign' | 'verify';
type Props = I18nProps & {};
type State = {
action: Actions
}
// FIXME React-router would probably be the best route, not home-grown
// flowlint-next-line unclear-type:off
const Components: { [Actions]: React$ComponentType<any> } = {
'hash': Hash,
'sign': Sign,
'verify': Verify
};
class ToolboxApp extends React.PureComponent<Props, State> {
state: State = {
action: 'hash'
};
render (): React$Node {
const { className, style } = this.props;
const { action } = this.state;
const Component = Components[action];
return (
<div
className={classes('toolbox--App', className)}
style={style}
>
{this.renderButtons()}
<Component />
</div>
);
}
renderButtons (): React$Node {
const { t } = this.props;
const { action } = this.state;
return (
<Button.Group className='accounts--App-navigation'>
<Button
isPrimary={action === 'hash'}
onClick={this.selectHash}
text={t('app.hash', {
defaultValue: 'Hash data'
})}
/>
<Button.Or />
<Button
isPrimary={action === 'sign'}
onClick={this.selectSign}
text={t('app.sign', {
defaultValue: 'Sign message'
})}
/>
<Button.Or />
<Button
isPrimary={action === 'verify'}
onClick={this.selectVerify}
text={t('app.verify', {
defaultValue: 'Verify signature'
})}
/>
</Button.Group>
);
}
selectHash = (): void => {
this.setState({ action: 'hash' });
}
selectSign = (): void => {
this.setState({ action: 'sign' });
}
selectVerify = (): void => {
this.setState({ action: 'verify' });
}
}
export default translate(ToolboxApp);