Updates for parachains (#1740)
* Updates for parachains * Split result conversion, linting * Pass through convertHex * Cleanup event specification
This commit is contained in:
parent
835fdf0a92
commit
5c2440146a
@ -1,4 +1,3 @@
|
||||
/* eslint-disable @typescript-eslint/camelcase */
|
||||
// Copyright 2017-2019 @polkadot/app-parachains authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
@ -14,24 +13,30 @@ import translate from '../translate';
|
||||
import Parachain from './Parachain';
|
||||
|
||||
interface Props extends I18nProps {
|
||||
parachains_parachains?: BN[];
|
||||
parachains?: BN[];
|
||||
}
|
||||
|
||||
function Parachains ({ parachains_parachains, t }: Props): React.ReactElement<Props> {
|
||||
function Parachains ({ parachains, t }: Props): React.ReactElement<Props> {
|
||||
return (
|
||||
<Column
|
||||
emptyText={t('no deployed parachains')}
|
||||
headerText={t('parachains')}
|
||||
>
|
||||
{parachains_parachains && parachains_parachains.map((paraId): React.ReactNode =>
|
||||
<Parachain key={paraId.toString()} paraId={paraId} />
|
||||
)}
|
||||
{parachains && parachains.map((paraId): React.ReactNode => (
|
||||
<Parachain
|
||||
key={paraId.toString()}
|
||||
paraId={paraId}
|
||||
/>
|
||||
))}
|
||||
</Column>
|
||||
);
|
||||
}
|
||||
|
||||
export default translate(
|
||||
withCalls<Props>(
|
||||
'query.parachains.parachains'
|
||||
['query.registrar.parachains', {
|
||||
fallbacks: ['query.parachains.parachains'],
|
||||
propName: 'parachains'
|
||||
}]
|
||||
)(Parachains)
|
||||
);
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
/* eslint-disable @typescript-eslint/camelcase */
|
||||
// Copyright 2017-2019 @polkadot/app-parachains authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
@ -14,22 +13,22 @@ import { formatNumber } from '@polkadot/util';
|
||||
import translate from '../translate';
|
||||
|
||||
interface Props extends I18nProps {
|
||||
parachains_nextFreeId?: BN;
|
||||
parachains_parachains?: BN[];
|
||||
nextFreeId?: BN;
|
||||
parachains?: BN[];
|
||||
}
|
||||
|
||||
function Summary ({ parachains_nextFreeId, parachains_parachains = [], t }: Props): React.ReactElement<Props> {
|
||||
function Summary ({ nextFreeId, parachains = [], t }: Props): React.ReactElement<Props> {
|
||||
return (
|
||||
<SummaryBox>
|
||||
<section>
|
||||
<CardSummary label={t('parachains')}>
|
||||
{formatNumber(parachains_parachains.length)}
|
||||
{formatNumber(parachains.length)}
|
||||
</CardSummary>
|
||||
</section>
|
||||
{parachains_nextFreeId && (
|
||||
{nextFreeId && (
|
||||
<section>
|
||||
<CardSummary label={t('next id')}>
|
||||
{formatNumber(parachains_nextFreeId)}
|
||||
{formatNumber(nextFreeId)}
|
||||
</CardSummary>
|
||||
</section>
|
||||
)}
|
||||
@ -39,7 +38,13 @@ function Summary ({ parachains_nextFreeId, parachains_parachains = [], t }: Prop
|
||||
|
||||
export default translate(
|
||||
withCalls<Props>(
|
||||
'query.parachains.nextFreeId',
|
||||
'query.parachains.parachains'
|
||||
['query.registrar.nextFreeId', {
|
||||
fallbacks: ['query.parachains.nextFreeId'],
|
||||
propName: 'nextFreeId'
|
||||
}],
|
||||
['query.registrar.parachains', {
|
||||
fallbacks: ['query.parachains.parachains'],
|
||||
propName: 'parachains'
|
||||
}]
|
||||
)(Summary)
|
||||
);
|
||||
|
||||
@ -8,7 +8,7 @@ import { BareProps } from './types';
|
||||
import React, { useState, createRef } from 'react';
|
||||
import Dropzone, { DropzoneRef } from 'react-dropzone';
|
||||
import styled from 'styled-components';
|
||||
import { formatNumber } from '@polkadot/util';
|
||||
import { formatNumber, isHex, u8aToString, hexToU8a } from '@polkadot/util';
|
||||
|
||||
import { classes } from './util';
|
||||
import Labelled from './Labelled';
|
||||
@ -19,6 +19,7 @@ interface Props extends BareProps, WithTranslation {
|
||||
// i.e. MIME types: 'application/json, text/plain', or '.json, .txt'
|
||||
accept?: string;
|
||||
clearContent?: boolean;
|
||||
convertHex?: boolean;
|
||||
help?: React.ReactNode;
|
||||
isDisabled?: boolean;
|
||||
isError?: boolean;
|
||||
@ -34,13 +35,26 @@ interface FileState {
|
||||
size: number;
|
||||
}
|
||||
|
||||
interface LoadEvent {
|
||||
target: {
|
||||
result: ArrayBuffer;
|
||||
};
|
||||
const BYTE_STR_0 = '0'.charCodeAt(0);
|
||||
const BYTE_STR_X = 'x'.charCodeAt(0);
|
||||
const NOOP = (): void => {};
|
||||
|
||||
function convertResult (result: ArrayBuffer, convertHex?: boolean): Uint8Array {
|
||||
const data = new Uint8Array(result);
|
||||
|
||||
// this converts the input (if detected as hex), vai the hex conversion route
|
||||
if (convertHex && data[0] === BYTE_STR_0 && data[1] === BYTE_STR_X) {
|
||||
const hex = u8aToString(data);
|
||||
|
||||
if (isHex(hex)) {
|
||||
return hexToU8a(hex);
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
function InputFile ({ accept, className, clearContent, help, isDisabled, isError = false, label, onChange, placeholder, t, withEllipsis, withLabel }: Props): React.ReactElement<Props> {
|
||||
function InputFile ({ accept, className, clearContent, convertHex, help, isDisabled, isError = false, label, onChange, placeholder, t, withEllipsis, withLabel }: Props): React.ReactElement<Props> {
|
||||
const dropRef = createRef<DropzoneRef>();
|
||||
const [file, setFile] = useState<FileState | undefined>();
|
||||
|
||||
@ -48,18 +62,16 @@ function InputFile ({ accept, className, clearContent, help, isDisabled, isError
|
||||
files.forEach((file): void => {
|
||||
const reader = new FileReader();
|
||||
|
||||
reader.onabort = (): void => { };
|
||||
reader.onerror = (): void => { };
|
||||
reader.onabort = NOOP;
|
||||
reader.onerror = NOOP;
|
||||
|
||||
// ummm... events are not properly specified here?
|
||||
(reader as any).onload = ({ target: { result } }: LoadEvent): void => {
|
||||
const data = new Uint8Array(result);
|
||||
const name = file.name;
|
||||
reader.onload = ({ target }: ProgressEvent<FileReader>): void => {
|
||||
if (target && target.result) {
|
||||
const name = file.name;
|
||||
const data = convertResult(target.result as ArrayBuffer, convertHex);
|
||||
|
||||
onChange && onChange(data, name);
|
||||
|
||||
if (dropRef) {
|
||||
setFile({
|
||||
onChange && onChange(data, name);
|
||||
dropRef && setFile({
|
||||
name,
|
||||
size: data.length
|
||||
});
|
||||
|
||||
@ -26,6 +26,7 @@ export default function File ({ className, isDisabled, isError = false, label, o
|
||||
style={style}
|
||||
>
|
||||
<InputFile
|
||||
convertHex
|
||||
isDisabled={isDisabled}
|
||||
isError={isError}
|
||||
label={label}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user