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 d246a3886e..5b2bcdd4b7 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 @@ -2,6 +2,7 @@ package com.walletconnect.web3.modal.ui.components.internal +import android.annotation.SuppressLint import androidx.compose.animation.AnimatedContent import androidx.compose.animation.ExperimentalAnimationApi import androidx.compose.animation.core.tween @@ -46,6 +47,7 @@ fun Web3ModalComponent( ) } +@SuppressLint("RestrictedApi") @Composable internal fun Web3ModalComponent( modifier: Modifier = Modifier, diff --git a/protocol/sign/src/main/kotlin/com/walletconnect/sign/common/adapters/SessionEventVOJsonAdapter.kt b/protocol/sign/src/main/kotlin/com/walletconnect/sign/common/adapters/SessionEventVOJsonAdapter.kt index d376af1723..92b28d0993 100644 --- a/protocol/sign/src/main/kotlin/com/walletconnect/sign/common/adapters/SessionEventVOJsonAdapter.kt +++ b/protocol/sign/src/main/kotlin/com/walletconnect/sign/common/adapters/SessionEventVOJsonAdapter.kt @@ -30,11 +30,23 @@ internal class SessionEventVOJsonAdapter(moshi: Moshi) : JsonAdapter { // Moshi does not handle malformed JSON where there is a missing key for an array or object val dataAny = anyAdapter.fromJson(reader) ?: throw Util.unexpectedNull("data", "data", reader) + data = if (dataAny is List<*>) { upsertArray(JSONArray(), dataAny).toString() - } else { + } else if (dataAny is Map<*, *>) { val paramsMap = dataAny as Map<*, *> upsertObject(JSONObject(), paramsMap).toString() + } else { + if (dataAny is Number) { + val castedNumber = if (dataAny.toDouble() % 1 == 0.0) { + dataAny.toLong() + } else { + dataAny.toDouble() + } + castedNumber.toString() + } else { + dataAny.toString() + } } } diff --git a/protocol/sign/src/test/kotlin/com/walletconnect/sign/adapters/SessionEventVOJsonAdapterTest.kt b/protocol/sign/src/test/kotlin/com/walletconnect/sign/adapters/SessionEventVOJsonAdapterTest.kt index cead8093d4..583b6dd946 100644 --- a/protocol/sign/src/test/kotlin/com/walletconnect/sign/adapters/SessionEventVOJsonAdapterTest.kt +++ b/protocol/sign/src/test/kotlin/com/walletconnect/sign/adapters/SessionEventVOJsonAdapterTest.kt @@ -11,6 +11,7 @@ import junit.framework.TestCase import org.json.JSONArray import org.junit.Test import kotlin.reflect.jvm.jvmName +import kotlin.test.assertEquals class SessionEventVOJsonAdapterTest { private val moshi: Moshi = Moshi.Builder() @@ -60,4 +61,10 @@ class SessionEventVOJsonAdapterTest { iterateJsonArrays(expectedParamsJsonArray, actualParamsJsonArray) } + + @Test + fun testParsingNumber() { + data = """1""".trimIndent() + assertEquals(data, serializedData) + } } \ No newline at end of file diff --git a/sample/modal/src/main/kotlin/com/walletconnect/sample/modal/common/Route.kt b/sample/modal/src/main/kotlin/com/walletconnect/sample/modal/common/Route.kt index 7a3b7124e8..f07a7384fa 100644 --- a/sample/modal/src/main/kotlin/com/walletconnect/sample/modal/common/Route.kt +++ b/sample/modal/src/main/kotlin/com/walletconnect/sample/modal/common/Route.kt @@ -1,7 +1,5 @@ package com.walletconnect.sample.modal.common -import androidx.navigation.NavController - const val messageArg = "messageArg" sealed class Route(val path: String) { @@ -10,8 +8,4 @@ sealed class Route(val path: String) { object Lab : Route("Lab") object AlertDialog : Route("Alert") -} - -fun NavController.openAlertDialog(message: String) { - navigate(Route.AlertDialog.path + "/$message") } \ No newline at end of file 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 ae09d5c5f1..366bcb1b79 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 @@ -19,7 +19,6 @@ import com.walletconnect.sample.common.getEthSignTypedData import com.walletconnect.sample.common.getPersonalSignBody import com.walletconnect.sample.common.ui.commons.BlueButton import com.walletconnect.sample.modal.ModalSampleDelegate -import com.walletconnect.sample.modal.common.openAlertDialog import com.walletconnect.web3.modal.client.Modal import com.walletconnect.web3.modal.client.Web3Modal import com.walletconnect.web3.modal.client.models.request.Request @@ -44,17 +43,20 @@ fun LabScreen( LaunchedEffect(Unit) { ModalSampleDelegate.wcEventModels.collect { event -> - when(event) { + when (event) { is Modal.Model.SessionRequestResponse -> { - when(event.result) { + when (event.result) { is Modal.Model.JsonRpcResponse.JsonRpcError -> { val error = event.result as Modal.Model.JsonRpcResponse.JsonRpcError - navController.openAlertDialog("Error Message: ${error.message}\n Error Code: ${error.code}") + Toast.makeText(context, "Error Message: ${error.message}\n Error Code: ${error.code}", Toast.LENGTH_SHORT).show() } - is Modal.Model.JsonRpcResponse.JsonRpcResult -> navController.openAlertDialog((event.result as Modal.Model.JsonRpcResponse.JsonRpcResult).result) + + is Modal.Model.JsonRpcResponse.JsonRpcResult -> Toast.makeText(context, (event.result as Modal.Model.JsonRpcResponse.JsonRpcResult).result, Toast.LENGTH_SHORT).show() } } - is Modal.Model.Error -> { navController.openAlertDialog(event.throwable.localizedMessage ?: "Something went wrong") } + + is Modal.Model.Error -> Toast.makeText(context, event.throwable.localizedMessage ?: "Something went wrong", Toast.LENGTH_SHORT).show() + else -> Unit } }