1- import React from "react" ;
2- import { useNavigation } from "@react-navigation/native" ;
1+ import React , { useState , useCallback } from "react" ;
2+ import { useNavigation , useFocusEffect } from "@react-navigation/native" ;
33import { useSelector } from "~/context/store" ;
44import { useTranslation } from "react-i18next" ;
55import { Switch } from "@ledgerhq/native-ui" ;
@@ -16,13 +16,23 @@ export default function AuthSecurityToggle() {
1616 const privacy = useSelector ( privacySelector ) ;
1717 const { navigate } = useNavigation ( ) ;
1818
19+ const [ isToggleOn , setIsToggleOn ] = useState ( ! ! privacy ?. hasPassword ) ;
20+
21+ useFocusEffect (
22+ useCallback ( ( ) => {
23+ setIsToggleOn ( ! ! privacy ?. hasPassword ) ;
24+ } , [ privacy ?. hasPassword ] ) ,
25+ ) ;
26+
1927 const onValueChange = ( authSecurityEnabled : boolean ) : void => {
2028 track ( "toggle_clicked" , {
2129 toggle : "Password Lock" ,
2230 page : ScreenName . GeneralSettings ,
2331 enabled : ! privacy ?. hasPassword ,
2432 } ) ;
2533
34+ setIsToggleOn ( authSecurityEnabled ) ;
35+
2636 navigate (
2737 authSecurityEnabled ? NavigatorName . PasswordAddFlow : NavigatorName . PasswordModifyFlow ,
2838 ) ;
@@ -40,11 +50,7 @@ export default function AuthSecurityToggle() {
4050 title = { t ( "settings.display.password" ) }
4151 desc = { getPasswordDesc ( ) }
4252 >
43- < Switch
44- checked = { ! ! privacy ?. hasPassword }
45- onChange = { onValueChange }
46- testID = "password-settings-switch"
47- />
53+ < Switch checked = { isToggleOn } onChange = { onValueChange } testID = "password-settings-switch" />
4854 </ SettingsRow >
4955 < BiometricsRow />
5056 </ >
0 commit comments