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

Allow non string values in wallet connect message (partial fix for #14) #15

Merged
merged 1 commit into from
Jul 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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 @@ -15,11 +15,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 @@ -84,10 +84,10 @@ class OkHttpTransport(
adapter.fromJson(text)?.toMessage()?.let { messageHandler(it) }
}

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