// 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 { ApiProps } from '@polkadot/ui-react-rx/types'; import type { I18nProps } from '@polkadot/ui-app/types'; import type { QueueTx, QueueTx$MessageSetStatus } from './types'; import React from 'react'; import Button from '@polkadot/ui-app/Button'; import Modal from '@polkadot/ui-app/Modal'; import classes from '@polkadot/ui-app/util/classes'; import keyring from '@polkadot/ui-keyring'; import withApi from '@polkadot/ui-react-rx/with/api'; import Extrinsic from './Extrinsic'; import Unlock from './Unlock'; import signMessage from './sign'; import submitMessage from './submit'; import translate from './translate'; type Props = I18nProps & ApiProps & { queue: Array, queueSetStatus: QueueTx$MessageSetStatus }; type UnlockI18n = { key: string, value: I18Next$Translate$Config } type State = { currentItem?: QueueTx, password: string, unlockError: UnlockI18n | null }; class Signer extends React.PureComponent { state: State; constructor (props: Props) { super(props); this.state = { apiSupport: 'poc-1', password: '', unlockError: null }; } static getDerivedStateFromProps ({ queue }: Props, { currentItem, password, unlockError }: State): State { const nextItem = queue.find(({ status }) => status === 'queued' ); const isSame = !!nextItem && !!currentItem && ( (!nextItem.publicKey && !currentItem.publicKey) || ( (nextItem.publicKey && nextItem.publicKey.toString()) === (currentItem.publicKey && currentItem.publicKey.toString()) ) ); return { currentItem: nextItem, password: isSame ? password : '', unlockError: isSame ? unlockError : null }; } componentDidUpdate (prevProps: Props, prevState: State) { const { currentItem } = this.state; if (currentItem && currentItem.status === 'queued' && currentItem.rpc.isSigned !== true) { this.sendItem(currentItem); } } render (): React$Node { const { className, style } = this.props; const { currentItem } = this.state; if (!currentItem || currentItem.rpc.isSigned !== true) { return null; } return ( {this.renderContent()} {this.renderButtons()} ); } renderButtons (): React$Node { const { t } = this.props; const { currentItem: { rpc: { isSigned = false } = {} } = {} } = this.state; return (