@@ -2,19 +2,33 @@ package com.web3auth.core
22
33import android.content.Intent
44import android.net.Uri
5- import androidx.browser.customtabs.CustomTabsIntent
65import com.google.gson.GsonBuilder
76import com.google.gson.JsonArray
87import com.google.gson.JsonObject
98import com.web3auth.core.api.ApiHelper
109import com.web3auth.core.api.ApiService
1110import com.web3auth.core.keystore.KeyStoreManagerUtils
12- import com.web3auth.core.types.*
11+ import com.web3auth.core.types.ChainConfig
12+ import com.web3auth.core.types.ErrorCode
13+ import com.web3auth.core.types.ExtraLoginOptions
14+ import com.web3auth.core.types.LoginConfigItem
15+ import com.web3auth.core.types.LoginParams
16+ import com.web3auth.core.types.MFALevel
17+ import com.web3auth.core.types.REDIRECT_URL
18+ import com.web3auth.core.types.SessionResponse
19+ import com.web3auth.core.types.SignResponse
20+ import com.web3auth.core.types.UnKnownException
21+ import com.web3auth.core.types.UserCancelledException
22+ import com.web3auth.core.types.UserInfo
23+ import com.web3auth.core.types.WEBVIEW_URL
24+ import com.web3auth.core.types.Web3AuthError
25+ import com.web3auth.core.types.Web3AuthOptions
26+ import com.web3auth.core.types.Web3AuthResponse
1327import com.web3auth.session_manager_android.SessionManager
1428import kotlinx.coroutines.GlobalScope
1529import kotlinx.coroutines.launch
1630import org.json.JSONObject
17- import java.util.*
31+ import java.util.Locale
1832import java.util.concurrent.CompletableFuture
1933
2034class Web3Auth (web3AuthOptions : Web3AuthOptions ) {
@@ -140,21 +154,9 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions) {
140154 Uri .Builder ().scheme(sdkUrl.scheme).encodedAuthority(sdkUrl.encodedAuthority)
141155 .encodedPath(sdkUrl.encodedPath).appendPath(" start" ).fragment(hash).build()
142156 // print("url: => $url")
143- val defaultBrowser = context.getDefaultBrowser()
144- val customTabsBrowsers = context.getCustomTabsBrowsers()
145-
146- if (customTabsBrowsers.contains(defaultBrowser)) {
147- val customTabs = CustomTabsIntent .Builder ().build()
148- customTabs.intent.setPackage(defaultBrowser)
149- customTabs.launchUrl(context, url)
150- } else if (customTabsBrowsers.isNotEmpty()) {
151- val customTabs = CustomTabsIntent .Builder ().build()
152- customTabs.intent.setPackage(customTabsBrowsers[0 ])
153- customTabs.launchUrl(context, url)
154- } else {
155- // Open in browser externally
156- context.startActivity(Intent (Intent .ACTION_VIEW , url))
157- }
157+ val intent = Intent (context, CustomChromeTabsActivity ::class .java)
158+ intent.putExtra(WEBVIEW_URL , url.toString())
159+ context.startActivity(intent)
158160 }
159161 }
160162 }
@@ -175,15 +177,19 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions) {
175177 if (ApiHelper .isNetworkAvailable(web3AuthOption.context)) {
176178
177179 // fetch project config
178- fetchProjectConfig()
179-
180- this .authorizeSession().whenComplete { resp, error ->
181- if (error == null ) {
182- web3AuthResponse = resp
180+ fetchProjectConfig().whenComplete { _, err ->
181+ if (err == null ) {
182+ this .authorizeSession().whenComplete { resp, error ->
183+ if (error == null ) {
184+ web3AuthResponse = resp
185+ initializeCf.complete(null )
186+ } else {
187+ print (error)
188+ }
189+ }
183190 } else {
184- print (error )
191+ initializeCf.completeExceptionally(err )
185192 }
186- initializeCf.complete(null )
187193 }
188194 }
189195 return initializeCf
@@ -377,9 +383,8 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions) {
377383 return sessionCompletableFuture
378384 }
379385
380- private fun fetchProjectConfig () {
381- val projectConfigCompletableFuture: CompletableFuture <ProjectConfigResponse > =
382- CompletableFuture ()
386+ private fun fetchProjectConfig (): CompletableFuture <Boolean > {
387+ val projectConfigCompletableFuture: CompletableFuture <Boolean > = CompletableFuture ()
383388 val web3AuthApi =
384389 ApiHelper .getInstance(web3AuthOption.network.name).create(ApiService ::class .java)
385390 GlobalScope .launch {
@@ -400,6 +405,7 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions) {
400405 web3AuthOption.whiteLabel!! .merge(response.whitelabel)
401406 }
402407 }
408+ projectConfigCompletableFuture.complete(true )
403409 } else {
404410 projectConfigCompletableFuture.completeExceptionally(
405411 Exception (
@@ -420,6 +426,7 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions) {
420426 )
421427 }
422428 }
429+ return projectConfigCompletableFuture
423430 }
424431
425432 /* *
@@ -646,13 +653,22 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions) {
646653 companion object {
647654
648655 private var signResponse: SignResponse ? = null
656+ private var isCustomTabsClosed: Boolean = false
649657 fun setSignResponse (_response : SignResponse ? ) {
650658 signResponse = _response
651659 }
652660
653661 fun getSignResponse (): SignResponse ? {
654662 return signResponse
655663 }
664+
665+ fun setCustomTabsClosed (_isCustomTabsClosed : Boolean ) {
666+ isCustomTabsClosed = _isCustomTabsClosed
667+ }
668+
669+ fun getCustomTabsClosed (): Boolean {
670+ return isCustomTabsClosed
671+ }
656672 }
657673}
658674
0 commit comments