11import { Box , Button , Heading , Layer , Text } from 'grommet' ;
2- import { useContext , useState } from 'react' ;
2+ import { useContext , useEffect , useState } from 'react' ;
33import { WalletContext } from 'renderer/context/walletContext' ;
44import truncateEthAddress from 'truncate-eth-address' ;
55import { useAccount , useConnect , useDisconnect } from 'wagmi' ;
6+ import { web3AuthInstance } from '../Web3AuthInstance' ;
7+ import { getPublicCompressed } from "@toruslabs/eccrypto" ;
68
79function Wallet ( ) {
810 const { address } = useAccount ( ) ;
@@ -21,6 +23,53 @@ function Wallet() {
2123 wagmiDisconnect ( ) ;
2224 } ;
2325
26+ interface UserInfo {
27+ email : string ;
28+ address : string ;
29+ name ?: string ;
30+ profileImage ?: string ;
31+ aggregateVerifier ?: string ;
32+ verifier ?: string ;
33+ verifierId ?: string ;
34+ typeOfLogin ?: string ;
35+ dappShare ?: string ;
36+ idToken ?: string ; //jwt
37+ oAuthIdToken ?: string ;
38+ oAuthAccessToken ?: string ;
39+ }
40+
41+ const loadUserInfo = async ( ) => {
42+ try {
43+ const privateKey = await web3AuthInstance . provider ?. request ( {
44+ method : "eth_private_key" ,
45+ } ) as string ;
46+
47+ const publicKey = getPublicCompressed ( Buffer . from ( privateKey . padStart ( 64 , "0" ) , "hex" ) ) . toString ( "hex" ) ;
48+ const user = await web3AuthInstance . getUserInfo ( ) ;
49+
50+ const res = await fetch ( "https://us-central1-flock-demo-design.cloudfunctions.net/postEmailToDB" , {
51+ method : "POST" ,
52+ headers : {
53+ "Content-Type" : "application/json" ,
54+ Authorization : "Bearer " + user . idToken ,
55+ } ,
56+ body : JSON . stringify ( { pubKey : publicKey , email : user . email , wallet : address } ) ,
57+ } ) ;
58+
59+ console . log ( res , "success!" )
60+ return res . json ( ) ;
61+
62+ } catch ( error ) {
63+ console . error ( 'Error loading user info:' , error ) ;
64+ }
65+ } ;
66+
67+ useEffect ( ( ) => {
68+ if ( address ) {
69+ loadUserInfo ( ) ;
70+ }
71+ } , [ address ] ) ;
72+
2473 if ( showWalletSettings ) {
2574 return (
2675 < Layer onEsc = { ( ) => setShowWalletSettings ( false ) } full >
0 commit comments