From ce79a80a188e5f55e7cf77cee5f08e01248b374c Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Wed, 2 Dec 2020 18:36:28 +0100 Subject: [PATCH] Optional pair type (account-only) (#409) --- packages/ui-keyring/src/Keyring.ts | 10 +++++----- packages/ui-keyring/src/observable/genericSubject.ts | 6 ++++-- packages/ui-keyring/src/observable/types.ts | 4 +++- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/packages/ui-keyring/src/Keyring.ts b/packages/ui-keyring/src/Keyring.ts index ad62b78a..ff05a764 100644 --- a/packages/ui-keyring/src/Keyring.ts +++ b/packages/ui-keyring/src/Keyring.ts @@ -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); }); } diff --git a/packages/ui-keyring/src/observable/genericSubject.ts b/packages/ui-keyring/src/observable/genericSubject.ts index e4f51cca..4e5b2d02 100644 --- a/packages/ui-keyring/src/observable/genericSubject.ts +++ b/packages/ui-keyring/src/observable/genericSubject.ts @@ -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) diff --git a/packages/ui-keyring/src/observable/types.ts b/packages/ui-keyring/src/observable/types.ts index 9f230c57..8f55a2f7 100644 --- a/packages/ui-keyring/src/observable/types.ts +++ b/packages/ui-keyring/src/observable/types.ts @@ -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; }