Skip to content

Commit

Permalink
PKG -- [fcl] Stop polling when React Native WebBrowser closed (#1690)
Browse files Browse the repository at this point in the history
* PKG -- [fcl] Stop polling when React Native WebBrowser closed

* changeset
  • Loading branch information
jribbink authored Jun 19, 2023
1 parent ec80946 commit 53d1f60
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/funny-waves-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@onflow/fcl": patch
---

Stop polling in React Native when browser has been closed
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ export const getExecHttpPost = (execLocal) => async({service, body, config, opts
return resp
} else if (resp.status === "PENDING") {
var canContinue = true
const [_, unmount] = await execLocal(normalizeLocalView(resp.local), {serviceEndpoint})
const [_, unmount] = await execLocal(
normalizeLocalView(resp.local),
{
serviceEndpoint,
onClose: () => (canContinue = false)
}
)

const close = () => {
try {
Expand Down
5 changes: 4 additions & 1 deletion packages/fcl/src/utils/react-native/exec-local.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ const VIEWS = {
"VIEW/TAB": renderBrowser,
}

export async function execLocal(service, opts = {serviceEndpoint: () => {}}) {
export async function execLocal(
service,
opts = {serviceEndpoint: () => {}, onClose: () => {}}
) {
const {serviceEndpoint} = opts
try {
return VIEWS[service.method](serviceEndpoint(service), opts)
Expand Down
11 changes: 8 additions & 3 deletions packages/fcl/src/utils/react-native/render-browser.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import * as WebBrowser from 'expo-web-browser';
import * as WebBrowser from "expo-web-browser"

export function renderBrowser(src) {
const webbrowser = WebBrowser.openAuthSessionAsync(src.toString());
export function renderBrowser(src, opts = {}) {
const webbrowser = WebBrowser.openAuthSessionAsync(src.toString())

const unmount = () => {
WebBrowser.dismissAuthSession()
}

// Call onClose when the webbrowser is closed
webbrowser.then(() => {
opts?.onClose()
})

return [webbrowser, unmount]
}

0 comments on commit 53d1f60

Please sign in to comment.