Skip to content
This repository has been archived by the owner on Mar 16, 2023. It is now read-only.

Commit

Permalink
feat(sdk): export current account as Account instance
Browse files Browse the repository at this point in the history
  • Loading branch information
LeilaWang committed Feb 26, 2020
1 parent f7166ed commit 7b4f81e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
7 changes: 5 additions & 2 deletions packages/extension/src/client/Aztec/ApiManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import EventListeners from '~/utils/EventListeners';
import Web3Service from '~/client/services/Web3Service';
import ApiPermissionService from '~/client/services/ApiPermissionService';
import ConnectionService from '~/client/services/ConnectionService';
import Account from '~/client/apis/Account';

export default class ApiManager {
constructor() {
Expand Down Expand Up @@ -106,12 +107,14 @@ export default class ApiManager {
error = null,
},
) => {
this.aztecAccount = aztecAccount;
this.aztecAccount = aztecAccount
? new Account(aztecAccount)
: null;
this.error = error;
this.eventListeners.notify(
'profileChanged',
'aztecAccountChanged',
aztecAccount,
this.aztecAccount,
error,
);
this.flushEnableListeners(options);
Expand Down
12 changes: 10 additions & 2 deletions packages/extension/src/client/Aztec/__tests__/ApiManager.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import asyncForEach from '~/utils/asyncForEach';
import Web3Service from '~/client/services/Web3Service';
import ConnectionService from '~/client/services/ConnectionService';
import ApiPermissionService from '~/client/services/ApiPermissionService';
import Account from '~/client/apis/Account';
import ApiManager from '../ApiManager';

jest.spyOn(ConnectionService, 'init')
Expand Down Expand Up @@ -119,10 +120,17 @@ describe('ApiManager.handleResolveSession', () => {
aztecAccount,
});

expect(manager.aztecAccount).toBe(aztecAccount);
expect(manager.aztecAccount).toBeInstanceOf(Account);
expect(manager.aztecAccount.address).toBe(aztecAccount.address);
expect(manager.error).toBe(null);
expect(profileListener).toHaveBeenCalledTimes(1);
expect(profileListener).toHaveBeenLastCalledWith('aztecAccountChanged', aztecAccount, null);
expect(profileListener).toHaveBeenLastCalledWith(
'aztecAccountChanged',
expect.objectContaining({
address: aztecAccount.address,
}),
null,
);
expect(flushEnableListenersSpy).toHaveBeenCalledTimes(1);
expect(flushEnableListenersSpy).toHaveBeenCalledWith(options);
});
Expand Down

0 comments on commit 7b4f81e

Please sign in to comment.