Pass KeyringStore to observables (#128)

This commit is contained in:
Jaco Greeff
2019-05-18 19:58:45 +02:00
committed by GitHub
parent 2b6e118736
commit 1b4ea9d2bf
6 changed files with 19 additions and 20 deletions
+1 -1
View File
@@ -17,7 +17,7 @@
}, },
"devDependencies": { "devDependencies": {
"@polkadot/keyring": "^0.91.0-beta.1", "@polkadot/keyring": "^0.91.0-beta.1",
"@polkadot/types": "^0.79.0-beta.6", "@polkadot/types": "^0.79.0-beta.31",
"@polkadot/util": "^0.91.0-beta.1" "@polkadot/util": "^0.91.0-beta.1"
}, },
"peerDependencies": { "peerDependencies": {
+1 -1
View File
@@ -105,7 +105,7 @@ export default class Base {
.forEach((pair: KeyringPair) => { .forEach((pair: KeyringPair) => {
const address = pair.address(); const address = pair.address();
this.accounts.add(address, { this.accounts.add(this._store, address, {
address, address,
meta: pair.getMeta() meta: pair.getMeta()
}); });
+9 -9
View File
@@ -89,16 +89,16 @@ export class Keyring extends Base implements KeyringStruct {
json.meta.whenEdited = Date.now(); json.meta.whenEdited = Date.now();
this.keyring.addFromJson(json); this.keyring.addFromJson(json);
this.accounts.add(json.address, json); this.accounts.add(this._store, json.address, json);
} }
forgetAccount (address: string): void { forgetAccount (address: string): void {
this.keyring.removePair(address); this.keyring.removePair(address);
this.accounts.remove(address); this.accounts.remove(this._store, address);
} }
forgetAddress (address: string): void { forgetAddress (address: string): void {
this.addresses.remove(address); this.addresses.remove(this._store, address);
} }
getAccount (address: string | Uint8Array): KeyringAddress { getAccount (address: string | Uint8Array): KeyringAddress {
@@ -157,7 +157,7 @@ export class Keyring extends Base implements KeyringStruct {
// FIXME Just for the transition period (ignoreChecksum) // FIXME Just for the transition period (ignoreChecksum)
const pair = this.keyring.addFromJson(json as KeyringPair$Json, true); const pair = this.keyring.addFromJson(json as KeyringPair$Json, true);
this.accounts.add(pair.address(), json); this.accounts.add(this._store, pair.address(), json);
} }
const [, hexAddr] = key.split(':'); const [, hexAddr] = key.split(':');
@@ -181,7 +181,7 @@ export class Keyring extends Base implements KeyringStruct {
); );
const [, hexAddr] = key.split(':'); const [, hexAddr] = key.split(':');
this.addresses.add(address, json); this.addresses.add(this._store, address, json);
this.rewriteKey(json, key, hexAddr, addressKey); this.rewriteKey(json, key, hexAddr, addressKey);
} }
@@ -225,7 +225,7 @@ export class Keyring extends Base implements KeyringStruct {
const json = pair.toJson(password); const json = pair.toJson(password);
this.keyring.addFromJson(json); this.keyring.addFromJson(json);
this.accounts.add(json.address, json); this.accounts.add(this._store, json.address, json);
return json; return json;
} }
@@ -237,7 +237,7 @@ export class Keyring extends Base implements KeyringStruct {
pair.setMeta(meta); pair.setMeta(meta);
json.meta = pair.getMeta(); json.meta = pair.getMeta();
this.accounts.add(json.address, json); this.accounts.add(this._store, json.address, json);
}); });
} }
@@ -258,7 +258,7 @@ export class Keyring extends Base implements KeyringStruct {
delete json.meta.isRecent; delete json.meta.isRecent;
this.addresses.add(address, json); this.addresses.add(this._store, address, json);
return json as KeyringPair$Json; return json as KeyringPair$Json;
} }
@@ -275,7 +275,7 @@ export class Keyring extends Base implements KeyringStruct {
} }
}; };
this.addresses.add(address, (json as KeyringJson)); this.addresses.add(this._store, address, (json as KeyringJson));
} }
return this.addresses.subject.getValue()[address]; return this.addresses.subject.getValue()[address];
@@ -2,11 +2,10 @@
// This software may be modified and distributed under the terms // This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details. // of the Apache-2.0 license. See the LICENSE file for details.
import { BehaviorSubject } from 'rxjs';
import { SubjectInfo, AddressSubject, SingleAddress } from './types'; import { SubjectInfo, AddressSubject, SingleAddress } from './types';
import { KeyringJson } from '../types'; import { KeyringJson, KeyringStore } from '../types';
import store from 'store'; import { BehaviorSubject } from 'rxjs';
import createOptionItem from '../options/item'; import createOptionItem from '../options/item';
import development from './development'; import development from './development';
@@ -36,7 +35,7 @@ export default function genericSubject (keyCreator: (address: string) => string,
development.subject.subscribe(next); development.subject.subscribe(next);
return { return {
add: (address: string, json: KeyringJson): SingleAddress => { add: (store: KeyringStore, address: string, json: KeyringJson): SingleAddress => {
current = { ...current }; current = { ...current };
current[address] = { current[address] = {
@@ -49,7 +48,7 @@ export default function genericSubject (keyCreator: (address: string) => string,
return current[address]; return current[address];
}, },
remove: (address: string) => { remove: (store: KeyringStore, address: string) => {
current = { ...current }; current = { ...current };
delete current[address]; delete current[address];
+3 -3
View File
@@ -4,7 +4,7 @@
import { BehaviorSubject } from 'rxjs'; import { BehaviorSubject } from 'rxjs';
import { KeyringSectionOption } from '../options/types'; import { KeyringSectionOption } from '../options/types';
import { KeyringJson } from '../types'; import { KeyringJson, KeyringStore } from '../types';
export type SingleAddress = { export type SingleAddress = {
json: KeyringJson, json: KeyringJson,
@@ -16,7 +16,7 @@ export type SubjectInfo = {
}; };
export type AddressSubject = { export type AddressSubject = {
add: (address: string, json: KeyringJson) => SingleAddress, add: (store: KeyringStore, address: string, json: KeyringJson) => SingleAddress,
remove: (address: string) => void, remove: (store: KeyringStore, address: string) => void,
subject: BehaviorSubject<SubjectInfo> subject: BehaviorSubject<SubjectInfo>
}; };
+1 -1
View File
@@ -1854,7 +1854,7 @@
resolved "https://registry.yarnpkg.com/@polkadot/ts/-/ts-0.1.56.tgz#ffd6e9c95704a7fb90b918193b9dc5c440114b27" resolved "https://registry.yarnpkg.com/@polkadot/ts/-/ts-0.1.56.tgz#ffd6e9c95704a7fb90b918193b9dc5c440114b27"
integrity sha512-wnt4zXxZXyz6WaubTO/I+nUElwV2DogFzdl6CrKfVn2PTWp8uHN06W9s40FH57ORtmQfDr9rLRP8Nq+oIyElbg== integrity sha512-wnt4zXxZXyz6WaubTO/I+nUElwV2DogFzdl6CrKfVn2PTWp8uHN06W9s40FH57ORtmQfDr9rLRP8Nq+oIyElbg==
"@polkadot/types@^0.79.0-beta.31", "@polkadot/types@^0.79.0-beta.6": "@polkadot/types@^0.79.0-beta.31":
version "0.79.0-beta.31" version "0.79.0-beta.31"
resolved "https://registry.yarnpkg.com/@polkadot/types/-/types-0.79.0-beta.31.tgz#3e66dec097653a17386f687a70a86bc2520894ea" resolved "https://registry.yarnpkg.com/@polkadot/types/-/types-0.79.0-beta.31.tgz#3e66dec097653a17386f687a70a86bc2520894ea"
integrity sha512-ibVRBIirFCUYSQsMFBLSNGl0hp86tWM2RXnx3MDT5WiX4qGUOEy5aKTFU+hCDC8NhHa5+oNw8EeIDZ3waRI/4g== integrity sha512-ibVRBIirFCUYSQsMFBLSNGl0hp86tWM2RXnx3MDT5WiX4qGUOEy5aKTFU+hCDC8NhHa5+oNw8EeIDZ3waRI/4g==