Browse Source

Merge pull request #111 from jahway603/master

Implemented custom wormhole to fix upstream issue #41
master
Duke Leto 4 years ago
committed by GitHub
parent
commit
560217d6ed
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      README.md
  2. 16
      app/src/main/java/org/myhush/silentdragon/ConnectionManager.kt
  3. 24
      app/src/main/java/org/myhush/silentdragon/DataModel.kt
  4. 39
      app/src/main/java/org/myhush/silentdragon/ui/SettingsActivity.kt
  5. 60
      app/src/main/res/layout/activity_about.xml
  6. 120
      app/src/main/res/layout/activity_settings.xml
  7. 11
      app/src/main/res/values/strings.xml

4
README.md

@ -96,7 +96,7 @@ the Google Play Store. For further information, [click here](release_build_proce
Contributions to this project are welcome and encouraged.
## License
## Support
This project is under the GNU Public License v3. For the full license, see [LICENSE](LICENSE).
For support or other questions, join us on [Discord](https://myhush.org/discord), or tweet at [@MyHushTeam](https://twitter.com/MyHushTeam), or toot at our [Mastodon](https://fosstodon.org/@myhushteam), or join [Telegram](http://myhush.org/telegram) or [file an issue](https://github.com/MyHush/SilentDragonAndroid/issues).

16
app/src/main/java/org/myhush/silentdragon/ConnectionManager.kt

@ -33,8 +33,8 @@ object ConnectionManager {
initCurrencies()
}
// Attempt a connection to the server. If there is no saved connection, we'll set the connection status
// to None
// Attempt a connection to the server
// If there is no saved connection, we'll set the connection status to None
private fun makeConnection(directConn : Boolean = true) {
val connString =
DataModel.getConnString(SilentDragonApp.appContext!!)
@ -79,11 +79,14 @@ object ConnectionManager {
DataModel.connStatus =
DataModel.ConnectionStatus.CONNECTING
val wormHoleValue = DataModel.getWormholeServer()
println("Connstatus = connecting")
val client = OkHttpClient.Builder().connectTimeout(5, TimeUnit.SECONDS).build()
val request = Request.Builder().url("wss://wormhole.myhush.org:443").build()
//val request = Request.Builder().url("ws://192.168.5.187:7070").build()
//val request = Request.Builder().url("wss://wormhole.myhush.org:443").build()
val request = Request.Builder().url("wss://" + wormHoleValue).build()
val listener = WebsocketClient(false)
DataModel.ws = client.newWebSocket(request, listener)
@ -115,6 +118,7 @@ object ConnectionManager {
i.putExtra("doDisconnect", doDisconnect)
SilentDragonApp.appContext?.sendBroadcast(i)
}
fun initCurrencies(){
try {
DataModel.currencySymbols["AUD"] = "$"
@ -156,9 +160,7 @@ object ConnectionManager {
}
}
}.start()
}catch (e: Exception){
e.printStackTrace()
}

24
app/src/main/java/org/myhush/silentdragon/DataModel.kt

@ -12,6 +12,7 @@ import org.libsodium.jni.NaCl
import org.libsodium.jni.Sodium
import java.math.BigInteger
object DataModel {
class MainResponse(val balance: Double, val maxspendable: Double, val maxzspendable: Double? = null,
val saplingAddress: String, val tAddress: String, val tokenName: String,
@ -33,8 +34,7 @@ object DataModel {
}
var ws : WebSocket? = null
enum class ConnectionStatus(val status: Int) {
DISCONNECTED(1),
CONNECTING(2),
@ -329,7 +329,27 @@ object DataModel {
Sodium.crypto_hash_sha256(tobin2, tobin1, tobin1.size)
return tobin2.toHexString()
}
/* functions to set custom wormhole value from Settings tab */
fun setWormholeServer(customWormHole: String) {
val settings = SilentDragonApp.appContext!!.getSharedPreferences("Secret", 0)
val editor = settings.edit()
editor.putString("wormhole", customWormHole)
//editor.apply()
editor.commit()
}
/* functions to get custom wormhole value */
fun getWormholeServer() : String? {
val settings = SilentDragonApp.appContext!!.getSharedPreferences("Secret", 0)
val wormHole = settings.getString("secret", "")
if (wormHole.isNullOrEmpty()) {
return settings.getString("wormhole", "https://wormhole.myhush.org:443" )
}
return settings.getString("wormhole", "" )
}
fun setSecretHex(secretHex: String) {

39
app/src/main/java/org/myhush/silentdragon/ui/SettingsActivity.kt

@ -2,12 +2,10 @@
package org.myhush.silentdragon.ui
import android.content.SharedPreferences
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.Adapter
import android.widget.AdapterView
import android.widget.ArrayAdapter
import android.widget.*
import androidx.appcompat.app.AppCompatActivity
import kotlinx.android.synthetic.main.activity_settings.*
import org.myhush.silentdragon.ConnectionManager
import org.myhush.silentdragon.DataModel
@ -43,6 +41,24 @@ class SettingsActivity : AppCompatActivity() {
updateUI()
}
btnSetWormhole.setOnClickListener {
val inputText = findViewById<View>(R.id.wormholeInput) as EditText
val result = findViewById<View>(R.id.lblCurrentWormhole) as TextView
val myhushDefaultWormhole : String = "wormhole.myhush.org:443"
val customWormhole = inputText.getText().toString()
// set to myhushDefaultWormhole if nothing in EditText (wormholeInput)
if (inputText.text.isBlank()) {
result.text = myhushDefaultWormhole
Toast.makeText(this, "Defaulting to: " + myhushDefaultWormhole, Toast.LENGTH_SHORT).show()
DataModel.setWormholeServer(myhushDefaultWormhole)
} else {
result.text = customWormhole
Toast.makeText(this, "Wormhole set to: " + customWormhole, Toast.LENGTH_SHORT).show()
DataModel.setWormholeServer(customWormhole)
}
}
spinnerCurrency!!.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(parent: AdapterView<*>, view: View, pos: Int, id: Long) {
@ -51,10 +67,11 @@ class SettingsActivity : AppCompatActivity() {
DataModel.selectedCurrency = cur // Set cur as selected
// Save currency
var pref: SharedPreferences = getSharedPreferences("MainFile",0)
var pref: SharedPreferences = getSharedPreferences("MainFile", 0)
var editor: SharedPreferences.Editor = pref.edit()
editor.putString("currency",
editor.putString(
"currency",
DataModel.selectedCurrency
)
@ -62,7 +79,6 @@ class SettingsActivity : AppCompatActivity() {
}
override fun onNothingSelected(parent: AdapterView<out Adapter>?) {}
}
}
@ -78,8 +94,11 @@ class SettingsActivity : AppCompatActivity() {
selectedIndex++
}
var adapter: ArrayAdapter<String> = ArrayAdapter(this, android.R.layout.simple_spinner_item, items)
var adapter: ArrayAdapter<String> = ArrayAdapter(
this,
android.R.layout.simple_spinner_item,
items
)
adapter.setDropDownViewResource(android.R.layout.simple_spinner_item)
spinnerCurrency.adapter = adapter
@ -98,5 +117,7 @@ class SettingsActivity : AppCompatActivity() {
lblServerVersion.text = DataModel.mainResponseData?.serverversion ?: getString(
R.string.not_connected
)
lblCurrentWormhole.text = DataModel.getWormholeServer()
}
}

60
app/src/main/res/layout/activity_about.xml

@ -158,6 +158,41 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/TwitterText" />
<TextView
android:id="@+id/Mastodon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:text="@string/mastodon"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/divider3" />
<TextView
android:id="@+id/MastodonText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="2dp"
android:text="@string/mastodon_link"
android:textColorLink="@android:color/white"
android:autoLink="web"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/Mastodon" />
<View
android:id="@+id/divider4"
android:layout_width="0dp"
android:layout_height="2dp"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="8dp"
android:background="?android:attr/listDivider"
android:visibility="visible"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/MastodonText" />
<TextView
android:id="@+id/Github"
android:layout_width="wrap_content"
@ -167,7 +202,7 @@
android:text="@string/github"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/divider3" />
app:layout_constraintTop_toBottomOf="@id/divider4" />
<TextView
android:id="@+id/GithubText"
@ -182,7 +217,7 @@
app:layout_constraintTop_toBottomOf="@+id/Github" />
<View
android:id="@+id/divider4"
android:id="@+id/divider5"
android:layout_width="0dp"
android:layout_height="2dp"
android:layout_marginStart="8dp"
@ -204,7 +239,7 @@
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/divider4" />
app:layout_constraintTop_toBottomOf="@id/divider5" />
<TextView
android:id="@+id/BugReportsText"
@ -221,7 +256,7 @@
app:layout_constraintTop_toBottomOf="@id/BugReports" />
<View
android:id="@+id/divider9"
android:id="@+id/divider6"
android:layout_width="0dp"
android:layout_height="2dp"
android:layout_marginStart="8dp"
@ -243,7 +278,7 @@
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/divider9" />
app:layout_constraintTop_toBottomOf="@id/divider6" />
<TextView
android:id="@+id/CreditText"
@ -260,7 +295,7 @@
app:layout_constraintTop_toBottomOf="@id/Credit" />
<View
android:id="@+id/divider5"
android:id="@+id/divider7"
android:layout_width="0dp"
android:layout_height="2dp"
android:layout_marginStart="8dp"
@ -282,7 +317,7 @@
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/divider5" />
app:layout_constraintTop_toBottomOf="@id/divider7" />
<TextView
android:id="@+id/LicenseText"
@ -297,7 +332,7 @@
app:layout_constraintTop_toBottomOf="@+id/License" />
<View
android:id="@+id/divider6"
android:id="@+id/divider8"
android:layout_width="0dp"
android:layout_height="2dp"
android:layout_marginStart="2dp"
@ -308,7 +343,6 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/LicenseText" />
<TextView
android:id="@+id/Version"
android:layout_width="wrap_content"
@ -318,7 +352,7 @@
android:text="@string/sda_version"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/divider6" />
app:layout_constraintTop_toBottomOf="@id/divider8" />
<TextView
android:id="@+id/lblVersionName"
@ -332,7 +366,7 @@
app:layout_constraintTop_toBottomOf="@+id/Version" />
<View
android:id="@+id/divider7"
android:id="@+id/divider9"
android:layout_width="0dp"
android:layout_height="2dp"
android:layout_marginStart="8dp"
@ -354,7 +388,7 @@
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/divider7" />
app:layout_constraintTop_toBottomOf="@id/divider9" />
<TextView
android:id="@+id/CopyrightText"
@ -369,7 +403,7 @@
app:layout_constraintTop_toBottomOf="@+id/Copyright" />
<View
android:id="@+id/divider8"
android:id="@+id/divider_last"
android:layout_width="0dp"
android:layout_height="2dp"
android:layout_marginStart="8dp"

120
app/src/main/res/layout/activity_settings.xml

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
@ -16,17 +16,9 @@
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0">
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintBottom_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintVertical_bias="1.0"
android:focusable="true"
android:focusableInTouchMode="true">
<TextView
android:id="@+id/textView"
@ -80,7 +72,7 @@
android:text="@string/wormhole_settings"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/divider"/>
app:layout_constraintTop_toBottomOf="@+id/divider" />
<CheckBox
android:id="@+id/chkDisallowInternet"
@ -95,7 +87,7 @@
app:layout_constraintTop_toBottomOf="@+id/textWormholeSettings" />
<TextView
android:id="@+id/textView4"
android:id="@+id/wormholeAlert"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
@ -107,50 +99,111 @@
app:layout_constraintTop_toBottomOf="@+id/chkDisallowInternet" />
<View
android:id="@+id/divider3"
android:id="@+id/divider5"
android:layout_width="0dp"
android:layout_height="2dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:background="?android:attr/listDivider"
android:visibility="visible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/wormholeAlert" />
<TextView
android:id="@+id/customWormholeTitle"
android:layout_width="wrap_content"
android:layout_height="19dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:text="@string/current_wormhole_title"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/divider5" />
<TextView
android:id="@+id/lblCurrentWormhole"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:text=""
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/customWormholeTitle"
app:layout_constraintTop_toBottomOf="@+id/divider5" />
<EditText
android:id="@+id/wormholeInput"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:clickable="false"
android:hint="@string/change_below"
android:inputType="text"
android:autoText="false"
android:textSize="14sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/customWormholeTitle" />
<Button
android:id="@+id/btnSetWormhole"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:text="@string/wormhole_custom"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/wormholeInput" />
<View
android:id="@+id/divider3"
android:layout_width="0dp"
android:layout_height="2dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:background="?android:attr/listDivider"
android:visibility="visible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView4" />
app:layout_constraintTop_toBottomOf="@+id/btnSetWormhole" />
<TextView
android:id="@+id/textView11"
android:layout_width="110dp"
android:layout_height="36dp"
android:layout_width="wrap_content"
android:layout_height="32dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="24dp"
android:text="@string/currency"
android:textAlignment="center"
android:textIsSelectable="false"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/divider3" />
<Spinner
android:id="@+id/spinnerCurrency"
android:layout_width="360dp"
android:layout_height="30dp"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_width="100dp"
android:layout_height="32dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView11" />
app:layout_constraintTop_toBottomOf="@+id/divider3" />
<View
android:id="@+id/divider4"
android:layout_width="0dp"
android:layout_height="2dp"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:background="?android:attr/listDivider"
android:visibility="visible"
@ -168,24 +221,25 @@
android:text="@string/silentdragon_version"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/divider4" />
app:layout_constraintTop_toBottomOf="@+id/divider4"
app:layout_constraintRight_toRightOf="@+id/lblServerVersion"/>
<TextView
android:id="@+id/lblServerVersion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginStart="32dp"
android:layout_marginTop="16dp"
android:text=""
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView10" />
app:layout_constraintStart_toEndOf="@+id/textView10"
app:layout_constraintTop_toBottomOf="@+id/divider4" />
<View
android:id="@+id/divider2"
android:layout_width="0dp"
android:layout_height="2dp"
android:layout_marginStart="8dp"
android:layout_marginTop="24dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:background="?android:attr/listDivider"
android:visibility="visible"
@ -195,4 +249,4 @@
app:layout_constraintTop_toBottomOf="@+id/lblServerVersion" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>

11
app/src/main/res/values/strings.xml

@ -14,6 +14,8 @@
<string name="address">Address</string>
<string name="cancel">Cancel</string>
<string name="amount">Amount</string>
<string name="wormhole">Wormhole</string>
<string name="test_string" translatable="false">Test String</string>
<!-- TxDetailsActivity.kt -->
<string name="reply">Reply</string>
@ -82,8 +84,12 @@
<string name="wormhole_settings">Wormhole Settings</string>
<string name="disallow_routing_over_external_service">Disallow routing over external service/internet</string>
<string name="only_attempts_direct_connection">If checked, the app will only attempt a direct connection to SilentDragon, and not route traffic over the internet via the WormHole service at wormhole.myhush.org . Please see the https://myhush.org/silentdragon for more details</string>
<string name="current_wormhole_title">Current Wormhole:</string>
<string name="myhush_default_wormhole" translatable="false">wormhole.myhush.org:443</string>
<string name="wormhole_custom">Set custom Wormhole</string>
<string name="currency">Currency</string>
<string name="silentdragon_version">SilentDragon version</string>
<string name="change_below">Enter wormhole\'s server:port here and click below</string>
<!-- activity_about.xml -->
<string name="website">Visit our website</string>
@ -94,6 +100,8 @@
<string name="telegram_link" translatable="false">https://www.myhush.org/telegram/</string>
<string name="twitter">Twitter</string>
<string name="twitter_link" translatable="false">https://www.myhush.org/twitter/</string>
<string name="mastodon">Mastodon</string>
<string name="mastodon_link" translatable="false">https://www.myhush.org/mastodon/</string>
<string name="github">GitHub</string>
<string name="github_link" translatable="false">https://github.com/MyHush/SilentDragonAndroid</string>
<string name="bugreports">Bug Reports</string>
@ -133,7 +141,8 @@
<string name="error_sending_transaction">Error Sending Transaction!</string>
<string name="memo_field_over_512">Memo field is too long! Must be at most 512 bytes.</string>
<string name="more_than_shielded_address">%1$s %2$s is more than the balance in your shielded address. This Tx will have to be sent from a transparent address, and will not be private.\n\nAre you absolutely sure?</string>
<string name="max_spend_in_a_single_tx">Can\'t spend more than %1$d %2$s in a single Tx"</string>
<!-- <string name="max_spend_in_a_single_tx">Can\'t spend more than %1$d %2$s in a single Tx"</string> -->
<string name="max_spend_in_a_single_tx">You tried to spend %1$d %2$s, but there is not enough HUSH in this single address currently. You might need to sweep funds into one address or wait for some funds to confirm.</string>
<string name="reply_to">Reply to</string>
<!-- content_send -->

Loading…
Cancel
Save