@@ -6,40 +6,18 @@ import { BN } from "bn.js";
66import { HiOutlineMail } from "react-icons/hi" ;
77import { COREKIT_STATUS } from "@web3auth/mpc-core-kit" ;
88import { useNavigate } from "react-router-dom" ;
9+ import { ShareDescription } from "./types" ;
10+ import { HiOutlineKey , HiOutlineLockOpen , HiOutlineDocumentDuplicate } from "react-icons/hi" ;
911
10- const FACTOR_MAP : Record < string , { title : string ; icon ?: string } > = {
11- device : { title : "Device" , icon : "mobile-icon" } ,
12- seedPhrase : { title : "Recovery Phrase" , icon : "key-solid-icon" } ,
13- social : { title : "Social Recovery Factor" , icon : "key-solid-icon" } ,
14- password : { title : "Password" , icon : "key-solid-icon" } ,
12+ const FACTOR_MAP : Record < string , { title : string ; icon ?: React . ReactNode } > = {
13+ Authenticator : { title : "Authenticator" , icon : < HiOutlineLockOpen className = "text-app-gray-900 dark:text-app-white w-5 h-5" /> } ,
14+ seedPhrase : { title : "Seed Phrase" , icon : < HiOutlineDocumentDuplicate className = "text-app-gray-900 dark:text-app-white w-5 h-5" /> } ,
15+ tssSecurityQuestions : { title : "Password" , icon : < HiOutlineKey className = "text-app-gray-900 dark:text-app-white w-5 h-5" /> } ,
1516} ;
1617
17-
18- const shareDetails = [
19- // Example share details
20- { shareType : "device" , details : "Chrome 91 (Windows)" } ,
21- { shareType : "seedPhrase" , details : "Recovery Phrase" } ,
22- ] . map ( ( share ) => ( {
23- title : FACTOR_MAP [ share . shareType ] ?. title || "" ,
24- details : share . details ,
25- icon : FACTOR_MAP [ share . shareType ] ?. icon || "" ,
26- } ) ) ;
27-
2818const MfaCard : React . FC = ( ) => {
29- const { setAddShareType, coreKitInstance, setCoreKitStatus } = useCoreKit ( ) ;
19+ const { setAddShareType, coreKitInstance, setCoreKitStatus, shareDescriptions , existingModules , userInfo } = useCoreKit ( ) ;
3020 const navigate = useNavigate ( ) ;
31- const [ userInfo , setUserInfo ] = React . useState < any > ( { } ) ;
32-
33- React . useEffect ( ( ) => {
34- const fetchUserInfo = async ( ) => {
35- if ( ! coreKitInstance ) {
36- return ;
37- }
38- const userInfo = await coreKitInstance . getUserInfo ( ) ;
39- setUserInfo ( userInfo ) ;
40- } ;
41- fetchUserInfo ( ) ;
42- } , [ coreKitInstance ] ) ;
4321
4422 const addMfa = ( addShareType : AddShareType ) => {
4523 console . log ( "Add MFA" ) ;
@@ -79,54 +57,62 @@ const MfaCard: React.FC = () => {
7957 </ div >
8058
8159 < div className = "flex flex-col gap-y-2" >
82- < Button size = "sm" className = "gap-2 w-full !border-app-gray-300 !text-app-gray-800 dark:!text-app-white" variant = "secondary" onClick = { ( ) => addMfa ( "password" ) } >
83- Add Password
84- </ Button >
85- < Button size = "sm" className = "gap-2 w-full !border-app-gray-300 !text-app-gray-800 dark:!text-app-white" variant = "secondary" onClick = { ( ) => addMfa ( "phrase" ) } >
86- Add Recovery Phrase
87- </ Button >
88- < Button size = "sm" className = "gap-2 w-full !border-app-gray-300 !text-app-gray-800 dark:!text-app-white" variant = "secondary" onClick = { ( ) => addMfa ( "authenticator" ) } >
89- Add Authenticator Share
90- </ Button >
60+ { ! existingModules . includes ( "tssSecurityQuestions" ) && (
61+ < Button size = "sm" className = "gap-2 w-full !border-app-gray-300 !text-app-gray-800 dark:!text-app-white" variant = "secondary" onClick = { ( ) => addMfa ( "password" ) } >
62+ Add Password
63+ </ Button >
64+ ) }
65+ { ! existingModules . includes ( "seedPhrase" ) && (
66+ < Button size = "sm" className = "gap-2 w-full !border-app-gray-300 !text-app-gray-800 dark:!text-app-white" variant = "secondary" onClick = { ( ) => addMfa ( "phrase" ) } >
67+ Add Recovery Phrase
68+ </ Button >
69+ ) }
70+ { ! existingModules . includes ( "Authenticator" ) && (
71+ < Button size = "sm" className = "gap-2 w-full !border-app-gray-300 !text-app-gray-800 dark:!text-app-white" variant = "secondary" onClick = { ( ) => addMfa ( "authenticator" ) } >
72+ Add Authenticator Share
73+ </ Button >
74+ ) }
9175 < Button size = "sm" className = "gap-2 w-full !border-app-gray-300 !text-app-gray-800 dark:!text-app-white" variant = "secondary" onClick = { ( ) => criticalReset ( ) } >
9276 Criticial Reset
9377 </ Button >
9478 </ div >
9579
9680 < div className = "mt-4 mb-0 border-t border-app-gray-200 dark:border-app-gray-500" > </ div >
97-
98- < div className = "divide-y divide-app-gray-200 dark:divide-app-gray-500" >
99- < div className = "flex items-center py-4" >
100- < div className = "mr-2" >
101- { [ "email_passwordless" , "jwt" ] . includes ( userInfo . typeOfLogin ) ? (
102- < HiOutlineMail className = "text-app-gray-900 dark:text-app-white w-5 h-5" name = "mail-icon" height = { 20 } width = { 20 } />
103- ) : (
104- < img
105- className = "w-5 h-5"
106- src = { `https://images.web3auth.io/login-${ userInfo . typeOfLogin } -active.svg` }
107- alt = { `${ userInfo . typeOfLogin } icon` }
108- />
109- ) }
110- </ div >
111- < div >
112- < h4 className = "text-sm font-semibold text-app-gray-900 dark:text-app-white first-letter:capitalize" > { userInfo . typeOfLogin } </ h4 >
113- < p className = "text-xs text-app-gray-400" > { userInfo . verifierId } </ p >
81+ {
82+ userInfo && (
83+ < div className = "divide-y divide-app-gray-200 dark:divide-app-gray-500" >
84+ < div className = "flex items-center py-4" >
85+ < div className = "mr-2" >
86+ { [ "email_passwordless" , "jwt" ] . includes ( userInfo . typeOfLogin ) ? (
87+ < HiOutlineMail className = "text-app-gray-900 dark:text-app-white w-5 h-5" name = "mail-icon" height = { 20 } width = { 20 } />
88+ ) : (
89+ < img
90+ className = "w-5 h-5"
91+ src = { `https://images.web3auth.io/login-${ userInfo . typeOfLogin } -active.svg` }
92+ alt = { `${ userInfo . typeOfLogin } icon` }
93+ />
94+ ) }
95+ </ div >
96+ < div >
97+ < h4 className = "text-sm font-semibold text-app-gray-900 dark:text-app-white first-letter:capitalize" > { userInfo . typeOfLogin } </ h4 >
98+ < p className = "text-xs text-app-gray-400" > { userInfo . verifierId } </ p >
99+ </ div >
114100 </ div >
101+ { shareDescriptions && shareDescriptions . length > 0 && shareDescriptions . map ( ( shareDescription : ShareDescription ) => (
102+ < div key = { shareDescription . module } className = "flex items-center py-4" >
103+ < div className = "mr-2" >
104+ { /* <Icon name={shareDetail.icon || "key-icon"} className="text-app-gray-900 dark:text-app-white w-5 h-5" /> */ }
105+ { FACTOR_MAP [ shareDescription . module ] . icon }
106+ </ div >
107+ < div >
108+ < h4 className = "text-sm font-semibold text-app-gray-900 dark:text-app-white" > { FACTOR_MAP [ shareDescription . module ] . title } </ h4 >
109+ < p className = "text-xs text-app-gray-400" > { new Date ( shareDescription . dateAdded ) . toLocaleString ( ) } </ p >
110+ </ div >
111+ </ div >
112+ ) ) }
115113 </ div >
116- {
117- // shareDetails.map((shareDetail) => (
118- // <div key={shareDetail.title} className="flex items-center py-4">
119- // <div className="mr-2">
120- // {/* <Icon name={shareDetail.icon || "key-icon"} className="text-app-gray-900 dark:text-app-white w-5 h-5" /> */ }
121- // </div>
122- // <div>
123- // <h4 className="text-sm font-semibold text-app-gray-900 dark:text-app-white">{shareDetail.title}</h4>
124- // <p className="text-xs text-app-gray-400">{shareDetail.details}</p>
125- // </div>
126- // </div>
127- // ))
128- }
129- </ div >
114+ )
115+ }
130116 </ Card >
131117 ) ;
132118} ;
0 commit comments