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

Commit

Permalink
fix(sdk): init aztec when DOMContentLoaded has already been fired
Browse files Browse the repository at this point in the history
  • Loading branch information
LeilaWang committed Mar 24, 2020
1 parent e362fa3 commit cef61cb
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions packages/extension/src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Aztec from '~/client/Aztec';

document.addEventListener('DOMContentLoaded', async () => {
const initializeAZTEC = async () => {
const aztec = new Aztec();
await aztec.generateInitialApis();
delete aztec.generateInitialApis;
Expand All @@ -11,4 +11,17 @@ document.addEventListener('DOMContentLoaded', async () => {
if (typeof window.aztecCallback === 'function') {
window.aztecCallback();
}
});
};

const readyStates = [
'complete',
'interactive',
];

if (readyStates.indexOf(document.readyState) >= 0) {
initializeAZTEC();
} else {
document.addEventListener('DOMContentLoaded', () => {
initializeAZTEC();
});
}

0 comments on commit cef61cb

Please sign in to comment.