Skip to content

Commit

Permalink
prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
turnekybc committed Dec 9, 2024
1 parent 45ec70a commit 12f2cd3
Showing 1 changed file with 31 additions and 33 deletions.
64 changes: 31 additions & 33 deletions packages/iframe-stamper/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export class IframeStamper {
// See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#sandbox
// We do not need any other permission than running scripts for import/export/auth frames.
iframe.setAttribute("sandbox", "allow-scripts allow-same-origin");
iframe.setAttribute("data-trusted-origin", this.trustedParentOrigin)
iframe.setAttribute("data-trusted-origin", this.trustedParentOrigin);

iframe.id = config.iframeElementId;
iframe.src = config.iframeUrl;
Expand All @@ -160,16 +160,18 @@ export class IframeStamper {
this.container.appendChild(this.iframe);
this.iframe.addEventListener("load", () => {
// Send a message to the iframe to initialize the message channel
this.iframe.contentWindow?.postMessage("init", this.iframeOrigin, [this.messageChannel.port2]);
})

this.iframe.contentWindow?.postMessage("init", this.iframeOrigin, [
this.messageChannel.port2,
]);
});

return new Promise((resolve, _reject) => {
this.messageChannel.port1.onmessage = (event) => {
if (event.data?.type === IframeEventType.PublicKeyReady) {
this.iframePublicKey = event.data["value"];
resolve(event.data["value"]);
}
}
};
});
}

Expand Down Expand Up @@ -198,15 +200,15 @@ export class IframeStamper {
this.messageChannel.port1.postMessage({
type: IframeEventType.InjectCredentialBundle,
value: bundle,
})
});
this.messageChannel.port1.onmessage = (event) => {
if (event.data?.type === IframeEventType.BundleInjected) {
resolve(event.data["value"]);
}
if (event.data?.type === IframeEventType.Error) {
reject(event.data["value"]);
}
}
};
});
}

Expand All @@ -233,14 +235,14 @@ export class IframeStamper {
);

return new Promise((resolve, reject) => {
this.messageChannel.port1.onmessage = (event) => {
this.messageChannel.port1.onmessage = (event) => {
if (event.data?.type === IframeEventType.BundleInjected) {
resolve(event.data["value"]);
}
if (event.data?.type === IframeEventType.Error) {
reject(event.data["value"]);
}
}
};
});
}

Expand All @@ -258,7 +260,7 @@ export class IframeStamper {
type: IframeEventType.InjectWalletExportBundle,
value: bundle,
organizationId,
})
});

return new Promise((resolve, reject) => {
this.messageChannel.port1.onmessage = (event) => {
Expand All @@ -268,7 +270,7 @@ export class IframeStamper {
if (event.data?.type === IframeEventType.Error) {
reject(event.data["value"]);
}
}
};
});
}

Expand All @@ -281,14 +283,12 @@ export class IframeStamper {
organizationId: string,
userId: string
): Promise<boolean> {
this.messageChannel.port1.postMessage(
{
type: IframeEventType.InjectImportBundle,
value: bundle,
organizationId,
userId,
},
);
this.messageChannel.port1.postMessage({
type: IframeEventType.InjectImportBundle,
value: bundle,
organizationId,
userId,
});

return new Promise((resolve, reject) => {
this.messageChannel.port1.onmessage = (event) => {
Expand All @@ -298,7 +298,7 @@ export class IframeStamper {
if (event.data?.type === IframeEventType.Error) {
reject(event.data["value"]);
}
}
};
});
}

Expand All @@ -309,11 +309,9 @@ export class IframeStamper {
* This is used during the wallet import flow.
*/
async extractWalletEncryptedBundle(): Promise<string> {
this.messageChannel.port1.postMessage(
{
type: IframeEventType.ExtractWalletEncryptedBundle,
},
);
this.messageChannel.port1.postMessage({
type: IframeEventType.ExtractWalletEncryptedBundle,
});

return new Promise((resolve, reject) => {
this.messageChannel.port1.onmessage = (event) => {
Expand All @@ -323,7 +321,7 @@ export class IframeStamper {
if (event.data?.type === IframeEventType.Error) {
reject(event.data["value"]);
}
}
};
});
}

Expand All @@ -348,7 +346,7 @@ export class IframeStamper {
if (event.data?.type === IframeEventType.Error) {
reject(event.data["value"]);
}
}
};
});
}

Expand All @@ -361,7 +359,7 @@ export class IframeStamper {
this.messageChannel.port1.postMessage({
type: IframeEventType.ApplySettings,
value: settingsStr,
})
});

return new Promise((resolve, reject) => {
this.messageChannel.port1.onmessage = (event) => {
Expand All @@ -371,8 +369,8 @@ export class IframeStamper {
if (event.data?.type === IframeEventType.Error) {
reject(event.data["value"]);
}
}
})
};
});
}

/**
Expand All @@ -388,8 +386,8 @@ export class IframeStamper {
this.messageChannel.port1.postMessage({
type: IframeEventType.StampRequest,
value: payload,
})
});

return new Promise((resolve, reject) => {
this.messageChannel.port1.onmessage = (event) => {
if (event.data?.type === IframeEventType.Stamp) {
Expand All @@ -401,7 +399,7 @@ export class IframeStamper {
if (event.data?.type === IframeEventType.Error) {
reject(event.data["value"]);
}
}
};
});
}
}

0 comments on commit 12f2cd3

Please sign in to comment.