mirror of
https://github.com/pezkuwichain/pezkuwi-ui.git
synced 2026-06-13 13:21:03 +00:00
Swap to eslint (#154)
* 311 problems (173 errors, 138 warnings) * Make a start... * swap to react config * Literally a handful left * Clean. * any removal * Use Record * Adjust versions * Update with latest eslint-standard ruleset * Update defaults.ts
This commit is contained in:
@@ -6,15 +6,13 @@ import React from 'react';
|
||||
import styled from 'styled-components';
|
||||
import IdentityIcon from '@polkadot/ui-identicon';
|
||||
|
||||
type Props = {
|
||||
address: string,
|
||||
className?: string,
|
||||
isUppercase: boolean,
|
||||
name: string,
|
||||
style?: {
|
||||
[index: string]: string
|
||||
}
|
||||
};
|
||||
interface Props {
|
||||
address: string;
|
||||
className?: string;
|
||||
isUppercase: boolean;
|
||||
name: string;
|
||||
style?: Record<string, string>;
|
||||
}
|
||||
|
||||
const Wrapper = styled.div`
|
||||
display: flex;
|
||||
@@ -54,7 +52,7 @@ const Wrapper = styled.div`
|
||||
`;
|
||||
|
||||
export default class KeyPair extends React.PureComponent<Props> {
|
||||
render () {
|
||||
public render (): React.ReactNode {
|
||||
const { address, className, isUppercase, name, style } = this.props;
|
||||
|
||||
return (
|
||||
|
||||
@@ -2,17 +2,19 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { KeyringStruct } from '../types';
|
||||
import keyringOptionInstance from '.';
|
||||
|
||||
describe('KeyringOption', () => {
|
||||
it('should not allow initOptions to be called more than once', () => {
|
||||
const state = {};
|
||||
describe('KeyringOption', (): void => {
|
||||
it('should not allow initOptions to be called more than once', (): void => {
|
||||
const state: Partial<KeyringStruct> = {};
|
||||
|
||||
// first call
|
||||
keyringOptionInstance.init(state as any);
|
||||
keyringOptionInstance.init(state as KeyringStruct);
|
||||
|
||||
// second call
|
||||
expect(() => {
|
||||
keyringOptionInstance.init(state as any);
|
||||
expect((): void => {
|
||||
keyringOptionInstance.init(state as KeyringStruct);
|
||||
}).toThrowError('Unable to initialise options more than once');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -13,14 +13,14 @@ import observableAll from '../observable';
|
||||
|
||||
let hasCalledInitOptions = false;
|
||||
|
||||
const sortByName = (a: SingleAddress, b: SingleAddress) => {
|
||||
const sortByName = (a: SingleAddress, b: SingleAddress): number => {
|
||||
const valueA = a.option.name;
|
||||
const valueB = b.option.name;
|
||||
|
||||
return valueA.localeCompare(valueB);
|
||||
};
|
||||
|
||||
const sortByCreated = (a: SingleAddress, b: SingleAddress) => {
|
||||
const sortByCreated = (a: SingleAddress, b: SingleAddress): number => {
|
||||
const valueA = a.json.meta.whenCreated || 0;
|
||||
const valueB = b.json.meta.whenCreated || 0;
|
||||
|
||||
@@ -36,9 +36,9 @@ const sortByCreated = (a: SingleAddress, b: SingleAddress) => {
|
||||
};
|
||||
|
||||
class KeyringOption implements KeyringOptionInstance {
|
||||
optionsSubject: BehaviorSubject<KeyringOptions> = new BehaviorSubject(this.emptyOptions());
|
||||
public readonly optionsSubject: BehaviorSubject<KeyringOptions> = new BehaviorSubject(this.emptyOptions());
|
||||
|
||||
createOptionHeader (name: string): KeyringSectionOption {
|
||||
public createOptionHeader (name: string): KeyringSectionOption {
|
||||
return {
|
||||
className: 'header disabled',
|
||||
name,
|
||||
@@ -48,10 +48,10 @@ class KeyringOption implements KeyringOptionInstance {
|
||||
};
|
||||
}
|
||||
|
||||
init (keyring: KeyringStruct): void {
|
||||
public init (keyring: KeyringStruct): void {
|
||||
assert(!hasCalledInitOptions, 'Unable to initialise options more than once');
|
||||
|
||||
observableAll.subscribe(() => {
|
||||
observableAll.subscribe((): void => {
|
||||
const options = this.emptyOptions();
|
||||
|
||||
this.addAccounts(keyring, options);
|
||||
@@ -59,15 +59,15 @@ class KeyringOption implements KeyringOptionInstance {
|
||||
this.addContracts(keyring, options);
|
||||
|
||||
options.address = this.linkItems({
|
||||
'Addresses': options.address,
|
||||
'Recent': options.recent
|
||||
Addresses: options.address,
|
||||
Recent: options.recent
|
||||
});
|
||||
options.account = this.linkItems({
|
||||
'Accounts': options.account,
|
||||
'Development': options.testing
|
||||
Accounts: options.account,
|
||||
Development: options.testing
|
||||
});
|
||||
options.contract = this.linkItems({
|
||||
'Contracts': options.contract
|
||||
Contracts: options.contract
|
||||
});
|
||||
|
||||
options.all = ([] as KeyringSectionOptions).concat(
|
||||
@@ -87,8 +87,8 @@ class KeyringOption implements KeyringOptionInstance {
|
||||
hasCalledInitOptions = true;
|
||||
}
|
||||
|
||||
private linkItems (items: { [index: string]: KeyringSectionOptions }) {
|
||||
return Object.keys(items).reduce((result, header) => {
|
||||
private linkItems (items: { [index: string]: KeyringSectionOptions }): KeyringSectionOptions {
|
||||
return Object.keys(items).reduce((result, header): KeyringSectionOptions => {
|
||||
const options = items[header];
|
||||
|
||||
return result.concat(
|
||||
@@ -106,7 +106,7 @@ class KeyringOption implements KeyringOptionInstance {
|
||||
Object
|
||||
.values(available)
|
||||
.sort(sortByName)
|
||||
.forEach(({ json: { meta: { isTesting = false } }, option }: SingleAddress) => {
|
||||
.forEach(({ json: { meta: { isTesting = false } }, option }: SingleAddress): void => {
|
||||
if (!isTesting) {
|
||||
options.account.push(option);
|
||||
} else {
|
||||
@@ -120,21 +120,17 @@ class KeyringOption implements KeyringOptionInstance {
|
||||
|
||||
Object
|
||||
.values(available)
|
||||
.filter(({ json }: SingleAddress) => {
|
||||
return json.meta.isRecent;
|
||||
})
|
||||
.filter(({ json }: SingleAddress): boolean => !!json.meta.isRecent)
|
||||
.sort(sortByCreated)
|
||||
.forEach(({ option }: SingleAddress) => {
|
||||
.forEach(({ option }: SingleAddress): void => {
|
||||
options.recent.push(option);
|
||||
});
|
||||
|
||||
Object
|
||||
.values(available)
|
||||
.filter(({ json }: SingleAddress) => {
|
||||
return !json.meta.isRecent;
|
||||
})
|
||||
.filter(({ json }: SingleAddress): boolean => !json.meta.isRecent)
|
||||
.sort(sortByName)
|
||||
.forEach(({ option }: SingleAddress) => {
|
||||
.forEach(({ option }: SingleAddress): void => {
|
||||
options.address.push(option);
|
||||
});
|
||||
}
|
||||
@@ -145,7 +141,7 @@ class KeyringOption implements KeyringOptionInstance {
|
||||
Object
|
||||
.values(available)
|
||||
.sort(sortByName)
|
||||
.forEach(({ option }: SingleAddress) => {
|
||||
.forEach(({ option }: SingleAddress): void => {
|
||||
options.contract.push(option);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -4,17 +4,19 @@
|
||||
|
||||
import { KeyringItemType, KeyringStruct } from '../types';
|
||||
|
||||
export type KeyringSectionOption = {
|
||||
className?: string,
|
||||
disabled?: boolean,
|
||||
content?: any | string, // node?
|
||||
key: string | null,
|
||||
name: string,
|
||||
text: any | string, // node?
|
||||
value: string | null
|
||||
};
|
||||
import React from 'react';
|
||||
|
||||
export type KeyringSectionOptions = Array<KeyringSectionOption>;
|
||||
export interface KeyringSectionOption {
|
||||
className?: string;
|
||||
disabled?: boolean;
|
||||
content?: React.ReactNode;
|
||||
key: string | null;
|
||||
name: string;
|
||||
text: React.ReactNode;
|
||||
value: string | null;
|
||||
}
|
||||
|
||||
export type KeyringSectionOptions = KeyringSectionOption[];
|
||||
|
||||
export type KeyringOptions = {
|
||||
[type in KeyringItemType | 'all' | 'allPlus' | 'recent' | 'testing']: KeyringSectionOptions
|
||||
|
||||
Reference in New Issue
Block a user