Skip to content

Commit 57d8118

Browse files
authored
Call window.close in backchannel dev wallet (#210)
1 parent 74fdd9a commit 57d8118

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

go/wallet/bundle.zip

464 Bytes
Binary file not shown.

src/utils.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,41 @@ export function getPollingId() {
1818
* This function is used to update a polling session with data from the frontchannel.
1919
* It is used to emulate a backchannel response from the frontchannel.
2020
*/
21-
export function updatePollingSession(baseUrl: string, data: any) {
21+
export async function updatePollingSession(baseUrl: string, data: any) {
2222
const body = {
2323
pollingId: getPollingId(),
2424
data,
2525
}
2626

27-
fetch(baseUrl + "/api/polling-session", {
27+
const response = await fetch(baseUrl + "/api/polling-session", {
2828
method: "POST",
2929
body: JSON.stringify(body),
3030
headers: {
3131
"Content-Type": "application/json",
3232
},
3333
})
34+
35+
if (!response.ok) {
36+
throw new Error("Failed to update polling session")
37+
}
38+
39+
// window.close() needs to be called at the end of a backchannel flow
40+
// to support Android devices where the parent FCL instance is unable
41+
// to dismiss the child window. We also have an extra safety check
42+
// to make sure we don't close the window if we're in an iframe.
43+
if (!inIframe()) {
44+
try {
45+
window.close()
46+
} catch (e) {}
47+
}
48+
}
49+
50+
export function inIframe() {
51+
try {
52+
return window.self !== window.top
53+
} catch (e) {
54+
return true
55+
}
3456
}
3557

3658
export function getBaseUrl() {

0 commit comments

Comments
 (0)