Skip to content

Commit

Permalink
Better errors for beta5
Browse files Browse the repository at this point in the history
  • Loading branch information
adityapk00 committed Feb 13, 2019
1 parent fa002fb commit aef787d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ android {
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "0.0.3-beta"
versionName "0.0.5-beta5"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ object ConnectionManager {

val client = OkHttpClient.Builder().connectTimeout(5, TimeUnit.SECONDS).build()
val request = Request.Builder().url("wss://wormhole.zecqtwallet.com:443").build()
//val request = Request.Builder().url("ws://192.168.5.187:7070").build()
val listener = WebsocketClient(false)

DataModel.ws = client.newWebSocket(request, listener)
Expand Down Expand Up @@ -138,7 +139,8 @@ object ConnectionManager {
sendErrorSignal(r.displayMsg, r.doDisconnect)

if (r.doDisconnect) {
webSocket?.close(1000, "Peer Error caused disconnect")
// We don't pass a reason here, because we already sent the error signal above
webSocket?.close(1000, null)
}

} else {
Expand All @@ -156,9 +158,9 @@ object ConnectionManager {
println("Connstatus = disconnected")

Log.i(TAG,"Closing : $code / $reason")
if (code == 1001) {
sendErrorSignal(reason, true)
}
//if (!reason.isNullOrEmpty()) {
// sendErrorSignal(reason, true)
//}
sendRefreshSignal(true)
}

Expand Down
14 changes: 9 additions & 5 deletions app/src/main/java/com/adityapk/zcash/zqwandroid/DataModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ object DataModel {
fun parseResponse(response: String) : ParseResponse {
val json = Parser.default().parse(StringBuilder(response)) as JsonObject

// Check if it has errored out
if (json.containsKey("error")) {
return ParseResponse(false, "Couldn't connect: ${json["error"].toString()}", true)
}

if (json.containsKey("ping")) {
return ParseResponse(false)
}

// Check if input string is encrypted
if (json.containsKey("nonce")) {
val decrypted = decrypt(json["nonce"].toString(), json["payload"].toString())
Expand All @@ -69,11 +78,6 @@ object DataModel {
return parseResponse(decrypted)
}

// Check if it has errored out
if (json.containsKey("error")) {
return ParseResponse(false, "Couldn't connect: ${json["error"].toString()}", true)
}

return when (json.string("command")) {
"getInfo" -> {
mainResponseData = Klaxon().parse<MainResponse>(response)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,11 @@ class MainActivity : AppCompatActivity(), TransactionItemFragment.OnFragmentInte
updateUI(updateTxns)
}
"error" -> {
val msg = intent.getStringExtra("msg") ?: "Unknown Error"
Snackbar.make(layoutConnect, msg, Snackbar.LENGTH_LONG).show()
val msg = intent.getStringExtra("msg")

if (!msg.isNullOrEmpty()) {
Snackbar.make(layoutConnect, msg, Snackbar.LENGTH_LONG).show()
}

// Also check if we need to disconnect
if (intent.getBooleanExtra("doDisconnect", false)) {
Expand Down

0 comments on commit aef787d

Please sign in to comment.