Skip to content

Commit

Permalink
Allow non string values in wallet connect message (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
rmeissner authored and ligi committed Jul 16, 2019
1 parent 2cf55ad commit 777b8cc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ class MoshiPayloadAdapter(moshi: Moshi) : Session.PayloadAdapter {
val data = params.firstOrNull() as? Map<*, *> ?: throw IllegalArgumentException("Invalid params")
val from = data["from"] as? String ?: throw IllegalArgumentException("from key missing")
val to = data["to"] as? String ?: throw IllegalArgumentException("to key missing")
val nonce =
data["nonce"] as? String ?: (data["nonce"] as? Double)?.toLong()?.toString()
val nonce = data["nonce"] as? String ?: (data["nonce"] as? Double)?.toLong()?.toString()
val gasPrice = data["gasPrice"] as? String
val gasLimit = data["gasLimit"] as? String
val value = data["value"] as? String ?: throw IllegalArgumentException("value key missing")
Expand Down Expand Up @@ -200,7 +199,7 @@ class MoshiPayloadAdapter(moshi: Moshi) : Session.PayloadAdapter {
)

private fun Session.MethodCall.Response.toMap() =
mutableMapOf(
mutableMapOf<String, Any>(
"id" to id,
"jsonrpc" to "2.0"
).apply {
Expand Down
12 changes: 6 additions & 6 deletions lib/src/main/kotlin/org/walletconnect/impls/OkHttpTransport.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ class OkHttpTransport(
moshi: Moshi
) : Session.Transport, WebSocketListener() {

private val adapter = moshi.adapter<Map<String, String>>(
private val adapter = moshi.adapter<Map<String, Any>>(
Types.newParameterizedType(
Map::class.java,
String::class.java,
String::class.java
Any::class.java
)
)

Expand Down Expand Up @@ -89,10 +89,10 @@ class OkHttpTransport(
}
}

private fun Map<String, String>.toMessage(): Session.Transport.Message? {
val topic = get("topic") ?: return null
val type = get("type") ?: return null
val payload = get("payload") ?: return null
private fun Map<String, Any>.toMessage(): Session.Transport.Message? {
val topic = get("topic")?.toString() ?: return null
val type = get("type")?.toString() ?: return null
val payload = get("payload")?.toString() ?: return null
return Session.Transport.Message(topic, type, payload)
}

Expand Down

0 comments on commit 777b8cc

Please sign in to comment.