diff --git a/.changeset/funny-waves-search.md b/.changeset/funny-waves-search.md new file mode 100644 index 000000000..42ee3ef44 --- /dev/null +++ b/.changeset/funny-waves-search.md @@ -0,0 +1,5 @@ +--- +"@onflow/fcl": patch +--- + +Stop polling in React Native when browser has been closed diff --git a/packages/fcl/src/current-user/exec-service/strategies/http-post.js b/packages/fcl/src/current-user/exec-service/strategies/http-post.js index 95ab50c9e..e2f5ae96b 100644 --- a/packages/fcl/src/current-user/exec-service/strategies/http-post.js +++ b/packages/fcl/src/current-user/exec-service/strategies/http-post.js @@ -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 { diff --git a/packages/fcl/src/utils/react-native/exec-local.js b/packages/fcl/src/utils/react-native/exec-local.js index 2132be135..30c250c5c 100644 --- a/packages/fcl/src/utils/react-native/exec-local.js +++ b/packages/fcl/src/utils/react-native/exec-local.js @@ -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) diff --git a/packages/fcl/src/utils/react-native/render-browser.js b/packages/fcl/src/utils/react-native/render-browser.js index c4b1ac870..6b0e867cf 100644 --- a/packages/fcl/src/utils/react-native/render-browser.js +++ b/packages/fcl/src/utils/react-native/render-browser.js @@ -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] }