Skip to content

Commit

Permalink
feat(ui-did-keyring): make loadAll method return Promise
Browse files Browse the repository at this point in the history
release-as: 0.7.0
  • Loading branch information
zzcwoshizz committed Jan 10, 2023
1 parent 465b6a9 commit 372f516
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 24 deletions.
27 changes: 17 additions & 10 deletions packages/ui-did-keyring/src/KiltDid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,23 @@ export class KiltDid extends KiltDidSuper {
this.#store = store ?? new BrowserStore();
}

public loadAll() {
this.#store.all((key, value) => {
if (kiltPairKeyRegex.test(key)) {
this.keyring.addFromJson(value as KeyringPair$Json);
}
});
this.#store.all((key, value) => {
if (kiltDidRegex.test(key)) {
this.addDid(value as DidUri);
}
public loadAll(): Promise<void> {
return new Promise((resolve) => {
this.#store.all((key, value) => {
const jsons: KeyringPair$Json[] = [];
const dids: DidUri[] = [];

if (kiltPairKeyRegex.test(key)) {
jsons.push(value as KeyringPair$Json);
} else if (kiltDidRegex.test(key)) {
dids.push(value as DidUri);
}

jsons.forEach((json) => this.keyring.addFromJson(json));
dids.forEach((did) => super.addDid(did));

resolve();
});
});
}

Expand Down
35 changes: 21 additions & 14 deletions packages/ui-did-keyring/src/ZkDid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,27 @@ export class ZkDid extends ZkDidSuper {
this.#store = store ?? new BrowserStore();
}

loadAll() {
this.#store.all((key, val) => {
if (zkPairKeyRegex.test(key)) {
const json = val as KeyringPair$Json;

this.keyring.addFromJson(json);
}
});
this.#store.all((key, val) => {
if (zkDidRegex.test(key)) {
const did = helpers.fromDidDocument(val as DidDocument, this.keyring);

this.dids.set(did.id, did);
}
public loadAll(): Promise<void> {
return new Promise((resolve) => {
this.#store.all((key, val) => {
const jsons: KeyringPair$Json[] = [];
const documents: DidDocument[] = [];

if (zkPairKeyRegex.test(key)) {
jsons.push(val as KeyringPair$Json);
} else if (zkDidRegex.test(key)) {
documents.push(val as DidDocument);
}

jsons.forEach((json) => this.keyring.addFromJson(json));
documents.forEach((document) => {
const did = helpers.fromDidDocument(document, this.keyring);

this.dids.set(did.id, did);
});

resolve();
});
});
}

Expand Down

0 comments on commit 372f516

Please sign in to comment.