Skip to content

Commit

Permalink
Add extensive pairing logs
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubuid committed Jan 16, 2024
1 parent 68c30e7 commit 88499b6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,23 @@ internal class PairingEngine(
val inactivePairing = Pairing(pairingTopic, relay, symmetricKey, registeredMethods)

return inactivePairing.runCatching {
logger.log("Pairing created successfully")
pairingRepository.insertPairing(this)
metadataRepository.upsertPeerMetadata(this.topic, selfMetaData, AppMetaDataType.SELF)
jsonRpcInteractor.subscribe(this.topic) { error -> return@subscribe onFailure(error) }
jsonRpcInteractor.subscribe(this.topic,
onSuccess = { logger.log("Pairing - subscribed on pairing topic: $pairingTopic") },
onFailure = { error ->
logger.error("Pairing - subscribed failure on pairing topic: $pairingTopic, error: $error")
return@subscribe onFailure(error)
})

this.toCore()
}.onFailure { throwable ->
crypto.removeKeys(pairingTopic.value)
pairingRepository.deletePairing(pairingTopic)
metadataRepository.deleteMetaData(pairingTopic)
jsonRpcInteractor.unsubscribe(pairingTopic)
logger.error("Pairing - subscribed failure on pairing topic: $pairingTopic, error: $throwable")
onFailure(throwable)
}.getOrNull()
}
Expand All @@ -138,14 +145,18 @@ internal class PairingEngine(
val symmetricKey = walletConnectUri.symKey

try {
logger.log("Pairing started: ${inactivePairing.topic}")
if (pairingRepository.getPairingOrNullByTopic(inactivePairing.topic) != null) {
val pairing = pairingRepository.getPairingOrNullByTopic(inactivePairing.topic)
if (!pairing!!.isNotExpired()) {
logger.error("Pairing expired: ${inactivePairing.topic}")
return onFailure(ExpiredPairingException("Pairing expired: ${pairing.topic}"))
}
if (pairing.isActive) {
logger.error("Pairing already exists error: ${inactivePairing.topic}")
return onFailure(PairWithExistingPairingIsNotAllowed(PAIRING_NOT_ALLOWED_MESSAGE))
} else {
logger.log("Emitting activate pairing: ${inactivePairing.topic}")
scope.launch {
supervisorScope {
_activePairingTopicFlow.emit(inactivePairing.topic)
Expand All @@ -157,8 +168,16 @@ internal class PairingEngine(
pairingRepository.insertPairing(inactivePairing)
}

jsonRpcInteractor.subscribe(topic = inactivePairing.topic, onSuccess = { onSuccess() }, onFailure = { error -> return@subscribe onFailure(error) })
jsonRpcInteractor.subscribe(topic = inactivePairing.topic,
onSuccess = {
logger.log("Subscribe pairing topic success: ${inactivePairing.topic}")
onSuccess()
}, onFailure = { error ->
logger.error("Subscribe pairing topic error: ${inactivePairing.topic}, error: $error")
return@subscribe onFailure(error)
})
} catch (e: Exception) {
logger.error("Subscribe pairing topic error: ${inactivePairing.topic}, error: $e")
crypto.removeKeys(walletConnectUri.topic.value)
jsonRpcInteractor.unsubscribe(inactivePairing.topic)
onFailure(e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ class Web3WalletApplication : Application() {
// For testing purposes only
FirebaseMessaging.getInstance().token.addOnSuccessListener { token ->
addFirebaseBeagleModules = {

Web3Wallet.registerDeviceToken(firebaseAccessToken = token, enableEncrypted = true,
onSuccess = {
Timber.tag(tag(this)).e("Successfully registered firebase token for Web3Wallet")
Expand Down Expand Up @@ -179,10 +178,7 @@ class Web3WalletApplication : Application() {
),
onSuccess = {
logger.log("Unregister Success")

EthAccountDelegate.privateKey = text


registerAccount()
},
onError = { logger.error(it.throwable.stackTraceToString()) }
Expand Down

0 comments on commit 88499b6

Please sign in to comment.