Skip to content

Commit

Permalink
feat: Refactor initialize function
Browse files Browse the repository at this point in the history
Signed-off-by: Gaurav Goel <[email protected]>
  • Loading branch information
grvgoel81 authored and Gaurav Goel committed Nov 11, 2024
1 parent 2bd91fb commit 3fd8be3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
9 changes: 3 additions & 6 deletions app/src/main/java/com/web3auth/sfaexample/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,11 @@ class MainActivity : AppCompatActivity() {
singleFactorAuth = SingleFactorAuth(web3AuthOptions, this)
loginParams = LoginParams(TEST_VERIFIER, TORUS_TEST_EMAIL, idToken)

val sfakey = singleFactorAuth.initialize(this.applicationContext)
sfakey.whenComplete { response, error ->
if (response != null) {
singleFactorAuth.initialize(this.applicationContext).whenComplete { res, err ->
if (err == null) {
val text =
"Public Address: ${response?.publicAddress} , Private Key: ${response?.privateKey}"
"Public Address: ${singleFactorAuth.getSessionData()?.publicAddress} , Private Key: ${singleFactorAuth.getSessionData()?.privateKey}"
tv.text = text
} else {
tv.text = error.message
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class SingleFactorAuth(
sessionManager = SessionManager(ctx, web3AuthOptions.getSessionTime(), ctx.packageName)
}

fun initialize(ctx: Context): CompletableFuture<SessionData?> {
fun initialize(ctx: Context): CompletableFuture<Nothing?> {
return CompletableFuture.supplyAsync {
val savedSessionId = SessionManager.getSessionIdFromStorage()
sessionManager.setSessionId(savedSessionId)
Expand Down Expand Up @@ -85,8 +85,8 @@ class SingleFactorAuth(
userInfo = finalUserInfo
)
state
}.thenApplyAsync({ sessionData ->
sessionData
}.thenApplyAsync({ _ ->
null
}, { Handler(Looper.getMainLooper()).post(it) }).exceptionally { ex ->
throw Exception("Initialization failed", ex)
}
Expand Down

0 comments on commit 3fd8be3

Please sign in to comment.