@@ -16,8 +16,6 @@ import com.web3auth.core.keystore.KeyStoreManagerUtils
1616import com.web3auth.core.types.AuthConnection
1717import com.web3auth.core.types.ErrorCode
1818import com.web3auth.core.types.ExtraLoginOptions
19- import com.web3auth.core.types.InitOptions
20- import com.web3auth.core.types.InitParams
2119import com.web3auth.core.types.LoginParams
2220import com.web3auth.core.types.MFALevel
2321import com.web3auth.core.types.ProjectConfigResponse
@@ -91,42 +89,6 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions, context: Context) : WebViewResu
9189 KeyStoreManagerUtils .getKeyGenerator()
9290 }
9391
94- private fun getInitOptions (): InitOptions {
95- return InitOptions (
96- clientId = web3AuthOption.clientId,
97- network = web3AuthOption.web3AuthNetwork.name.lowercase(Locale .ROOT ),
98- redirectUrl = web3AuthOption.redirectUrl.toString(),
99- whiteLabel = web3AuthOption.walletServicesConfig?.whiteLabel.let { gson.toJson(it) },
100- authConnectionConfig = web3AuthOption.authConnectionConfig?.let { gson.toJson(it) },
101- buildEnv = web3AuthOption.authBuildEnv.name.lowercase(Locale .ROOT ),
102- mfaSettings = web3AuthOption.mfaSettings?.let { gson.toJson(it) },
103- sessionTime = web3AuthOption.sessionTime,
104- originData = web3AuthOption.originData?.let { gson.toJson(it) },
105- dashboardUrl = web3AuthOption.dashboardUrl
106- )
107- }
108-
109- /* *
110- * Retrieves the initialization parameters as a JSONObject.
111- *
112- * @param params The optional login parameters required for initialization. Default is null.
113- * @return The initialization parameters as a JSONObject.
114- */
115- private fun getInitParams (params : LoginParams ? ): InitParams {
116- return InitParams (
117- authConnection = params?.authConnection?.name?.lowercase(Locale .ROOT ),
118- authConnectionId = params?.authConnectionId,
119- groupedAuthConnectionId = params?.groupedAuthConnectionId,
120- extraLoginOptions = params?.extraLoginOptions?.let { gson.toJson(it) },
121- redirectUrl = web3AuthOption.redirectUrl.toString(),
122- mfaLevel = params?.mfaLevel?.name?.lowercase(Locale .ROOT ),
123- curve = params?.curve?.name?.lowercase(Locale .ROOT ),
124- dappShare = params?.dappShare,
125- appState = params?.appState,
126- dappUrl = params?.dappUrl
127- )
128- }
129-
13092 /* *
13193 * Makes a request with the specified action type and login parameters.
13294 *
@@ -154,7 +116,9 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions, context: Context) : WebViewResu
154116 web3AuthOption.web3AuthNetwork.toString().lowercase(Locale .ROOT )
155117 )
156118
157- val initParamsJson = JSONObject (gson.toJson(params))
119+ val initParamsJson = params?.let {
120+ JSONObject (gson.toJson(it))
121+ } ? : JSONObject ()
158122
159123 if (actionType == " manage_mfa" ) {
160124 initParamsJson.put(" redirectUrl" , web3AuthOption.dashboardUrl)
@@ -310,7 +274,7 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions, context: Context) : WebViewResu
310274 sessionManager.setSessionId(sessionId)
311275
312276 // Rehydrate Session
313- this .authorizeSession(web3AuthOption.redirectUrl.toString() , baseContext)
277+ this .authorizeSession(web3AuthOption.redirectUrl, baseContext)
314278 .whenComplete { resp, error ->
315279 runOnUIThread {
316280 if (error == null ) {
@@ -360,7 +324,7 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions, context: Context) : WebViewResu
360324 * @param loginParams The login parameters required for authentication.
361325 * @return A CompletableFuture<Web3AuthResponse> representing the asynchronous operation, containing the Web3AuthResponse upon successful login.
362326 */
363- fun login (loginParams : LoginParams ): CompletableFuture <Web3AuthResponse > {
327+ private fun login (loginParams : LoginParams ): CompletableFuture <Web3AuthResponse > {
364328 web3AuthOption.authConnectionConfig
365329 ?.firstOrNull()
366330 ?.let { config ->
@@ -443,12 +407,14 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions, context: Context) : WebViewResu
443407 sessionManager.setSessionId(sessionId)
444408 sessionManager.createSession(gson.toJson(response), ctx)
445409 .whenComplete { result, err ->
446- if (err == null ) {
447- web3AuthResponse = response
448- SessionManager .saveSessionIdToStorage(result)
449- sessionManager.setSessionId(result)
450- if (::loginCompletableFuture.isInitialized)
451- loginCompletableFuture.complete(web3AuthResponse)
410+ runOnUIThread {
411+ if (err == null ) {
412+ web3AuthResponse = response
413+ SessionManager .saveSessionIdToStorage(result)
414+ sessionManager.setSessionId(result)
415+ if (::loginCompletableFuture.isInitialized)
416+ loginCompletableFuture.complete(web3AuthResponse)
417+ }
452418 }
453419 }
454420 }
0 commit comments