cleanup captcha step
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
import React, {useEffect, useRef} from 'react'
|
import {useEffect, useMemo, useRef} from 'react'
|
||||||
import {StyleSheet} from 'react-native'
|
|
||||||
import {WebView, type WebViewNavigation} from 'react-native-webview'
|
import {WebView, type WebViewNavigation} from 'react-native-webview'
|
||||||
import {type ShouldStartLoadRequest} from 'react-native-webview/lib/WebViewTypes'
|
import {type ShouldStartLoadRequest} from 'react-native-webview/lib/WebViewTypes'
|
||||||
|
|
||||||
@@ -43,7 +42,7 @@ export function CaptchaWebView({
|
|||||||
}
|
}
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
const redirectHost = React.useMemo(() => {
|
const redirectHost = useMemo(() => {
|
||||||
if (!state?.serviceUrl) return 'bsky.app'
|
if (!state?.serviceUrl) return 'bsky.app'
|
||||||
|
|
||||||
return state?.serviceUrl &&
|
return state?.serviceUrl &&
|
||||||
@@ -52,18 +51,14 @@ export function CaptchaWebView({
|
|||||||
: 'bsky.app'
|
: 'bsky.app'
|
||||||
}, [state?.serviceUrl])
|
}, [state?.serviceUrl])
|
||||||
|
|
||||||
const wasSuccessful = React.useRef(false)
|
const wasSuccessful = useRef(false)
|
||||||
|
|
||||||
const onShouldStartLoadWithRequest = React.useCallback(
|
const onShouldStartLoadWithRequest = (event: ShouldStartLoadRequest) => {
|
||||||
(event: ShouldStartLoadRequest) => {
|
|
||||||
const urlp = new URL(event.url)
|
const urlp = new URL(event.url)
|
||||||
return ALLOWED_HOSTS.includes(urlp.host)
|
return ALLOWED_HOSTS.includes(urlp.host)
|
||||||
},
|
}
|
||||||
[],
|
|
||||||
)
|
|
||||||
|
|
||||||
const onNavigationStateChange = React.useCallback(
|
const onNavigationStateChange = (e: WebViewNavigation) => {
|
||||||
(e: WebViewNavigation) => {
|
|
||||||
if (wasSuccessful.current) return
|
if (wasSuccessful.current) return
|
||||||
|
|
||||||
const urlp = new URL(e.url)
|
const urlp = new URL(e.url)
|
||||||
@@ -86,15 +81,17 @@ export function CaptchaWebView({
|
|||||||
} else {
|
} else {
|
||||||
onSuccess(code)
|
onSuccess(code)
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
[redirectHost, stateParam, onSuccess, onError],
|
|
||||||
)
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<WebView
|
<WebView
|
||||||
source={{uri: url}}
|
source={{uri: url}}
|
||||||
javaScriptEnabled
|
javaScriptEnabled
|
||||||
style={styles.webview}
|
style={{
|
||||||
|
flex: 1,
|
||||||
|
backgroundColor: 'transparent',
|
||||||
|
borderRadius: 10,
|
||||||
|
}}
|
||||||
onShouldStartLoadWithRequest={onShouldStartLoadWithRequest}
|
onShouldStartLoadWithRequest={onShouldStartLoadWithRequest}
|
||||||
onNavigationStateChange={onNavigationStateChange}
|
onNavigationStateChange={onNavigationStateChange}
|
||||||
scrollEnabled={false}
|
scrollEnabled={false}
|
||||||
@@ -107,11 +104,3 @@ export function CaptchaWebView({
|
|||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
|
||||||
webview: {
|
|
||||||
flex: 1,
|
|
||||||
backgroundColor: 'transparent',
|
|
||||||
borderRadius: 10,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|||||||
Reference in New Issue
Block a user