@@ -12,7 +12,7 @@ import {
1212} from "@react-navigation/native" ;
1313import type { EnvironmentId } from "@t3tools/contracts" ;
1414import { AsyncResult } from "effect/reactivity" ;
15- import { useCallback , useEffect , useRef , useState } from "react" ;
15+ import { useEffect , useRef , useState } from "react" ;
1616import { Linking , Pressable , StyleSheet , View } from "react-native" ;
1717import Svg , { Defs , RadialGradient , Rect , Stop } from "react-native-svg" ;
1818import { useSafeAreaInsets } from "react-native-safe-area-context" ;
@@ -95,19 +95,19 @@ export function ConnectionsNewRouteScreen({
9595 }
9696 } , [ pairingConnectionError ] ) ;
9797
98- const handleHostChange = useCallback ( ( value : string ) => {
98+ const handleHostChange = ( value : string ) => {
9999 setHostInput ( value ) ;
100100 setPendingConnectionError ( null ) ;
101- } , [ ] ) ;
101+ } ;
102102
103- const handleCodeChange = useCallback ( ( value : string ) => {
103+ const handleCodeChange = ( value : string ) => {
104104 setCodeInput ( value ) ;
105105 setPendingConnectionError ( null ) ;
106- } , [ ] ) ;
106+ } ;
107107
108108 useEffect ( ( ) => ( ) => setPendingConnectionError ( null ) , [ ] ) ;
109109
110- const handleScanPress = useCallback ( async ( ) => {
110+ const handleScanPress = async ( ) => {
111111 const permission = await requestCameraPermission ( ) ;
112112 if ( permission . granted ) {
113113 setScanComplete ( false ) ;
@@ -122,68 +122,62 @@ export function ConnectionsNewRouteScreen({
122122 { text : "Open Settings" , onPress : ( ) => void Linking . openSettings ( ) } ,
123123 ] ,
124124 ) ;
125- } , [ requestCameraPermission ] ) ;
125+ } ;
126126
127- const handleQrScan = useCallback (
128- ( { data } : { readonly data : string } ) => {
129- if ( scannerLocked ) {
130- return ;
131- }
127+ const handleQrScan = ( { data } : { readonly data : string } ) => {
128+ if ( scannerLocked ) {
129+ return ;
130+ }
132131
133- setScannerLocked ( true ) ;
132+ setScannerLocked ( true ) ;
134133
135- try {
136- const pairingUrl = extractPairingUrlFromQrPayload ( data ) ;
137- const { host, code } = parsePairingUrl ( pairingUrl ) ;
138- setHostInput ( host ) ;
139- setCodeInput ( code ) ;
140- onChangeConnectionPairingUrl ( pairingUrl ) ;
141- setScanComplete ( true ) ;
134+ try {
135+ const pairingUrl = extractPairingUrlFromQrPayload ( data ) ;
136+ const { host, code } = parsePairingUrl ( pairingUrl ) ;
137+ setHostInput ( host ) ;
138+ setCodeInput ( code ) ;
139+ onChangeConnectionPairingUrl ( pairingUrl ) ;
140+ setScanComplete ( true ) ;
141+ setScannerLocked ( false ) ;
142+ } catch ( error ) {
143+ void Haptics . notificationAsync ( Haptics . NotificationFeedbackType . Error ) ;
144+ Dialog . alert (
145+ "Invalid QR code" ,
146+ error instanceof Error ? error . message : "Scanned QR code was not recognized." ,
147+ ) ;
148+ setTimeout ( ( ) => {
142149 setScannerLocked ( false ) ;
143- } catch ( error ) {
144- void Haptics . notificationAsync ( Haptics . NotificationFeedbackType . Error ) ;
145- Dialog . alert (
146- "Invalid QR code" ,
147- error instanceof Error ? error . message : "Scanned QR code was not recognized." ,
148- ) ;
149- setTimeout ( ( ) => {
150- setScannerLocked ( false ) ;
151- } , 600 ) ;
152- }
153- } ,
154- [ onChangeConnectionPairingUrl , scannerLocked ] ,
155- ) ;
150+ } , 600 ) ;
151+ }
152+ } ;
156153
157- const connectAndClose = useCallback (
158- async ( pairingUrl : string ) => {
159- setIsSubmitting ( true ) ;
160- onChangeConnectionPairingUrl ( pairingUrl ) ;
161- try {
162- const result = await onConnectPress ( pairingUrl , params . routeFor ) ;
163- void Haptics . notificationAsync (
164- AsyncResult . isSuccess ( result )
165- ? Haptics . NotificationFeedbackType . Success
166- : Haptics . NotificationFeedbackType . Error ,
167- ) ;
168- if ( AsyncResult . isSuccess ( result ) ) {
169- // Return to whatever opened the sheet. Replacing it with Home would
170- // nest Home inside any sheet still below it.
171- if ( ! navigation . canGoBack ( ) ) {
172- navigation . dispatch ( StackActions . replace ( "Home" ) ) ;
173- } else {
174- navigation . goBack ( ) ;
175- }
154+ const connectAndClose = async ( pairingUrl : string ) => {
155+ setIsSubmitting ( true ) ;
156+ onChangeConnectionPairingUrl ( pairingUrl ) ;
157+ await ( async ( ) => {
158+ const result = await onConnectPress ( pairingUrl , params . routeFor ) ;
159+ void Haptics . notificationAsync (
160+ AsyncResult . isSuccess ( result )
161+ ? Haptics . NotificationFeedbackType . Success
162+ : Haptics . NotificationFeedbackType . Error ,
163+ ) ;
164+ if ( AsyncResult . isSuccess ( result ) ) {
165+ // Return to whatever opened the sheet. Replacing it with Home would
166+ // nest Home inside any sheet still below it.
167+ if ( ! navigation . canGoBack ( ) ) {
168+ navigation . dispatch ( StackActions . replace ( "Home" ) ) ;
169+ } else {
170+ navigation . goBack ( ) ;
176171 }
177- } finally {
178- setIsSubmitting ( false ) ;
179172 }
180- } ,
181- [ navigation , onChangeConnectionPairingUrl , onConnectPress , params . routeFor ] ,
182- ) ;
173+ } ) ( ) . finally ( ( ) => {
174+ setIsSubmitting ( false ) ;
175+ } ) ;
176+ } ;
183177
184- const handleSubmit = useCallback ( async ( ) => {
178+ const handleSubmit = async ( ) => {
185179 await connectAndClose ( buildPairingUrl ( hostInput , codeInput ) ) ;
186- } , [ codeInput , connectAndClose , hostInput ] ) ;
180+ } ;
187181
188182 useEffect ( ( ) => {
189183 if ( ! shouldAutoConnect || attemptedAutoConnectRef . current === routePairingUrl ) {
0 commit comments