Optional pair type (account-only) (#409)

This commit is contained in:
Jaco Greeff
2020-12-02 18:36:28 +01:00
committed by GitHub
parent 9c72628a39
commit ce79a80a18
3 changed files with 12 additions and 8 deletions
+5 -5
View File
@@ -95,7 +95,7 @@ export class Keyring extends Base implements KeyringStruct {
json.meta.whenEdited = Date.now();
this.keyring.addFromJson(json);
this.accounts.add(this._store, pair.address, json);
this.accounts.add(this._store, pair.address, json, pair.type);
}
public forgetAccount (address: string): void {
@@ -180,7 +180,7 @@ export class Keyring extends Base implements KeyringStruct {
// FIXME Just for the transition period (ignoreChecksum)
const pair = this.keyring.addFromJson(json as KeyringPair$Json, true);
this.accounts.add(this._store, pair.address, json);
this.accounts.add(this._store, pair.address, json, pair.type);
}
const [, hexAddr] = key.split(':');
@@ -237,7 +237,7 @@ export class Keyring extends Base implements KeyringStruct {
};
const pair = this.keyring.addFromAddress(address, json.meta);
this.accounts.add(this._store, pair.address, json);
this.accounts.add(this._store, pair.address, json, pair.type);
}
private allowGenesis (json?: KeyringJson | { meta: KeyringJson$Meta } | null): boolean {
@@ -315,7 +315,7 @@ export class Keyring extends Base implements KeyringStruct {
const json = pair.toJson(password);
this.keyring.addFromJson(json);
this.accounts.add(this._store, pair.address, json);
this.accounts.add(this._store, pair.address, json, pair.type);
return json;
}
@@ -327,7 +327,7 @@ export class Keyring extends Base implements KeyringStruct {
pair.setMeta(meta);
json.meta = pair.meta;
this.accounts.add(this._store, address, json);
this.accounts.add(this._store, address, json, pair.type);
});
}
@@ -1,6 +1,7 @@
// Copyright 2017-2020 @polkadot/ui-keyring authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { KeypairType } from '@polkadot/util-crypto/types';
import type { SubjectInfo, AddressSubject, SingleAddress } from './types';
import type { KeyringJson, KeyringStore } from '../types';
@@ -32,12 +33,13 @@ export default function genericSubject (keyCreator: (address: string) => string,
development.subject.subscribe(next);
return {
add: (store: KeyringStore, address: string, json: KeyringJson): SingleAddress => {
add: (store: KeyringStore, address: string, json: KeyringJson, type?: KeypairType): SingleAddress => {
current = { ...current };
current[address] = {
json: { ...json, address },
option: createOptionItem(address, json.meta.name)
option: createOptionItem(address, json.meta.name),
type
};
// we do not store dev accounts, injected or hardware (the latter two are external/transient)
+3 -1
View File
@@ -2,12 +2,14 @@
// SPDX-License-Identifier: Apache-2.0
import type { BehaviorSubject } from 'rxjs';
import type { KeypairType } from '@polkadot/util-crypto/types';
import type { KeyringSectionOption } from '../options/types';
import type { KeyringJson, KeyringStore } from '../types';
export interface SingleAddress {
json: KeyringJson;
option: KeyringSectionOption;
type?: KeypairType;
}
export interface SubjectInfo {
@@ -15,7 +17,7 @@ export interface SubjectInfo {
}
export interface AddressSubject {
add: (store: KeyringStore, address: string, json: KeyringJson) => SingleAddress;
add: (store: KeyringStore, address: string, json: KeyringJson, type?: KeypairType) => SingleAddress;
remove: (store: KeyringStore, address: string) => void;
subject: BehaviorSubject<SubjectInfo>;
}