Skip to content

Commit

Permalink
Remove initialization counter
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubuid committed Oct 29, 2024
1 parent 893084b commit 9eea756
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,13 @@ object WalletKit {
@Throws(IllegalStateException::class)
fun initialize(params: Wallet.Params.Init, onSuccess: () -> Unit = {}, onError: (Wallet.Model.Error) -> Unit) {
coreClient = params.core
var clientInitCounter = 0
val onSuccessfulInitialization: () -> Unit = { clientInitCounter++ }

SignClient.initialize(Sign.Params.Init(params.core), onSuccess = onSuccessfulInitialization) { error ->
SignClient.initialize(Sign.Params.Init(params.core), onSuccess = onSuccess) { error ->
if (error.throwable is SignClientAlreadyInitializedException) {
onSuccessfulInitialization()
onSuccess()
} else {
onError(Wallet.Model.Error(error.throwable))
}
}
validateInitializationCount(clientInitCounter, onSuccess, onError)
}

@Throws(IllegalStateException::class)
Expand Down Expand Up @@ -340,24 +336,4 @@ object WalletKit {
fun getListOfVerifyContexts(): List<Wallet.Model.VerifyContext> {
return SignClient.getListOfVerifyContexts().map { verifyContext -> verifyContext.toWallet() }
}

private fun validateInitializationCount(clientInitCounter: Int, onSuccess: () -> Unit, onError: (Wallet.Model.Error) -> Unit) {
scope.launch {
try {
withTimeout(TIMEOUT) {
while (true) {
if (clientInitCounter == 2) {
onSuccess()
return@withTimeout
}
delay(100)
}
}
} catch (e: Exception) {
onError(Wallet.Model.Error(e))
}
}
}

private const val TIMEOUT: Long = 10000
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ class WalletKitApplication : Application() {
FirebaseMessaging.getInstance().token.addOnSuccessListener { token ->
WalletKit.registerDeviceToken(firebaseAccessToken = token, enableEncrypted = true,
onSuccess = {
println("kobe; Successfully registered firebase token for Web3Wallet: $token")
println("Successfully registered firebase token for Web3Wallet: $token")
},
onError = {
println("kobe; Error while registering firebase token for Web3Wallet: ${it.throwable}")
println("Error while registering firebase token for Web3Wallet: ${it.throwable}")
}
)
}
Expand Down

0 comments on commit 9eea756

Please sign in to comment.