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

Commit

Permalink
fix(sdk): initialize Aztec when document is ready
Browse files Browse the repository at this point in the history
  • Loading branch information
LeilaWang committed Feb 13, 2020
1 parent 0bcb489 commit 3beac02
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default function acceptConnection() {
type: backgroundReadyEvent,
}, '*');

const connection = Connection;
const connection = new Connection();
let networkConfig;

window.addEventListener('message', async (event) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/extension/src/background/utils/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -492,4 +492,4 @@ class Connection {
}
}

export default new Connection();
export default Connection;
3 changes: 3 additions & 0 deletions packages/extension/src/client/Aztec/ApiManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import ConnectionService from '~/client/services/ConnectionService';

export default class ApiManager {
constructor() {
ConnectionService.init();

this.eventListeners = new EventListeners(['profileChanged']);
this.enableProfileChangeListener = null;
this.enabledOptions = null;
Expand Down Expand Up @@ -206,6 +208,7 @@ export default class ApiManager {
}

async refreshSession(options, cb, setApis) {
this.enabledOptions = null;
await this.disable(setApis);
return this.enable(options, cb, setApis);
}
Expand Down
4 changes: 3 additions & 1 deletion packages/extension/src/client/Aztec/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import {
} from '~/utils/log';
import ApiManager from './ApiManager';

const manager = new ApiManager();
let manager;

class Aztec {
constructor() {
manager = new ApiManager();

const apis = manager.generateDefaultApis();
Object.keys(apis).forEach((apiName) => {
this[apiName] = apis[apiName];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ import getApiKeyApproval from '~/client/utils/getApiKeyApproval';
import backgroundFrame from './backgroundFrame';

class ConnectionService {
constructor() {
async init() {
this.clientId = randomId();
this.setInitialVars();
backgroundFrame.init();
await backgroundFrame.init();
}

setInitialVars() {
Expand Down
14 changes: 8 additions & 6 deletions packages/extension/src/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import Aztec from '~/client/Aztec';

window.aztec = new Aztec();
document.addEventListener('DOMContentLoaded', () => {
window.aztec = new Aztec();

// TODO - callback's name should be configurable through url:
// /sdk/aztec/?key=API_KEY&callback=aztecCallback
if (typeof window.aztecCallback === 'function') {
window.aztecCallback();
}
// TODO - callback's name should be configurable through url:
// /sdk/aztec/?key=API_KEY&callback=aztecCallback
if (typeof window.aztecCallback === 'function') {
window.aztecCallback();
}
});

0 comments on commit 3beac02

Please sign in to comment.