Skip to content

Commit

Permalink
Merge pull request #1246 from WalletConnect/develop
Browse files Browse the repository at this point in the history
BOM 1.20.0
  • Loading branch information
Talhaali00 authored Nov 16, 2023
2 parents 71968f3 + 40f59af commit eff4339
Show file tree
Hide file tree
Showing 71 changed files with 1,165 additions and 406 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/usr/bin/env kotlin
@file:Suppress("PrivatePropertyName")
@file:DependsOn("io.github.typesafegithub:github-workflows-kt:1.4.0")

import io.github.typesafegithub.workflows.actions.actions.CheckoutV4
import io.github.typesafegithub.workflows.domain.RunnerType.UbuntuLatest
import io.github.typesafegithub.workflows.domain.actions.Action
import io.github.typesafegithub.workflows.domain.actions.RegularAction
import io.github.typesafegithub.workflows.domain.triggers.Release
import io.github.typesafegithub.workflows.dsl.expressions.Contexts
import io.github.typesafegithub.workflows.dsl.expressions.expr
import io.github.typesafegithub.workflows.dsl.workflow
import io.github.typesafegithub.workflows.yaml.writeToFile
import org.intellij.lang.annotations.Language

private val SLACK_WEBHOOK_URL_KOTLIN by Contexts.secrets

workflow(
name = "Slack Release Notifications",
on = listOf(
Release(_customArguments = mapOf("types" to listOf("published")))
),
sourceFile = __FILE__.toPath(),
) {
job(
id = "push-notifications",
runsOn = UbuntuLatest,
_customArguments = mapOf(
"strategy" to mapOf(
"matrix" to mapOf(
"conf" to listOf(
mapOf("webhook_url" to expr { SLACK_WEBHOOK_URL_KOTLIN }),
)
)
)
)
) {
uses(
name = "Check out",
action = CheckoutV4()
)
uses(
name = "Notify Channel",
action = SlackGithubAction(),
env = linkedMapOf(
"SLACK_WEBHOOK_URL" to expr { "matrix.conf.webhook_url" },
"SLACK_WEBHOOK_TYPE" to "INCOMING_WEBHOOK"
)
)
}
}.writeToFile(addConsistencyCheck = false)

private class SlackGithubAction : RegularAction<Action.Outputs>(
actionOwner = "slackapi",
actionName = "slack-github-action",
actionVersion = "v1.24.0"
) {
@Language("JSON")
private val slackPayload =
"""
{
"text":"Kotlin Release ${expr { github.eventRelease.release.name }} was just released. Please update and let us know if you have any issues."
}
""".trimIndent()

override fun buildOutputObject(stepId: String): Outputs = Outputs(stepId)

override fun toYamlArguments(): LinkedHashMap<String, String> =
linkedMapOf(
"payload" to slackPayload
)
}
31 changes: 31 additions & 0 deletions .github/workflows/slack_release_notifications_workflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# This file was generated using Kotlin DSL (.github/workflows/scripts/slack_release_notifications_workflow.main.kts).
# If you want to modify the workflow, please change the Kotlin file and regenerate this YAML file.
# Generated with https://github.com/typesafegithub/github-workflows-kt

name: 'Slack Release Notifications'
on:
release:
types:
- 'published'
jobs:
push-notifications:
runs-on: 'ubuntu-latest'
strategy:
matrix:
conf:
- webhook_url: '${{ secrets.SLACK_WEBHOOK_URL_KOTLIN }}'
steps:
- id: 'step-0'
name: 'Check out'
uses: 'actions/checkout@v4'
- id: 'step-1'
name: 'Notify Channel'
uses: 'slackapi/[email protected]'
with:
payload: |-
{
"text":"Kotlin Release ${{ github.event.release.name }} was just released. Please update and let us know if you have any issues."
}
env:
SLACK_WEBHOOK_URL: '${{ matrix.conf.webhook_url }}'
SLACK_WEBHOOK_TYPE: 'INCOMING_WEBHOOK'
1 change: 1 addition & 0 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ WalletConnect v2 protocols for Android applications.

| BOM | [Core SDK](core/android) | [Sign SDK](protocol/sign) | [Auth SDK](protocol/auth) | [Chat SDK](protocol/chat) | [Notify SDK](protocol/notify) | [web3wallet](product/web3wallet) | [web3modal](product/web3modal) | [WalletConnectModal](product/walletconnectmodal) |
|-----------------------------------------------------------------------------------------|--------------------------|---------------------------|---------------------------|---------------------------|:------------------------------|----------------------------------|--------------------------------|--------------------------------------------------|
| 1.20.0 | 1.25.0 | 2.23.0 | 1.23.0 | 1.0.0.beta22 | 1.0.0-beta03 | 1.18.0 | 1.0.0 | 1.0.0-beta02 |
| 1.19.1 | 1.24.0 | 2.22.0 | 1.22.0 | 1.0.0.beta21 | 1.0.0-beta02 | 1.17.0 | 1.0.0-beta02 | 1.0.0-beta01 |
| 1.19.0 | 1.24.0 | 2.22.0 | 1.22.0 | 1.0.0.beta21 | 1.0.0-beta02 | 1.17.0 | 1.0.0-beta01 | 1.0.0-beta01 |
| 1.18.0 | 1.23.0 | 2.21.0 | 1.21.0 | 1.0.0.beta20 | 1.0.0-beta01 | 1.16.0 | 1.0.0-alpha11 | 1.0.0-alpha07 |
Expand Down
2 changes: 2 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ repositories {
gradlePluginPortal()
}

//kotlin.jvmToolchain(JavaVersion.VERSION_11.majorVersion.toInt())

dependencies {
implementation("com.android.tools.build:gradle:8.0.2") // when changing, remember to change version in Versions.kt in buildSrc module
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.21") // when changing, remember to change version in Versions.kt in buildSrc module
Expand Down
20 changes: 10 additions & 10 deletions buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ const val KEY_PUBLISH_ARTIFACT_ID = "PUBLISH_ARTIFACT_ID"
const val KEY_SDK_NAME = "SDK_NAME"

//Latest versions
const val BOM_VERSION = "1.19.1"
const val BOM_VERSION = "1.20.0"
const val FOUNDATION_VERSION = "1.12.0"
const val CORE_VERSION = "1.24.0"
const val SIGN_VERSION = "2.22.0"
const val AUTH_VERSION = "1.22.0"
const val CHAT_VERSION = "1.0.0-beta21"
const val NOTIFY_VERSION = "1.0.0-beta02"
const val WEB_3_WALLET = "1.17.0"
const val WEB_3_MODAL = "1.0.0-beta02"
const val WC_MODAL_VERSION = "1.0.0-beta01"
const val MODAL_CORE_VERSION = "1.0.0-beta01"
const val CORE_VERSION = "1.25.0"
const val SIGN_VERSION = "2.23.0"
const val AUTH_VERSION = "1.23.0"
const val CHAT_VERSION = "1.0.0-beta22"
const val NOTIFY_VERSION = "1.0.0-beta03"
const val WEB_3_WALLET = "1.18.0"
const val WEB_3_MODAL = "1.0.0"
const val WC_MODAL_VERSION = "1.0.0-beta02"
const val MODAL_CORE_VERSION = "1.0.0-beta02"

val jvmVersion = JavaVersion.VERSION_11
const val MIN_SDK: Int = 23
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package com.walletconnect.wcmodal.client

import com.walletconnect.android.internal.common.scope
import com.walletconnect.android.internal.common.wcKoinApp
import com.walletconnect.wcmodal.domain.WalletConnectModalDelegate
import com.walletconnect.sign.client.Sign
import com.walletconnect.sign.client.SignClient
import com.walletconnect.sign.common.exceptions.SignClientAlreadyInitializedException
import com.walletconnect.wcmodal.di.walletConnectModalModule
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach

object WalletConnectModal {

Expand Down Expand Up @@ -38,24 +42,53 @@ object WalletConnectModal {
) {
SignClient.initialize(
init = Sign.Params.Init(init.core),
onSuccess = {
this.excludedWalletsIds = init.excludedWalletIds
this.recommendedWalletsIds = init.recommendedWalletsIds
_sessionParams = init.sessionParams
runCatching {
wcKoinApp.modules(walletConnectModalModule())
setDelegate(WalletConnectModalDelegate)
}.onFailure { error -> onError(Modal.Model.Error(error)) }
onSuccess()
},
onSuccess = { onInitializedClient(init, onSuccess, onError) },
onError = { error ->
onError(Modal.Model.Error(error.throwable))
return@initialize
if (error.throwable is SignClientAlreadyInitializedException) {
onInitializedClient(init, onSuccess, onError)
} else {
onError(Modal.Model.Error(error.throwable))
return@initialize
}
}
)
}

private fun onInitializedClient(
init: Modal.Params.Init,
onSuccess: () -> Unit = {},
onError: (Modal.Model.Error) -> Unit
) {
this.excludedWalletsIds = init.excludedWalletIds
this.recommendedWalletsIds = init.recommendedWalletsIds
_sessionParams = init.sessionParams
runCatching {
wcKoinApp.modules(walletConnectModalModule())
setInternalDelegate(WalletConnectModalDelegate)
}.onFailure { error -> return@onInitializedClient onError(Modal.Model.Error(error)) }
onSuccess()
}

@Throws(IllegalStateException::class)
fun setDelegate(delegate: ModalDelegate) {
WalletConnectModalDelegate.wcEventModels.onEach { event ->
when(event) {
is Modal.Model.ApprovedSession -> delegate.onSessionApproved(event)
is Modal.Model.ConnectionState -> delegate.onConnectionStateChange(event)
is Modal.Model.DeletedSession.Success -> delegate.onSessionDelete(event)
is Modal.Model.Error -> delegate.onError(event)
is Modal.Model.RejectedSession -> delegate.onSessionRejected(event)
is Modal.Model.Session -> delegate.onSessionExtend(event)
is Modal.Model.SessionEvent -> delegate.onSessionEvent(event)
is Modal.Model.SessionRequestResponse -> delegate.onSessionRequestResponse(event)
is Modal.Model.UpdatedSession -> delegate.onSessionUpdate(event)
else -> Unit
}
}.launchIn(scope)
}

@Throws(IllegalStateException::class)
private fun setInternalDelegate(delegate: ModalDelegate) {
val signDelegate = object : SignClient.DappDelegate {
override fun onSessionApproved(approvedSession: Sign.Model.ApprovedSession) {
delegate.onSessionApproved(approvedSession.toModal())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,14 @@ internal object WalletConnectModalDelegate : WalletConnectModal.ModalDelegate {
}

override fun onConnectionStateChange(state: Modal.Model.ConnectionState) {

scope.launch {
_wcEventModels.emit(state)
}
}

override fun onError(error: Modal.Model.Error) {
Timber.e(error.throwable)
scope.launch {
_wcEventModels.emit(error)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.walletconnect.android.internal.common.scope
import com.walletconnect.android.internal.common.wcKoinApp
import com.walletconnect.sign.client.Sign
import com.walletconnect.sign.client.SignClient
import com.walletconnect.sign.common.exceptions.SignClientAlreadyInitializedException
import com.walletconnect.web3.modal.di.web3ModalModule
import com.walletconnect.web3.modal.domain.delegate.Web3ModalDelegate
import com.walletconnect.web3.modal.domain.model.InvalidSessionException
Expand All @@ -12,6 +13,8 @@ import com.walletconnect.web3.modal.domain.usecase.DeleteSessionDataUseCase
import com.walletconnect.web3.modal.domain.usecase.GetSelectedChainUseCase
import com.walletconnect.web3.modal.domain.usecase.GetSessionTopicUseCase
import com.walletconnect.web3.modal.utils.toChain
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine
Expand Down Expand Up @@ -61,21 +64,32 @@ object Web3Modal {
SignClient.initialize(
init = Sign.Params.Init(init.core),
onSuccess = {
this.excludedWalletsIds = init.excludedWalletIds
this.recommendedWalletsIds = init.recommendedWalletsIds
runCatching {
wcKoinApp.modules(web3ModalModule())
setDelegate(Web3ModalDelegate)
}.onFailure { error -> onError(Modal.Model.Error(error)) }
onSuccess()
onInitializedClient(init, onSuccess, onError)
},
onError = { error ->
onError(Modal.Model.Error(error.throwable))
return@initialize
if (error.throwable is SignClientAlreadyInitializedException) {
onInitializedClient(init, onSuccess, onError)
} else {
return@initialize onError(Modal.Model.Error(error.throwable))
}
}
)
}

private fun onInitializedClient(
init: Modal.Params.Init,
onSuccess: () -> Unit = {},
onError: (Modal.Model.Error) -> Unit
) {
this.excludedWalletsIds = init.excludedWalletIds
this.recommendedWalletsIds = init.recommendedWalletsIds
runCatching {
wcKoinApp.modules(web3ModalModule())
setInternalDelegate(Web3ModalDelegate)
}.onFailure { error -> return@onInitializedClient onError(Modal.Model.Error(error)) }
onSuccess()
}

fun setChains(chains: List<Modal.Model.Chain>) {
this.chains = chains
}
Expand All @@ -90,6 +104,24 @@ object Web3Modal {

@Throws(IllegalStateException::class)
fun setDelegate(delegate: ModalDelegate) {
Web3ModalDelegate.wcEventModels.onEach { event ->
when(event) {
is Modal.Model.ApprovedSession -> delegate.onSessionApproved(event)
is Modal.Model.ConnectionState -> delegate.onConnectionStateChange(event)
is Modal.Model.DeletedSession.Success -> delegate.onSessionDelete(event)
is Modal.Model.Error -> delegate.onError(event)
is Modal.Model.RejectedSession -> delegate.onSessionRejected(event)
is Modal.Model.Session -> delegate.onSessionExtend(event)
is Modal.Model.SessionEvent -> delegate.onSessionEvent(event)
is Modal.Model.SessionRequestResponse -> delegate.onSessionRequestResponse(event)
is Modal.Model.UpdatedSession -> delegate.onSessionUpdate(event)
else -> Unit
}
}.launchIn(scope)
}

@Throws(IllegalStateException::class)
private fun setInternalDelegate(delegate: ModalDelegate) {
val signDelegate = object : SignClient.DappDelegate {
override fun onSessionApproved(approvedSession: Sign.Model.ApprovedSession) {
delegate.onSessionApproved(approvedSession.toModal())
Expand All @@ -112,6 +144,7 @@ object Web3Modal {
}

override fun onSessionDelete(deletedSession: Sign.Model.DeletedSession) {
scope.launch { deleteSessionDataUseCase() }
delegate.onSessionDelete(deletedSession.toModal())
}

Expand Down Expand Up @@ -178,11 +211,10 @@ object Web3Modal {
onError(InvalidSessionException.toModalError())
return
}

scope.launch { deleteSessionDataUseCase() }
SignClient.disconnect(
Sign.Params.Disconnect(sessionTopic),
{
scope.launch { deleteSessionDataUseCase() }
onSuccess(it.toModal())
},
{ onError(it.toModal()) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,14 @@ internal object Web3ModalDelegate : Web3Modal.ModalDelegate {
}

override fun onConnectionStateChange(state: Modal.Model.ConnectionState) {

scope.launch {
_wcEventModels.emit(state)
}
}

override fun onError(error: Modal.Model.Error) {

scope.launch {
_wcEventModels.emit(error)
}
}
}
Loading

0 comments on commit eff4339

Please sign in to comment.