eslint fixes (round 2) (#1401)
* eslint fixes (round 2) * ui-params converted * Tiny. * Classes fix * Some type cleanups * Cleanup traling , * < 1k * Small additions * <750 * Mini updates modifiers * More ui-app cleanups * 312 problems (182 errors, 130 warnings)
This commit is contained in:
parent
fdb0beae1f
commit
144c8bbd85
@ -15,7 +15,7 @@ const KEY_CODE = 'code:';
|
||||
const codeRegex = new RegExp(`^${KEY_CODE}`, '');
|
||||
|
||||
class Store extends EventEmitter {
|
||||
private allCode: { [index: string]: CodeStored } = {};
|
||||
private allCode: Record<string, CodeStored> = {};
|
||||
|
||||
public get hasCode (): boolean {
|
||||
return Object.keys(this.allCode).length !== 0;
|
||||
|
||||
@ -15,13 +15,13 @@ import { withApi, withCalls, withMulti } from '@polkadot/ui-api';
|
||||
import translate from '../translate';
|
||||
|
||||
type Props = TxModalProps & ApiProps & {
|
||||
memberCount: number
|
||||
memberCount: number;
|
||||
};
|
||||
|
||||
type State = TxModalState & {
|
||||
method: Method | null,
|
||||
threshold: BN | null
|
||||
};
|
||||
interface State extends TxModalState {
|
||||
method: Method | null;
|
||||
threshold: BN | null;
|
||||
}
|
||||
|
||||
class Propose extends TxModal<Props, State> {
|
||||
constructor (props: Props) {
|
||||
@ -35,18 +35,21 @@ class Propose extends TxModal<Props, State> {
|
||||
this.state = this.defaultState;
|
||||
}
|
||||
|
||||
static getDerivedStateFromProps ({ memberCount }: Props, { threshold }: State) {
|
||||
public static getDerivedStateFromProps ({ memberCount }: Props, { threshold }: State): Pick<State, never> | null {
|
||||
if (!threshold && memberCount > 0) {
|
||||
const simpleMajority = new BN((memberCount / 2) + 1);
|
||||
|
||||
return { threshold: simpleMajority };
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
headerText = () => this.props.t('Propose a council motion');
|
||||
protected headerText = (): string => this.props.t('Propose a council motion');
|
||||
|
||||
txMethod = () => 'collective.propose';
|
||||
txParams = () => {
|
||||
protected txMethod = (): string => 'collective.propose';
|
||||
|
||||
protected txParams = (): [BN | null, ...Proposal[]] => {
|
||||
const { method, threshold } = this.state;
|
||||
|
||||
return [
|
||||
@ -55,7 +58,7 @@ class Propose extends TxModal<Props, State> {
|
||||
];
|
||||
}
|
||||
|
||||
isDisabled = () => {
|
||||
protected isDisabled = (): boolean => {
|
||||
const { memberCount = 0 } = this.props;
|
||||
const { accountId, method, threshold } = this.state;
|
||||
|
||||
@ -65,7 +68,7 @@ class Propose extends TxModal<Props, State> {
|
||||
return !accountId || !hasMethod || !hasThreshold;
|
||||
}
|
||||
|
||||
renderTrigger = () => {
|
||||
protected renderTrigger = (): React.ReactNode => {
|
||||
const { t } = this.props;
|
||||
|
||||
return (
|
||||
@ -80,7 +83,7 @@ class Propose extends TxModal<Props, State> {
|
||||
);
|
||||
}
|
||||
|
||||
renderContent = () => {
|
||||
protected renderContent = (): React.ReactNode => {
|
||||
const { apiDefaultTxSudo, memberCount = 0, t } = this.props;
|
||||
const { threshold } = this.state;
|
||||
|
||||
@ -111,12 +114,14 @@ class Propose extends TxModal<Props, State> {
|
||||
);
|
||||
}
|
||||
|
||||
private onChangeThreshold = (threshold?: BN): void => {
|
||||
private onChangeThreshold = (threshold: BN | null = null): void => {
|
||||
const { memberCount = 0 } = this.props;
|
||||
|
||||
if (memberCount > 0 && !this.defaultState.threshold) {
|
||||
this.defaultState.threshold = new BN((memberCount / 2) + 1);
|
||||
}
|
||||
this.setState({ threshold } as State);
|
||||
|
||||
this.setState({ threshold });
|
||||
}
|
||||
|
||||
private onChangeExtrinsic = (method: Method): void => {
|
||||
@ -124,7 +129,7 @@ class Propose extends TxModal<Props, State> {
|
||||
return;
|
||||
}
|
||||
|
||||
this.setState({ method } as State);
|
||||
this.setState({ method });
|
||||
}
|
||||
}
|
||||
|
||||
@ -133,12 +138,10 @@ export default withMulti(
|
||||
translate,
|
||||
withApi,
|
||||
withCalls(
|
||||
[
|
||||
'query.elections.members',
|
||||
{
|
||||
propName: 'memberCount',
|
||||
transform: (value: Array<any>) => value.length
|
||||
}
|
||||
]
|
||||
['query.elections.members', {
|
||||
propName: 'memberCount',
|
||||
transform: (value: any[]): number =>
|
||||
value.length
|
||||
}]
|
||||
)
|
||||
);
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
/* eslint-disable @typescript-eslint/camelcase */
|
||||
// Copyright 2017-2019 @polkadot/app-democracy authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
@ -52,7 +53,7 @@ class Referendum extends React.PureComponent<Props, State> {
|
||||
votedTotal: new BN(0)
|
||||
};
|
||||
|
||||
static getDerivedStateFromProps ({ democracy_referendumVotesFor }: Props, prevState: State): State | null {
|
||||
public static getDerivedStateFromProps ({ democracy_referendumVotesFor }: Props, prevState: State): State | null {
|
||||
if (!democracy_referendumVotesFor) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
/* eslint-disable @typescript-eslint/camelcase */
|
||||
// Copyright 2017-2019 @polkadot/ui-reactive authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
@ -26,7 +27,7 @@ class BestHash extends React.PureComponent<Props> {
|
||||
chain_subscribeNewHead
|
||||
? chain_subscribeNewHead.hash.toHex()
|
||||
: undefined
|
||||
}
|
||||
}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@ -2,10 +2,11 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { Codec } from '@polkadot/types/types';
|
||||
import { I18nProps } from '@polkadot/ui-app/types';
|
||||
|
||||
import React from 'react';
|
||||
import { DigestItem, Struct, Tuple, U8a, Vector, getTypeDef } from '@polkadot/types';
|
||||
import { DigestItem, Struct, Tuple, TypeDef, U8a, Vector, getTypeDef } from '@polkadot/types';
|
||||
import { Column } from '@polkadot/ui-app';
|
||||
import Params from '@polkadot/ui-params';
|
||||
|
||||
@ -30,7 +31,8 @@ class Logs extends React.PureComponent<Props> {
|
||||
);
|
||||
}
|
||||
|
||||
private renderItem = (item: DigestItem, index: number) => {
|
||||
private renderItem = (item: DigestItem, index: number): React.ReactNode => {
|
||||
const { t } = this.props;
|
||||
let content: React.ReactNode;
|
||||
|
||||
if (item.value instanceof Struct) {
|
||||
@ -55,7 +57,7 @@ class Logs extends React.PureComponent<Props> {
|
||||
<h3>{item.type.toString()}</h3>
|
||||
</div>
|
||||
<details>
|
||||
<summary>Details</summary>
|
||||
<summary>{t('Details')}</summary>
|
||||
{content}
|
||||
</details>
|
||||
</article>
|
||||
@ -63,7 +65,7 @@ class Logs extends React.PureComponent<Props> {
|
||||
);
|
||||
}
|
||||
|
||||
private formatU8a (value: U8a) {
|
||||
private formatU8a (value: U8a): React.ReactNode {
|
||||
return (
|
||||
<Params
|
||||
isDisabled
|
||||
@ -73,13 +75,13 @@ class Logs extends React.PureComponent<Props> {
|
||||
);
|
||||
}
|
||||
|
||||
private formatStruct (struct: Struct) {
|
||||
const types: { [index: string]: string } = struct.Type;
|
||||
const params = Object.keys(types).map((name) => ({
|
||||
private formatStruct (struct: Struct): React.ReactNode {
|
||||
const types: Record<string, string> = struct.Type;
|
||||
const params = Object.keys(types).map((name): { name: string; type: TypeDef } => ({
|
||||
name,
|
||||
type: getTypeDef(types[name])
|
||||
}));
|
||||
const values = struct.toArray().map((value) => ({
|
||||
const values = struct.toArray().map((value): { isValid: boolean; value: Codec } => ({
|
||||
isValid: true,
|
||||
value
|
||||
}));
|
||||
@ -93,12 +95,12 @@ class Logs extends React.PureComponent<Props> {
|
||||
);
|
||||
}
|
||||
|
||||
private formatTuple (tuple: Tuple) {
|
||||
private formatTuple (tuple: Tuple): React.ReactNode {
|
||||
const types = tuple.Types;
|
||||
const params = types.map((type) => ({
|
||||
const params = types.map((type): { type: TypeDef } => ({
|
||||
type: getTypeDef(type)
|
||||
}));
|
||||
const values = tuple.toArray().map((value) => ({
|
||||
const values = tuple.toArray().map((value): { isValid: boolean; value: Codec } => ({
|
||||
isValid: true,
|
||||
value
|
||||
}));
|
||||
@ -112,13 +114,13 @@ class Logs extends React.PureComponent<Props> {
|
||||
);
|
||||
}
|
||||
|
||||
private formatVector (vector: Vector<any>) {
|
||||
private formatVector (vector: Vector<any>): React.ReactNode {
|
||||
const type = getTypeDef(vector.Type);
|
||||
const values = vector.toArray().map((value) => ({
|
||||
const values = vector.toArray().map((value): { isValid: boolean; value: Codec } => ({
|
||||
isValid: true,
|
||||
value
|
||||
}));
|
||||
const params = values.map((_, index) => ({
|
||||
const params = values.map((_, index): { name: string; type: TypeDef } => ({
|
||||
name: `${index}`,
|
||||
type
|
||||
}));
|
||||
|
||||
@ -25,7 +25,7 @@ interface State {
|
||||
class Summary extends React.PureComponent<Props, State> {
|
||||
public state: State = {};
|
||||
|
||||
static getDerivedStateFromProps ({ info = {} }: Props): State | null {
|
||||
public static getDerivedStateFromProps ({ info = {} }: Props): State | null {
|
||||
if (!info.peers) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -29,17 +29,18 @@ interface State {
|
||||
|
||||
class App extends React.PureComponent<Props, State> {
|
||||
private isActive: boolean = true;
|
||||
|
||||
public state: State = {
|
||||
nextRefresh: Date.now()
|
||||
};
|
||||
|
||||
componentDidMount () {
|
||||
this.getStatus().catch(() => {
|
||||
public componentDidMount (): void {
|
||||
this.getStatus().catch((): void => {
|
||||
// ignore
|
||||
});
|
||||
}
|
||||
|
||||
componentWillUnmount () {
|
||||
public componentWillUnmount (): void {
|
||||
const { timerId } = this.state;
|
||||
|
||||
this.isActive = false;
|
||||
@ -69,7 +70,7 @@ class App extends React.PureComponent<Props, State> {
|
||||
);
|
||||
}
|
||||
|
||||
private setInfo (info?: Info) {
|
||||
private setInfo (info?: Info): void {
|
||||
if (!this.isActive) {
|
||||
return;
|
||||
}
|
||||
@ -81,7 +82,7 @@ class App extends React.PureComponent<Props, State> {
|
||||
});
|
||||
}
|
||||
|
||||
private getStatus = async () => {
|
||||
private getStatus = async (): Promise<void> => {
|
||||
const { api } = this.props;
|
||||
|
||||
try {
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
/* eslint-disable @typescript-eslint/camelcase */
|
||||
// Copyright 2017-2019 @polkadot/app-explorer authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
@ -63,7 +64,7 @@ class ExplorerApp extends React.Component<Props, State> {
|
||||
|
||||
// assign the events on the index - this way we keep a record of these, even when swapping
|
||||
// tabs withing this app, all the events as received will be shown
|
||||
static getDerivedStateFromProps ({ system_events = [] }: Props, prevState: State): State | null {
|
||||
public static getDerivedStateFromProps ({ system_events = [] }: Props, prevState: State): State | null {
|
||||
const prevEventHash = xxhashAsHex(stringToU8a(JSON.stringify(system_events)));
|
||||
|
||||
if (prevEventHash === prevState.prevEventHash) {
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
/* eslint-disable @typescript-eslint/camelcase */
|
||||
// Copyright 2017-2019 @polkadot/ui-reactive authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
@ -25,15 +25,16 @@ interface State {
|
||||
isValid: boolean;
|
||||
isValidUnsigned: boolean;
|
||||
method: Method | null;
|
||||
accountNonce: BN;
|
||||
accountId: string;
|
||||
accountNonce?: BN;
|
||||
accountId?: string;
|
||||
}
|
||||
|
||||
class Selection extends TxComponent<Props, State> {
|
||||
public state: State = {
|
||||
isValid: false,
|
||||
isValidUnsigned: false
|
||||
} as State;
|
||||
isValidUnsigned: false,
|
||||
method: null
|
||||
};
|
||||
|
||||
public render (): React.ReactNode {
|
||||
const { apiDefaultTxSudo, t } = this.props;
|
||||
@ -94,7 +95,7 @@ class Selection extends TxComponent<Props, State> {
|
||||
);
|
||||
}
|
||||
|
||||
private nextState (newState: State): void {
|
||||
private nextState (newState: Partial<State>): void {
|
||||
this.setState(
|
||||
(prevState: State): State => {
|
||||
const { method = prevState.method, accountNonce = prevState.accountNonce, accountId = prevState.accountId } = newState;
|
||||
@ -116,15 +117,15 @@ class Selection extends TxComponent<Props, State> {
|
||||
}
|
||||
|
||||
private onChangeExtrinsic = (method: Method | null = null): void => {
|
||||
this.nextState({ method } as State);
|
||||
this.nextState({ method });
|
||||
}
|
||||
|
||||
private onChangeNonce = (accountNonce: BN = new BN(0)): void => {
|
||||
this.nextState({ accountNonce } as State);
|
||||
this.nextState({ accountNonce });
|
||||
}
|
||||
|
||||
private onChangeSender = (accountId: string): void => {
|
||||
this.nextState({ accountId, accountNonce: new BN(0) } as State);
|
||||
this.nextState({ accountId, accountNonce: new BN(0) });
|
||||
}
|
||||
|
||||
private getExtrinsic (): SubmittableExtrinsic | null {
|
||||
|
||||
@ -38,7 +38,7 @@ class ActionButtons extends React.PureComponent<Props, State> {
|
||||
const {
|
||||
props: { isCustomExample, isRunning, removeSnippet, runJs, stopJs, t },
|
||||
state: { isOpen, shareText, snippetName }
|
||||
} = this;
|
||||
} = this;
|
||||
|
||||
return (
|
||||
<div className='action-button'>
|
||||
|
||||
@ -91,7 +91,7 @@ class Playground extends React.PureComponent<Props, State> {
|
||||
// There's a ticket and an ongoing process of updating SUI to the new lifecycle methods (here: componentDidMount).
|
||||
// Please check https://github.com/Semantic-Org/Semantic-UI-React/issues/2732 for details
|
||||
// This needs to change to componentDidMount() as soon as the original MUI component got updated
|
||||
componentWillMount () {
|
||||
public componentWillMount (): void {
|
||||
const { match: { params: { base64 } } } = this.props;
|
||||
|
||||
const sharedExample = base64 ? this.decodeBase64(base64) : undefined;
|
||||
@ -107,13 +107,13 @@ class Playground extends React.PureComponent<Props, State> {
|
||||
|
||||
const selected = options.find(option => option.value === localData.selectedValue);
|
||||
|
||||
this.setState((prevState: State): State => ({
|
||||
this.setState((prevState: State): Pick<State, never> => ({
|
||||
customExamples,
|
||||
isCustomExample: (selected && selected.type === 'custom') || false,
|
||||
options,
|
||||
selected: sharedExample || selected || this.snippets[0],
|
||||
sharedExample
|
||||
}) as State);
|
||||
}));
|
||||
}
|
||||
|
||||
public render (): React.ReactNode {
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
/* eslint-disable @typescript-eslint/camelcase */
|
||||
// Copyright 2017-2019 @polkadot/ui-staking authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
@ -36,7 +37,7 @@ class BondExtra extends TxComponent<Props, State> {
|
||||
extrinsic: null
|
||||
};
|
||||
|
||||
componentDidUpdate (prevProps: Props, prevState: State) {
|
||||
public componentDidUpdate (prevProps: Props, prevState: State): void {
|
||||
const { balances_fees } = this.props;
|
||||
const { extrinsic } = this.state;
|
||||
|
||||
@ -89,7 +90,7 @@ class BondExtra extends TxComponent<Props, State> {
|
||||
);
|
||||
}
|
||||
|
||||
private renderContent () {
|
||||
private renderContent (): React.ReactNode {
|
||||
const { stashId, t } = this.props;
|
||||
const { maxBalance } = this.state;
|
||||
const available = <span className='label'>{t('available ')}</span>;
|
||||
@ -138,7 +139,7 @@ class BondExtra extends TxComponent<Props, State> {
|
||||
});
|
||||
}
|
||||
|
||||
private setMaxBalance = () => {
|
||||
private setMaxBalance = (): void => {
|
||||
const { api, system_accountNonce = ZERO, balances_fees = ZERO_FEES, balances_all = ZERO_BALANCE } = this.props;
|
||||
const { maxAdditional } = this.state;
|
||||
|
||||
@ -171,7 +172,7 @@ class BondExtra extends TxComponent<Props, State> {
|
||||
});
|
||||
}
|
||||
|
||||
private onChangeValue = (maxAdditional?: BN) => {
|
||||
private onChangeValue = (maxAdditional?: BN): void => {
|
||||
this.nextState({ maxAdditional });
|
||||
}
|
||||
}
|
||||
|
||||
@ -29,7 +29,7 @@ class ValidateController extends React.PureComponent<Props, State> {
|
||||
error: null
|
||||
};
|
||||
|
||||
static getDerivedStateFromProps ({ accountId, bondedId, controllerId, defaultController, onError, stashId, t }: Props, prevState: State): State {
|
||||
public static getDerivedStateFromProps ({ accountId, bondedId, controllerId, defaultController, onError, stashId, t }: Props, prevState: State): State {
|
||||
const error = (() => {
|
||||
if (defaultController === controllerId) {
|
||||
// don't show an error if the selected controller is the default
|
||||
|
||||
@ -26,7 +26,7 @@ class ValidateSession extends React.PureComponent<Props, State> {
|
||||
error: null
|
||||
};
|
||||
|
||||
static getDerivedStateFromProps ({ onError, sessionId, stashId, t }: Props, prevState: State): State | null {
|
||||
public static getDerivedStateFromProps ({ onError, sessionId, stashId, t }: Props, prevState: State): State | null {
|
||||
let error = null;
|
||||
|
||||
try {
|
||||
|
||||
@ -24,7 +24,7 @@ class InputValidationUnstakeThreshold extends React.PureComponent<Props, State>
|
||||
error: null
|
||||
};
|
||||
|
||||
static getDerivedStateFromProps ({ onError, t, unstakeThreshold }: Props, prevState: State): State | null {
|
||||
public static getDerivedStateFromProps ({ onError, t, unstakeThreshold }: Props, prevState: State): State | null {
|
||||
let error = null;
|
||||
|
||||
if (!unstakeThreshold) {
|
||||
|
||||
@ -48,7 +48,7 @@ class Nominate extends React.PureComponent<Props, State> {
|
||||
);
|
||||
}
|
||||
|
||||
renderButtons () {
|
||||
public renderButtons (): React.ReactNode {
|
||||
const { controllerId, onClose, t } = this.props;
|
||||
const { nominees } = this.state;
|
||||
|
||||
@ -75,7 +75,7 @@ class Nominate extends React.PureComponent<Props, State> {
|
||||
);
|
||||
}
|
||||
|
||||
renderContent () {
|
||||
public renderContent (): React.ReactNode {
|
||||
const { controllerId, stashId, stashOptions, t } = this.props;
|
||||
|
||||
return (
|
||||
|
||||
@ -77,7 +77,7 @@ class SetSessionKey extends React.PureComponent<Props, State> {
|
||||
);
|
||||
}
|
||||
|
||||
private renderContent () {
|
||||
private renderContent (): React.ReactNode {
|
||||
const { controllerId, stashId, t } = this.props;
|
||||
const { sessionId } = this.state;
|
||||
|
||||
@ -112,11 +112,11 @@ class SetSessionKey extends React.PureComponent<Props, State> {
|
||||
);
|
||||
}
|
||||
|
||||
private onChangeSession = (sessionId: string) => {
|
||||
private onChangeSession = (sessionId: string): void => {
|
||||
this.setState({ sessionId });
|
||||
}
|
||||
|
||||
private onSessionError = (sessionError: string | null) => {
|
||||
private onSessionError = (sessionError: string | null): void => {
|
||||
this.setState({ sessionError });
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
/* eslint-disable @typescript-eslint/camelcase */
|
||||
// Copyright 2017-2019 @polkadot/ui-staking authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
@ -40,7 +41,7 @@ const BalanceWrapper = styled.div`
|
||||
class Unbond extends TxComponent<Props, State> {
|
||||
public state: State = {};
|
||||
|
||||
componentDidUpdate (prevProps: Props) {
|
||||
public componentDidUpdate (prevProps: Props): void {
|
||||
const { staking_ledger } = this.props;
|
||||
|
||||
if (staking_ledger !== prevProps.staking_ledger) {
|
||||
@ -89,7 +90,7 @@ class Unbond extends TxComponent<Props, State> {
|
||||
);
|
||||
}
|
||||
|
||||
private renderContent () {
|
||||
private renderContent (): React.ReactNode {
|
||||
const { controllerId, stashId, t } = this.props;
|
||||
const { maxBalance } = this.state;
|
||||
|
||||
@ -139,7 +140,7 @@ class Unbond extends TxComponent<Props, State> {
|
||||
});
|
||||
}
|
||||
|
||||
private setMaxBalance = () => {
|
||||
private setMaxBalance = (): void => {
|
||||
const { staking_ledger } = this.props;
|
||||
|
||||
if (!staking_ledger || staking_ledger.isNone) {
|
||||
@ -153,7 +154,7 @@ class Unbond extends TxComponent<Props, State> {
|
||||
});
|
||||
}
|
||||
|
||||
private onChangeValue = (maxUnbond?: BN) => {
|
||||
private onChangeValue = (maxUnbond?: BN): void => {
|
||||
this.nextState({ maxUnbond });
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,7 +35,7 @@ class Validate extends TxComponent<Props, State> {
|
||||
|
||||
// inject the preferences returned via RPC once into the state (from this
|
||||
// point forward it will be entirely managed by the actual inputs)
|
||||
static getDerivedStateFromProps (props: Props, state: State): State | null {
|
||||
public static getDerivedStateFromProps (props: Props, state: State): State | null {
|
||||
if (state.unstakeThreshold && state.validatorPayment) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -81,7 +81,7 @@ class NewStake extends TxComponent<Props, State> {
|
||||
);
|
||||
}
|
||||
|
||||
private renderContent () {
|
||||
private renderContent (): React.ReactNode {
|
||||
const { t } = this.props;
|
||||
const { controllerId, controllerError, bondValue, destination, stashId } = this.state;
|
||||
const hasValue = !!bondValue && bondValue.gtn(0);
|
||||
@ -160,23 +160,23 @@ class NewStake extends TxComponent<Props, State> {
|
||||
});
|
||||
}
|
||||
|
||||
private onChangeController = (controllerId: string) => {
|
||||
private onChangeController = (controllerId: string): void => {
|
||||
this.nextState({ controllerId });
|
||||
}
|
||||
|
||||
private onChangeDestination = (destination: number) => {
|
||||
private onChangeDestination = (destination: number): void => {
|
||||
this.nextState({ destination });
|
||||
}
|
||||
|
||||
private onChangeStash = (stashId: string) => {
|
||||
private onChangeStash = (stashId: string): void => {
|
||||
this.nextState({ stashId });
|
||||
}
|
||||
|
||||
private onChangeValue = (bondValue?: BN) => {
|
||||
private onChangeValue = (bondValue?: BN): void => {
|
||||
this.nextState({ bondValue });
|
||||
}
|
||||
|
||||
private onControllerError = (controllerError: string | null) => {
|
||||
private onControllerError = (controllerError: string | null): void => {
|
||||
this.setState({ controllerError });
|
||||
}
|
||||
}
|
||||
|
||||
@ -39,7 +39,7 @@ const cache: CacheInstance[] = [];
|
||||
class Query extends React.PureComponent<Props, State> {
|
||||
public state: State = { spread: {} } as State;
|
||||
|
||||
static getCachedComponent (query: QueryTypes): CacheInstance {
|
||||
public static getCachedComponent (query: QueryTypes): CacheInstance {
|
||||
const { id, key, params = [] } = query as StorageModuleQuery;
|
||||
|
||||
if (!cache[id]) {
|
||||
@ -66,7 +66,7 @@ class Query extends React.PureComponent<Props, State> {
|
||||
return cache[id];
|
||||
}
|
||||
|
||||
static createComponent (type: string, Component: React.ComponentType<any>, defaultProps: DefaultProps, renderHelper: ComponentRenderer) {
|
||||
public static createComponent (type: string, Component: React.ComponentType<any>, defaultProps: DefaultProps, renderHelper: ComponentRenderer) {
|
||||
return {
|
||||
Component,
|
||||
// In order to replace the default component during runtime we can provide a RenderFn to create a new 'plugged' component
|
||||
@ -83,7 +83,7 @@ class Query extends React.PureComponent<Props, State> {
|
||||
};
|
||||
}
|
||||
|
||||
static getDerivedStateFromProps ({ value }: Props) {
|
||||
public static getDerivedStateFromProps ({ value }: Props) {
|
||||
const Component = Query.getCachedComponent(value).Component;
|
||||
const inputs: React.ReactNode[] = isU8a(value.key)
|
||||
? []
|
||||
|
||||
@ -28,6 +28,7 @@ interface State {
|
||||
|
||||
class Modules extends TxComponent<Props, State> {
|
||||
private defaultValue: any;
|
||||
|
||||
public state: State;
|
||||
|
||||
public constructor (props: Props) {
|
||||
@ -55,10 +56,7 @@ class Modules extends TxComponent<Props, State> {
|
||||
defaultValue={this.defaultValue}
|
||||
label={t('selected state query')}
|
||||
onChange={this.onChangeKey}
|
||||
help={
|
||||
meta && meta.documentation
|
||||
&& meta.documentation.join(' ')
|
||||
}
|
||||
help={meta && meta.documentation && meta.documentation.join(' ')}
|
||||
/>
|
||||
<Params
|
||||
key={`${section}.${method}:params` /* force re-render on change */}
|
||||
@ -82,15 +80,16 @@ class Modules extends TxComponent<Props, State> {
|
||||
|
||||
private nextState (newState: State): void {
|
||||
this.setState(
|
||||
(prevState: State) => {
|
||||
(prevState: State): Pick<State, never> => {
|
||||
const { key = prevState.key, values = prevState.values } = newState;
|
||||
const hasParam = key.creator.meta.type.isMap;
|
||||
const isValid = values.length === (hasParam ? 1 : 0) &&
|
||||
values.reduce((isValid, value) =>
|
||||
isValid &&
|
||||
!isUndefined(value) &&
|
||||
!isUndefined(value.value) &&
|
||||
value.isValid,
|
||||
values.reduce(
|
||||
(isValid, value): boolean =>
|
||||
isValid &&
|
||||
!isUndefined(value) &&
|
||||
!isUndefined(value.value) &&
|
||||
value.isValid,
|
||||
true
|
||||
);
|
||||
|
||||
|
||||
@ -33,10 +33,10 @@ class SetKey extends React.PureComponent<Props, State> {
|
||||
|
||||
this.state = {
|
||||
selected: props.sudoKey
|
||||
} as State;
|
||||
};
|
||||
}
|
||||
|
||||
componentWillReceiveProps ({ sudoKey = this.props.sudoKey }) {
|
||||
public componentWillReceiveProps ({ sudoKey = this.props.sudoKey }): void {
|
||||
if (sudoKey !== this.props.sudoKey) {
|
||||
this.setState({ selected: sudoKey });
|
||||
}
|
||||
@ -49,25 +49,27 @@ class SetKey extends React.PureComponent<Props, State> {
|
||||
return (
|
||||
<section>
|
||||
<section className={`${className} ui--row`}>
|
||||
{isMine ? (
|
||||
<>
|
||||
<SudoInputAddress
|
||||
value={selected}
|
||||
label={t('sudo key')}
|
||||
isInput={true}
|
||||
onChange={this.onChange}
|
||||
type='all'
|
||||
/>
|
||||
<TxButton
|
||||
accountId={sudoKey}
|
||||
isDisabled={!isMine || sudoKey === selected}
|
||||
isPrimary
|
||||
label={t('Reassign')}
|
||||
params={[selected]}
|
||||
tx='sudo.setKey'
|
||||
/>
|
||||
</>
|
||||
) : (
|
||||
{isMine
|
||||
? (
|
||||
<>
|
||||
<SudoInputAddress
|
||||
value={selected}
|
||||
label={t('sudo key')}
|
||||
isInput={true}
|
||||
onChange={this.onChange}
|
||||
type='all'
|
||||
/>
|
||||
<TxButton
|
||||
accountId={sudoKey}
|
||||
isDisabled={!isMine || sudoKey === selected}
|
||||
isPrimary
|
||||
label={t('Reassign')}
|
||||
params={[selected]}
|
||||
tx='sudo.setKey'
|
||||
/>
|
||||
</>
|
||||
)
|
||||
: (
|
||||
<SudoLabelled
|
||||
className='ui--Dropdown'
|
||||
label={t('sudo key')}
|
||||
@ -75,17 +77,18 @@ class SetKey extends React.PureComponent<Props, State> {
|
||||
>
|
||||
<AddressMini value={sudoKey} />
|
||||
</SudoLabelled>
|
||||
)}
|
||||
</section>
|
||||
{this.willLose() && (
|
||||
<article className='warning padded'>
|
||||
<div>
|
||||
<Icon name='warning' />
|
||||
{t('You will no longer have sudo access')}
|
||||
</div>
|
||||
</article>
|
||||
)}
|
||||
)
|
||||
}
|
||||
</section>
|
||||
{this.willLose() && (
|
||||
<article className='warning padded'>
|
||||
<div>
|
||||
<Icon name='warning' />
|
||||
{t('You will no longer have sudo access')}
|
||||
</div>
|
||||
</article>
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
@ -96,12 +99,13 @@ class SetKey extends React.PureComponent<Props, State> {
|
||||
private willLose = (): boolean => {
|
||||
const { allAccounts, isMine, sudoKey } = this.props;
|
||||
const { selected } = this.state;
|
||||
|
||||
return (
|
||||
isMine &&
|
||||
!!Object.keys(allAccounts).length &&
|
||||
!!selected &&
|
||||
selected !== sudoKey &&
|
||||
!Object.keys(allAccounts).find(s => s === selected)
|
||||
!Object.keys(allAccounts).find((s): boolean => s === selected)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -14,7 +14,7 @@ import { withApi, withMulti } from '@polkadot/ui-api';
|
||||
import translate from './translate';
|
||||
|
||||
type Props = I18nProps & ApiProps & ComponentProps & {
|
||||
onChange: (accountId?: string) => void
|
||||
onChange: (accountId?: string) => void;
|
||||
};
|
||||
|
||||
interface State {
|
||||
@ -32,7 +32,8 @@ class Propose extends TxComponent<Props, State> {
|
||||
const { apiDefaultTxSudo, isMine, sudoKey, t } = this.props;
|
||||
const { method, isValid } = this.state;
|
||||
|
||||
return isMine ? (
|
||||
return isMine
|
||||
? (
|
||||
<section>
|
||||
<Extrinsic
|
||||
defaultValue={apiDefaultTxSudo}
|
||||
@ -52,7 +53,8 @@ class Propose extends TxComponent<Props, State> {
|
||||
/>
|
||||
</Button.Group>
|
||||
</section>
|
||||
) : (
|
||||
)
|
||||
: (
|
||||
<article className='error padded'>
|
||||
<div>
|
||||
<Icon name='ban' />
|
||||
@ -62,7 +64,7 @@ class Propose extends TxComponent<Props, State> {
|
||||
);
|
||||
}
|
||||
|
||||
private nextState (newState: State): void {
|
||||
private nextState (newState: Partial<State>): void {
|
||||
this.setState(
|
||||
(prevState: State): State => {
|
||||
const { method = prevState.method } = newState;
|
||||
@ -81,7 +83,7 @@ class Propose extends TxComponent<Props, State> {
|
||||
return;
|
||||
}
|
||||
|
||||
this.nextState({ method } as State);
|
||||
this.nextState({ method });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -33,7 +33,7 @@ class Hash extends React.PureComponent<Props, State> {
|
||||
);
|
||||
}
|
||||
|
||||
renderInput () {
|
||||
public renderInput (): React.ReactNode {
|
||||
const { t } = this.props;
|
||||
const { data, isHexData } = this.state;
|
||||
|
||||
@ -65,7 +65,7 @@ class Hash extends React.PureComponent<Props, State> {
|
||||
);
|
||||
}
|
||||
|
||||
renderOutput () {
|
||||
public renderOutput (): React.ReactNode {
|
||||
const { t } = this.props;
|
||||
const { hash } = this.state;
|
||||
|
||||
|
||||
@ -55,7 +55,7 @@ class Account extends React.PureComponent<Props, State> {
|
||||
);
|
||||
}
|
||||
|
||||
renderNonce () {
|
||||
public renderNonce (): React.ReactNode {
|
||||
const { t } = this.props;
|
||||
const { accountId } = this.state;
|
||||
|
||||
|
||||
@ -68,7 +68,7 @@ class Sign extends React.PureComponent<Props, State> {
|
||||
);
|
||||
}
|
||||
|
||||
renderAccount () {
|
||||
public renderAccount (): React.ReactNode {
|
||||
const { t } = this.props;
|
||||
|
||||
return (
|
||||
@ -85,7 +85,7 @@ class Sign extends React.PureComponent<Props, State> {
|
||||
);
|
||||
}
|
||||
|
||||
renderUnlockWarning () {
|
||||
public renderUnlockWarning (): React.ReactNode {
|
||||
const { t } = this.props;
|
||||
const { isLocked } = this.state;
|
||||
|
||||
@ -109,7 +109,7 @@ class Sign extends React.PureComponent<Props, State> {
|
||||
);
|
||||
}
|
||||
|
||||
renderInput () {
|
||||
public renderInput (): React.ReactNode {
|
||||
const { t } = this.props;
|
||||
const { data, isHexData } = this.state;
|
||||
|
||||
@ -141,7 +141,7 @@ class Sign extends React.PureComponent<Props, State> {
|
||||
);
|
||||
}
|
||||
|
||||
renderSignature () {
|
||||
public renderSignature (): React.ReactNode {
|
||||
const { t } = this.props;
|
||||
const { signature } = this.state;
|
||||
|
||||
@ -160,7 +160,7 @@ class Sign extends React.PureComponent<Props, State> {
|
||||
);
|
||||
}
|
||||
|
||||
renderUnlock () {
|
||||
public renderUnlock (): React.ReactNode {
|
||||
const { currentPair, isUnlockVisible } = this.state;
|
||||
|
||||
if (!isUnlockVisible) {
|
||||
@ -175,7 +175,7 @@ class Sign extends React.PureComponent<Props, State> {
|
||||
);
|
||||
}
|
||||
|
||||
nextState = (newState: State): void => {
|
||||
private nextState = (newState: State): void => {
|
||||
this.setState(
|
||||
(prevState: State): State => {
|
||||
const { currentPair = prevState.currentPair, data = prevState.data, isHexData = prevState.isHexData, isUnlockVisible = prevState.isUnlockVisible } = newState;
|
||||
|
||||
@ -28,10 +28,10 @@ class Unlock extends TxComponent<Props, State> {
|
||||
unlockError: null
|
||||
};
|
||||
|
||||
static getDerivedStateFromProps ({ pair }: Props): State {
|
||||
public static getDerivedStateFromProps ({ pair }: Props): Pick<State, never> {
|
||||
return {
|
||||
address: (pair && pair.address) || ''
|
||||
} as State;
|
||||
};
|
||||
}
|
||||
|
||||
public render (): React.ReactNode {
|
||||
|
||||
@ -53,15 +53,14 @@ class ToolboxApp extends React.PureComponent<Props, State> {
|
||||
]
|
||||
};
|
||||
}
|
||||
|
||||
public render (): React.ReactNode {
|
||||
const { allAccounts, basePath } = this.props;
|
||||
const { tabs } = this.state;
|
||||
const hasAccounts = allAccounts && Object.keys(allAccounts).length !== 0;
|
||||
const filteredTabs = hasAccounts
|
||||
? tabs
|
||||
: tabs.filter(({ name }) =>
|
||||
!['sign', 'verify'].includes(name)
|
||||
);
|
||||
: tabs.filter(({ name }): boolean => !['sign', 'verify'].includes(name));
|
||||
|
||||
return (
|
||||
<main className='toolbox--App'>
|
||||
|
||||
@ -30,24 +30,26 @@ class Approve extends TxModal<Props, State> {
|
||||
isApproving: false
|
||||
};
|
||||
|
||||
private approveOptions = () => [
|
||||
private approveOptions = (): { text: string; value: boolean }[] => [
|
||||
{ text: this.props.t('Aye, I approve'), value: true },
|
||||
{ text: this.props.t('Nay, I do not approve'), value: false }
|
||||
]
|
||||
|
||||
headerText = () => this.props.t('Approve or reject proposal');
|
||||
protected headerText = (): string => this.props.t('Approve or reject proposal');
|
||||
|
||||
txMethod = () => 'collective.propose';
|
||||
txParams = () => {
|
||||
protected txMethod = (): string => 'collective.propose';
|
||||
|
||||
protected txParams = (): [number, any] => {
|
||||
const { api, proposalId, threshold } = this.props;
|
||||
const { isApproving } = this.state;
|
||||
|
||||
const method = isApproving ? 'approveProposal' : 'rejectProposal';
|
||||
const spendProposal = api.tx.treasury[method](proposalId);
|
||||
|
||||
return [threshold, spendProposal];
|
||||
}
|
||||
|
||||
renderTrigger = () => {
|
||||
protected renderTrigger = (): React.ReactNode => {
|
||||
const { t } = this.props;
|
||||
return (
|
||||
<div className='ui--Row-buttons'>
|
||||
@ -63,7 +65,7 @@ class Approve extends TxModal<Props, State> {
|
||||
);
|
||||
}
|
||||
|
||||
renderPreContent = () => {
|
||||
protected renderPreContent = (): React.ReactNode => {
|
||||
const { proposalInfo = null } = this.props;
|
||||
|
||||
if (!proposalInfo) {
|
||||
@ -73,7 +75,7 @@ class Approve extends TxModal<Props, State> {
|
||||
return proposalInfo;
|
||||
}
|
||||
|
||||
renderContent = () => {
|
||||
protected renderContent = (): React.ReactNode => {
|
||||
const { t } = this.props;
|
||||
const { isApproving } = this.state;
|
||||
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
/* eslint-disable @typescript-eslint/camelcase */
|
||||
// Copyright 2017-2019 @polkadot/app-democracy authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
@ -34,14 +35,14 @@ class ProposalsBase extends React.PureComponent<Props> {
|
||||
proposalIndices: [] as BN[]
|
||||
};
|
||||
|
||||
static getDerivedStateFromProps ({ isApprovals = false, treasury_approvals = [] as BN[], treasury_proposalCount = new BN(0) }: Props) {
|
||||
public static getDerivedStateFromProps ({ isApprovals = false, treasury_approvals = [] as BN[], treasury_proposalCount = new BN(0) }: Props): Pick<State, never> {
|
||||
let proposalIndices: BN[] = [];
|
||||
|
||||
if (isApprovals) {
|
||||
proposalIndices = treasury_approvals;
|
||||
} else {
|
||||
for (let i = 0; i < treasury_proposalCount.toNumber(); i++) {
|
||||
if (!treasury_approvals.find(index => index.eqn(i))) {
|
||||
if (!treasury_approvals.find((index): boolean => index.eqn(i))) {
|
||||
proposalIndices.push(new BN(i));
|
||||
}
|
||||
}
|
||||
@ -66,11 +67,11 @@ class ProposalsBase extends React.PureComponent<Props> {
|
||||
);
|
||||
}
|
||||
|
||||
private renderProposals () {
|
||||
private renderProposals (): React.ReactNode {
|
||||
const { isApprovals } = this.props;
|
||||
const { proposalIndices } = this.state;
|
||||
|
||||
return proposalIndices.map((proposalId) => (
|
||||
return proposalIndices.map((proposalId): React.ReactNode => (
|
||||
<Proposal
|
||||
isApproved={isApprovals}
|
||||
onPopulate={this.onPopulateProposal}
|
||||
@ -81,17 +82,18 @@ class ProposalsBase extends React.PureComponent<Props> {
|
||||
));
|
||||
}
|
||||
|
||||
onRespond = () => {
|
||||
protected onRespond = (): void => {
|
||||
const { history } = this.props;
|
||||
|
||||
history.push('/council/motions');
|
||||
}
|
||||
|
||||
private onPopulateProposal = () => {
|
||||
this.setState(({ isEmpty }: State) => {
|
||||
private onPopulateProposal = (): void => {
|
||||
this.setState(({ isEmpty }: State): Pick<State, never> | null => {
|
||||
if (isEmpty) {
|
||||
return { isEmpty: false };
|
||||
}
|
||||
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@ -26,6 +26,7 @@ class Propose extends TxModal<Props, State> {
|
||||
headerText = () => this.props.t('Submit a spend proposal');
|
||||
|
||||
txMethod = () => 'treasury.proposeSpend';
|
||||
|
||||
txParams = () => {
|
||||
const { beneficiary, value } = this.state;
|
||||
|
||||
@ -34,7 +35,7 @@ class Propose extends TxModal<Props, State> {
|
||||
];
|
||||
}
|
||||
|
||||
isDisabled = () => {
|
||||
protected isDisabled = (): boolean => {
|
||||
const { accountId, beneficiary, value } = this.state;
|
||||
const hasValue = !!value && value.gtn(0);
|
||||
const hasBeneficiary = !!beneficiary;
|
||||
@ -42,7 +43,7 @@ class Propose extends TxModal<Props, State> {
|
||||
return !accountId || !hasValue || !hasBeneficiary;
|
||||
}
|
||||
|
||||
renderTrigger = () => {
|
||||
protected renderTrigger = (): React.ReactNode => {
|
||||
const { t } = this.props;
|
||||
|
||||
return (
|
||||
@ -57,7 +58,7 @@ class Propose extends TxModal<Props, State> {
|
||||
);
|
||||
}
|
||||
|
||||
renderContent = () => {
|
||||
protected renderContent = (): React.ReactNode => {
|
||||
const { t } = this.props;
|
||||
const { value } = this.state;
|
||||
const hasValue = !!value && value.gtn(0);
|
||||
|
||||
@ -36,7 +36,7 @@ interface State {
|
||||
class Settings extends TxComponent<Props, State> {
|
||||
public state: State = {};
|
||||
|
||||
static getDerivedStateFromProps ({ proposalBond, proposalBondMinimum, spendPeriod, burn, pot }: Props, state: State) {
|
||||
public static getDerivedStateFromProps ({ proposalBond, proposalBondMinimum, spendPeriod, burn, pot }: Props, state: State): State {
|
||||
const newState: State = {};
|
||||
|
||||
if (proposalBond && !state.proposalBond) {
|
||||
@ -173,27 +173,27 @@ class Settings extends TxComponent<Props, State> {
|
||||
}
|
||||
|
||||
private onChangeAccount = (accountId: string): void => {
|
||||
this.nextState({ accountId } as State);
|
||||
this.nextState({ accountId });
|
||||
}
|
||||
|
||||
private onChangeProposalBond = (proposalBond?: BN): void => {
|
||||
this.nextState({ proposalBond } as State);
|
||||
this.nextState({ proposalBond });
|
||||
}
|
||||
|
||||
private onChangeProposalBondMinimum = (proposalBondMinimum?: BN): void => {
|
||||
this.nextState({ proposalBondMinimum } as State);
|
||||
this.nextState({ proposalBondMinimum });
|
||||
}
|
||||
|
||||
private onChangeSpendPeriod = (spendPeriod?: BN): void => {
|
||||
this.nextState({ spendPeriod } as State);
|
||||
this.nextState({ spendPeriod });
|
||||
}
|
||||
|
||||
private onChangeBurn = (burn?: BN): void => {
|
||||
this.nextState({ burn } as State);
|
||||
this.nextState({ burn });
|
||||
}
|
||||
|
||||
private onChangePot = (pot?: BN): void => {
|
||||
this.nextState({ pot } as State);
|
||||
this.nextState({ pot });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -46,14 +46,14 @@ class Apps extends React.Component<Props, State> {
|
||||
};
|
||||
}
|
||||
|
||||
componentDidMount () {
|
||||
public componentDidMount (): void {
|
||||
this.setState({
|
||||
menuOpen: false,
|
||||
isMenu: window.innerWidth >= SIDEBAR_MENU_THRESHOLD ? false : true
|
||||
isMenu: window.innerWidth < SIDEBAR_MENU_THRESHOLD
|
||||
});
|
||||
}
|
||||
|
||||
componentDidUpdate () {
|
||||
public componentDidUpdate (): void {
|
||||
this.handleMenuTransition();
|
||||
}
|
||||
|
||||
@ -81,9 +81,9 @@ class Apps extends React.Component<Props, State> {
|
||||
}
|
||||
|
||||
private collapse = (): void => {
|
||||
this.setState(({ isCollapsed }: State) => ({
|
||||
this.setState(({ isCollapsed }: State): Pick<State, never> => ({
|
||||
isCollapsed: !isCollapsed
|
||||
}), () => {
|
||||
}), (): void => {
|
||||
store.set('sidebar', this.state);
|
||||
});
|
||||
}
|
||||
@ -110,7 +110,7 @@ class Apps extends React.Component<Props, State> {
|
||||
|
||||
switch (transition) {
|
||||
case SideBarTransition.MINIMISED_AND_EXPANDED:
|
||||
setTimeout(() => {
|
||||
setTimeout((): void => {
|
||||
this.setState({
|
||||
isMenu: true,
|
||||
isCollapsed: false,
|
||||
@ -120,7 +120,7 @@ class Apps extends React.Component<Props, State> {
|
||||
break;
|
||||
|
||||
case SideBarTransition.EXPANDED_AND_MAXIMISED:
|
||||
setTimeout(() => {
|
||||
setTimeout((): void => {
|
||||
this.setState({
|
||||
isMenu: false,
|
||||
isCollapsed: store.get('sidebar').isCollapsed,
|
||||
@ -134,7 +134,7 @@ class Apps extends React.Component<Props, State> {
|
||||
}
|
||||
}
|
||||
|
||||
private renderMenuBg = () => {
|
||||
private renderMenuBg = (): React.ReactNode => {
|
||||
return (
|
||||
<div
|
||||
className={`apps-Menu-bg ${this.state.menuOpen ? 'open' : 'closed'}`}
|
||||
@ -169,7 +169,7 @@ class Apps extends React.Component<Props, State> {
|
||||
break;
|
||||
|
||||
default:
|
||||
this.setState(({ isCollapsed }: State) => ({
|
||||
this.setState(({ isCollapsed }: State): Pick<State, never> => ({
|
||||
isCollapsed: !isCollapsed
|
||||
}));
|
||||
break;
|
||||
|
||||
@ -6,11 +6,9 @@ import React from 'react';
|
||||
import { Redirect } from 'react-router';
|
||||
import routing from '@polkadot/apps-routing';
|
||||
|
||||
type Props = {};
|
||||
|
||||
const defaultTo = `/${routing.default}`;
|
||||
|
||||
export default class NotFound extends React.PureComponent<Props> {
|
||||
export default class NotFound extends React.PureComponent<{}> {
|
||||
public render (): React.ReactNode {
|
||||
return (
|
||||
<Redirect to={defaultTo} />
|
||||
|
||||
@ -18,7 +18,7 @@ import translate from '../translate';
|
||||
import NotFound from './NotFound';
|
||||
|
||||
type Props = I18nProps & ApiProps & {
|
||||
location: Location
|
||||
location: Location;
|
||||
};
|
||||
|
||||
const Wrapper = styled.div`
|
||||
@ -54,7 +54,7 @@ class Content extends React.Component<Props> {
|
||||
public render (): React.ReactNode {
|
||||
const { isApiConnected, isApiReady, location, t } = this.props;
|
||||
const app = location.pathname.slice(1) || '';
|
||||
const { Component, display: { needsApi }, name } = routing.routes.find((route) =>
|
||||
const { Component, display: { needsApi }, name } = routing.routes.find((route): boolean =>
|
||||
!!(route && app.indexOf(route.name) === 0)
|
||||
) || unknown;
|
||||
|
||||
@ -69,7 +69,7 @@ class Content extends React.Component<Props> {
|
||||
return (
|
||||
<Wrapper>
|
||||
<QueueConsumer>
|
||||
{({ queueAction, stqueue, txqueue }: QueueProps) => (
|
||||
{({ queueAction, stqueue, txqueue }: QueueProps): React.ReactNode => (
|
||||
<>
|
||||
<Component
|
||||
basePath={`/${name}`}
|
||||
|
||||
@ -11,7 +11,7 @@ import React from 'react';
|
||||
import { NavLink } from 'react-router-dom';
|
||||
import { Icon, Menu, Tooltip } from '@polkadot/ui-app';
|
||||
import accountObservable from '@polkadot/ui-keyring/observable/accounts';
|
||||
import { withApi,withCalls, withMulti, withObservable } from '@polkadot/ui-api';
|
||||
import { withApi, withCalls, withMulti, withObservable } from '@polkadot/ui-api';
|
||||
import { isFunction } from '@polkadot/util';
|
||||
|
||||
import translate from '../translate';
|
||||
@ -92,7 +92,7 @@ class Item extends React.PureComponent<Props> {
|
||||
private isVisible (): boolean {
|
||||
const { allAccounts = {}, isApiConnected, isApiReady, route: { display: { isHidden, needsAccounts, needsApi, needsSudo }, name }, sudo_key: sudoKey } = this.props;
|
||||
const hasAccounts = Object.keys(allAccounts).length !== 0;
|
||||
const hasSudo = !!Object.keys(allAccounts).find(address => address === sudoKey);
|
||||
const hasSudo = !!Object.keys(allAccounts).find((address): boolean => address === sudoKey);
|
||||
|
||||
if (isHidden) {
|
||||
return false;
|
||||
|
||||
@ -36,6 +36,7 @@ const Wrapper = styled.div`
|
||||
}
|
||||
`;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
const pkgJson = require('../../package.json');
|
||||
|
||||
class NodeInfo extends React.PureComponent<Props> {
|
||||
@ -52,7 +53,7 @@ class NodeInfo extends React.PureComponent<Props> {
|
||||
);
|
||||
}
|
||||
|
||||
private renderNode () {
|
||||
private renderNode (): React.ReactNode {
|
||||
const { isApiReady } = this.props;
|
||||
|
||||
if (!isApiReady) {
|
||||
|
||||
@ -20,7 +20,7 @@ const LOGOS_SMALL: LogoMap = new Map([
|
||||
['substrate', substrateSmall]
|
||||
]);
|
||||
|
||||
export default function getLogo (isSmall: boolean) {
|
||||
export default function getLogo (isSmall: boolean): any {
|
||||
return isSmall
|
||||
? (LOGOS_SMALL.get(settings.uiTheme) || polkadotSmall)
|
||||
: (LOGOS_NORMAL.get(settings.uiTheme) || polkadotLogo);
|
||||
|
||||
@ -8,9 +8,9 @@ import React from 'react';
|
||||
import styled from 'styled-components';
|
||||
import { BestNumber, Chain, NodeName, NodeVersion } from '@polkadot/ui-reactive';
|
||||
|
||||
type Props = {
|
||||
className?: string
|
||||
};
|
||||
interface Props {
|
||||
className?: string;
|
||||
}
|
||||
|
||||
class TopBar extends React.PureComponent<Props> {
|
||||
public render (): React.ReactNode {
|
||||
|
||||
@ -50,7 +50,7 @@ ReactDOM.render(
|
||||
<Suspense fallback='...'>
|
||||
<Queue>
|
||||
<QueueConsumer>
|
||||
{({ queueExtrinsic, queueSetTxStatus }) => (
|
||||
{({ queueExtrinsic, queueSetTxStatus }): React.ReactNode => (
|
||||
<Api
|
||||
queueExtrinsic={queueExtrinsic}
|
||||
queueSetTxStatus={queueSetTxStatus}
|
||||
|
||||
@ -31,7 +31,7 @@ class Accounts extends React.PureComponent<Props, State> {
|
||||
isHidden: false
|
||||
};
|
||||
|
||||
static getDerivedStateFromProps ({ allAccounts }: Props, prevState: State): State | null {
|
||||
public static getDerivedStateFromProps ({ allAccounts }: Props, prevState: State): Pick<State, never> | null {
|
||||
if (!allAccounts) {
|
||||
return null;
|
||||
}
|
||||
@ -44,7 +44,7 @@ class Accounts extends React.PureComponent<Props, State> {
|
||||
|
||||
return {
|
||||
hasAccounts
|
||||
} as State;
|
||||
};
|
||||
}
|
||||
|
||||
public render (): React.ReactNode {
|
||||
@ -74,7 +74,7 @@ class Accounts extends React.PureComponent<Props, State> {
|
||||
);
|
||||
}
|
||||
|
||||
private onClose = () => {
|
||||
private onClose = (): void => {
|
||||
this.setState({ isHidden: true });
|
||||
}
|
||||
}
|
||||
|
||||
@ -22,7 +22,7 @@ class Connecting extends React.PureComponent<Props> {
|
||||
return this.renderExtension() || this.renderConnecting();
|
||||
}
|
||||
|
||||
private renderExtension () {
|
||||
private renderExtension (): React.ReactNode {
|
||||
const { className, isWaitingInjected, t } = this.props;
|
||||
|
||||
if (!isWaitingInjected) {
|
||||
@ -39,7 +39,7 @@ class Connecting extends React.PureComponent<Props> {
|
||||
);
|
||||
}
|
||||
|
||||
private renderConnecting () {
|
||||
private renderConnecting (): React.ReactNode {
|
||||
const { className, isApiConnected, t } = this.props;
|
||||
|
||||
if (isApiConnected) {
|
||||
|
||||
@ -6,7 +6,7 @@ import { ApiProps } from './types';
|
||||
|
||||
import React from 'react';
|
||||
|
||||
const ApiContext: React.Context<ApiProps> = React.createContext({} as ApiProps);
|
||||
const ApiContext: React.Context<ApiProps> = React.createContext({} as unknown as ApiProps);
|
||||
const ApiConsumer: React.Consumer<ApiProps> = ApiContext.Consumer;
|
||||
const ApiProvider: React.Provider<ApiProps> = ApiContext.Provider;
|
||||
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
export default function echoTransform <T> (x: T, index: number): T {
|
||||
return x;
|
||||
}
|
||||
|
||||
@ -4,12 +4,13 @@
|
||||
|
||||
import { CallState } from '../types';
|
||||
|
||||
import { Subscription } from 'rxjs';
|
||||
import { interval } from 'rxjs/observable/interval';
|
||||
|
||||
const interval$ = interval(500);
|
||||
|
||||
export default function intervalSubscribe<T, Props, State extends CallState> (that: React.Component<Props, State>) {
|
||||
return interval$.subscribe(() => {
|
||||
export default function intervalSubscribe<T, Props, State extends CallState> (that: React.Component<Props, State>): Subscription {
|
||||
return interval$.subscribe((): void => {
|
||||
const elapsed = Date.now() - ((that.state.callUpdatedAt as number) || 0);
|
||||
const callUpdated = elapsed <= 1500;
|
||||
|
||||
|
||||
@ -12,7 +12,7 @@ function flatten (key: string | null, value: any): any {
|
||||
}
|
||||
|
||||
if (Array.isArray(value)) {
|
||||
return value.map((item) =>
|
||||
return value.map((item): any =>
|
||||
flatten(null, item)
|
||||
);
|
||||
}
|
||||
|
||||
@ -11,7 +11,7 @@ export default function triggerChange (value?: any, ...callOnResult: (OnChangeCb
|
||||
return;
|
||||
}
|
||||
|
||||
callOnResult.forEach((callOnResult) => {
|
||||
callOnResult.forEach((callOnResult): void => {
|
||||
if (isObservable(callOnResult)) {
|
||||
callOnResult.next(value);
|
||||
} else if (isFunction(callOnResult)) {
|
||||
|
||||
@ -12,12 +12,12 @@ import { ApiConsumer } from '../ApiContext';
|
||||
|
||||
export default function withApi <P extends ApiProps> (Inner: React.ComponentType<P>, defaultProps: DefaultProps = {}): React.ComponentType<any> {
|
||||
return class WithApi extends React.PureComponent<SubtractProps<P, ApiProps>> {
|
||||
component: any = React.createRef();
|
||||
private component: any = React.createRef();
|
||||
|
||||
public render (): React.ReactNode {
|
||||
return (
|
||||
<ApiConsumer>
|
||||
{(apiProps?: ApiProps) => {
|
||||
{(apiProps?: ApiProps): React.ReactNode => {
|
||||
assert(apiProps && apiProps.api, `Application root must be wrapped inside 'rx-react/Api' to provide API context`);
|
||||
|
||||
return (
|
||||
|
||||
@ -9,9 +9,9 @@ import React from 'react';
|
||||
|
||||
import withCall from './call';
|
||||
|
||||
type Props<T> = BaseProps<T> & {
|
||||
callResult?: T
|
||||
};
|
||||
interface Props<T> extends BaseProps<T> {
|
||||
callResult?: T;
|
||||
}
|
||||
|
||||
export default function withCallDiv<T> (endpoint: string, options: Options = {}) {
|
||||
return (render: (value?: T) => React.ReactNode, defaultProps: DefaultProps = {}): React.ComponentType<any> => {
|
||||
|
||||
@ -30,17 +30,17 @@ export default function withObservable<T, P> (observable: Observable<P>, { callO
|
||||
subscriptions: []
|
||||
};
|
||||
|
||||
componentDidMount () {
|
||||
public componentDidMount (): void {
|
||||
this.setState({
|
||||
subscriptions: [
|
||||
observable
|
||||
.pipe(
|
||||
map(transform),
|
||||
catchError(() =>
|
||||
catchError((): Observable<any> =>
|
||||
of(undefined)
|
||||
)
|
||||
)
|
||||
.subscribe((value: any) =>
|
||||
.subscribe((value: any): void =>
|
||||
this.triggerUpdate(this.props, value)
|
||||
),
|
||||
intervalObservable(this)
|
||||
@ -48,13 +48,13 @@ export default function withObservable<T, P> (observable: Observable<P>, { callO
|
||||
});
|
||||
}
|
||||
|
||||
componentWillUnmount () {
|
||||
this.state.subscriptions.forEach((subscription) =>
|
||||
public componentWillUnmount (): void {
|
||||
this.state.subscriptions.forEach((subscription): void =>
|
||||
subscription.unsubscribe()
|
||||
);
|
||||
}
|
||||
|
||||
triggerUpdate = (props: any, callResult?: T): void => {
|
||||
private triggerUpdate = (props: any, callResult?: T): void => {
|
||||
try {
|
||||
if (isEqual(callResult, this.state.callResult)) {
|
||||
return;
|
||||
|
||||
@ -8,23 +8,23 @@ import React from 'react';
|
||||
|
||||
export type Transform = (value: any, index: number) => any;
|
||||
|
||||
export type DefaultProps = {
|
||||
callOnResult?: OnChangeCb,
|
||||
[index: string]: any
|
||||
};
|
||||
export interface DefaultProps {
|
||||
callOnResult?: OnChangeCb;
|
||||
[index: string]: any;
|
||||
}
|
||||
|
||||
export type Options = {
|
||||
at?: Uint8Array | string,
|
||||
atProp?: string,
|
||||
callOnResult?: OnChangeCb,
|
||||
isMulti?: boolean,
|
||||
params?: any[],
|
||||
paramName?: string,
|
||||
paramPick?: (props: any) => any,
|
||||
paramValid?: boolean,
|
||||
propName?: string,
|
||||
transform?: Transform
|
||||
};
|
||||
export interface Options {
|
||||
at?: Uint8Array | string;
|
||||
atProp?: string;
|
||||
callOnResult?: OnChangeCb;
|
||||
isMulti?: boolean;
|
||||
params?: any[];
|
||||
paramName?: string;
|
||||
paramPick?: (props: any) => any;
|
||||
paramValid?: boolean;
|
||||
propName?: string;
|
||||
transform?: Transform;
|
||||
}
|
||||
|
||||
export type RenderFn = (value?: any) => React.ReactNode;
|
||||
|
||||
@ -32,10 +32,10 @@ export type StorageTransform = (input: any, index: number) => any | null;
|
||||
|
||||
export type HOC = (Component: React.ComponentType<any>, defaultProps?: DefaultProps, render?: RenderFn) => React.ComponentType<any>;
|
||||
|
||||
export type ApiMethod = {
|
||||
name: string,
|
||||
section?: string
|
||||
};
|
||||
export interface ApiMethod {
|
||||
name: string;
|
||||
section?: string;
|
||||
}
|
||||
|
||||
export type ComponentRenderer = (render: RenderFn, defaultProps?: DefaultProps) => React.ComponentType<any>;
|
||||
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
// Copyright 2017-2019 @polkadot/ui-reactive authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
// Copyright 2017-2019 @polkadot/ui-reactive 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,14 +14,14 @@ import Card from './Card';
|
||||
import ProposedAction, { styles as proposedActionStyles } from './ProposedAction';
|
||||
import { styles as rowStyles } from './Row';
|
||||
|
||||
type Props = RouteComponentProps & {
|
||||
className?: string,
|
||||
children?: React.ReactNode,
|
||||
accessory?: React.ReactNode,
|
||||
proposal?: Proposal | null,
|
||||
idNumber: BN | number | string,
|
||||
expandNested?: boolean
|
||||
};
|
||||
interface Props extends RouteComponentProps {
|
||||
className?: string;
|
||||
children?: React.ReactNode;
|
||||
accessory?: React.ReactNode;
|
||||
proposal?: Proposal | null;
|
||||
idNumber: BN | number | string;
|
||||
expandNested?: boolean;
|
||||
}
|
||||
|
||||
export const styles = `
|
||||
${rowStyles}
|
||||
@ -47,7 +47,7 @@ class ActionItem extends React.PureComponent<Props> {
|
||||
);
|
||||
}
|
||||
|
||||
private renderProposal () {
|
||||
private renderProposal (): React.ReactNode {
|
||||
const { idNumber, proposal, expandNested } = this.props;
|
||||
|
||||
return (
|
||||
|
||||
@ -14,9 +14,9 @@ import LinkPolkascan from './LinkPolkascan';
|
||||
|
||||
import translate from './translate';
|
||||
|
||||
type Props = AddressProps & {
|
||||
withExplorer?: boolean
|
||||
};
|
||||
interface Props extends AddressProps {
|
||||
withExplorer?: boolean;
|
||||
}
|
||||
|
||||
class AddressCard extends React.PureComponent<Props> {
|
||||
public render (): React.ReactNode {
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
/* eslint-disable @typescript-eslint/camelcase */
|
||||
// Copyright 2017-2019 @polkadot/ui-app authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
@ -17,33 +18,33 @@ import Label from './Label';
|
||||
import translate from './translate';
|
||||
|
||||
// true to display, or (for bonded) provided values [own, ...all extras]
|
||||
export type BalanceActiveType = {
|
||||
available?: boolean,
|
||||
bonded?: boolean | BN[],
|
||||
free?: boolean,
|
||||
redeemable?: boolean,
|
||||
unlocking?: boolean
|
||||
};
|
||||
export interface BalanceActiveType {
|
||||
available?: boolean;
|
||||
bonded?: boolean | BN[];
|
||||
free?: boolean;
|
||||
redeemable?: boolean;
|
||||
unlocking?: boolean;
|
||||
}
|
||||
|
||||
export type CryptoActiveType = {
|
||||
crypto?: boolean,
|
||||
nonce?: boolean
|
||||
};
|
||||
export interface CryptoActiveType {
|
||||
crypto?: boolean;
|
||||
nonce?: boolean;
|
||||
}
|
||||
|
||||
export type ValidatorPrefsType = {
|
||||
unstakeThreshold?: boolean,
|
||||
validatorPayment?: boolean
|
||||
};
|
||||
export interface ValidatorPrefsType {
|
||||
unstakeThreshold?: boolean;
|
||||
validatorPayment?: boolean;
|
||||
}
|
||||
|
||||
type Props = BareProps & I18nProps & {
|
||||
address: string,
|
||||
balances_all?: DerivedBalances,
|
||||
children?: React.ReactNode,
|
||||
staking_info?: DerivedStaking,
|
||||
withBalance?: boolean | BalanceActiveType,
|
||||
withRewardDestination?: boolean,
|
||||
withExtended?: boolean | CryptoActiveType,
|
||||
withValidatorPrefs?: boolean | ValidatorPrefsType
|
||||
address: string;
|
||||
balances_all?: DerivedBalances;
|
||||
children?: React.ReactNode;
|
||||
staking_info?: DerivedStaking;
|
||||
withBalance?: boolean | BalanceActiveType;
|
||||
withRewardDestination?: boolean;
|
||||
withExtended?: boolean | CryptoActiveType;
|
||||
withValidatorPrefs?: boolean | ValidatorPrefsType;
|
||||
};
|
||||
|
||||
class AddressInfo extends React.PureComponent<Props> {
|
||||
@ -68,13 +69,11 @@ class AddressInfo extends React.PureComponent<Props> {
|
||||
);
|
||||
}
|
||||
|
||||
private renderBalances () {
|
||||
private renderBalances (): React.ReactNode {
|
||||
const { balances_all, staking_info, t, withBalance = true } = this.props;
|
||||
const balanceDisplay = withBalance === true
|
||||
? { available: true, bonded: true, free: true, redeemable: true, unlocking: true }
|
||||
: withBalance
|
||||
? withBalance
|
||||
: undefined;
|
||||
: withBalance || undefined;
|
||||
|
||||
if (!balanceDisplay || !balances_all) {
|
||||
return null;
|
||||
@ -117,15 +116,15 @@ class AddressInfo extends React.PureComponent<Props> {
|
||||
}
|
||||
|
||||
// either true (filtered above already) or [own, ...all extras bonded funds from nominators]
|
||||
private renderBonded (bonded: true | BN[]) {
|
||||
private renderBonded (bonded: true | BN[]): React.ReactNode {
|
||||
const { staking_info, t } = this.props;
|
||||
let value = undefined;
|
||||
let value;
|
||||
|
||||
if (Array.isArray(bonded)) {
|
||||
// Get the sum of funds bonded by any nominator (if available)
|
||||
const extras = bonded.filter((value, index) => index !== 0);
|
||||
const extra = extras.reduce((total, value) => total.add(value), new BN(0)).gtn(0)
|
||||
? `(+${extras.map((bonded) => formatBalance(bonded)).join(', ')})`
|
||||
const extras = bonded.filter((value, index): boolean => index !== 0);
|
||||
const extra = extras.reduce((total, value): BN => total.add(value), new BN(0)).gtn(0)
|
||||
? `(+${extras.map((bonded): string => formatBalance(bonded)).join(', ')})`
|
||||
: '';
|
||||
|
||||
value = `${formatBalance(bonded[0])} ${extra}`;
|
||||
@ -143,13 +142,11 @@ class AddressInfo extends React.PureComponent<Props> {
|
||||
: undefined;
|
||||
}
|
||||
|
||||
private renderExtended () {
|
||||
private renderExtended (): React.ReactNode {
|
||||
const { balances_all, t, address, withExtended } = this.props;
|
||||
const extendedDisplay = withExtended === true
|
||||
? { crypto: true, nonce: true }
|
||||
: withExtended
|
||||
? withExtended
|
||||
: undefined;
|
||||
: withExtended || undefined;
|
||||
|
||||
if (!extendedDisplay || !balances_all) {
|
||||
return null;
|
||||
@ -176,7 +173,7 @@ class AddressInfo extends React.PureComponent<Props> {
|
||||
);
|
||||
}
|
||||
|
||||
private renderRewardDestination () {
|
||||
private renderRewardDestination (): React.ReactNode {
|
||||
const { staking_info, withRewardDestination, t } = this.props;
|
||||
|
||||
if (!withRewardDestination) {
|
||||
@ -193,7 +190,7 @@ class AddressInfo extends React.PureComponent<Props> {
|
||||
);
|
||||
}
|
||||
|
||||
private renderRedeemButton () {
|
||||
private renderRedeemButton (): React.ReactNode {
|
||||
const { staking_info, t } = this.props;
|
||||
|
||||
return (staking_info && staking_info.controllerId && (
|
||||
@ -211,13 +208,13 @@ class AddressInfo extends React.PureComponent<Props> {
|
||||
));
|
||||
}
|
||||
|
||||
private renderUnlocking () {
|
||||
private renderUnlocking (): React.ReactNode {
|
||||
const { staking_info, t } = this.props;
|
||||
|
||||
return (
|
||||
staking_info &&
|
||||
staking_info.unlocking &&
|
||||
staking_info.unlocking.map(({ remainingBlocks, value }, index) => (
|
||||
staking_info.unlocking.map(({ remainingBlocks, value }, index): React.ReactNode => (
|
||||
<div key={index}>
|
||||
{formatBalance(value)}
|
||||
<Icon
|
||||
@ -234,11 +231,11 @@ class AddressInfo extends React.PureComponent<Props> {
|
||||
);
|
||||
}
|
||||
|
||||
private renderValidatorPrefs () {
|
||||
private renderValidatorPrefs (): React.ReactNode {
|
||||
const { staking_info, t, withValidatorPrefs = false } = this.props;
|
||||
const validatorPrefsDisplay = withValidatorPrefs === true
|
||||
? { unstakeThreshold: true, validatorPayment: true }
|
||||
: withValidatorPrefs;
|
||||
? { unstakeThreshold: true, validatorPayment: true }
|
||||
: withValidatorPrefs;
|
||||
|
||||
if (!validatorPrefsDisplay || !staking_info || !staking_info.validatorPrefs) {
|
||||
return null;
|
||||
|
||||
@ -15,19 +15,19 @@ import BalanceDisplay from './Balance';
|
||||
import BondedDisplay from './Bonded';
|
||||
import IdentityIcon from './IdentityIcon';
|
||||
|
||||
type Props = BareProps & {
|
||||
balance?: BN | BN[],
|
||||
bonded?: BN | BN[],
|
||||
children?: React.ReactNode,
|
||||
iconInfo?: React.ReactNode,
|
||||
isPadded?: boolean,
|
||||
isShort?: boolean,
|
||||
type?: KeyringItemType,
|
||||
value?: AccountId | AccountIndex | Address | string,
|
||||
withAddress?: boolean,
|
||||
withBalance?: boolean,
|
||||
withBonded?: boolean
|
||||
};
|
||||
interface Props extends BareProps {
|
||||
balance?: BN | BN[];
|
||||
bonded?: BN | BN[];
|
||||
children?: React.ReactNode;
|
||||
iconInfo?: React.ReactNode;
|
||||
isPadded?: boolean;
|
||||
isShort?: boolean;
|
||||
type?: KeyringItemType;
|
||||
value?: AccountId | AccountIndex | Address | string;
|
||||
withAddress?: boolean;
|
||||
withBalance?: boolean;
|
||||
withBonded?: boolean;
|
||||
}
|
||||
|
||||
class AddressMini extends React.PureComponent<Props> {
|
||||
public render (): React.ReactNode {
|
||||
@ -67,7 +67,7 @@ class AddressMini extends React.PureComponent<Props> {
|
||||
);
|
||||
}
|
||||
|
||||
private renderAddressOrName (address: string) {
|
||||
private renderAddressOrName (address: string): React.ReactNode {
|
||||
const { isShort = true, withAddress = true, type } = this.props;
|
||||
|
||||
if (!withAddress) {
|
||||
@ -78,7 +78,7 @@ class AddressMini extends React.PureComponent<Props> {
|
||||
|
||||
return (
|
||||
<div className={`ui--AddressMini-address ${name ? 'withName' : 'withAddr'}`}>{
|
||||
name || (
|
||||
name || (
|
||||
isShort
|
||||
? toShortAddress(address)
|
||||
: address
|
||||
@ -87,7 +87,7 @@ class AddressMini extends React.PureComponent<Props> {
|
||||
);
|
||||
}
|
||||
|
||||
private renderBalance () {
|
||||
private renderBalance (): React.ReactNode {
|
||||
const { balance, value, withBalance = false } = this.props;
|
||||
|
||||
if (!withBalance || !value) {
|
||||
@ -102,7 +102,7 @@ class AddressMini extends React.PureComponent<Props> {
|
||||
);
|
||||
}
|
||||
|
||||
private renderBonded () {
|
||||
private renderBonded (): React.ReactNode {
|
||||
const { bonded, value, withBonded = false } = this.props;
|
||||
|
||||
if (!withBonded || !value) {
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
/* eslint-disable @typescript-eslint/camelcase */
|
||||
// Copyright 2017-2019 @polkadot/ui-app authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
@ -44,7 +45,7 @@ class AddressRow extends Row<Props, State> {
|
||||
this.state = this.createState();
|
||||
}
|
||||
|
||||
static getDerivedStateFromProps ({ accounts_idAndIndex = [], defaultName, type, value }: Props, prevState: State) {
|
||||
public static getDerivedStateFromProps ({ accounts_idAndIndex = [], defaultName, type, value }: Props, prevState: State): State | null {
|
||||
const [_accountId] = accounts_idAndIndex;
|
||||
const accountId = _accountId || value;
|
||||
const address = accountId
|
||||
@ -52,7 +53,7 @@ class AddressRow extends Row<Props, State> {
|
||||
: DEFAULT_ADDR;
|
||||
const name = getAddressName(address, type, false, defaultName || '<unknown>') || '';
|
||||
const tags = getAddressTags(address, type);
|
||||
const state = { tags } as State;
|
||||
const state: Partial<State> = { tags };
|
||||
let hasChanged = false;
|
||||
|
||||
if (address !== prevState.address) {
|
||||
@ -66,7 +67,7 @@ class AddressRow extends Row<Props, State> {
|
||||
}
|
||||
|
||||
return hasChanged
|
||||
? state
|
||||
? state as State
|
||||
: null;
|
||||
}
|
||||
|
||||
@ -96,7 +97,7 @@ class AddressRow extends Row<Props, State> {
|
||||
);
|
||||
}
|
||||
|
||||
private createState () {
|
||||
private createState (): State {
|
||||
const { accounts_idAndIndex = [], defaultName, type, value } = this.props;
|
||||
const [_accountId] = accounts_idAndIndex;
|
||||
const accountId = _accountId || value;
|
||||
@ -114,7 +115,7 @@ class AddressRow extends Row<Props, State> {
|
||||
};
|
||||
}
|
||||
|
||||
protected renderAddressAndName () {
|
||||
protected renderAddressAndName (): React.ReactNode {
|
||||
const { withAddressOrName = false } = this.props;
|
||||
|
||||
if (withAddressOrName) {
|
||||
@ -129,7 +130,7 @@ class AddressRow extends Row<Props, State> {
|
||||
}
|
||||
}
|
||||
|
||||
private renderAddress () {
|
||||
private renderAddress (): React.ReactNode {
|
||||
const { address } = this.state;
|
||||
|
||||
return (
|
||||
@ -144,7 +145,7 @@ class AddressRow extends Row<Props, State> {
|
||||
);
|
||||
}
|
||||
|
||||
private renderAccountIndex () {
|
||||
private renderAccountIndex (): React.ReactNode {
|
||||
const { accounts_idAndIndex = [], withIndex } = this.props;
|
||||
const [, accountIndex] = accounts_idAndIndex;
|
||||
|
||||
@ -159,7 +160,7 @@ class AddressRow extends Row<Props, State> {
|
||||
);
|
||||
}
|
||||
|
||||
private renderBalances () {
|
||||
private renderBalances (): React.ReactNode {
|
||||
const { accounts_idAndIndex = [], withBalance } = this.props;
|
||||
const [accountId] = accounts_idAndIndex;
|
||||
|
||||
@ -177,7 +178,7 @@ class AddressRow extends Row<Props, State> {
|
||||
);
|
||||
}
|
||||
|
||||
private renderIcon () {
|
||||
private renderIcon (): React.ReactNode {
|
||||
const { accounts_idAndIndex = [], iconInfo, withIcon = true } = this.props;
|
||||
const { address } = this.state;
|
||||
const [accountId] = accounts_idAndIndex;
|
||||
@ -207,7 +208,7 @@ class AddressRow extends Row<Props, State> {
|
||||
);
|
||||
}
|
||||
|
||||
private renderLabel () {
|
||||
private renderLabel (): React.ReactNode {
|
||||
const { label } = this.props;
|
||||
|
||||
if (!label) {
|
||||
@ -219,7 +220,7 @@ class AddressRow extends Row<Props, State> {
|
||||
);
|
||||
}
|
||||
|
||||
protected saveName = () => {
|
||||
protected saveName = (): void => {
|
||||
const { address, name } = this.state;
|
||||
const trimmedName = name.trim();
|
||||
const meta = {
|
||||
@ -241,7 +242,7 @@ class AddressRow extends Row<Props, State> {
|
||||
}
|
||||
}
|
||||
|
||||
protected saveTags = () => {
|
||||
protected saveTags = (): void => {
|
||||
const { address, tags } = this.state;
|
||||
const meta = {
|
||||
tags,
|
||||
|
||||
@ -10,10 +10,10 @@ import { Available } from '@polkadot/ui-reactive';
|
||||
|
||||
import { classes } from './util';
|
||||
|
||||
export type Props = BareProps & {
|
||||
label?: React.ReactNode,
|
||||
params?: AccountId | AccountIndex | Address | string | Uint8Array | null
|
||||
};
|
||||
export interface Props extends BareProps {
|
||||
label?: React.ReactNode;
|
||||
params?: AccountId | AccountIndex | Address | string | Uint8Array | null;
|
||||
}
|
||||
|
||||
export default class AvailableDisplay extends React.PureComponent<Props> {
|
||||
public render (): React.ReactNode {
|
||||
|
||||
@ -12,12 +12,12 @@ import { Balance } from '@polkadot/ui-reactive';
|
||||
|
||||
import { classes } from './util';
|
||||
|
||||
export type Props = BareProps & {
|
||||
balance?: BN | BN[],
|
||||
label?: React.ReactNode,
|
||||
params?: AccountId | AccountIndex | Address | string | Uint8Array | null,
|
||||
withLabel?: boolean
|
||||
};
|
||||
export interface Props extends BareProps {
|
||||
balance?: BN | BN[];
|
||||
label?: React.ReactNode;
|
||||
params?: AccountId | AccountIndex | Address | string | Uint8Array | null;
|
||||
withLabel?: boolean;
|
||||
}
|
||||
|
||||
export default class BalanceDisplay extends React.PureComponent<Props> {
|
||||
public render (): React.ReactNode {
|
||||
@ -39,14 +39,14 @@ export default class BalanceDisplay extends React.PureComponent<Props> {
|
||||
);
|
||||
}
|
||||
|
||||
private renderProvided () {
|
||||
private renderProvided (): React.ReactNode {
|
||||
const { balance, className, label, style } = this.props;
|
||||
let value = `${formatBalance(Array.isArray(balance) ? balance[0] : balance)}`;
|
||||
|
||||
if (Array.isArray(balance)) {
|
||||
const totals = balance.filter((value, index) => index !== 0);
|
||||
const total = totals.reduce((total, value) => total.add(value), new BN(0)).gtn(0)
|
||||
? `(+${totals.map((balance) => formatBalance(balance)).join(', ')})`
|
||||
const totals = balance.filter((value, index): boolean => index !== 0);
|
||||
const total = totals.reduce((total, value): BN => total.add(value), new BN(0)).gtn(0)
|
||||
? `(+${totals.map((balance): string => formatBalance(balance)).join(', ')})`
|
||||
: '';
|
||||
|
||||
value = `${value} ${total}`;
|
||||
|
||||
@ -12,12 +12,12 @@ import { Bonded } from '@polkadot/ui-reactive';
|
||||
|
||||
import { classes } from './util';
|
||||
|
||||
export type Props = BareProps & {
|
||||
bonded?: BN | BN[],
|
||||
label?: React.ReactNode,
|
||||
params?: AccountId | AccountIndex | Address | string | Uint8Array | null,
|
||||
withLabel?: boolean
|
||||
};
|
||||
export interface Props extends BareProps {
|
||||
bonded?: BN | BN[];
|
||||
label?: React.ReactNode;
|
||||
params?: AccountId | AccountIndex | Address | string | Uint8Array | null;
|
||||
withLabel?: boolean;
|
||||
}
|
||||
|
||||
export default class BondedDisplay extends React.PureComponent<Props> {
|
||||
public render (): React.ReactNode {
|
||||
@ -39,14 +39,14 @@ export default class BondedDisplay extends React.PureComponent<Props> {
|
||||
);
|
||||
}
|
||||
|
||||
private renderProvided () {
|
||||
private renderProvided (): React.ReactNode {
|
||||
const { bonded, className, label, style } = this.props;
|
||||
let value = `${formatBalance(Array.isArray(bonded) ? bonded[0] : bonded)}`;
|
||||
|
||||
if (Array.isArray(bonded)) {
|
||||
const totals = bonded.filter((value, index) => index !== 0);
|
||||
const total = totals.reduce((total, value) => total.add(value), new BN(0)).gtn(0)
|
||||
? `(+${totals.map((bonded) => formatBalance(bonded)).join(', ')})`
|
||||
const totals = bonded.filter((value, index): boolean => index !== 0);
|
||||
const total = totals.reduce((total, value): BN => total.add(value), new BN(0)).gtn(0)
|
||||
? `(+${totals.map((bonded): string => formatBalance(bonded)).join(', ')})`
|
||||
: '';
|
||||
|
||||
value = `${value} ${total}`;
|
||||
|
||||
@ -13,12 +13,12 @@ import settings from '@polkadot/ui-settings';
|
||||
import { classes } from './util';
|
||||
import Icon from './Icon';
|
||||
|
||||
type Props = BareProps & {
|
||||
children: React.ReactNode,
|
||||
color?: SemanticCOLORS,
|
||||
icon?: SemanticICONS,
|
||||
label?: React.ReactNode
|
||||
};
|
||||
interface Props extends BareProps {
|
||||
children: React.ReactNode;
|
||||
color?: SemanticCOLORS;
|
||||
icon?: SemanticICONS;
|
||||
label?: React.ReactNode;
|
||||
}
|
||||
|
||||
class Bubble extends React.PureComponent<Props> {
|
||||
public render (): React.ReactNode {
|
||||
|
||||
@ -5,10 +5,10 @@
|
||||
import React from 'react';
|
||||
import styled from 'styled-components';
|
||||
|
||||
type Props = {
|
||||
children: React.ReactNode,
|
||||
className?: string
|
||||
};
|
||||
interface Props {
|
||||
children: React.ReactNode;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
class Card extends React.PureComponent<Props> {
|
||||
public render (): React.ReactNode {
|
||||
|
||||
@ -14,14 +14,15 @@ type Props = CollectionProps;
|
||||
type State = CollectionState;
|
||||
|
||||
class CardGrid extends Collection<Props, State> {
|
||||
static getDerivedStateFromProps ({ children, headerText }: Props) {
|
||||
public static getDerivedStateFromProps ({ children, headerText }: Props): State {
|
||||
if (!children || (children as any[]).length <= 0) {
|
||||
return { isEmpty: true, showHeader: !!headerText };
|
||||
}
|
||||
|
||||
return { isEmpty: false, showHeader: true };
|
||||
}
|
||||
|
||||
renderEmpty () {
|
||||
protected renderEmpty (): React.ReactNode {
|
||||
const { buttons, headerText, t } = this.props;
|
||||
|
||||
if (headerText) {
|
||||
@ -45,7 +46,7 @@ class CardGrid extends Collection<Props, State> {
|
||||
);
|
||||
}
|
||||
|
||||
renderCollection () {
|
||||
public renderCollection (): React.ReactNode {
|
||||
const { children } = this.props;
|
||||
|
||||
return (
|
||||
@ -96,5 +97,4 @@ export default translate(
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
`);
|
||||
`);
|
||||
|
||||
@ -13,20 +13,20 @@ import { isUndefined } from '@polkadot/util';
|
||||
import Progress, { Colors as ProgressColors } from './Progress';
|
||||
import Labelled from './Labelled';
|
||||
|
||||
type ProgressProps = {
|
||||
color?: ProgressColors,
|
||||
hideValue?: boolean,
|
||||
isPercent?: boolean,
|
||||
total?: BN | UInt,
|
||||
value?: BN | UInt
|
||||
};
|
||||
interface ProgressProps {
|
||||
color?: ProgressColors;
|
||||
hideValue?: boolean;
|
||||
isPercent?: boolean;
|
||||
total?: BN | UInt;
|
||||
value?: BN | UInt;
|
||||
}
|
||||
|
||||
type Props = BareProps & {
|
||||
children?: React.ReactNode,
|
||||
help?: React.ReactNode,
|
||||
label: React.ReactNode,
|
||||
progress?: ProgressProps
|
||||
};
|
||||
interface Props extends BareProps {
|
||||
children?: React.ReactNode;
|
||||
help?: React.ReactNode;
|
||||
label: React.ReactNode;
|
||||
progress?: ProgressProps;
|
||||
}
|
||||
|
||||
class CardSummary extends React.PureComponent<Props> {
|
||||
public render (): React.ReactNode {
|
||||
@ -40,7 +40,7 @@ class CardSummary extends React.PureComponent<Props> {
|
||||
progress.isPercent
|
||||
? '100'
|
||||
: total.toString()
|
||||
}`
|
||||
}`
|
||||
: (
|
||||
progress.isPercent
|
||||
? value.muln(100).div(total).toString()
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
/* eslint-disable @typescript-eslint/camelcase */
|
||||
// Copyright 2017-2019 @polkadot/ui-app authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
@ -56,7 +57,7 @@ class CodeRow extends Row<Props, State> {
|
||||
this.state = this.createState();
|
||||
}
|
||||
|
||||
static getDerivedStateFromProps ({ code: { json }, accounts_idAndIndex = [] }: Props, prevState: State): State | null {
|
||||
public static getDerivedStateFromProps ({ code: { json }, accounts_idAndIndex = [] }: Props, prevState: State): State | null {
|
||||
const codeHash = json.codeHash || DEFAULT_HASH;
|
||||
const name = json.name || DEFAULT_NAME;
|
||||
const tags = json.tags || [];
|
||||
@ -66,7 +67,7 @@ class CodeRow extends Row<Props, State> {
|
||||
? accountId.toString()
|
||||
: DEFAULT_ADDR;
|
||||
|
||||
const state = { tags } as State;
|
||||
const state: Partial<State> = { tags };
|
||||
let hasChanged = false;
|
||||
|
||||
if (codeHash !== prevState.codeHash) {
|
||||
@ -85,7 +86,7 @@ class CodeRow extends Row<Props, State> {
|
||||
}
|
||||
|
||||
return hasChanged
|
||||
? state
|
||||
? state as State
|
||||
: null;
|
||||
}
|
||||
|
||||
@ -112,7 +113,7 @@ class CodeRow extends Row<Props, State> {
|
||||
);
|
||||
}
|
||||
|
||||
private createState () {
|
||||
private createState (): State {
|
||||
const { code: { json: { codeHash = DEFAULT_HASH, name = DEFAULT_NAME, tags = [] } } } = this.props;
|
||||
|
||||
return {
|
||||
@ -125,7 +126,7 @@ class CodeRow extends Row<Props, State> {
|
||||
};
|
||||
}
|
||||
|
||||
protected renderCodeHash () {
|
||||
protected renderCodeHash (): React.ReactNode {
|
||||
const { codeHash } = this.state;
|
||||
|
||||
return (
|
||||
@ -145,7 +146,7 @@ class CodeRow extends Row<Props, State> {
|
||||
);
|
||||
}
|
||||
|
||||
protected renderButtons () {
|
||||
protected renderButtons (): React.ReactNode {
|
||||
const { buttons } = this.props;
|
||||
|
||||
if (!buttons) {
|
||||
@ -159,7 +160,7 @@ class CodeRow extends Row<Props, State> {
|
||||
);
|
||||
}
|
||||
|
||||
protected renderIcon () {
|
||||
protected renderIcon (): React.ReactNode {
|
||||
return (
|
||||
<CodeIcon>
|
||||
<Icon
|
||||
@ -170,7 +171,7 @@ class CodeRow extends Row<Props, State> {
|
||||
);
|
||||
}
|
||||
|
||||
protected renderMessages () {
|
||||
protected renderMessages (): React.ReactNode {
|
||||
const { code: { contractAbi }, withMessages } = this.props;
|
||||
|
||||
if (!withMessages || !contractAbi) {
|
||||
@ -185,7 +186,7 @@ class CodeRow extends Row<Props, State> {
|
||||
);
|
||||
}
|
||||
|
||||
protected saveName = async () => {
|
||||
protected saveName = async (): Promise<void> => {
|
||||
const { codeHash, name } = this.state;
|
||||
const trimmedName = name.trim();
|
||||
|
||||
@ -197,7 +198,7 @@ class CodeRow extends Row<Props, State> {
|
||||
}
|
||||
}
|
||||
|
||||
protected saveTags = async () => {
|
||||
protected saveTags = async (): Promise<void> => {
|
||||
const { codeHash, tags } = this.state;
|
||||
|
||||
if (codeHash) {
|
||||
|
||||
@ -6,19 +6,19 @@ import { I18nProps } from '@polkadot/ui-app/types';
|
||||
|
||||
import React from 'react';
|
||||
|
||||
export type CollectionProps = I18nProps & {
|
||||
buttons?: React.ReactNode,
|
||||
children: React.ReactNode,
|
||||
className?: string,
|
||||
headerText?: React.ReactNode,
|
||||
isEmpty?: boolean,
|
||||
emptyText?: React.ReactNode
|
||||
};
|
||||
export interface CollectionProps extends I18nProps {
|
||||
buttons?: React.ReactNode;
|
||||
children: React.ReactNode;
|
||||
className?: string;
|
||||
headerText?: React.ReactNode;
|
||||
isEmpty?: boolean;
|
||||
emptyText?: React.ReactNode;
|
||||
}
|
||||
|
||||
export type CollectionState = {
|
||||
isEmpty: boolean,
|
||||
showHeader?: boolean
|
||||
};
|
||||
export interface CollectionState {
|
||||
isEmpty: boolean;
|
||||
showHeader?: boolean;
|
||||
}
|
||||
|
||||
export const collectionStyles = `
|
||||
.ui--Collection-header {
|
||||
@ -51,7 +51,7 @@ export default class Collection<P extends CollectionProps, S extends CollectionS
|
||||
return !children || (Array.isArray(children) && children.length === 0);
|
||||
}
|
||||
|
||||
static getDerivedStateFromProps ({ children }: CollectionProps) {
|
||||
public static getDerivedStateFromProps ({ children }: CollectionProps): Pick<any, never> {
|
||||
return {
|
||||
isEmpty: Collection.isEmpty(children)
|
||||
};
|
||||
@ -72,7 +72,7 @@ export default class Collection<P extends CollectionProps, S extends CollectionS
|
||||
);
|
||||
}
|
||||
|
||||
protected renderHeader () {
|
||||
protected renderHeader (): React.ReactNode {
|
||||
const { buttons, headerText } = this.props;
|
||||
|
||||
return (
|
||||
@ -87,7 +87,7 @@ export default class Collection<P extends CollectionProps, S extends CollectionS
|
||||
);
|
||||
}
|
||||
|
||||
protected renderEmpty () {
|
||||
protected renderEmpty (): React.ReactNode {
|
||||
const { emptyText, t } = this.props;
|
||||
|
||||
return (
|
||||
|
||||
@ -5,10 +5,10 @@
|
||||
import React from 'react';
|
||||
import styled from 'styled-components';
|
||||
|
||||
type Props = {
|
||||
children: React.ReactNode,
|
||||
className?: string
|
||||
};
|
||||
interface Props {
|
||||
children: React.ReactNode;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
class Columar extends React.PureComponent<Props> {
|
||||
public render (): React.ReactNode {
|
||||
|
||||
@ -27,7 +27,7 @@ class Column extends Collection<Props, State> {
|
||||
);
|
||||
}
|
||||
|
||||
renderCollection () {
|
||||
public renderCollection (): React.ReactNode {
|
||||
const { children } = this.props;
|
||||
|
||||
return children;
|
||||
|
||||
@ -13,15 +13,15 @@ import Button from './Button';
|
||||
import translate from './translate';
|
||||
import styled from 'styled-components';
|
||||
|
||||
type Props = BareProps & {
|
||||
children?: React.ReactNode,
|
||||
icon?: string,
|
||||
isAddress?: boolean,
|
||||
value?: any
|
||||
};
|
||||
interface Props extends BareProps {
|
||||
children?: React.ReactNode;
|
||||
icon?: string;
|
||||
isAddress?: boolean;
|
||||
value?: any;
|
||||
}
|
||||
|
||||
type InnerProps = Props & I18nProps & {
|
||||
queueAction: QueueAction$Add
|
||||
queueAction: QueueAction$Add;
|
||||
};
|
||||
|
||||
class CopyButtonInner extends React.PureComponent<InnerProps> {
|
||||
@ -70,7 +70,7 @@ class CopyButton extends React.PureComponent<Props> {
|
||||
public render (): React.ReactNode {
|
||||
return (
|
||||
<QueueConsumer>
|
||||
{({ queueAction }) => (
|
||||
{({ queueAction }): React.ReactNode => (
|
||||
<CopyButtonI18n
|
||||
{...this.props}
|
||||
queueAction={queueAction}
|
||||
|
||||
@ -10,10 +10,10 @@ import keyring from '@polkadot/ui-keyring';
|
||||
|
||||
import { classes } from './util';
|
||||
|
||||
type Props = BareProps & {
|
||||
accountId: AccountId | AccountIndex | Address | string | Uint8Array | null,
|
||||
label?: string
|
||||
};
|
||||
interface Props extends BareProps {
|
||||
accountId: AccountId | AccountIndex | Address | string | Uint8Array | null;
|
||||
label?: string;
|
||||
}
|
||||
|
||||
export default class CryptoType extends React.PureComponent<Props> {
|
||||
public render (): React.ReactNode {
|
||||
|
||||
@ -9,11 +9,11 @@ import React from 'react';
|
||||
import styled from 'styled-components';
|
||||
import { classes } from '@polkadot/ui-app/util';
|
||||
|
||||
type Props = BareProps & {
|
||||
code: string,
|
||||
isValid?: boolean,
|
||||
onEdit: (code: string) => void
|
||||
};
|
||||
interface Props extends BareProps {
|
||||
code: string;
|
||||
isValid?: boolean;
|
||||
onEdit: (code: string) => void;
|
||||
}
|
||||
|
||||
/**
|
||||
* @name Editor
|
||||
@ -36,9 +36,10 @@ type Props = BareProps & {
|
||||
*/
|
||||
class Editor extends React.Component<Props> {
|
||||
private id: string = `flask-${Date.now()}`;
|
||||
|
||||
private editor: any;
|
||||
|
||||
componentDidMount () {
|
||||
public componentDidMount (): void {
|
||||
const { onEdit } = this.props;
|
||||
|
||||
this.editor = new CodeFlask(`#${this.id}`, {
|
||||
@ -48,18 +49,18 @@ class Editor extends React.Component<Props> {
|
||||
|
||||
this.editor.updateCode(this.props.code);
|
||||
|
||||
this.editor.editorRoot.addEventListener('keydown', () => {
|
||||
this.editor.editorRoot.addEventListener('keydown', (): void => {
|
||||
this.editor.onUpdate(onEdit);
|
||||
});
|
||||
}
|
||||
|
||||
shouldComponentUpdate (nextProps: Props): boolean {
|
||||
public shouldComponentUpdate (nextProps: Props): boolean {
|
||||
return (
|
||||
nextProps.code !== this.props.code
|
||||
);
|
||||
}
|
||||
|
||||
componentDidUpdate () {
|
||||
public componentDidUpdate (): void {
|
||||
this.editor.updateCode(this.props.code);
|
||||
}
|
||||
|
||||
|
||||
@ -2,26 +2,27 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { Codec } from '@polkadot/types/types';
|
||||
import { BareProps } from './types';
|
||||
|
||||
import React from 'react';
|
||||
import { Event, getTypeDef } from '@polkadot/types';
|
||||
import { Event, TypeDef, getTypeDef } from '@polkadot/types';
|
||||
import Params from '@polkadot/ui-params';
|
||||
|
||||
import { classes } from './util';
|
||||
|
||||
export type Props = BareProps & {
|
||||
children?: React.ReactNode,
|
||||
value: Event
|
||||
};
|
||||
export interface Props extends BareProps {
|
||||
children?: React.ReactNode;
|
||||
value: Event;
|
||||
}
|
||||
|
||||
export default class EventDisplay extends React.PureComponent<Props> {
|
||||
public render (): React.ReactNode {
|
||||
const { children, className, style, value } = this.props;
|
||||
const params = value.typeDef.map(({ type }) => ({
|
||||
const params = value.typeDef.map(({ type }): { type: TypeDef } => ({
|
||||
type: getTypeDef(type)
|
||||
}));
|
||||
const values = value.data.map((value) => ({
|
||||
const values = value.data.map((value): { isValid: boolean; value: Codec } => ({
|
||||
isValid: true,
|
||||
value
|
||||
}));
|
||||
|
||||
@ -30,7 +30,7 @@ type Props = BareProps & ApiProps & {
|
||||
|
||||
interface State {
|
||||
methodfn: MethodFunction;
|
||||
params: { name: string, type: TypeDef }[];
|
||||
params: { name: string; type: TypeDef }[];
|
||||
values: RawParam[];
|
||||
}
|
||||
|
||||
@ -74,12 +74,12 @@ class ExtrinsicDisplay extends React.PureComponent<Props, State> {
|
||||
);
|
||||
}
|
||||
|
||||
private nextState (newState: State): void {
|
||||
this.setState(newState, () => {
|
||||
private nextState (newState: Pick< State, never>): void {
|
||||
this.setState(newState, (): void => {
|
||||
const { onChange } = this.props;
|
||||
const { methodfn, params, values } = this.state;
|
||||
|
||||
const isValid = values.reduce((isValid, value) =>
|
||||
const isValid = values.reduce((isValid, value): boolean =>
|
||||
isValid &&
|
||||
!isUndefined(value) &&
|
||||
!isUndefined(value.value) &&
|
||||
@ -91,7 +91,7 @@ class ExtrinsicDisplay extends React.PureComponent<Props, State> {
|
||||
if (isValid) {
|
||||
try {
|
||||
method = methodfn(
|
||||
...values.map(({ value }) => value)
|
||||
...values.map(({ value }): any => value)
|
||||
);
|
||||
} catch (error) {
|
||||
// swallow
|
||||
@ -111,7 +111,7 @@ class ExtrinsicDisplay extends React.PureComponent<Props, State> {
|
||||
}
|
||||
|
||||
private onChangeValues = (values: RawParam[]): void => {
|
||||
this.nextState({ values } as State);
|
||||
this.nextState({ values });
|
||||
}
|
||||
|
||||
private getParams (methodfn: MethodFunction): { name: string; type: TypeDef }[] {
|
||||
|
||||
@ -9,9 +9,9 @@ import styled from 'styled-components';
|
||||
|
||||
import media from './media';
|
||||
|
||||
type Props = BareProps & {
|
||||
children: React.ReactNode
|
||||
};
|
||||
interface Props extends BareProps {
|
||||
children: React.ReactNode;
|
||||
}
|
||||
|
||||
class FilterOverlay extends React.PureComponent<Props> {
|
||||
public render (): React.ReactNode {
|
||||
|
||||
@ -40,7 +40,7 @@ class Forget extends React.PureComponent<Props> {
|
||||
);
|
||||
}
|
||||
|
||||
private headerText = () => {
|
||||
private headerText = (): string => {
|
||||
const { mode = 'account', t } = this.props;
|
||||
switch (mode) {
|
||||
case 'account':
|
||||
@ -54,8 +54,9 @@ class Forget extends React.PureComponent<Props> {
|
||||
}
|
||||
}
|
||||
|
||||
private content = () => {
|
||||
private content = (): React.ReactNode => {
|
||||
const { mode = 'account', t } = this.props;
|
||||
|
||||
switch (mode) {
|
||||
case 'account':
|
||||
return (
|
||||
@ -88,7 +89,7 @@ class Forget extends React.PureComponent<Props> {
|
||||
}
|
||||
}
|
||||
|
||||
private renderButtons () {
|
||||
private renderButtons (): React.ReactNode {
|
||||
const { onClose, onForget, t } = this.props;
|
||||
|
||||
return (
|
||||
@ -110,7 +111,7 @@ class Forget extends React.PureComponent<Props> {
|
||||
);
|
||||
}
|
||||
|
||||
private renderContent () {
|
||||
private renderContent (): React.ReactNode {
|
||||
const { address, code, mode = 'account' } = this.props;
|
||||
|
||||
switch (mode) {
|
||||
@ -120,7 +121,7 @@ class Forget extends React.PureComponent<Props> {
|
||||
return (
|
||||
<AddressRow
|
||||
isInline
|
||||
value={address!}
|
||||
value={address || ''}
|
||||
>
|
||||
{this.content()}
|
||||
</AddressRow>
|
||||
@ -129,7 +130,7 @@ class Forget extends React.PureComponent<Props> {
|
||||
return (
|
||||
<CodeRow
|
||||
isInline
|
||||
code={code!}
|
||||
code={code || ''}
|
||||
>
|
||||
{this.content()}
|
||||
</CodeRow>
|
||||
|
||||
@ -40,8 +40,8 @@ const Wrapper = styled.div`
|
||||
position: fixed;
|
||||
right: -50rem;
|
||||
top: 0;
|
||||
transition-duration: .5s;
|
||||
transition-property: all;
|
||||
transition-duration: .5s;
|
||||
z-index: 10;
|
||||
|
||||
.help-button {
|
||||
@ -80,7 +80,7 @@ export default class HelpOverlay extends React.PureComponent<Props, State> {
|
||||
);
|
||||
}
|
||||
|
||||
private renderButton (name: 'close' | 'help circle') {
|
||||
private renderButton (name: 'close' | 'help circle'): React.ReactNode {
|
||||
return (
|
||||
<div className='help-button'>
|
||||
<Icon
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
/* eslint-disable @typescript-eslint/camelcase */
|
||||
// Copyright 2017-2019 @polkadot/ui-app authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
@ -65,14 +66,14 @@ class IdentityIcon extends React.PureComponent<Props, State> {
|
||||
isValidator: false
|
||||
};
|
||||
|
||||
static getDerivedStateFromProps ({ session_validators = [], staking_bonded, value }: Props, prevState: State): State | null {
|
||||
public static getDerivedStateFromProps ({ session_validators = [], staking_bonded, value }: Props, prevState: State): State | null {
|
||||
const address = value
|
||||
? value.toString()
|
||||
: null;
|
||||
const bonded = staking_bonded && staking_bonded.isSome
|
||||
? staking_bonded.unwrap().toString()
|
||||
: null;
|
||||
const isValidator = !!session_validators.find((validator) =>
|
||||
const isValidator = !!session_validators.find((validator): boolean =>
|
||||
[address, bonded].includes(validator.toString())
|
||||
);
|
||||
|
||||
@ -86,7 +87,7 @@ class IdentityIcon extends React.PureComponent<Props, State> {
|
||||
|
||||
return (
|
||||
<QueueConsumer>
|
||||
{({ queueAction }) =>
|
||||
{({ queueAction }): React.ReactNode =>
|
||||
<CopyIconI18N
|
||||
isHighlight={isValidator}
|
||||
{...this.props}
|
||||
|
||||
@ -8,11 +8,11 @@ import styled from 'styled-components';
|
||||
import { classes } from './util';
|
||||
import Labelled from './Labelled';
|
||||
|
||||
type Props = {
|
||||
children: React.ReactNode
|
||||
className?: string,
|
||||
interface Props {
|
||||
children: React.ReactNode;
|
||||
className?: string;
|
||||
type?: 'error' | 'info' | 'warning';
|
||||
};
|
||||
}
|
||||
|
||||
const Wrapper = styled.div`
|
||||
background: white;
|
||||
|
||||
@ -67,7 +67,7 @@ const transformToAccountId = (value: string): string | null => {
|
||||
: accountId;
|
||||
};
|
||||
|
||||
const createOption = (address: string) => {
|
||||
const createOption = (address: string): KeyringSectionOption => {
|
||||
let isRecent: boolean | undefined;
|
||||
const pair = keyring.getAccount(address);
|
||||
let name: string | undefined;
|
||||
@ -91,30 +91,30 @@ const createOption = (address: string) => {
|
||||
class InputAddress extends React.PureComponent<Props, State> {
|
||||
public state: State = {};
|
||||
|
||||
static getDerivedStateFromProps ({ value }: Props): State | null {
|
||||
public static getDerivedStateFromProps ({ value }: Props): Pick<State, never> | null {
|
||||
try {
|
||||
return {
|
||||
value: Array.isArray(value)
|
||||
? value.map(addressToAddress)
|
||||
: (addressToAddress(value) || undefined)
|
||||
|
||||
} as State;
|
||||
};
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static readOptions () {
|
||||
public static readOptions () {
|
||||
return store.get(STORAGE_KEY) || { defaults: {} };
|
||||
}
|
||||
|
||||
static getLastValue (type: KeyringOption$Type = DEFAULT_TYPE) {
|
||||
public static getLastValue (type: KeyringOption$Type = DEFAULT_TYPE) {
|
||||
const options = InputAddress.readOptions();
|
||||
|
||||
return options.defaults[type];
|
||||
}
|
||||
|
||||
static setLastValue (type: KeyringOption$Type = DEFAULT_TYPE, value: string) {
|
||||
public static setLastValue (type: KeyringOption$Type = DEFAULT_TYPE, value: string): void {
|
||||
const options = InputAddress.readOptions();
|
||||
|
||||
options.defaults[type] = value;
|
||||
@ -133,7 +133,7 @@ class InputAddress extends React.PureComponent<Props, State> {
|
||||
const lastValue = InputAddress.getLastValue(type);
|
||||
const lastOption = this.getLastOptionValue();
|
||||
const actualValue = transformToAddress(
|
||||
isDisabled || (defaultValue && this.hasValue(defaultValue))
|
||||
isDisabled || (defaultValue && this.hasValue(defaultValue))
|
||||
? defaultValue
|
||||
: (
|
||||
this.hasValue(lastValue)
|
||||
@ -141,13 +141,13 @@ class InputAddress extends React.PureComponent<Props, State> {
|
||||
: (lastOption && lastOption.value)
|
||||
)
|
||||
);
|
||||
const actualOptions = options
|
||||
? options
|
||||
: (
|
||||
isDisabled && actualValue
|
||||
? [createOption(actualValue)]
|
||||
: (optionsAll ? optionsAll[type] : [])
|
||||
);
|
||||
const actualOptions = options || (
|
||||
isDisabled && actualValue
|
||||
? [createOption(actualValue)]
|
||||
: optionsAll
|
||||
? optionsAll[type]
|
||||
: []
|
||||
);
|
||||
let _defaultValue;
|
||||
|
||||
if (value !== undefined) {
|
||||
@ -208,9 +208,7 @@ class InputAddress extends React.PureComponent<Props, State> {
|
||||
return;
|
||||
}
|
||||
|
||||
const available = optionsAll[type].filter(({ value }) =>
|
||||
!!value
|
||||
);
|
||||
const available = optionsAll[type].filter(({ value }): boolean => !!value);
|
||||
|
||||
return available.length
|
||||
? available[available.length - 1]
|
||||
@ -224,12 +222,10 @@ class InputAddress extends React.PureComponent<Props, State> {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !!optionsAll[type].find(({ value }) =>
|
||||
test === value
|
||||
);
|
||||
return !!optionsAll[type].find(({ value }): boolean => test === value);
|
||||
}
|
||||
|
||||
private onChange = (address: string) => {
|
||||
private onChange = (address: string): void => {
|
||||
const { onChange, type } = this.props;
|
||||
|
||||
InputAddress.setLastValue(type, address);
|
||||
@ -237,14 +233,14 @@ class InputAddress extends React.PureComponent<Props, State> {
|
||||
onChange && onChange(transformToAccountId(address));
|
||||
}
|
||||
|
||||
private onChangeMulti = (addresses: string[]) => {
|
||||
private onChangeMulti = (addresses: string[]): void => {
|
||||
const { onChangeMulti } = this.props;
|
||||
|
||||
if (onChangeMulti) {
|
||||
onChangeMulti(
|
||||
addresses
|
||||
.map(transformToAccountId)
|
||||
.filter((address) => address) as string[]
|
||||
.filter((address): string => address as string) as string[]
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -253,14 +249,14 @@ class InputAddress extends React.PureComponent<Props, State> {
|
||||
const { isInput = true } = this.props;
|
||||
const query = _query.trim();
|
||||
const queryLower = query.toLowerCase();
|
||||
const matches = filteredOptions.filter((item) =>
|
||||
const matches = filteredOptions.filter((item): boolean =>
|
||||
item.value !== null && (
|
||||
item.name.toLowerCase().indexOf(queryLower) !== -1 ||
|
||||
item.value.toLowerCase().indexOf(queryLower) !== -1
|
||||
)
|
||||
);
|
||||
|
||||
const valueMatches = matches.filter((item) =>
|
||||
const valueMatches = matches.filter((item): boolean =>
|
||||
item.value !== null
|
||||
);
|
||||
|
||||
@ -276,12 +272,12 @@ class InputAddress extends React.PureComponent<Props, State> {
|
||||
}
|
||||
}
|
||||
|
||||
return matches.filter((item, index) => {
|
||||
return matches.filter((item, index): boolean => {
|
||||
const isLast = index === matches.length - 1;
|
||||
const nextItem = matches[index + 1];
|
||||
const hasNext = nextItem && nextItem.value;
|
||||
|
||||
return item.value !== null || (!isLast && hasNext);
|
||||
return item.value !== null || (!isLast && !!hasNext);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,22 +9,22 @@ import React from 'react';
|
||||
import { BitLengthOption } from '@polkadot/ui-app/constants';
|
||||
import { InputNumber } from '@polkadot/ui-app';
|
||||
|
||||
type Props = BareProps & {
|
||||
autoFocus?: boolean,
|
||||
defaultValue?: BN | string,
|
||||
help?: React.ReactNode,
|
||||
isDisabled?: boolean,
|
||||
isError?: boolean,
|
||||
label?: any,
|
||||
maxValue?: BN,
|
||||
onChange?: (value?: BN) => void,
|
||||
onEnter?: () => void,
|
||||
placeholder?: string,
|
||||
value?: BN | string,
|
||||
withEllipsis?: boolean,
|
||||
withLabel?: boolean,
|
||||
withMax?: boolean
|
||||
};
|
||||
interface Props extends BareProps {
|
||||
autoFocus?: boolean;
|
||||
defaultValue?: BN | string;
|
||||
help?: React.ReactNode;
|
||||
isDisabled?: boolean;
|
||||
isError?: boolean;
|
||||
label?: any;
|
||||
maxValue?: BN;
|
||||
onChange?: (value?: BN) => void;
|
||||
onEnter?: () => void;
|
||||
placeholder?: string;
|
||||
value?: BN | string;
|
||||
withEllipsis?: boolean;
|
||||
withLabel?: boolean;
|
||||
withMax?: boolean;
|
||||
}
|
||||
|
||||
const DEFAULT_BITLENGTH = BitLengthOption.CHAIN_SPEC as BitLength;
|
||||
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
/* eslint-disable @typescript-eslint/camelcase */
|
||||
// Copyright 2017-2019 @polkadot/ui-app authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
@ -57,8 +58,9 @@ class InputBalanceBonded extends React.PureComponent<Props, State> {
|
||||
maxBalance: ZERO
|
||||
};
|
||||
}
|
||||
|
||||
public render (): React.ReactNode {
|
||||
const { autoFocus, className, defaultValue, help, isDisabled, isError, label, onChange, onEnter, placeholder,style, value, withEllipsis, withLabel, withMax } = this.props;
|
||||
const { autoFocus, className, defaultValue, help, isDisabled, isError, label, onChange, onEnter, placeholder, style, value, withEllipsis, withLabel, withMax } = this.props;
|
||||
const { maxBalance } = this.state;
|
||||
|
||||
return (
|
||||
@ -85,7 +87,7 @@ class InputBalanceBonded extends React.PureComponent<Props, State> {
|
||||
);
|
||||
}
|
||||
|
||||
componentDidUpdate (prevProps: Props, prevState: State) {
|
||||
public componentDidUpdate (prevProps: Props, prevState: State): void {
|
||||
const { balances_all, balances_fees, controllerId, destination } = this.props;
|
||||
const { extrinsic } = this.state;
|
||||
const hasLengthChanged = ((extrinsic && extrinsic.encodedLength) || 0) !== ((prevState.extrinsic && prevState.extrinsic.encodedLength) || 0);
|
||||
@ -100,7 +102,7 @@ class InputBalanceBonded extends React.PureComponent<Props, State> {
|
||||
}
|
||||
}
|
||||
|
||||
private setMaxBalance = () => {
|
||||
private setMaxBalance = (): void => {
|
||||
const { api, balances_fees = ZERO_FEES, balances_all = ZERO_BALANCE, controllerId, destination, extrinsicProp, system_accountNonce = ZERO } = this.props;
|
||||
const { transactionBaseFee, transactionByteFee } = balances_fees;
|
||||
const { freeBalance } = balances_all;
|
||||
@ -113,8 +115,8 @@ class InputBalanceBonded extends React.PureComponent<Props, State> {
|
||||
|
||||
if (extrinsicProp === 'staking.bond') {
|
||||
extrinsic = controllerId && (destination || destination === 0)
|
||||
? api.tx.staking.bond(controllerId, prevMax, destination)
|
||||
: null;
|
||||
? api.tx.staking.bond(controllerId, prevMax, destination)
|
||||
: null;
|
||||
} else if (extrinsicProp === 'staking.unbond') {
|
||||
extrinsic = api.tx.staking.unbond(prevMax);
|
||||
} else if (extrinsicProp === 'staking.bondExtra') {
|
||||
|
||||
@ -9,9 +9,9 @@ import Label from 'semantic-ui-react/dist/commonjs/elements/Label/Label';
|
||||
|
||||
import { classes } from './util';
|
||||
|
||||
type Props = BareProps & {
|
||||
label?: React.ReactNode
|
||||
};
|
||||
interface Props extends BareProps {
|
||||
label?: React.ReactNode;
|
||||
}
|
||||
|
||||
const defaultLabel: React.ReactNode = (
|
||||
<div> </div>
|
||||
|
||||
@ -12,13 +12,13 @@ import ApiPromise from '@polkadot/api/promise';
|
||||
import Dropdown from '../Dropdown';
|
||||
import { classes } from '../util';
|
||||
|
||||
type Props = BareProps & {
|
||||
api: ApiPromise,
|
||||
isError?: boolean,
|
||||
onChange: (value: MethodFunction) => void,
|
||||
options: DropdownOptions,
|
||||
value: MethodFunction
|
||||
};
|
||||
interface Props extends BareProps {
|
||||
api: ApiPromise;
|
||||
isError?: boolean;
|
||||
onChange: (value: MethodFunction) => void;
|
||||
options: DropdownOptions;
|
||||
value: MethodFunction;
|
||||
}
|
||||
|
||||
export default class SelectMethod extends React.PureComponent<Props> {
|
||||
public render (): React.ReactNode {
|
||||
|
||||
@ -11,13 +11,13 @@ import React from 'react';
|
||||
import Dropdown from '../Dropdown';
|
||||
import { classes } from '../util';
|
||||
|
||||
type Props = BareProps & {
|
||||
defaultValue?: string,
|
||||
isError?: boolean,
|
||||
onChange: (value: string) => void,
|
||||
options: DropdownOptions,
|
||||
value: MethodFunction
|
||||
};
|
||||
interface Props extends BareProps {
|
||||
defaultValue?: string;
|
||||
isError?: boolean;
|
||||
onChange: (value: string) => void;
|
||||
options: DropdownOptions;
|
||||
value: MethodFunction;
|
||||
}
|
||||
|
||||
export default class SelectSection extends React.PureComponent<Props> {
|
||||
public render (): React.ReactNode {
|
||||
|
||||
@ -47,11 +47,11 @@ class InputExtrinsic extends React.PureComponent<Props, State> {
|
||||
} as State;
|
||||
}
|
||||
|
||||
static getDerivedStateFromProps ({ api }: Props, { value }: State): State | null {
|
||||
public static getDerivedStateFromProps ({ api }: Props, { value }: State): Pick<State, never> {
|
||||
return {
|
||||
optionsMethod: methodOptions(api, value.section),
|
||||
optionsSection: sectionOptions(api)
|
||||
} as State;
|
||||
};
|
||||
}
|
||||
|
||||
public render (): React.ReactNode {
|
||||
@ -96,7 +96,7 @@ class InputExtrinsic extends React.PureComponent<Props, State> {
|
||||
return;
|
||||
}
|
||||
|
||||
this.setState({ value: newValue }, () =>
|
||||
this.setState({ value: newValue }, (): void =>
|
||||
onChange(newValue)
|
||||
);
|
||||
}
|
||||
@ -112,7 +112,7 @@ class InputExtrinsic extends React.PureComponent<Props, State> {
|
||||
const optionsMethod = methodOptions(api, newSection);
|
||||
const fn = api.tx[newSection][optionsMethod[0].value];
|
||||
|
||||
this.setState({ optionsMethod }, () =>
|
||||
this.setState({ optionsMethod }, (): void =>
|
||||
this.onKeyChange(fn)
|
||||
);
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { DropdownOptions } from '../../util/types';
|
||||
import { DropdownOption, DropdownOptions } from '../../util/types';
|
||||
|
||||
import React from 'react';
|
||||
import ApiPromise from '@polkadot/api/promise';
|
||||
@ -17,11 +17,11 @@ export default function createOptions (api: ApiPromise, sectionName: string): Dr
|
||||
return Object
|
||||
.keys(section)
|
||||
.sort()
|
||||
.map((value) => {
|
||||
.map((value): DropdownOption => {
|
||||
const method = section[value];
|
||||
const inputs = method.meta.args
|
||||
.filter((arg) => arg.type.toString() !== 'Origin')
|
||||
.map((arg) => arg.name.toString())
|
||||
.filter((arg): boolean => arg.type.toString() !== 'Origin')
|
||||
.map((arg): string => arg.name.toString())
|
||||
.join(', ');
|
||||
|
||||
return {
|
||||
|
||||
@ -10,8 +10,8 @@ export default function createOptions (api: ApiPromise): DropdownOptions {
|
||||
return Object
|
||||
.keys(api.tx)
|
||||
.sort()
|
||||
.filter((name) => Object.keys(api.tx[name]).length)
|
||||
.map((name) => ({
|
||||
.filter((name): number => Object.keys(api.tx[name]).length)
|
||||
.map((name): { text: string; value: string } => ({
|
||||
text: name,
|
||||
value: name
|
||||
}));
|
||||
|
||||
@ -42,12 +42,13 @@ interface LoadEvent {
|
||||
}
|
||||
|
||||
class InputFile extends React.PureComponent<Props, State> {
|
||||
dropZone: any;
|
||||
public state: State;
|
||||
private dropZone: any;
|
||||
|
||||
public state: State = {};
|
||||
|
||||
public constructor (props: Props) {
|
||||
super(props);
|
||||
this.state = {} as State;
|
||||
|
||||
this.dropZone = React.createRef();
|
||||
}
|
||||
|
||||
@ -88,22 +89,22 @@ class InputFile extends React.PureComponent<Props, State> {
|
||||
) : dropZone;
|
||||
}
|
||||
|
||||
private onDrop = (files: File[]) => {
|
||||
private onDrop = (files: File[]): void => {
|
||||
const { onChange } = this.props;
|
||||
|
||||
files.forEach((file) => {
|
||||
files.forEach((file): void => {
|
||||
const reader = new FileReader();
|
||||
|
||||
reader.onabort = () => {
|
||||
reader.onabort = (): void => {
|
||||
// ignore
|
||||
};
|
||||
|
||||
reader.onerror = () => {
|
||||
reader.onerror = (): void => {
|
||||
// ignore
|
||||
};
|
||||
|
||||
// @ts-ignore ummm... events are not properly specified here?
|
||||
reader.onload = ({ target: { result } }: LoadEvent) => {
|
||||
reader.onload = ({ target: { result } }: LoadEvent): void => {
|
||||
const data = new Uint8Array(result);
|
||||
const name = file.name;
|
||||
|
||||
|
||||
@ -39,7 +39,7 @@ type Props = BareProps & I18nProps & {
|
||||
interface State {
|
||||
isPreKeyDown: boolean;
|
||||
isValid: boolean;
|
||||
siOptions: { value: string, text: string }[];
|
||||
siOptions: { value: string; text: string }[];
|
||||
siUnit: string;
|
||||
value: string;
|
||||
valueBN: BN;
|
||||
@ -54,7 +54,7 @@ class InputNumber extends React.PureComponent<Props, State> {
|
||||
super(props);
|
||||
|
||||
const { defaultValue, isSi, value } = this.props;
|
||||
let valueBN = new BN(value || 0);
|
||||
const valueBN = new BN(value || 0);
|
||||
const si = formatBalance.findSi('-');
|
||||
|
||||
this.state = {
|
||||
@ -63,7 +63,7 @@ class InputNumber extends React.PureComponent<Props, State> {
|
||||
: (defaultValue || valueBN).toString(),
|
||||
isPreKeyDown: false,
|
||||
isValid: !isUndefined(value),
|
||||
siOptions: formatBalance.getOptions().map(({ power, text, value }) => ({
|
||||
siOptions: formatBalance.getOptions().map(({ power, text, value }): { text: string; value: string } => ({
|
||||
value,
|
||||
text: power === 0
|
||||
? InputNumber.units
|
||||
@ -74,12 +74,13 @@ class InputNumber extends React.PureComponent<Props, State> {
|
||||
};
|
||||
}
|
||||
|
||||
static units: string = 'Unit';
|
||||
static setUnit (units: string = InputNumber.units): void {
|
||||
public static units: string = 'Unit';
|
||||
|
||||
public static setUnit (units: string = InputNumber.units): void {
|
||||
InputNumber.units = units;
|
||||
}
|
||||
|
||||
static getDerivedStateFromProps ({ isDisabled, isSi, defaultValue = '0' }: Props): Partial<State> | null {
|
||||
public static getDerivedStateFromProps ({ isDisabled, isSi, defaultValue = '0' }: Props): Partial<State> | null {
|
||||
if (!isDisabled || !isSi) {
|
||||
return null;
|
||||
}
|
||||
@ -120,7 +121,7 @@ class InputNumber extends React.PureComponent<Props, State> {
|
||||
);
|
||||
}
|
||||
|
||||
private renderSiDropdown () {
|
||||
private renderSiDropdown (): React.ReactNode {
|
||||
const { siOptions, siUnit } = this.state;
|
||||
|
||||
return (
|
||||
@ -134,7 +135,7 @@ class InputNumber extends React.PureComponent<Props, State> {
|
||||
);
|
||||
}
|
||||
|
||||
private renderMaxButton () {
|
||||
private renderMaxButton (): React.ReactNode {
|
||||
const { valueBN } = this.state;
|
||||
const { maxValue } = this.props;
|
||||
|
||||
@ -179,9 +180,9 @@ class InputNumber extends React.PureComponent<Props, State> {
|
||||
private regex = (): RegExp => {
|
||||
const { isDecimal, isSi } = this.props;
|
||||
return new RegExp(
|
||||
(isSi || isDecimal) ?
|
||||
`^(0|[1-9]\\d*)(\\${KEYS.DECIMAL}\\d*)?$` :
|
||||
`^(0|[1-9]\\d*)$`
|
||||
(isSi || isDecimal)
|
||||
? `^(0|[1-9]\\d*)(\\${KEYS.DECIMAL}\\d*)?$`
|
||||
: `^(0|[1-9]\\d*)$`
|
||||
);
|
||||
}
|
||||
|
||||
@ -215,13 +216,7 @@ class InputNumber extends React.PureComponent<Props, State> {
|
||||
|
||||
if (event.key.length === 1 && !isPreKeyDown) {
|
||||
const { selectionStart: i, selectionEnd: j, value } = event.target as HTMLInputElement;
|
||||
const newValue = `${
|
||||
value.substring(0, i!)
|
||||
}${
|
||||
event.key
|
||||
}${
|
||||
value.substring(j!)
|
||||
}`;
|
||||
const newValue = `${value.substring(0, i || 0)}${event.key}${value.substring(j || 0)}`;
|
||||
|
||||
if (!this.regex().test(newValue)) {
|
||||
event.preventDefault();
|
||||
@ -240,12 +235,11 @@ class InputNumber extends React.PureComponent<Props, State> {
|
||||
|
||||
if (!this.regex().test(newValue)) {
|
||||
event.preventDefault();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private selectSiUnit = (siUnit: string): void => {
|
||||
this.setState((prevState: State) => {
|
||||
this.setState((prevState: State): Pick<State, never> => {
|
||||
const { bitLength, onChange } = this.props;
|
||||
const valueBN = this.inputValueToBn(prevState.value, siUnit);
|
||||
const isValid = this.isValidNumber(valueBN, bitLength);
|
||||
@ -264,13 +258,13 @@ class InputNumber extends React.PureComponent<Props, State> {
|
||||
});
|
||||
}
|
||||
|
||||
private setToMaxValue = () => {
|
||||
this.setState((prevState: State) => {
|
||||
private setToMaxValue = (): void => {
|
||||
this.setState((prevState: State): Pick<State, never> => {
|
||||
const { bitLength, maxValue, onChange } = this.props;
|
||||
const { siUnit = prevState.siUnit } = this.state;
|
||||
|
||||
if (!maxValue) {
|
||||
return {} as State;
|
||||
return {};
|
||||
}
|
||||
|
||||
const isValid = this.isValidNumber(maxValue, bitLength);
|
||||
@ -321,16 +315,17 @@ class InputNumber extends React.PureComponent<Props, State> {
|
||||
return `${
|
||||
div.gt(ZERO) ? div.toString() : '0'
|
||||
}${
|
||||
mod.gt(ZERO) ?
|
||||
(() => {
|
||||
mod.gt(ZERO)
|
||||
? ((): string => {
|
||||
const padding = Math.max(
|
||||
mod.toString().length,
|
||||
base.toString().length - div.toString().length,
|
||||
bn.toString().length - div.toString().length
|
||||
);
|
||||
|
||||
return `.${mod.toString(10, padding).replace(/0*$/, '')}`;
|
||||
})() :
|
||||
''
|
||||
})()
|
||||
: ''
|
||||
}`;
|
||||
}
|
||||
|
||||
|
||||
@ -13,12 +13,12 @@ import map from '@polkadot/jsonrpc';
|
||||
import Dropdown from '../Dropdown';
|
||||
import { classes } from '../util';
|
||||
|
||||
type Props = BareProps & {
|
||||
isError?: boolean,
|
||||
onChange: (value: RpcMethod) => void,
|
||||
options: DropdownOptions,
|
||||
value: RpcMethod
|
||||
};
|
||||
interface Props extends BareProps {
|
||||
isError?: boolean;
|
||||
onChange: (value: RpcMethod) => void;
|
||||
options: DropdownOptions;
|
||||
value: RpcMethod;
|
||||
}
|
||||
|
||||
export default class SelectMethod extends React.PureComponent<Props> {
|
||||
public render (): React.ReactNode {
|
||||
|
||||
@ -11,13 +11,13 @@ import React from 'react';
|
||||
import Dropdown from '../Dropdown';
|
||||
import { classes } from '../util';
|
||||
|
||||
type Props = BareProps & {
|
||||
defaultValue?: string,
|
||||
isError?: boolean,
|
||||
onChange: (value: string) => void,
|
||||
options: DropdownOptions,
|
||||
value: RpcMethod
|
||||
};
|
||||
interface Props extends BareProps {
|
||||
defaultValue?: string;
|
||||
isError?: boolean;
|
||||
onChange: (value: string) => void;
|
||||
options: DropdownOptions;
|
||||
value: RpcMethod;
|
||||
}
|
||||
|
||||
export default class SelectSection extends React.PureComponent<Props> {
|
||||
public render (): React.ReactNode {
|
||||
|
||||
@ -14,10 +14,10 @@ import Dropdown from '../Dropdown';
|
||||
import { classes } from '../util';
|
||||
|
||||
type Props = ApiProps & BareProps & {
|
||||
isError?: boolean,
|
||||
onChange: (value: StorageEntryPromise) => void,
|
||||
options: DropdownOptions,
|
||||
value: StorageEntryPromise
|
||||
isError?: boolean;
|
||||
onChange: (value: StorageEntryPromise) => void;
|
||||
options: DropdownOptions;
|
||||
value: StorageEntryPromise;
|
||||
};
|
||||
|
||||
class SelectKey extends React.PureComponent<Props> {
|
||||
|
||||
@ -11,13 +11,13 @@ import React from 'react';
|
||||
import Dropdown from '../Dropdown';
|
||||
import { classes } from '../util';
|
||||
|
||||
type Props = BareProps & {
|
||||
defaultValue?: StorageEntryPromise,
|
||||
isError?: boolean,
|
||||
onChange: (value: string) => void,
|
||||
options: DropdownOptions,
|
||||
value: StorageEntryPromise
|
||||
};
|
||||
interface Props extends BareProps {
|
||||
defaultValue?: StorageEntryPromise;
|
||||
isError?: boolean;
|
||||
onChange: (value: string) => void;
|
||||
options: DropdownOptions;
|
||||
value: StorageEntryPromise;
|
||||
}
|
||||
|
||||
export default class SelectSection extends React.PureComponent<Props> {
|
||||
public render (): React.ReactNode {
|
||||
|
||||
@ -48,7 +48,7 @@ const tags = loadTags();
|
||||
|
||||
export default class InputTags extends React.PureComponent<Props> {
|
||||
public state: State = {
|
||||
options: tags.map((value) => ({
|
||||
options: tags.map((value): { key: string; text: string; value: string } => ({
|
||||
key: value, text: value, value
|
||||
}))
|
||||
};
|
||||
@ -84,7 +84,7 @@ export default class InputTags extends React.PureComponent<Props> {
|
||||
tags.push(value);
|
||||
saveTags(tags);
|
||||
|
||||
this.setState(({ options }: State) => ({
|
||||
this.setState(({ options }: State): Pick<State, never> => ({
|
||||
options: [...options, { key: value, text: value, value }]
|
||||
}));
|
||||
}
|
||||
|
||||
@ -10,19 +10,19 @@ import styled from 'styled-components';
|
||||
import Icon from './Icon';
|
||||
import { classes } from './util';
|
||||
|
||||
export type InsetProps = RouteComponentProps & {
|
||||
className?: string,
|
||||
children?: React.ReactNode
|
||||
isCollapsible?: boolean,
|
||||
header?: React.ReactNode,
|
||||
href?: string | null,
|
||||
withTopMargin?: boolean,
|
||||
withBottomMargin?: boolean
|
||||
};
|
||||
export interface InsetProps extends RouteComponentProps {
|
||||
className?: string;
|
||||
children?: React.ReactNode;
|
||||
isCollapsible?: boolean;
|
||||
header?: React.ReactNode;
|
||||
href?: string | null;
|
||||
withTopMargin?: boolean;
|
||||
withBottomMargin?: boolean;
|
||||
}
|
||||
|
||||
type State = {
|
||||
isCollapsed: boolean
|
||||
};
|
||||
interface State {
|
||||
isCollapsed: boolean;
|
||||
}
|
||||
|
||||
class Inset extends React.PureComponent<InsetProps, State> {
|
||||
public state: State = {
|
||||
@ -72,14 +72,14 @@ class Inset extends React.PureComponent<InsetProps, State> {
|
||||
);
|
||||
}
|
||||
|
||||
private onClick = () => {
|
||||
private onClick = (): void => {
|
||||
const { history, href } = this.props;
|
||||
|
||||
history.push(href!);
|
||||
href && history.push(href);
|
||||
}
|
||||
|
||||
private toggleCollapsed = () => {
|
||||
this.setState(({ isCollapsed }: State) => {
|
||||
private toggleCollapsed = (): void => {
|
||||
this.setState(({ isCollapsed }: State): Pick<State, never> => {
|
||||
return {
|
||||
isCollapsed: !isCollapsed
|
||||
};
|
||||
|
||||
@ -8,11 +8,11 @@ import React from 'react';
|
||||
|
||||
import LabelHelp from './LabelHelp';
|
||||
|
||||
type Props = BareProps & {
|
||||
help?: React.ReactNode,
|
||||
label?: React.ReactNode,
|
||||
withEllipsis?: boolean
|
||||
};
|
||||
interface Props extends BareProps {
|
||||
help?: React.ReactNode;
|
||||
label?: React.ReactNode;
|
||||
withEllipsis?: boolean;
|
||||
}
|
||||
|
||||
export default class Label extends React.PureComponent<Props> {
|
||||
public render (): React.ReactNode {
|
||||
|
||||
@ -11,13 +11,13 @@ import Icon from './Icon';
|
||||
import { classes } from './util';
|
||||
import Tooltip from './Tooltip';
|
||||
|
||||
type Props = BareProps & {
|
||||
help: React.ReactNode
|
||||
};
|
||||
interface Props extends BareProps {
|
||||
help: React.ReactNode;
|
||||
}
|
||||
|
||||
type State = {
|
||||
tooltipOpen: boolean
|
||||
};
|
||||
interface State {
|
||||
tooltipOpen: boolean;
|
||||
}
|
||||
|
||||
const Wrapper = styled.div`
|
||||
cursor: help;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user