Skip to content

Commit 8f31a45

Browse files
committed
feat: working code for login in pnp
Signed-off-by: Gaurav Goel <[email protected]>
1 parent 9f146c3 commit 8f31a45

File tree

5 files changed

+241
-74
lines changed

5 files changed

+241
-74
lines changed

app/src/main/java/com/web3auth/app/MainActivity.kt

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.web3auth.app
22

33
import android.content.Intent
4-
import android.net.Uri
54
import android.os.Bundle
65
import android.text.method.ScrollingMovementMethod
76
import android.util.Log
@@ -24,13 +23,11 @@ import com.web3auth.core.isPhoneNumberValid
2423
import com.web3auth.core.types.AuthConnection
2524
import com.web3auth.core.types.AuthConnectionConfig
2625
import com.web3auth.core.types.BuildEnv
27-
import com.web3auth.core.types.ChainNamespace
28-
import com.web3auth.core.types.Chains
29-
import com.web3auth.core.types.ExtraLoginOptions
3026
import com.web3auth.core.types.Language
3127
import com.web3auth.core.types.LoginParams
3228
import com.web3auth.core.types.ThemeModes
3329
import com.web3auth.core.types.UserInfo
30+
import com.web3auth.core.types.WalletServicesConfig
3431
import com.web3auth.core.types.Web3AuthOptions
3532
import com.web3auth.core.types.Web3AuthResponse
3633
import com.web3auth.core.types.WhiteLabelData
@@ -62,17 +59,20 @@ class MainActivity : AppCompatActivity(), AdapterView.OnItemClickListener {
6259
private var selectedLoginProvider: AuthConnection = AuthConnection.GOOGLE
6360

6461
private val gson = Gson()
62+
private var TEST_VERIFIER = "torus-test-health"
63+
private var TORUS_TEST_EMAIL = "[email protected]"
64+
private var SFA_ClientId = "YOUR_CLIENT_ID"
6565

6666
private fun signIn() {
6767
val hintEmailEditText = findViewById<EditText>(R.id.etEmailHint)
68-
var extraLoginOptions: ExtraLoginOptions? = null
68+
var loginHint: String? = null
6969
if (selectedLoginProvider == AuthConnection.EMAIL_PASSWORDLESS) {
7070
val hintEmail = hintEmailEditText.text.toString()
7171
if (hintEmail.isBlank() || !hintEmail.isEmailValid()) {
7272
Toast.makeText(this, "Please enter a valid Email.", Toast.LENGTH_LONG).show()
7373
return
7474
}
75-
extraLoginOptions = ExtraLoginOptions(login_hint = hintEmail)
75+
loginHint = hintEmail
7676
}
7777

7878
if (selectedLoginProvider == AuthConnection.SMS_PASSWORDLESS) {
@@ -81,13 +81,15 @@ class MainActivity : AppCompatActivity(), AdapterView.OnItemClickListener {
8181
Toast.makeText(this, "Please enter a valid Number.", Toast.LENGTH_LONG).show()
8282
return
8383
}
84-
extraLoginOptions = ExtraLoginOptions(login_hint = hintPhNo)
84+
loginHint = hintPhNo
8585
}
8686

8787
val loginCompletableFuture: CompletableFuture<Web3AuthResponse> = web3Auth.connectTo(
8888
LoginParams(
89-
AuthConnection.GOOGLE,
90-
authConnectionId = "w3ads", groupedAuthConnectionId = "aggregate-mobile"
89+
selectedLoginProvider,
90+
//authConnectionId = "w3ads",
91+
//groupedAuthConnectionId = "aggregate-mobile",
92+
loginHint = loginHint,
9193
), ctx = this.applicationContext
9294
)
9395
loginCompletableFuture.whenComplete { _, error ->
@@ -184,15 +186,17 @@ class MainActivity : AppCompatActivity(), AdapterView.OnItemClickListener {
184186
val options = Web3AuthOptions(
185187
clientId = "BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ",
186188
web3AuthNetwork = Web3AuthNetwork.SAPPHIRE_MAINNET,
187-
redirectUrl = Uri.parse("torusapp://org.torusresearch.web3authexample"),
189+
redirectUrl = "torusapp://org.torusresearch.web3authexample",
188190
//sdkUrl = "https://auth.mocaverse.xyz",
189191
//walletSdkUrl = "https://lrc-mocaverse.web3auth.io",
190-
whiteLabel = WhiteLabelData(
191-
"Web3Auth Sample App", null, null, null,
192-
Language.EN, ThemeModes.LIGHT, true,
193-
hashMapOf(
194-
"primary" to "#123456",
195-
"onPrimary" to "#0000FF"
192+
walletServicesConfig = WalletServicesConfig(
193+
whiteLabel = WhiteLabelData(
194+
"Web3Auth Sample App", null, null, null,
195+
Language.EN, ThemeModes.LIGHT, true,
196+
hashMapOf(
197+
"primary" to "#123456",
198+
"onPrimary" to "#0000FF"
199+
)
196200
)
197201
),
198202
authConnectionConfig = authConfig,
@@ -240,16 +244,7 @@ class MainActivity : AppCompatActivity(), AdapterView.OnItemClickListener {
240244

241245
val launchWalletButton = findViewById<Button>(R.id.launchWalletButton)
242246
launchWalletButton.setOnClickListener {
243-
val launchWalletCompletableFuture = web3Auth.showWalletUI(
244-
chainConfig = listOf(
245-
Chains(
246-
chainId = "0x89",
247-
rpcTarget = "https://1rpc.io/matic",
248-
chainNamespace = ChainNamespace.EIP155
249-
)
250-
),
251-
chainId = "0x89",
252-
)
247+
val launchWalletCompletableFuture = web3Auth.showWalletUI()
253248
launchWalletCompletableFuture.whenComplete { _, error ->
254249
if (error == null) {
255250
Log.d("MainActivity_Web3Auth", "Wallet launched successfully")
@@ -268,11 +263,7 @@ class MainActivity : AppCompatActivity(), AdapterView.OnItemClickListener {
268263
add("Android")
269264
}
270265
val signMsgCompletableFuture = web3Auth.request(
271-
chainConfig = Chains(
272-
chainId = "0x89",
273-
rpcTarget = "https://polygon-rpc.com/",
274-
chainNamespace = ChainNamespace.EIP155
275-
), "personal_sign", requestParams = params, appState = "web3Auth"
266+
"personal_sign", requestParams = params, appState = "web3Auth"
276267
)
277268
signMsgCompletableFuture.whenComplete { signResult, error ->
278269
if (error == null) {

0 commit comments

Comments
 (0)