@@ -2,19 +2,33 @@ package com.web3auth.core
2
2
3
3
import android.content.Intent
4
4
import android.net.Uri
5
- import androidx.browser.customtabs.CustomTabsIntent
6
5
import com.google.gson.GsonBuilder
7
6
import com.google.gson.JsonArray
8
7
import com.google.gson.JsonObject
9
8
import com.web3auth.core.api.ApiHelper
10
9
import com.web3auth.core.api.ApiService
11
10
import 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
13
27
import com.web3auth.session_manager_android.SessionManager
14
28
import kotlinx.coroutines.GlobalScope
15
29
import kotlinx.coroutines.launch
16
30
import org.json.JSONObject
17
- import java.util.*
31
+ import java.util.Locale
18
32
import java.util.concurrent.CompletableFuture
19
33
20
34
class Web3Auth (web3AuthOptions : Web3AuthOptions ) {
@@ -140,21 +154,9 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions) {
140
154
Uri .Builder ().scheme(sdkUrl.scheme).encodedAuthority(sdkUrl.encodedAuthority)
141
155
.encodedPath(sdkUrl.encodedPath).appendPath(" start" ).fragment(hash).build()
142
156
// 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)
158
160
}
159
161
}
160
162
}
@@ -175,15 +177,19 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions) {
175
177
if (ApiHelper .isNetworkAvailable(web3AuthOption.context)) {
176
178
177
179
// 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
+ }
183
190
} else {
184
- print (error )
191
+ initializeCf.completeExceptionally(err )
185
192
}
186
- initializeCf.complete(null )
187
193
}
188
194
}
189
195
return initializeCf
@@ -377,9 +383,8 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions) {
377
383
return sessionCompletableFuture
378
384
}
379
385
380
- private fun fetchProjectConfig () {
381
- val projectConfigCompletableFuture: CompletableFuture <ProjectConfigResponse > =
382
- CompletableFuture ()
386
+ private fun fetchProjectConfig (): CompletableFuture <Boolean > {
387
+ val projectConfigCompletableFuture: CompletableFuture <Boolean > = CompletableFuture ()
383
388
val web3AuthApi =
384
389
ApiHelper .getInstance(web3AuthOption.network.name).create(ApiService ::class .java)
385
390
GlobalScope .launch {
@@ -400,6 +405,7 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions) {
400
405
web3AuthOption.whiteLabel!! .merge(response.whitelabel)
401
406
}
402
407
}
408
+ projectConfigCompletableFuture.complete(true )
403
409
} else {
404
410
projectConfigCompletableFuture.completeExceptionally(
405
411
Exception (
@@ -420,6 +426,7 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions) {
420
426
)
421
427
}
422
428
}
429
+ return projectConfigCompletableFuture
423
430
}
424
431
425
432
/* *
@@ -646,13 +653,22 @@ class Web3Auth(web3AuthOptions: Web3AuthOptions) {
646
653
companion object {
647
654
648
655
private var signResponse: SignResponse ? = null
656
+ private var isCustomTabsClosed: Boolean = false
649
657
fun setSignResponse (_response : SignResponse ? ) {
650
658
signResponse = _response
651
659
}
652
660
653
661
fun getSignResponse (): SignResponse ? {
654
662
return signResponse
655
663
}
664
+
665
+ fun setCustomTabsClosed (_isCustomTabsClosed : Boolean ) {
666
+ isCustomTabsClosed = _isCustomTabsClosed
667
+ }
668
+
669
+ fun getCustomTabsClosed (): Boolean {
670
+ return isCustomTabsClosed
671
+ }
656
672
}
657
673
}
658
674
0 commit comments