@@ -4,37 +4,54 @@ import * as WebBrowser from "expo-web-browser";
44
55import { Button , Dimensions , ScrollView , StyleSheet , Text , TextInput , View } from "react-native" ;
66import Constants , { AppOwnership } from "expo-constants" ;
7- import React , { useEffect , useState } from "react" ;
8- import Web3Auth , { ChainNamespace , LOGIN_PROVIDER } from "@web3auth/react-native-sdk" ;
7+ import { useEffect , useState } from "react" ;
8+ import Web3Auth , { ChainNamespace , LOGIN_PROVIDER , OpenloginUserInfo } from "@web3auth/react-native-sdk" ;
99
1010import RPC from "../ethersRPC" ; // for using ethers.js
1111
12+ const chainConfig = {
13+ chainNamespace : ChainNamespace . EIP155 ,
14+ chainId : "0xaa36a7" ,
15+ rpcTarget : "https://rpc.ankr.com/eth_sepolia" ,
16+ // Avoid using public rpcTarget in production.
17+ // Use services like Infura, Quicknode etc
18+ displayName : "Ethereum Sepolia Testnet" ,
19+ blockExplorerUrl : "https://sepolia.etherscan.io" ,
20+ ticker : "ETH" ,
21+ tickerName : "Ethereum" ,
22+ decimals : 18 ,
23+ logo : "https://cryptologos.cc/logos/ethereum-eth-logo.png" ,
24+ } ;
25+
1226const resolvedRedirectUrl =
13- Constants . appOwnership == AppOwnership . Expo || Constants . appOwnership == AppOwnership . Guest
27+ Constants . appOwnership == AppOwnership . Expo
1428 ? Linking . createURL ( "web3auth" , { } )
1529 : Linking . createURL ( "web3auth" , { scheme : "com.anonymous.rnexpoexample" } ) ;
1630
17- const clientId = "BILxiaDYbvlcwNdeJsyXEUDieKdYPIHfSdvEabzidwYZ3zaGsEN6noiM5u8f-5wuIksJcOn-Ga1LWNqen1eUZbw " ;
31+ const clientId = "BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ " ;
1832
1933export default function App ( ) {
2034 const [ key , setKey ] = useState ( "" ) ;
21- const [ userInfo , setUserInfo ] = useState ( "" ) ;
35+ const [ userInfo , setUserInfo ] = useState ( { } ) ;
2236 const [ console , setConsole ] = useState ( "" ) ;
23- const [ web3auth , setWeb3Auth ] = useState ( null ) ;
24- const [ email , setEmail ] = React . useState ( "[email protected] " ) ; 37+ const [ web3auth , setWeb3Auth ] = useState < Web3Auth | null > ( null ) ;
38+ const [ email , setEmail ] = useState ( "[email protected] " ) ; 2539
2640 useEffect ( ( ) => {
2741 const init = async ( ) => {
2842 try {
2943 const auth = new Web3Auth ( WebBrowser , SecureStore , {
3044 clientId,
31- network : "cyan" , // or other networks
45+ network : "sapphire_mainnet" , // or other networks
46+ redirectUrl : resolvedRedirectUrl ,
47+ enableLogging : true ,
48+ buildEnv : "testing" ,
3249 } ) ;
3350 setWeb3Auth ( auth ) ;
3451 await auth . init ( ) ;
3552 if ( auth ?. privKey ) {
3653 uiConsole ( "Re logged in" ) ;
37- setUserInfo ( auth . userInfo ( ) ) ;
54+ setUserInfo ( auth . userInfo ( ) as OpenloginUserInfo ) ;
3855 setKey ( auth . privKey ) ;
3956 }
4057 } catch ( e ) {
@@ -47,16 +64,16 @@ export default function App() {
4764 const login = async ( ) => {
4865 try {
4966 setConsole ( "Logging in" ) ;
50- await web3auth . login ( {
67+ await web3auth ? .login ( {
5168 loginProvider : LOGIN_PROVIDER . EMAIL_PASSWORDLESS ,
5269 redirectUrl : resolvedRedirectUrl ,
5370 extraLoginOptions : {
5471 login_hint : email ,
5572 } ,
5673 } ) ;
5774
58- if ( web3auth . privKey ) {
59- setUserInfo ( web3auth . userInfo ( ) ) ;
75+ if ( web3auth ? .privKey ) {
76+ setUserInfo ( web3auth ? .userInfo ( ) as OpenloginUserInfo ) ;
6077 setKey ( web3auth . privKey ) ;
6178 uiConsole ( "Logged In" ) ;
6279 }
@@ -84,13 +101,7 @@ export default function App() {
84101 }
85102
86103 setConsole ( "Launch Wallet Services" ) ;
87- await web3auth . launchWalletServices ( {
88- chainNamespace : ChainNamespace . EIP155 ,
89- decimals : 18 ,
90- chainId : "0x1" ,
91- rpcTarget : "https://mainnet.infura.io/v3/daeee53504be4cd3a997d4f2718d33e0" ,
92- ticker : "ETH" ,
93- } ) ;
104+ await web3auth . launchWalletServices ( chainConfig ) ;
94105 } ;
95106
96107 const logout = async ( ) => {
@@ -103,7 +114,7 @@ export default function App() {
103114 await web3auth . logout ( ) ;
104115
105116 if ( ! web3auth . privKey ) {
106- setUserInfo ( undefined ) ;
117+ setUserInfo ( { } ) ;
107118 setKey ( "" ) ;
108119 uiConsole ( "Logged out" ) ;
109120 }
@@ -233,7 +244,7 @@ export default function App() {
233244 uiConsole ( res ) ;
234245 } ;
235246
236- const uiConsole = ( ...args ) => {
247+ const uiConsole = ( ...args : unknown [ ] ) => {
237248 setConsole ( `${ JSON . stringify ( args || { } , null , 2 ) } \n\n\n\n${ console } ` ) ;
238249 } ;
239250
0 commit comments