@@ -3,21 +3,18 @@ package com.web3auth.app
33import android.content.Intent
44import android.net.Uri
55import android.os.Bundle
6+ import android.text.method.ScrollingMovementMethod
67import android.util.Log
78import android.view.View
89import android.widget.*
910import androidx.appcompat.app.AppCompatActivity
1011import com.google.android.material.textfield.TextInputLayout
1112import com.google.gson.Gson
12- import com.web3auth.core.types.WhiteLabelData
13- import com.web3auth.core.types.Provider
1413import com.web3auth.core.Web3Auth
1514import com.web3auth.core.isEmailValid
16- import com.web3auth.core.types.ExtraLoginOptions
17- import com.web3auth.core.types.LoginParams
18- import com.web3auth.core.types.Web3AuthOptions
19- import com.web3auth.core.types.Web3AuthResponse
15+ import com.web3auth.core.types.*
2016import java8.util.concurrent.CompletableFuture
17+ import org.json.JSONObject
2118
2219class MainActivity : AppCompatActivity (), AdapterView.OnItemClickListener {
2320 private lateinit var web3Auth: Web3Auth
@@ -59,19 +56,18 @@ class MainActivity : AppCompatActivity(), AdapterView.OnItemClickListener {
5956 if (error == null ) {
6057 reRender(loginResponse)
6158 } else {
62- Log .d(" MainActivity_Web3Auth" , error.message ? : " Something went wrong" )
59+ Log .d(" MainActivity_Web3Auth" , error.message ? : " Something went wrong" )
6360 }
64-
6561 }
6662 }
6763
6864 private fun signOut () {
69- val logoutCompletableFuture = web3Auth.logout()
65+ val logoutCompletableFuture = web3Auth.logout()
7066 logoutCompletableFuture.whenComplete { _, error ->
7167 if (error == null ) {
7268 reRender(Web3AuthResponse ())
7369 } else {
74- Log .d(" MainActivity_Web3Auth" , error.message ? : " Something went wrong" )
70+ Log .d(" MainActivity_Web3Auth" , error.message ? : " Something went wrong" )
7571 }
7672 }
7773 }
@@ -86,7 +82,9 @@ class MainActivity : AppCompatActivity(), AdapterView.OnItemClickListener {
8682 val key = web3AuthResponse.privKey
8783 val userInfo = web3AuthResponse.userInfo
8884 if (key is String && key.isNotEmpty()) {
89- contentTextView.text = gson.toJson(web3AuthResponse)
85+ val jsonObject = JSONObject (gson.toJson(web3AuthResponse))
86+ contentTextView.text = jsonObject.toString(4 )
87+ contentTextView.movementMethod = ScrollingMovementMethod ()
9088 contentTextView.visibility = View .VISIBLE
9189 signInButton.visibility = View .GONE
9290 signOutButton.visibility = View .VISIBLE
@@ -107,21 +105,39 @@ class MainActivity : AppCompatActivity(), AdapterView.OnItemClickListener {
107105
108106 // Configure Web3Auth
109107 web3Auth = Web3Auth (
110- Web3AuthOptions (context = this ,
111- clientId = getString(R .string.web3auth_project_id),
112- network = Web3Auth .Network .MAINNET ,
113- redirectUrl = Uri .parse(" torusapp://org.torusresearch.web3authexample/redirect" ),
108+ Web3AuthOptions (
109+ context = this ,
110+ clientId = getString(R .string.web3auth_project_id),
111+ network = Web3Auth .Network .MAINNET ,
112+ redirectUrl = Uri .parse(" torusapp://org.torusresearch.web3authexample/redirect" ),
114113 whiteLabel = WhiteLabelData (
115114 " Web3Auth Sample App" , null , null , " en" , true ,
116115 hashMapOf(
117116 " primary" to " #123456"
118117 )
118+ ),
119+ loginConfig = hashMapOf(
120+ " loginConfig" to LoginConfigItem (
121+ " torus" ,
122+ typeOfLogin = TypeOfLogin .GOOGLE ,
123+ name = " "
124+ )
119125 )
120126 )
121127 )
122128
123129 web3Auth.setResultUrl(intent.data)
124130
131+ // for session response
132+ val sessionResponse: CompletableFuture <Web3AuthResponse > = web3Auth.sessionResponse()
133+ sessionResponse.whenComplete { loginResponse, error ->
134+ if (error == null ) {
135+ reRender(loginResponse)
136+ } else {
137+ Log .d(" MainActivity_Web3Auth" , error.message ? : " Something went wrong" )
138+ }
139+ }
140+
125141 // Setup UI and event handlers
126142 val signInButton = findViewById<Button >(R .id.signInButton)
127143 signInButton.setOnClickListener { signIn() }
0 commit comments