// Copyright 2017-2019 @polkadot/app-123code 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 { AppProps, I18nProps } from '@polkadot/ui-app/types'; import { ApiProps } from '@polkadot/ui-api/types'; import { SubjectInfo } from '@polkadot/ui-keyring/observable/types'; import { ComponentProps } from './types'; import React from 'react'; import { Route, Switch } from 'react-router'; import { Icon, Tabs } from '@polkadot/ui-app'; import { withApi, withCalls, withMulti, withObservable } from '@polkadot/ui-api'; import accountObservable from '@polkadot/ui-keyring/observable/accounts'; import SetKey from './SetKey'; import Sudo from './Sudo'; import translate from './translate'; type Props = AppProps & ApiProps & I18nProps & { allAccounts: SubjectInfo, sudo_key?: string }; type State = { isMine: boolean }; class App extends React.PureComponent { state: State = { isMine: false }; static getDerivedStateFromProps ({ allAccounts = {}, sudo_key }: Props): State | null { return { isMine: !!sudo_key && !!Object.keys(allAccounts).find((key) => key === sudo_key.toString()) }; } render () { const { basePath, t } = this.props; const { isMine } = this.state; return (
{isMine ? ( ) : (
{t('You do not have access to the current sudo key')}
)}
); } private renderComponent (Component: React.ComponentType) { return (): React.ReactNode => { const { allAccounts = {}, sudo_key: sudoKey = '' } = this.props; const { isMine } = this.state; return ( ); }; } } export default withMulti( App, translate, withApi, withCalls( ['query.sudo.key', { transform: key => key.toString() }] ), withObservable(accountObservable.subject, { propName: 'allAccounts' }) );