Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BOM_1.0.0 #8

Merged
merged 60 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
4c08ee6
Connect when intention to use Relay
jakubuid Aug 26, 2024
6b147a8
Open connection lifecycle
jakubuid Aug 29, 2024
c8c53b7
Add init event
jakubuid Aug 29, 2024
2dbab7b
Add retry connection flow
jakubuid Aug 30, 2024
d50bfc5
Handle connection retries
jakubuid Sep 2, 2024
20caac1
Merge branch 'develop' of github.com:WalletConnect/WalletConnectKotli…
jakubuid Sep 2, 2024
3eb4a7c
Clean up
jakubuid Sep 2, 2024
598e3f3
Test fixing
jakubuid Sep 3, 2024
e740b02
Init migration commit
jakubuid Sep 3, 2024
894648e
Merge pull request #1 from reown-com/feat/open_connection_lifecycle
jakubuid Sep 3, 2024
ec96798
Merge branch 'develop' of github.com:reown-com/reown-kotlin into reow…
jakubuid Sep 3, 2024
cafab5b
Remove Chat and Auth SDKs
jakubuid Sep 4, 2024
7cd42ca
ReadMes update
jakubuid Sep 4, 2024
2cf8eeb
Rename Web3Wallet to WalletKit
jakubuid Sep 4, 2024
861bba0
Change activity and application class names
jakubuid Sep 4, 2024
7975bff
Rename Web3Modal to AppKit
jakubuid Sep 4, 2024
b1a3fff
Rename com.walletconnect.foundation to com.walletconnect.reown
jakubuid Sep 4, 2024
7bf671d
Remove walletconnectModal and use AppKit in sample Dapp
jakubuid Sep 4, 2024
f8bcdac
Migrate android core and modal core package to reown
jakubuid Sep 4, 2024
f5e4f78
Migrate sign to reown
jakubuid Sep 4, 2024
4592d1f
Migrate notify to reown
jakubuid Sep 5, 2024
13f0e1b
Migrate web3wallet to walletkit
jakubuid Sep 5, 2024
847ff78
Migrate web3modal to appkit
jakubuid Sep 5, 2024
1e2ee7c
Migrate sample wallet
jakubuid Sep 5, 2024
ed1aa4b
Migrate sample dapp
jakubuid Sep 5, 2024
241df1a
Fix SessionViewModel
jakubuid Sep 5, 2024
72a6204
Migrate sample common
jakubuid Sep 5, 2024
0526b40
Migrate sample modal
jakubuid Sep 5, 2024
cc5fb40
Migrate utils
jakubuid Sep 5, 2024
cb2380d
Change group id for maven central
jakubuid Sep 5, 2024
77792a6
Migrate last deps imports
jakubuid Sep 5, 2024
62b03a4
Clean up
jakubuid Sep 5, 2024
fdfb90f
Update
jakubuid Sep 5, 2024
ba4b8e9
Disable sonarcloud for now
jakubuid Sep 6, 2024
60641c4
Remove faulty dependency
jakubuid Sep 6, 2024
dc4bef3
Comment out firebase testers groups
jakubuid Sep 6, 2024
ea19003
Add new testers group
jakubuid Sep 6, 2024
3840bfb
Update
jakubuid Sep 6, 2024
309088b
Update user agent format
jakubuid Sep 9, 2024
12b4560
Typo
jakubuid Sep 9, 2024
97b0a27
Update publishing plugins
jakubuid Sep 9, 2024
011fe7b
ReadMe update
jakubuid Sep 9, 2024
b82f8a5
Merge pull request #2 from reown-com/reown_migration
jakubuid Sep 9, 2024
3fb9e5a
Updates
jakubuid Sep 10, 2024
bfcd177
Fix build
jakubuid Sep 10, 2024
96f85b1
Merge pull request #3 from reown-com/migration_clean_ups
jakubuid Sep 11, 2024
280c291
Fix calling activity twice on deep link flow
jakubuid Sep 12, 2024
6c7934b
Update app links
jakubuid Sep 12, 2024
e23a8b0
Optimize deep linking flow
jakubuid Sep 12, 2024
2bf0f74
New x-sdk-type
jakubuid Sep 12, 2024
a6b9b50
Merge pull request #4 from reown-com/sample_init
jakubuid Sep 13, 2024
029ac6e
Merge pull request #5 from reown-com/new_x-sdk-type
jakubuid Sep 13, 2024
886949a
Restore Sample Dapp state
jakubuid Sep 13, 2024
448f0fe
Fix disconnect ui glitch
jakubuid Sep 13, 2024
ff3ff80
Merge pull request #6 from reown-com/improve_dapp_state
jakubuid Sep 14, 2024
ead1ec8
Update nav component
jakubuid Sep 16, 2024
0c25d99
Fix Android Lint
jakubuid Sep 16, 2024
43bf105
Fix Android Lint
jakubuid Sep 16, 2024
a00f683
Merge pull request #7 from reown-com/update_navigation_dependency
jakubuid Sep 16, 2024
29bb931
Update
jakubuid Sep 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Open connection lifecycle
  • Loading branch information
jakubuid committed Aug 29, 2024
commit 6b147a8f720c348d4f174d1bd8061ca5b03904f0
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class CoreProtocol(private val koinApp: KoinApplication = wcKoinApp) : CoreInter
module { single { Echo } },
module { single { Push } },
module { single { Verify } },
coreJsonRpcModule(),
coreJsonRpcModule(connectionType),
corePairingModule(Pairing, PairingController),
keyServerModule(keyServerUrl),
explorerModule(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.walletconnect.android.internal.common

import com.tinder.scarlet.retry.BackoffStrategy
import kotlin.math.pow

class ConditionalExponentialBackoffStrategy(
private val initialDurationMillis: Long,
private val maxDurationMillis: Long
) : BackoffStrategy {
init {
require(initialDurationMillis > 0) { "initialDurationMillis, $initialDurationMillis, must be positive" }
require(maxDurationMillis > 0) { "maxDurationMillis, $maxDurationMillis, must be positive" }
}

override var shouldBackoff: Boolean = false

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

override fun backoffDurationMillisAt(retryCount: Int): Long =
maxDurationMillis.toDouble().coerceAtMost(initialDurationMillis.toDouble() * 2.0.pow(retryCount.toDouble())).toLong()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.walletconnect.android.internal.common.connection

import kotlinx.coroutines.flow.StateFlow

interface ConnectionLifecycle {
val onResume: StateFlow<Boolean?>
fun reconnect()
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,38 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.launch
import java.util.concurrent.TimeUnit

internal class DefaultConnectionLifecycle(
application: Application,
private val lifecycleRegistry: LifecycleRegistry = LifecycleRegistry()
) : Lifecycle by lifecycleRegistry {
) : Lifecycle by lifecycleRegistry, ConnectionLifecycle {
private val job = SupervisorJob()
private var scope = CoroutineScope(job + Dispatchers.Default)

private val _onResume = MutableStateFlow<Boolean?>(null)
override val onResume: StateFlow<Boolean?> = _onResume.asStateFlow()

init {
application.registerActivityLifecycleCallbacks(ActivityLifecycleCallbacks())
}

fun connect() {
println("kobe: ApplicationResumedLifecycle; connect()")

override fun reconnect() {
println("kobe: reconnect()")
lifecycleRegistry.onNext(Lifecycle.State.Stopped.WithReason())
lifecycleRegistry.onNext(Lifecycle.State.Started)
}

fun disconnect() {
println("kobe: ApplicationResumedLifecycle; disconnect()")

lifecycleRegistry.onNext(Lifecycle.State.Stopped.WithReason(ShutdownReason(1000, "App is paused")))
}

private inner class ActivityLifecycleCallbacks : Application.ActivityLifecycleCallbacks {
var isResumed: Boolean = false
var job: Job? = null

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

job = scope.launch {
Expand All @@ -52,21 +53,24 @@ internal class DefaultConnectionLifecycle(
println("kobe: onPaused; disconnect()")
lifecycleRegistry.onNext(Lifecycle.State.Stopped.WithReason(ShutdownReason(1000, "App is paused")))
job = null
_onResume.value = false
}
}
}

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

if (job?.isActive == true) {
job?.cancel()
job = null
}

//todo: should auto-connect on resume when subscriptions are present
// println("kobe: onResume; connect()")
// lifecycleRegistry.onNext(Lifecycle.State.Started)

scope.launch {
_onResume.value = true
}
}

override fun onActivityStarted(activity: Activity) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ package com.walletconnect.android.internal.common.connection

import com.tinder.scarlet.Lifecycle
import com.tinder.scarlet.lifecycle.LifecycleRegistry
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow

internal class ManualConnectionLifecycle(
private val lifecycleRegistry: LifecycleRegistry = LifecycleRegistry(),
) : Lifecycle by lifecycleRegistry {
) : Lifecycle by lifecycleRegistry, ConnectionLifecycle {
fun connect() {
lifecycleRegistry.onNext(Lifecycle.State.Started)
}
Expand All @@ -16,7 +18,10 @@ internal class ManualConnectionLifecycle(
lifecycleRegistry.onNext(Lifecycle.State.Stopped.WithReason())
}

fun restart() {
override val onResume: StateFlow<Boolean?>
get() = MutableStateFlow(null)

override fun reconnect() {
lifecycleRegistry.onNext(Lifecycle.State.Stopped.WithReason())
lifecycleRegistry.onNext(Lifecycle.State.Started)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
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
import com.walletconnect.android.internal.common.json_rpc.domain.link_mode.LinkModeJsonRpcInteractor
import com.walletconnect.android.internal.common.json_rpc.domain.link_mode.LinkModeJsonRpcInteractorInterface
Expand All @@ -9,16 +12,26 @@ import com.walletconnect.android.internal.common.model.type.RelayJsonRpcInteract
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.utils.JsonAdapterEntry
import com.walletconnect.utils.addDeserializerEntry
import com.walletconnect.utils.addSerializerEntry
import org.koin.android.ext.koin.androidContext
import org.koin.core.qualifier.named
import org.koin.core.scope.Scope
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() = module {
fun coreJsonRpcModule(connectionType: ConnectionType) = module {

single<RelayJsonRpcInteractorInterface> {
RelayJsonRpcInteractor(
Expand All @@ -27,7 +40,8 @@ fun coreJsonRpcModule() = module {
jsonRpcHistory = get(),
pushMessageStorage = get(),
logger = get(named(AndroidCommonDITags.LOGGER)),
connectionLifecycle = get(named(AndroidCommonDITags.DEFAULT_CONNECTION_LIFECYCLE))
connectionLifecycle = getConnectionLifecycle(connectionType),
backoffStrategy = get()
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import com.squareup.moshi.Moshi
import com.tinder.scarlet.Lifecycle
import com.tinder.scarlet.Scarlet
import com.tinder.scarlet.messageadapter.moshi.MoshiMessageAdapter
import com.tinder.scarlet.retry.ExponentialBackoffStrategy
import com.tinder.scarlet.websocket.okhttp.newWebSocketFactory
import com.walletconnect.android.BuildConfig
import com.walletconnect.android.internal.common.ConditionalExponentialBackoffStrategy
import com.walletconnect.android.internal.common.connection.ConnectivityState
import com.walletconnect.android.internal.common.connection.DefaultConnectionLifecycle
import com.walletconnect.android.internal.common.connection.ManualConnectionLifecycle
Expand Down Expand Up @@ -111,16 +111,15 @@ fun coreAndroidNetworkModule(serverUrl: String, connectionType: ConnectionType,

single<DefaultConnectionLifecycle>(named(AndroidCommonDITags.DEFAULT_CONNECTION_LIFECYCLE)) {
DefaultConnectionLifecycle(androidApplication())
// AndroidLifecycle.ofApplicationForeground(androidApplication()) //todo: combine with connectivity check?
}

single { ExponentialBackoffStrategy(INIT_BACKOFF_MILLIS, TimeUnit.SECONDS.toMillis(MAX_BACKOFF_SEC)) }
single { ConditionalExponentialBackoffStrategy(INIT_BACKOFF_MILLIS, TimeUnit.SECONDS.toMillis(MAX_BACKOFF_SEC)) }

single { FlowStreamAdapter.Factory() }

single(named(AndroidCommonDITags.SCARLET)) {
Scarlet.Builder()
.backoffStrategy(get<ExponentialBackoffStrategy>())
.backoffStrategy((get<ConditionalExponentialBackoffStrategy>()))
.webSocketFactory(get<OkHttpClient>(named(AndroidCommonDITags.OK_HTTP)).newWebSocketFactory(get<String>(named(AndroidCommonDITags.RELAY_URL))))
.lifecycle(getLifecycle(connectionType))
.addMessageAdapterFactory(get<MoshiMessageAdapter.Factory>(named(AndroidCommonDITags.MSG_ADAPTER)))
Expand Down
Loading