diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml index a81f431de..5570349cf 100644 --- a/.github/release-drafter.yml +++ b/.github/release-drafter.yml @@ -1,3 +1,4 @@ +commitish: master template: | ## What's Changed diff --git a/.github/workflows/ci_github_release.yml b/.github/workflows/ci_github_release.yml index d83dcb3d0..a4191b810 100644 --- a/.github/workflows/ci_github_release.yml +++ b/.github/workflows/ci_github_release.yml @@ -1,4 +1,4 @@ -name: Create Release +name: Create GitHub Release on: push: @@ -19,15 +19,16 @@ jobs: with: config-name: release-drafter.yml env: - GITHUB_TOKEN: ${{ secrets.ASSIGN_TO_PROJECT_GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Create GitHub Release uses: actions/create-release@v1 env: - GITHUB_TOKEN: ${{ secrets.ASSIGN_TO_PROJECT_GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: tag_name: ${{ github.ref }} release_name: ${{ github.ref }} body: ${{ steps.drafter.outputs.changelog }} draft: false - prerelease: false \ No newline at end of file + prerelease: false + target_commitish: master diff --git a/.github/workflows/ci_release_articacts.yml b/.github/workflows/ci_release_articacts.yml index 2b8d22bd9..6162de0ee 100644 --- a/.github/workflows/ci_release_articacts.yml +++ b/.github/workflows/ci_release_articacts.yml @@ -83,4 +83,9 @@ jobs: OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }} OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }} run: | - ./gradlew closeAndReleaseMultipleRepositories \ No newline at end of file + ./gradlew closeAndReleaseMultipleRepositories + - name: Push Tag + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + ./gradlew pushTagToMain diff --git a/.github/workflows/slack_release_notifications_workflow.yaml b/.github/workflows/slack_release_notifications_workflow.yaml index 8da905bc9..bfbbe6549 100644 --- a/.github/workflows/slack_release_notifications_workflow.yaml +++ b/.github/workflows/slack_release_notifications_workflow.yaml @@ -5,7 +5,7 @@ name: 'Slack Release Notifications' on: release: - types: [ published, edited ] + types: [ published ] jobs: push-notifications: runs-on: 'ubuntu-latest' diff --git a/ReadMe.md b/ReadMe.md index 310bacd55..3e496e2aa 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -23,6 +23,7 @@ dependencies { | 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.33.1 | 1.33.1 | 2.33.1 | 1.28.5 | 1.0.0.beta32 | 1.3.6 | 1.33.1 | 1.6.1 | 1.5.6 | | 1.33.0 | 1.33.0 | 2.33.0 | 1.28.4 | 1.0.0.beta31 | 1.3.5 | 1.33.0 | 1.6.0 | 1.5.5 | | 1.32.1 | 1.32.0 | 2.32.0 | 1.28.3 | 1.0.0.beta30 | 1.3.4 | 1.32.1 | 1.5.4 | 1.5.4 | | 1.31.3 | 1.31.2 | 2.31.2 | 1.28.2 | 1.0.0.beta30 | 1.3.2 | 1.31.2 | 1.5.2 | 1.5.2 | diff --git a/build.gradle.kts b/build.gradle.kts index 65cc6c46d..95bbe91ef 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,4 +1,3 @@ - import com.android.build.gradle.BaseExtension import org.apache.http.client.methods.HttpGet import org.apache.http.client.methods.HttpPost @@ -131,20 +130,21 @@ tasks.register("closeAndReleaseMultipleRepositories") { description = "Release all Sonatype staging repositories" doLast { - val repos = fetchRepositoryIds() + val repos = fetchOpenRepositoryIds() if (repos.isEmpty()) { println("No open repositories found") return@doLast } closeRepositories(repos) - waitForAllRepositoriesToClose(repos) + waitForAllRepositoriesToDesireState(repos, "closed") releaseRepositories(repos) + waitForAllRepositoriesToDesireState(repos, "released") + dropRepositories(repos) waitForArtifactsToBeAvailable() - //todo task for pushing a tag } } -fun fetchRepositoryIds(): List { +fun fetchOpenRepositoryIds(): List { val client = HttpClients.createDefault() val httpGet = HttpGet("$nexusUrl/profile_repositories").apply { setHeader("Authorization", "Basic " + Base64.getEncoder().encodeToString("$nexusUsername:$nexusPassword".toByteArray())) @@ -189,9 +189,36 @@ fun closeRepositories(repoIds: List) { } """.trimIndent() executePostRequest(closeUrl, json) + println("Closed repositories: ${repoIds.joinToString(", ")}") } -fun waitForAllRepositoriesToClose(repoIds: List) { +fun releaseRepositories(repoIds: List) { + val releaseUrl = "$nexusUrl/bulk/promote" + val json = """ + { + "data": { + "stagedRepositoryIds": ${repoIds.joinToString(prefix = "[\"", separator = "\",\"", postfix = "\"]")} + } + } + """.trimIndent() + println("Released repositories: ${repoIds.joinToString(", ")}") + executePostRequest(releaseUrl, json) +} + +fun dropRepositories(repoIds: List) { + val dropUrl = "$nexusUrl/bulk/drop" + val json = """ + { + "data": { + "stagedRepositoryIds": ${repoIds.joinToString(prefix = "[\"", separator = "\",\"", postfix = "\"]")} + } + } + """.trimIndent() + executePostRequest(dropUrl, json) + println("Dropped repositories: ${repoIds.joinToString(", ")}") +} + +fun waitForAllRepositoriesToDesireState(repoIds: List, desireState: String) { val client = HttpClients.createDefault() val statusUrl = "$nexusUrl/repository/" val closedRepos = mutableSetOf() @@ -207,11 +234,11 @@ fun waitForAllRepositoriesToClose(repoIds: List) { val responseBody = EntityUtils.toString(response.entity) val state = parseRepositoryState(responseBody, repoId) - if (state == "closed") { + if (state == desireState) { println("Repository $repoId is now in state: $state") closedRepos.add(repoId) } else { - println("Waiting for repository $repoId to be closed, current state: $state") + println("Waiting for repository $repoId to be $desireState, current state: $state") } } } @@ -221,37 +248,50 @@ fun waitForAllRepositoriesToClose(repoIds: List) { } } -fun releaseRepositories(repoIds: List) { - val releaseUrl = "$nexusUrl/bulk/promote" - val json = """ - { - "data": { - "stagedRepositoryIds": ${repoIds.joinToString(prefix = "[\"", separator = "\",\"", postfix = "\"]")} - } - } - """.trimIndent() - executePostRequest(releaseUrl, json) -} - fun waitForArtifactsToBeAvailable() { + val repoIds: List = repoIdWithVersion.map { it.first } val client = HttpClients.createDefault() - var artifactsAvailable = false - - while (!artifactsAvailable) { - artifactsAvailable = repoIdWithVersion.all { (repoId, version) -> - val artifactUrl = "https://repo1.maven.org/maven2/com/walletconnect/$repoId/$version/" - val httpGet = HttpGet(artifactUrl) - val response = client.execute(httpGet) - response.statusLine.statusCode == 200 + val artifactUrls = repoIdWithVersion.map { (repoId, version) -> + println("Checking: https://repo1.maven.org/maven2/com/walletconnect/$repoId/$version/") + "https://repo1.maven.org/maven2/com/walletconnect/$repoId/$version/" + } + val maxRetries = 20 + var attempt = 0 + val availableRepos = mutableSetOf() + + while (availableRepos.size < repoIds.size && attempt < maxRetries) { + artifactUrls.forEachIndexed { index, artifactUrl -> + if (!availableRepos.contains(repoIds[index])) { + val httpGet = HttpGet(artifactUrl) + try { + val response = client.execute(httpGet) + val statusCode = response.statusLine.statusCode + EntityUtils.consume(response.entity) // Ensure the response is fully consumed + if (statusCode == 200 || statusCode == 201) { + println("Artifact for repository ${repoIds[index]} is now available.") + availableRepos.add(repoIds[index]) + } else { + println("Artifact for repository ${repoIds[index]} not yet available. Status code: $statusCode") + } + } catch (e: Exception) { + println("Error checking artifact for repository ${repoIds[index]}: ${e.message}") + } finally { + httpGet.releaseConnection() // Ensure the connection is released + } + } } - - if (!artifactsAvailable) { - println("Artifacts not yet available. Waiting...") - Thread.sleep(30000) // Wait for 30 seconds before retrying - } else { - println("All artifacts are now available.") + if (availableRepos.size < repoIds.size) { + println("Waiting for artifacts to be available... Attempt: ${attempt + 1}") + attempt++ + Thread.sleep(10000) // Wait for 10 seconds before retrying } } + + if (availableRepos.size < repoIds.size) { + throw RuntimeException("Artifacts were not available after ${maxRetries * 10} seconds.") + } else { + println("All artifacts are now available.") + } } fun executePostRequest(url: String, json: String) { @@ -287,6 +327,20 @@ fun parseRepositoryState(xmlResponse: String, repositoryId: String): String? { return null } +tasks.register("createTag") { + val tagName = "BOM_$BOM_VERSION" + commandLine("git", "tag", tagName) +} + +tasks.register("pushTagToMain") { + val tagName = "BOM_$BOM_VERSION" + val repoUrl = "https://github.com/WalletConnect/WalletConnectKotlinV2.git" + val token = System.getenv("GITHUB_TOKEN") ?: throw GradleException("GITHUB_TOKEN environment variable is not set") + dependsOn("createTag") + val authenticatedRepoUrl = repoUrl.replace("https://", "https://$token:@") + commandLine("git", "push", authenticatedRepoUrl, tagName, "refs/heads/main") +} + private val repoIdWithVersion = listOf( Pair(ANDROID_BOM, BOM_VERSION), Pair(FOUNDATION, FOUNDATION_VERSION), diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index 6e3912f03..d817ff4d7 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -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.33.0" -const val FOUNDATION_VERSION = "1.17.3" -const val CORE_VERSION = "1.33.0" -const val SIGN_VERSION = "2.33.0" -const val AUTH_VERSION = "1.28.4" -const val CHAT_VERSION = "1.0.0-beta31" -const val NOTIFY_VERSION = "1.3.5" -const val WEB_3_WALLET_VERSION = "1.33.0" -const val WEB_3_MODAL_VERSION = "1.6.0" -const val WC_MODAL_VERSION = "1.5.5" -const val MODAL_CORE_VERSION = "1.6.0" +const val BOM_VERSION = "1.33.1" +const val FOUNDATION_VERSION = "1.17.4" +const val CORE_VERSION = "1.33.1" +const val SIGN_VERSION = "2.33.1" +const val AUTH_VERSION = "1.28.5" +const val CHAT_VERSION = "1.0.0-beta32" +const val NOTIFY_VERSION = "1.3.6" +const val WEB_3_WALLET_VERSION = "1.33.1" +const val WEB_3_MODAL_VERSION = "1.6.1" +const val WC_MODAL_VERSION = "1.5.6" +const val MODAL_CORE_VERSION = "1.6.1" //Artifact ids const val ANDROID_BOM = "android-bom" diff --git a/core/android/src/main/kotlin/com/walletconnect/android/internal/common/di/AndroidCommonDITags.kt b/core/android/src/main/kotlin/com/walletconnect/android/internal/common/di/AndroidCommonDITags.kt index 82df0337e..b64ab6dd7 100644 --- a/core/android/src/main/kotlin/com/walletconnect/android/internal/common/di/AndroidCommonDITags.kt +++ b/core/android/src/main/kotlin/com/walletconnect/android/internal/common/di/AndroidCommonDITags.kt @@ -3,7 +3,6 @@ package com.walletconnect.android.internal.common.di enum class AndroidCommonDITags { MOSHI, SHARED_INTERCEPTOR, - FAIL_OVER_INTERCEPTOR, LOGGING_INTERCEPTOR, AUTHENTICATOR, OK_HTTP, diff --git a/core/android/src/main/kotlin/com/walletconnect/android/internal/common/di/BaseStorageModule.kt b/core/android/src/main/kotlin/com/walletconnect/android/internal/common/di/BaseStorageModule.kt index aea224217..0f0948058 100644 --- a/core/android/src/main/kotlin/com/walletconnect/android/internal/common/di/BaseStorageModule.kt +++ b/core/android/src/main/kotlin/com/walletconnect/android/internal/common/di/BaseStorageModule.kt @@ -29,24 +29,6 @@ import org.koin.dsl.module import com.walletconnect.android.internal.common.scope as wcScope fun baseStorageModule(storagePrefix: String = String.Empty, bundleId: String) = module { - - fun Scope.createCoreDB(): AndroidCoreDatabase = AndroidCoreDatabase( - driver = get(named(AndroidBuildVariantDITags.ANDROID_CORE_DATABASE_DRIVER)), - MetaDataAdapter = MetaData.Adapter( - iconsAdapter = get(named(AndroidCommonDITags.COLUMN_ADAPTER_LIST)), - typeAdapter = get(named(AndroidCommonDITags.COLUMN_ADAPTER_APPMETADATATYPE)) - ), - VerifyContextAdapter = VerifyContext.Adapter( - validationAdapter = get(named(AndroidCommonDITags.COLUMN_ADAPTER_VALIDATION)) - ), - EventDaoAdapter = EventDao.Adapter( - traceAdapter = get(named(AndroidCommonDITags.COLUMN_ADAPTER_LIST)) - ), - JsonRpcHistoryDaoAdapter = JsonRpcHistoryDao.Adapter( - transport_typeAdapter = get(named(AndroidCommonDITags.COLUMN_ADAPTER_TRANSPORT_TYPE)) - ) - ) - single, String>>(named(AndroidCommonDITags.COLUMN_ADAPTER_LIST)) { object : ColumnAdapter, String> { override fun decode(databaseValue: String): List = @@ -82,6 +64,23 @@ fun baseStorageModule(storagePrefix: String = String.Empty, bundleId: String) = single>(named(AndroidCommonDITags.COLUMN_ADAPTER_VALIDATION)) { EnumColumnAdapter() } + fun Scope.createCoreDB(): AndroidCoreDatabase = AndroidCoreDatabase( + driver = get(named(AndroidBuildVariantDITags.ANDROID_CORE_DATABASE_DRIVER)), + MetaDataAdapter = MetaData.Adapter( + iconsAdapter = get(named(AndroidCommonDITags.COLUMN_ADAPTER_LIST)), + typeAdapter = get(named(AndroidCommonDITags.COLUMN_ADAPTER_APPMETADATATYPE)) + ), + VerifyContextAdapter = VerifyContext.Adapter( + validationAdapter = get(named(AndroidCommonDITags.COLUMN_ADAPTER_VALIDATION)) + ), + EventDaoAdapter = EventDao.Adapter( + traceAdapter = get(named(AndroidCommonDITags.COLUMN_ADAPTER_LIST)) + ), + JsonRpcHistoryDaoAdapter = JsonRpcHistoryDao.Adapter( + transport_typeAdapter = get(named(AndroidCommonDITags.COLUMN_ADAPTER_TRANSPORT_TYPE)) + ) + ) + single(named(AndroidBuildVariantDITags.ANDROID_CORE_DATABASE)) { try { createCoreDB().also { database -> diff --git a/foundation/src/test/kotlin/com/walletconnect/foundation/RelayTest.kt b/foundation/src/test/kotlin/com/walletconnect/foundation/RelayTest.kt index b2d74b704..65fd13cf1 100644 --- a/foundation/src/test/kotlin/com/walletconnect/foundation/RelayTest.kt +++ b/foundation/src/test/kotlin/com/walletconnect/foundation/RelayTest.kt @@ -42,7 +42,7 @@ sealed class TestState { @ExperimentalCoroutinesApi class RelayTest { private val testProjectId: String = requireNotNull(System.getProperty("TEST_PROJECT_ID")) - private val testRelayUrl: String = "https://staging.relay.walletconnect.org" + private val testRelayUrl: String = requireNotNull(System.getProperty("TEST_RELAY_URL")) private val serverUrl = "$testRelayUrl?projectId=$testProjectId" private val sdkVersion: String = System.getProperty("SDK_VERSION") + "-relayTest" private val testJob: CompletableJob = SupervisorJob() @@ -97,7 +97,7 @@ class RelayTest { runBlocking { val start = System.currentTimeMillis() // Await test finish or check if timeout occurred - while (testState.value is TestState.Idle && !didTimeout(start, 20000L)) { + while (testState.value is TestState.Idle && !didTimeout(start, 60000L)) { delay(10) } @@ -138,7 +138,7 @@ class RelayTest { runBlocking { val start = System.currentTimeMillis() // Await test finish or check if timeout occurred - while (testState.value is TestState.Idle && !didTimeout(start, 10000L)) { + while (testState.value is TestState.Idle && !didTimeout(start, 60000L)) { delay(10) } diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/engine/Web3ModalEngine.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/engine/Web3ModalEngine.kt index e76851cf7..45364bc90 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/engine/Web3ModalEngine.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/engine/Web3ModalEngine.kt @@ -59,6 +59,7 @@ internal class Web3ModalEngine( internal var recommendedWalletsIds: MutableList = mutableListOf() internal var siweRequestIdWithMessage: Pair? = null private lateinit var coinbaseClient: CoinbaseClient + internal var shouldDisconnect: Boolean = true fun setup( init: Modal.Params.Init, @@ -165,7 +166,7 @@ internal class Web3ModalEngine( } } - private fun openWalletApp(topic: String, onError: (Throwable) -> Unit) { + private fun openWalletApp(topic: String, onError: (RedirectMissingThrowable) -> Unit) { val redirect = SignClient.getActiveSessionByTopic(topic)?.redirect ?: String.Empty try { val intent = Intent(Intent.ACTION_VIEW, Uri.parse(redirect)) @@ -173,7 +174,7 @@ internal class Web3ModalEngine( intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK) wcKoinApp.koin.get().startActivity(intent) } catch (e: Throwable) { - onError(e) + onError(RedirectMissingThrowable("Please redirect to a wallet manually")) } } @@ -205,6 +206,7 @@ internal class Web3ModalEngine( onSuccess = { sendEventUseCase.send(Props(EventType.TRACK, EventType.Track.DISCONNECT_SUCCESS)) scope.launch { deleteSessionDataUseCase() } + shouldDisconnect = true onSuccess() }, onError = { @@ -346,4 +348,6 @@ internal class Web3ModalEngine( "Coinbase Client needs to be initialized first using the initialize function" } } + + internal class RedirectMissingThrowable(message: String) : Throwable(message) } diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/Web3ModalViewModel.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/Web3ModalViewModel.kt index 0891cc236..08a9f47aa 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/Web3ModalViewModel.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/Web3ModalViewModel.kt @@ -14,6 +14,7 @@ internal class Web3ModalViewModel : ViewModel() { private val web3ModalEngine: Web3ModalEngine = wcKoinApp.koin.get() private val _modalState: MutableStateFlow = MutableStateFlow(Web3ModalState.Loading) + val shouldDisconnect get() = web3ModalEngine.shouldDisconnect val modalState: StateFlow get() = _modalState.asStateFlow() @@ -23,6 +24,13 @@ internal class Web3ModalViewModel : ViewModel() { initModalState() } + fun disconnect() { + web3ModalEngine.disconnect( + onSuccess = { println("Disconnected successfully") }, + onError = { println("Disconnect error: $it") } + ) + } + internal fun initModalState() { viewModelScope.launch { web3ModalEngine.getActiveSession()?.let { _ -> diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/Web3ModalComponent.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/Web3ModalComponent.kt index e34bc7f4e..d246a3886 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/Web3ModalComponent.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/Web3ModalComponent.kt @@ -63,13 +63,14 @@ internal fun Web3ModalComponent( .onEach { event -> when (event) { is Modal.Model.SIWEAuthenticateResponse.Result, is Modal.Model.SessionAuthenticateResponse.Result -> closeModal() - is Modal.Model.ApprovedSession, is Modal.Model.DeletedSession.Success -> { + is Modal.Model.ApprovedSession -> { if (Web3Modal.authPayloadParams != null) { navController.navigate(Route.SIWE_FALLBACK.path) } else { closeModal() } } + is Modal.Model.DeletedSession.Success -> closeModal() else -> Unit } @@ -79,7 +80,13 @@ internal fun Web3ModalComponent( ComposableLifecycleEffect( onEvent = { _, event -> - coroutineScope.launch { event.toComponentEvent() } + coroutineScope.launch { + event.toComponentEvent(onClosed = { + if (navController.currentDestination?.route == Route.SIWE_FALLBACK.path && web3ModalViewModel.shouldDisconnect) { + web3ModalViewModel.disconnect() + } + }) + } } ) diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/navigation/Navigator.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/navigation/Navigator.kt index 91c139a39..0fbee267d 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/navigation/Navigator.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/navigation/Navigator.kt @@ -27,7 +27,7 @@ internal fun ConsumeNavigationEventsEffect( is NavigationEvent.PopBackStack -> navController.popBackStack() is NavigationEvent.PopBackStackTo -> navController.popBackStack(it.path, it.inclusive) is NavigationEvent.Close -> closeModal?.invoke() - is NavigationEvent.ShowError -> { snackBar.showErrorSnack(it.message ?: "Something went wrong") } + is NavigationEvent.ShowError -> snackBar.showErrorSnack(it.message ?: "Something went wrong") } if (navController.currentDestination == null) { closeModal?.invoke() diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/ConnectViewModel.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/ConnectViewModel.kt index c20334a88..d31016185 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/ConnectViewModel.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/connect/ConnectViewModel.kt @@ -97,11 +97,12 @@ internal class ConnectViewModel : ViewModel(), Navigator by NavigatorImpl(), Par fun sendSIWEOverPersonalSign() { _isConfirmLoading.value = true + web3ModalEngine.shouldDisconnect = false val account = web3ModalEngine.getAccount() ?: throw IllegalStateException("Account is null") val issuer = "did:pkh:${account.chain.id}:${account.address}" val siweMessage = web3ModalEngine.formatSIWEMessage(Web3Modal.authPayloadParams!!, issuer) val msg = siweMessage.encodeToByteArray().joinToString(separator = "", prefix = "0x") { eachByte -> "%02x".format(eachByte) } - val body = "[\"$msg\", \"$account\"]" + val body = "[\"$msg\", \"${account.address}\"]" web3ModalEngine.request( request = Request("personal_sign", body), onSuccess = { sendRequest -> @@ -109,8 +110,12 @@ internal class ConnectViewModel : ViewModel(), Navigator by NavigatorImpl(), Par web3ModalEngine.siweRequestIdWithMessage = Pair((sendRequest as SentRequestResult.WalletConnect).requestId, siweMessage) }, onError = { + if (it !is Web3ModalEngine.RedirectMissingThrowable) { + web3ModalEngine.shouldDisconnect = true + } + _isConfirmLoading.value = false - showError(it.localizedMessage) + showError(it.message) }, ) } diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/utils/Lifecycle.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/utils/Lifecycle.kt index 3fcccfe15..017cb533f 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/utils/Lifecycle.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/utils/Lifecycle.kt @@ -25,10 +25,14 @@ internal fun ComposableLifecycleEffect( } } -internal fun Lifecycle.Event.toComponentEvent() { +internal fun Lifecycle.Event.toComponentEvent(onClosed: () -> Unit) { when (this) { Lifecycle.Event.ON_CREATE, Lifecycle.Event.ON_START, Lifecycle.Event.ON_RESUME -> ComponentDelegate.openModalEvent() - Lifecycle.Event.ON_DESTROY, Lifecycle.Event.ON_STOP, Lifecycle.Event.ON_PAUSE -> ComponentDelegate.closeModalEvent() + + Lifecycle.Event.ON_DESTROY, Lifecycle.Event.ON_STOP, Lifecycle.Event.ON_PAUSE -> { + onClosed() + ComponentDelegate.closeModalEvent() + } else -> Unit } } diff --git a/protocol/sign/src/main/kotlin/com/walletconnect/sign/di/StorageModule.kt b/protocol/sign/src/main/kotlin/com/walletconnect/sign/di/StorageModule.kt index 254701dde..d9dbb4455 100644 --- a/protocol/sign/src/main/kotlin/com/walletconnect/sign/di/StorageModule.kt +++ b/protocol/sign/src/main/kotlin/com/walletconnect/sign/di/StorageModule.kt @@ -25,6 +25,8 @@ import com.walletconnect.android.internal.common.scope as wcScope @JvmSynthetic internal fun storageModule(dbName: String): Module = module { + includes(sdkBaseStorageModule(SignDatabase.Schema, dbName)) + fun Scope.createSignDB(): SignDatabase = SignDatabase( driver = get(named(dbName)), NamespaceDaoAdapter = NamespaceDao.Adapter( @@ -59,8 +61,6 @@ internal fun storageModule(dbName: String): Module = module { ) ) - includes(sdkBaseStorageModule(SignDatabase.Schema, dbName)) - single { try { createSignDB().also { signDatabase -> diff --git a/sample/modal/src/main/kotlin/com/walletconnect/sample/modal/ui/LabScreen.kt b/sample/modal/src/main/kotlin/com/walletconnect/sample/modal/ui/LabScreen.kt index 1f2ddb157..ae09d5c5f 100644 --- a/sample/modal/src/main/kotlin/com/walletconnect/sample/modal/ui/LabScreen.kt +++ b/sample/modal/src/main/kotlin/com/walletconnect/sample/modal/ui/LabScreen.kt @@ -24,8 +24,8 @@ import com.walletconnect.web3.modal.client.Modal import com.walletconnect.web3.modal.client.Web3Modal import com.walletconnect.web3.modal.client.models.request.Request import com.walletconnect.web3.modal.client.models.request.SentRequestResult -import com.walletconnect.web3.modal.ui.components.button.AccountButtonType import com.walletconnect.web3.modal.ui.Web3ModalTheme +import com.walletconnect.web3.modal.ui.components.button.AccountButtonType import com.walletconnect.web3.modal.ui.components.button.NetworkButton import com.walletconnect.web3.modal.ui.components.button.Web3Button import com.walletconnect.web3.modal.ui.components.button.rememberWeb3ModalState