// Copyright 2017-2018 @polkadot/app-toolbox authors & contributors // This software may be modified and distributed under the terms // of the ISC license. See the LICENSE file for details. // @flow import type { I18nProps as Props } from '@polkadot/ui-app/types'; import type { KeyringPair } from '@polkadot/util-keyring/types'; import React from 'react'; import Button from '@polkadot/ui-app/Button'; import Input from '@polkadot/ui-app/Input'; import InputAddress from '@polkadot/ui-app/InputAddress'; import Output from '@polkadot/ui-app/Output'; import Static from '@polkadot/ui-app/Static'; import classes from '@polkadot/ui-app/util/classes'; import keyring from '@polkadot/ui-keyring'; import hexToU8a from '@polkadot/util/hex/toU8a'; import isHex from '@polkadot/util/is/hex'; import u8aFromString from '@polkadot/util/u8a/fromString'; import u8aToHex from '@polkadot/util/u8a/toHex'; import Unlock from './Unlock'; import translate from './translate'; type State = { currentPair: KeyringPair | null, defaultValue?: string, data: string, isHexData: boolean, isLocked: boolean, isUnlockVisible: boolean, signature: string }; class Sign extends React.PureComponent { state: State; constructor (props: Props) { super(props); const pairs = keyring.getPairs(); const currentPair = pairs[0] || null; this.state = { currentPair, defaultValue: currentPair ? currentPair.address() : void 0, data: '', isHexData: false, isLocked: currentPair ? !currentPair.hasSecretKey() : false, isUnlockVisible: false, signature: '' }; } render (): React$Node { const { className, style } = this.props; return (
{this.renderAccount()} {this.renderInput()} {this.renderSignature()} {this.renderUnlock()} {this.renderButtons()}
); } renderAccount (): React$Node { const { t } = this.props; const { defaultValue } = this.state; return (
); } renderButtons (): React$Node { const { t } = this.props; const { isLocked } = this.state; if (!isLocked) { return null; } return (