Adjust base library usage of for vs reduce/map (#1151)

* Adjust base library usage of `for` vs `reduce/map`

* Additional

* Adjust
This commit is contained in:
Jaco
2021-10-31 08:27:14 +02:00
committed by GitHub
parent 7ef169585f
commit a4cefa4bfc
20 changed files with 130 additions and 87 deletions
+1 -5
View File
@@ -262,11 +262,7 @@ export class Keyring implements KeyringInstance {
* @description Returns an array list of all the public keys associated with each of the keyring pair values that are stored in the keyring pair dictionary.
*/
public getPublicKeys (): Uint8Array[] {
return this.#pairs
.all()
.map(({ publicKey }): Uint8Array =>
publicKey
);
return this.#pairs.all().map(({ publicKey }) => publicKey);
}
/**
+2 -2
View File
@@ -121,7 +121,7 @@ export function createTestKeyring (options: KeyringOptions = {}, isDerived = tru
const keyring = new Keyring(options);
const pairs: PairDef[] = (options.type && options.type === 'ethereum') ? PAIRSETHEREUM : PAIRSSR25519;
pairs.forEach(({ name, publicKey, secretKey, seed, type }): void => {
for (const { name, publicKey, secretKey, seed, type } of pairs) {
if (!name && !seed) {
throw new Error('Testing pair should have either a name or a seed');
}
@@ -139,7 +139,7 @@ export function createTestKeyring (options: KeyringOptions = {}, isDerived = tru
pair.lock = (): void => {
// we don't have lock/unlock functionality here
};
});
}
return keyring;
}
+4 -6
View File
@@ -15,11 +15,9 @@ export function createTestPairs (options?: KeyringOptions, isDerived = true): Te
const pairs = keyring.getPairs();
const map: TestKeyringMap = { nobody: nobody() };
return pairs.reduce((result, pair): TestKeyringMap => {
const { name } = pair.meta;
for (const p of pairs) {
map[p.meta.name as string] = p;
}
result[name as string] = pair;
return result;
}, map);
return map;
}