@@ -10,13 +10,17 @@ import android.view.ViewTreeObserver.OnScrollChangedListener
1010import android.webkit.*
1111import androidx.appcompat.app.AppCompatActivity
1212import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
13- import com.web3auth.core.types.WALLET_URL
13+ import com.google.gson.GsonBuilder
14+ import com.web3auth.core.types.REDIRECT_URL
15+ import com.web3auth.core.types.SignResponse
16+ import com.web3auth.core.types.WEBVIEW_URL
1417
1518class WebViewActivity : AppCompatActivity () {
1619
1720 private lateinit var webView: WebView
1821 private var swipeRefreshLayout: SwipeRefreshLayout ? = null
1922 private var mOnScrollChangedListener: OnScrollChangedListener ? = null
23+ private val gson = GsonBuilder ().disableHtmlEscaping().create()
2024
2125 @SuppressLint(" SetJavaScriptEnabled" )
2226 override fun onCreate (savedInstanceState : Bundle ? ) {
@@ -27,12 +31,26 @@ class WebViewActivity : AppCompatActivity() {
2731
2832 val extras = intent.extras
2933 if (extras != null ) {
30- val walletUrl = extras.getString(WALLET_URL )
34+ val webViewUrl = extras.getString(WEBVIEW_URL )
35+ val redirectUrl = extras.getString(REDIRECT_URL )
3136
3237 webView.webViewClient = object : WebViewClient () {
3338 override fun shouldOverrideUrlLoading (view : WebView ? , url : String? ): Boolean {
34- if (walletUrl != null ) {
35- view?.loadUrl(walletUrl)
39+ if (redirectUrl?.isNotEmpty() == true ) {
40+ if (url?.contains(redirectUrl) == true ) {
41+ val uri = Uri .parse(url)
42+ val hashUri = Uri .parse(uri.host + " ?" + uri.fragment)
43+ val b64Params = hashUri.getQueryParameter(" b64Params" )
44+ val b64ParamString =
45+ decodeBase64URLString(b64Params!! ).toString(Charsets .UTF_8 )
46+ val signResponse =
47+ gson.fromJson(b64ParamString, SignResponse ::class .java)
48+ Web3Auth .setSignResponse(signResponse)
49+ finish()
50+ }
51+ }
52+ if (webViewUrl != null ) {
53+ view?.loadUrl(webViewUrl)
3654 }
3755 return false
3856 }
@@ -48,8 +66,8 @@ class WebViewActivity : AppCompatActivity() {
4866 webSettings.userAgentString = null
4967 webSettings.setSupportMultipleWindows(true )
5068
51- if (walletUrl != null ) {
52- webView.loadUrl(walletUrl )
69+ if (webViewUrl != null ) {
70+ webView.loadUrl(webViewUrl )
5371 }
5472 }
5573
0 commit comments