11import { createContext , type ReactNode , useCallback , useContext , useState } from 'react' ;
2- import type { InstanceInfo , LocationInfo } from '../../../rust-api/types' ;
2+ import type { InstanceInfo , LocationInfo , MfaMethodValue } from '../../../rust-api/types' ;
33import { MfaMethod } from '../../../rust-api/types' ;
44import { LocationCardViews , type LocationCardViewsValue } from './types' ;
55
@@ -10,6 +10,8 @@ interface LocationCardContextValue {
1010 previousView : LocationCardViewsValue | null ;
1111 setView : ( view : LocationCardViewsValue ) => void ;
1212 startMfa : ( ) => void ;
13+ localMfaMethod : MfaMethodValue ;
14+ setLocalMfaMethod : ( method : MfaMethodValue ) => void ;
1315}
1416
1517const LocationCardContext = createContext < LocationCardContextValue | null > ( null ) ;
@@ -37,6 +39,9 @@ export const LocationCardProvider = ({
3739 const [ currentView , setCurrentView ] = useState < LocationCardViewsValue > (
3840 location . active ? LocationCardViews . Connected : LocationCardViews . Default ,
3941 ) ;
42+ const [ localMfaMethod , setLocalMfaMethod ] = useState < MfaMethodValue > (
43+ location . mfa_method ?? MfaMethod . Totp ,
44+ ) ;
4045
4146 const setView = useCallback (
4247 ( view : LocationCardViewsValue ) => {
@@ -47,7 +52,7 @@ export const LocationCardProvider = ({
4752 ) ;
4853
4954 const startMfa = useCallback ( ( ) => {
50- switch ( location . mfa_method ) {
55+ switch ( localMfaMethod ) {
5156 case MfaMethod . Totp :
5257 setView ( LocationCardViews . MfaTotp ) ;
5358 break ;
@@ -61,7 +66,7 @@ export const LocationCardProvider = ({
6166 setView ( LocationCardViews . MfaMobile ) ;
6267 break ;
6368 }
64- } , [ location . mfa_method , setView ] ) ;
69+ } , [ localMfaMethod , setView ] ) ;
6570
6671 return (
6772 < LocationCardContext . Provider
@@ -72,6 +77,8 @@ export const LocationCardProvider = ({
7277 location,
7378 instance,
7479 startMfa,
80+ localMfaMethod,
81+ setLocalMfaMethod,
7582 } }
7683 >
7784 { children }
0 commit comments