Skip to content

Commit

Permalink
Call window.close in backchannel dev wallet (#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
jribbink authored Jun 23, 2023
1 parent 74fdd9a commit 57d8118
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Binary file modified go/wallet/bundle.zip
Binary file not shown.
26 changes: 24 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,41 @@ export function getPollingId() {
* This function is used to update a polling session with data from the frontchannel.
* It is used to emulate a backchannel response from the frontchannel.
*/
export function updatePollingSession(baseUrl: string, data: any) {
export async function updatePollingSession(baseUrl: string, data: any) {
const body = {
pollingId: getPollingId(),
data,
}

fetch(baseUrl + "/api/polling-session", {
const response = await fetch(baseUrl + "/api/polling-session", {
method: "POST",
body: JSON.stringify(body),
headers: {
"Content-Type": "application/json",
},
})

if (!response.ok) {
throw new Error("Failed to update polling session")
}

// window.close() needs to be called at the end of a backchannel flow
// to support Android devices where the parent FCL instance is unable
// to dismiss the child window. We also have an extra safety check
// to make sure we don't close the window if we're in an iframe.
if (!inIframe()) {
try {
window.close()
} catch (e) {}
}
}

export function inIframe() {
try {
return window.self !== window.top
} catch (e) {
return true
}
}

export function getBaseUrl() {
Expand Down

0 comments on commit 57d8118

Please sign in to comment.