Skip to content

Commit

Permalink
feat: implement window.close request in viewBinding
Browse files Browse the repository at this point in the history
  • Loading branch information
micwallace committed Jul 27, 2023
1 parent 1f1dcf8 commit c4e9760
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions javascript/engine-js/src/view/ViewController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export enum ViewEvent {
export enum RequestFromView {
SIGN_PERSONAL_MESSAGE = "signPersonalMessage",
PUT_USER_INPUT = "putUserInput",
CLOSE = "close"
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export class NewViewer {

private async processUrlLoad(){

// TODO: Support attestation in hash parameters too
const queryStr = document.location.search.substring(1);

if (!queryStr)
Expand All @@ -72,6 +73,7 @@ export class NewViewer {
tsMeta = await this.addFormSubmit("url", {tsId: tokenScript.getSourceInfo().tsId, image: definition.meta.image});

document.location.hash = "";
window.history.replaceState({}, document.title, "/");

this.showToast.emit({
type: "success",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ export abstract class AbstractViewBinding implements IViewBinding {
/*document.addEventListener("DOMContentLoaded", function() {
sendUserInputValues();
});*/
const closing = window.close;
window.close = function () {
postMessageToEngine("close", undefined);
closing();
};
`;
}

Expand Down Expand Up @@ -207,6 +213,10 @@ export abstract class AbstractViewBinding implements IViewBinding {
await this.tokenScript.getViewController().setUserEntryValues(params);
break;

case RequestFromView.CLOSE:
this.unloadTokenView()
break;

default:
throw new Error("TokenScript view API method: " + method + " is not implemented.");
}
Expand Down

0 comments on commit c4e9760

Please sign in to comment.