@@ -8,6 +8,8 @@ import { HiOutlineDuplicate } from "react-icons/hi";
88import { HiOutlineCheckCircle } from "react-icons/hi" ;
99import { Link } from "./Link" ;
1010import useUnifiedRPC from "../composibles/useRpc" ;
11+ import { Dropdown } from "./DropDown" ;
12+ import { TextField } from "./TextField" ;
1113
1214const UserCard : React . FC = ( ) => {
1315 const { drawerHeading, setDrawerHeading, drawerInfo, setDrawerInfo, userInfo, coreKitInstance } = useCoreKit ( ) ;
@@ -18,7 +20,37 @@ const UserCard: React.FC = () => {
1820 const [ imageError , setImageError ] = React . useState ( false ) ;
1921 const [ currentDrawerHeading , setCurrentDrawerHeading ] = React . useState ( "" ) ;
2022 const [ currentDrawerInfo , setCurrentDrawerInfo ] = React . useState < any > ( null ) ;
23+ const [ walletAddresses , setWalletAddresses ] = React . useState < { index : number ; address : string } [ ] > ( [ ] ) ;
24+ const [ selectedWallet , setSelectedWallet ] = React . useState < string > ( "" ) ;
25+ const [ newWalletName , setNewWalletName ] = React . useState < string > ( "" ) ;
2126
27+ const fetchWalletAddresses = async ( ) => {
28+ const indices = await coreKitInstance . getTssWalletIndices ( ) ;
29+ indices . push ( { address : account , index : 0 } )
30+ indices . sort ( ( a , b ) => a . index - b . index ) ;
31+ setWalletAddresses ( indices ) ;
32+ if ( indices . length > 0 ) {
33+ setSelectedWallet ( indices [ 1 ] . address ) ;
34+ }
35+ } ;
36+
37+ React . useEffect ( ( ) => {
38+ if ( account )
39+ fetchWalletAddresses ( ) ;
40+ } , [ account ] ) ;
41+
42+ const createNewWallet = async ( ) => {
43+ const indices = coreKitInstance . getTssWalletIndices ( ) ;
44+ const newIndex = indices [ indices . length - 1 ] . index + 1 ;
45+ await coreKitInstance . setTssWalletIndex ( newIndex ) ;
46+ await fetchWalletAddresses ( ) ;
47+ } ;
48+
49+ const switchTssWalletIndex = async ( ) => {
50+ console . log ( "1" , coreKitInstance . getTssWalletIndices ( ) ) ;
51+ await coreKitInstance . setTssWalletIndex ( 1 ) ;
52+ console . log ( "2" , coreKitInstance . getTssWalletIndices ( ) ) ;
53+ } ;
2254 React . useEffect ( ( ) => {
2355 if ( drawerHeading ) {
2456 setCurrentDrawerHeading ( drawerHeading ) ;
@@ -35,7 +67,6 @@ const UserCard: React.FC = () => {
3567 }
3668 } , [ drawerInfo ] ) ;
3769
38-
3970 React . useEffect ( ( ) => {
4071 const getAccountRPC = async ( ) => {
4172 if ( coreKitInstance . state . userInfo ) {
@@ -55,6 +86,7 @@ const UserCard: React.FC = () => {
5586 setIsCopied ( true ) ;
5687 navigator . clipboard . writeText ( account ) ;
5788 setTimeout ( ( ) => {
89+ switchTssWalletIndex ( ) ;
5890 setIsCopied ( false ) ;
5991 } , 1000 ) ;
6092 } ;
@@ -101,27 +133,53 @@ const UserCard: React.FC = () => {
101133 </ div >
102134 < div className = "my-4 border-t border-app-gray-200 dark:border-app-gray-600" > </ div >
103135 < div className = "space-y-2" >
104- < Button
105- size = "sm"
106- className = "gap-2 w-full !border-app-gray-300 !text-app-gray-800 dark:!text-app-white"
107- variant = "secondary"
108- onClick = { handleCopyAddress }
109- >
110- { getTruncateString ( account ) }
111- < div className = "relative" >
112- { isCopied && (
113- < div className = "absolute bottom-[150%] left-1/2 -translate-x-1/2 bg-app-white dark:bg-app-gray-600 py-2 px-4 rounded-lg text-black text-sm text-center w-max shadow-md" >
114- Copied
115- < div className = "absolute border-8 border-b-0 border-r-transparent border-t-app-white dark:border-t-app-gray-600 border-l-transparent top-[100%] left-[calc(50%_-_8px)]" > </ div >
116- </ div >
117- ) }
118- { isCopied ? (
119- < HiOutlineCheckCircle className = { `cursor-pointer ${ isCopied ? "text-app-success" : "text-app-gray-800 dark:text-app-white" } ` } />
120- ) : (
121- < HiOutlineDuplicate className = { `cursor-pointer ${ isCopied ? "text-app-success" : "text-app-gray-800 dark:text-app-white" } ` } />
122- ) }
123- </ div >
136+ {
137+ selectedWallet && (
138+ < Dropdown
139+ options = { walletAddresses . map ( ( wallet ) => ( { name : getTruncateString ( wallet . address ) , value : wallet . address } ) ) }
140+ defaultValue = { selectedWallet }
141+ onChange = { ( val ) => setSelectedWallet ( val as string ) }
142+ classes = { { container : "w-full" } }
143+ />
144+ )
145+ }
146+ < TextField
147+ value = { newWalletName }
148+ onChange = { ( e ) => setNewWalletName ( e . target . value ) }
149+ label = "New Wallet Name"
150+ pill = { true }
151+ type = "text"
152+ className = "w-full rounded-md"
153+ placeholder = "Enter wallet name"
154+ />
155+ < Button onClick = { createNewWallet } className = "my-4" variant = "primary" block >
156+ Create New Wallet { selectedWallet }
124157 </ Button >
158+ {
159+ account && (
160+ < Button
161+ size = "sm"
162+ className = "gap-2 w-full !border-app-gray-300 !text-app-gray-800 dark:!text-app-white"
163+ variant = "secondary"
164+ onClick = { handleCopyAddress }
165+ >
166+ { getTruncateString ( account ) }
167+ < div className = "relative" >
168+ { isCopied && (
169+ < div className = "absolute bottom-[150%] left-1/2 -translate-x-1/2 bg-app-white dark:bg-app-gray-600 py-2 px-4 rounded-lg text-black text-sm text-center w-max shadow-md" >
170+ Copied
171+ < div className = "absolute border-8 border-b-0 border-r-transparent border-t-app-white dark:border-t-app-gray-600 border-l-transparent top-[100%] left-[calc(50%_-_8px)]" > </ div >
172+ </ div >
173+ ) }
174+ { isCopied ? (
175+ < HiOutlineCheckCircle className = { `cursor-pointer ${ isCopied ? "text-app-success" : "text-app-gray-800 dark:text-app-white" } ` } />
176+ ) : (
177+ < HiOutlineDuplicate className = { `cursor-pointer ${ isCopied ? "text-app-success" : "text-app-gray-800 dark:text-app-white" } ` } />
178+ ) }
179+ </ div >
180+ </ Button >
181+ )
182+ }
125183 </ div >
126184 < Drawer
127185 open = { openConsole }
0 commit comments