Skip to content

Commit

Permalink
feat: update currentIdentity with new currentPair
Browse files Browse the repository at this point in the history
  • Loading branch information
shuffledex committed Mar 30, 2020
1 parent 5061f8c commit 55896e3
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/context/index.ts
Expand Up @@ -137,10 +137,29 @@ export class Context {
/**
* Set a pair as the current account keyring pair
*/
public setPair(address: string): void {
const { keyring } = this;
public async setPair(address: string): Promise<void> {
const {
keyring,
polymeshApi: {
query: { identity },
},
} = this;
try {
this.currentPair = keyring.getPair(address);
const newCurrentPair = keyring.getPair(address);

const identityIds = await identity.keyToIdentityIds(newCurrentPair.publicKey);

const did = identityIds.unwrap().asUnique;

if (!did) {
throw new PolymeshError({
code: ErrorCode.FatalError,
message: 'The address is not present in the keyring set',
});
}

this.currentPair = newCurrentPair;
this.currentIdentity = new Identity({ did: did.toString() }, this);
} catch (e) {
throw new PolymeshError({
code: ErrorCode.FatalError,
Expand Down

0 comments on commit 55896e3

Please sign in to comment.