Skip to content

Commit

Permalink
Add retry connection flow
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubuid committed Aug 30, 2024
1 parent c8c53b7 commit 2dbab7b
Show file tree
Hide file tree
Showing 18 changed files with 330 additions and 294 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class ConditionalExponentialBackoffStrategy(
override var shouldBackoff: Boolean = false

fun shouldBackoff(shouldBackoff: Boolean) {
println("kobe:be Sending shouldBackoff: $shouldBackoff")
this.shouldBackoff = shouldBackoff
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import android.os.Bundle
import com.tinder.scarlet.Lifecycle
import com.tinder.scarlet.ShutdownReason
import com.tinder.scarlet.lifecycle.LifecycleRegistry
import com.walletconnect.foundation.network.ConnectionLifecycle
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
Expand All @@ -34,7 +35,6 @@ internal class DefaultConnectionLifecycle(
}

override fun reconnect() {
println("kobe: reconnect()")
lifecycleRegistry.onNext(Lifecycle.State.Stopped.WithReason())
lifecycleRegistry.onNext(Lifecycle.State.Started)
}
Expand All @@ -44,13 +44,11 @@ internal class DefaultConnectionLifecycle(
var job: Job? = null

override fun onActivityPaused(activity: Activity) {
println("kobe: pause")
isResumed = false

job = scope.launch {
delay(TimeUnit.SECONDS.toMillis(30))
if (!isResumed) {
println("kobe: onPaused; disconnect()")
lifecycleRegistry.onNext(Lifecycle.State.Stopped.WithReason(ShutdownReason(1000, "App is paused")))
job = null
_onResume.value = false
Expand All @@ -59,7 +57,6 @@ internal class DefaultConnectionLifecycle(
}

override fun onActivityResumed(activity: Activity) {
println("kobe: resume")
isResumed = true

if (job?.isActive == true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package com.walletconnect.android.internal.common.connection

import com.tinder.scarlet.Lifecycle
import com.tinder.scarlet.lifecycle.LifecycleRegistry
import com.walletconnect.foundation.network.ConnectionLifecycle
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.walletconnect.android.internal.common.di

import com.squareup.moshi.Moshi
import com.walletconnect.android.internal.common.connection.ConnectionLifecycle
import com.walletconnect.android.internal.common.connection.DefaultConnectionLifecycle
import com.walletconnect.android.internal.common.connection.ManualConnectionLifecycle
import com.walletconnect.android.internal.common.json_rpc.data.JsonRpcSerializer
Expand All @@ -13,6 +12,7 @@ import com.walletconnect.android.internal.common.model.type.SerializableJsonRpc
import com.walletconnect.android.pairing.model.PairingJsonRpcMethod
import com.walletconnect.android.pairing.model.PairingRpc
import com.walletconnect.android.relay.ConnectionType
import com.walletconnect.foundation.network.ConnectionLifecycle
import com.walletconnect.utils.JsonAdapterEntry
import com.walletconnect.utils.addDeserializerEntry
import com.walletconnect.utils.addSerializerEntry
Expand All @@ -23,13 +23,6 @@ import org.koin.dsl.module
import kotlin.reflect.KClass


fun Scope.getConnectionLifecycle(connectionType: ConnectionType): ConnectionLifecycle =
if (connectionType == ConnectionType.MANUAL) {
get<ManualConnectionLifecycle>(named(AndroidCommonDITags.MANUAL_CONNECTION_LIFECYCLE))
} else {
get<DefaultConnectionLifecycle>(named(AndroidCommonDITags.DEFAULT_CONNECTION_LIFECYCLE))
}

@JvmSynthetic
fun coreJsonRpcModule(connectionType: ConnectionType) = module {

Expand All @@ -40,7 +33,6 @@ fun coreJsonRpcModule(connectionType: ConnectionType) = module {
jsonRpcHistory = get(),
pushMessageStorage = get(),
logger = get(named(AndroidCommonDITags.LOGGER)),
connectionLifecycle = getConnectionLifecycle(connectionType),
backoffStrategy = get()
)
}
Expand Down
Loading

0 comments on commit 2dbab7b

Please sign in to comment.