// Copyright 2017-2019 @polkadot/app-settings 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 React from 'react'; import store from 'store'; import styled from 'styled-components'; import { getTypeRegistry } from '@polkadot/types'; import { Button, Editor, InputFile, Labelled } from '@polkadot/ui-app'; import { ActionStatus } from '@polkadot/ui-app/Status/types'; import { isJsonObject, stringToU8a, u8aToString } from '@polkadot/util'; import translate from './translate'; type Props = AppProps & I18nProps & { onStatusChange: (status: ActionStatus) => void }; type State = { code: string, isJsonValid: boolean, isTypesValid: boolean, types: { [index: string]: any } | {}, typesPlaceholder?: string }; const Wrapper = styled.div` .editor { height: 300px; position: relative; } `; class Developer extends React.PureComponent { private defaultCode: string = `{\n\n}`; constructor (props: Props) { super(props); const types = store.get('types') || {}; const names = Object.keys(types); this.state = { code: Object.keys(types).length ? JSON.stringify(types, null, 2) : this.defaultCode, isJsonValid: true, isTypesValid: true, types: names.length ? types : {}, typesPlaceholder: names.length ? names.join(', ') : undefined }; } render () { const { t } = this.props; const { code, isJsonValid, isTypesValid, types, typesPlaceholder } = this.state; const typesHasNoEntries = Object.keys(types).length === 0; return (