Cleanup Codeclimate smells (#11)

* Cleanup Codeclimate smells

* Add Codeclimate badges
This commit is contained in:
Jaco Greeff
2018-12-08 16:37:05 +01:00
committed by GitHub
parent 9aaea82544
commit 91db30af82
11 changed files with 134 additions and 140 deletions
+2 -2
View File
@@ -11,8 +11,8 @@
"license": "Apache-2.0",
"dependencies": {
"@babel/runtime": "^7.1.5",
"@polkadot/keyring": "^0.33.9",
"@polkadot/types": "^0.33.5",
"@polkadot/keyring": "^0.33.11",
"@polkadot/types": "^0.33.6",
"store": "^2.0.12"
}
}
+6 -14
View File
@@ -4,7 +4,7 @@
import { Prefix } from '@polkadot/keyring/address/types';
import { KeyringInstance as BaseKeyringInstance, KeyringPair, KeyringPair$Meta, KeyringPair$Json } from '@polkadot/keyring/types';
import { AccountSubject, AddressSubject, SingleAddress } from './observable/types';
import { AddressSubject, SingleAddress } from './observable/types';
import { KeyringAddress, KeyringJson, KeyringJson$Meta, KeyringStruct } from './types';
import store from 'store';
@@ -22,7 +22,7 @@ import keyringOption from './options';
// Chain determination occurs outside of Keyring. Loading `keyring.loadAll()` is triggered
// from the API after the chain is received
class Keyring implements KeyringStruct {
private _accounts: AccountSubject;
private _accounts: AddressSubject;
private _addresses: AddressSubject;
private _keyring?: BaseKeyringInstance;
private _prefix: Prefix;
@@ -81,9 +81,7 @@ class Keyring implements KeyringStruct {
private addTimestamp (pair: KeyringPair): void {
if (!pair.getMeta().whenCreated) {
pair.setMeta({
whenCreated: Date.now()
});
pair.setMeta({ whenCreated: Date.now() });
}
}
@@ -147,12 +145,8 @@ class Keyring implements KeyringStruct {
return Object
.keys(available)
.map((address) =>
this.getAddress(address, 'account')
)
.filter((account) =>
env.isDevelopment() || account.getMeta().isTesting !== true
);
.map((address) => this.getAddress(address, 'account'))
.filter((account) => env.isDevelopment() || account.getMeta().isTesting !== true);
}
getAddress (_address: string | Uint8Array, type: 'account' | 'address' = 'address'): KeyringAddress {
@@ -181,9 +175,7 @@ class Keyring implements KeyringStruct {
return Object
.keys(available)
.map((address) =>
this.getAddress(address)
);
.map((address) => this.getAddress(address));
}
getPair (address: string | Uint8Array): KeyringPair {
@@ -11,26 +11,27 @@ import store from 'store';
import createOptionItem from '../options/item';
import development from './development';
function callNext (current: SubjectInfo, subject: BehaviorSubject<any>, withTest: boolean) {
const isDevMode = development.isDevelopment();
subject.next(
Object.keys(current).reduce((filtered, key) => {
const { json: { meta: { isTesting = false } = {} } = {} } = current[key];
if (!withTest || isDevMode || isTesting !== true) {
filtered[key] = current[key];
}
return filtered;
}, {} as SubjectInfo)
);
}
export default function genericSubject (keyCreator: (address: string) => string, withTest: boolean = false): AddressSubject {
let current: SubjectInfo = {};
const subject = new BehaviorSubject({});
const next = (): void => {
const isDevMode = development.isDevelopment();
subject.next(
Object
.keys(current)
.reduce((filtered, key) => {
const { json: { meta: { isTesting = false } = {} } = {} } = current[key];
if (!withTest || isDevMode || isTesting !== true) {
filtered[key] = current[key];
}
return filtered;
}, {} as SubjectInfo)
);
};
const next = (): void =>
callNext(current, subject, withTest);
development.subject.subscribe(next);
@@ -6,11 +6,6 @@ import { BehaviorSubject } from 'rxjs';
import { KeyringSectionOption } from '../options/types';
import { KeyringJson } from '../types';
export type SingleAccount = {
json: KeyringJson,
option: KeyringSectionOption
};
export type SingleAddress = {
json: KeyringJson,
option: KeyringSectionOption
@@ -20,12 +15,6 @@ export type SubjectInfo = {
[index: string]: SingleAddress
};
export type AccountSubject = {
add: (account: string, json: KeyringJson) => SingleAccount,
remove: (account: string) => void,
subject: BehaviorSubject<SubjectInfo>
};
export type AddressSubject = {
add: (address: string, json: KeyringJson) => SingleAddress,
remove: (address: string) => void,
+2 -3
View File
@@ -7,6 +7,7 @@ import { SingleAddress } from '../observable/types';
import { KeyringOptions, KeyringOptionInstance, KeyringSectionOption, KeyringSectionOptions } from './types';
import { BehaviorSubject } from 'rxjs';
import { assert } from '@polkadot/util';
import observableAll from '../observable';
@@ -26,9 +27,7 @@ class KeyringOption implements KeyringOptionInstance {
}
init (keyring: KeyringStruct): void {
if (hasCalledInitOptions) {
throw new Error('Unable to initialise options more than once');
}
assert(!hasCalledInitOptions, 'Unable to initialise options more than once');
observableAll.subscribe((value) => {
const options = this.emptyOptions();
+2 -2
View File
@@ -3,7 +3,7 @@
// of the Apache-2.0 license. See the LICENSE file for details.
import { KeyringInstance as BaseKeyringInstance, KeyringPair, KeyringPair$Meta, KeyringPair$Json } from '@polkadot/keyring/types';
import { AccountSubject, AddressSubject, SingleAddress } from './observable/types';
import { AddressSubject, SingleAddress } from './observable/types';
export type KeyringJson$Meta = {
isRecent?: boolean,
@@ -28,7 +28,7 @@ export type KeyringAddress = {
};
export interface KeyringStruct {
readonly accounts: AccountSubject;
readonly accounts: AddressSubject;
readonly addresses: AddressSubject;
readonly keyring: BaseKeyringInstance | undefined;