Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent multiple iframes creation #365

Merged
merged 8 commits into from
Dec 2, 2024
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ await provider.send("eth_requestAccounts", []);
const signer = await provider.getSigner();

// Initialize the SDK
// Note: `idOS.init` must only be called once; calling it again will throw an error.
const idos = await idOS.init({enclaveOptions: {container: "#idos-container"}});
await idos.setSigner("EVM", signer);

Expand Down
5 changes: 4 additions & 1 deletion packages/idos-sdk-js/src/lib/idos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ interface InitParams {

export class idOS {
static initializing = false;

static instance: idOS;
static near = Grants.near;
static evm = Grants.evm;
static kwil = KwilWrapper.defaults;
Expand Down Expand Up @@ -62,12 +62,14 @@ export class idOS {
}

static async init(params: InitParams): Promise<idOS> {
if (idOS.instance) return idOS.instance;
idOS.initializing = true;

const idos = new idOS({
...params,
kwilWrapper: await KwilWrapper.init(params),
});
idOS.instance = idos;
await idos.enclave.load();

return idos;
Expand Down Expand Up @@ -109,6 +111,7 @@ export class idOS {

async reset({ enclave = false } = {}): Promise<void> {
this.store.reset();
idOS.initializing = false;
if (enclave) await this.enclave.reset();
}

Expand Down