Remove code from BitsyApplication that is not going to be used.
- Add checks to ImportBrainkeyActivity to make sure the PIN and Brainkey have the correct length/structure.
This commit is contained in:
parent
fcbd82e570
commit
22a0735379
5 changed files with 65 additions and 34 deletions
|
@ -2,10 +2,62 @@ package cy.agorise.bitsybitshareswallet.activities
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import cy.agorise.bitsybitshareswallet.R
|
import cy.agorise.bitsybitshareswallet.R
|
||||||
|
import cy.agorise.bitsybitshareswallet.utils.Constants
|
||||||
|
import cy.agorise.graphenej.BrainKey
|
||||||
|
import cy.agorise.graphenej.UserAccount
|
||||||
|
import kotlinx.android.synthetic.main.activity_import_brainkey.*
|
||||||
|
|
||||||
class ImportBrainkeyActivity : ConnectedActivity() {
|
class ImportBrainkeyActivity : ConnectedActivity() {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Private variable that will hold an instance of the [BrainKey] class
|
||||||
|
*/
|
||||||
|
private var mBrainKey: BrainKey? = null
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User account associated with the key derived from the brainkey that the user just typed in
|
||||||
|
*/
|
||||||
|
private var mUserAccount: UserAccount? = null
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List of user account candidates, this is required in order to allow the user to select a single
|
||||||
|
* user account in case one key (derived from the brainkey) controls more than one account.
|
||||||
|
*/
|
||||||
|
private var mUserAccountCandidates: List<UserAccount>? = null
|
||||||
|
|
||||||
|
private var mKeyReferencesAttempts = 0
|
||||||
|
|
||||||
|
private var keyReferencesRequestId: Long = 0
|
||||||
|
private var getAccountsRequestId: Long = 0
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_import_brainkey)
|
setContentView(R.layout.activity_import_brainkey)
|
||||||
|
|
||||||
|
btnImport.setOnClickListener { importAccount() }
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun importAccount() {
|
||||||
|
val trimmedBrainKey = tietBrainKey.text!!.toString().trim { it <= ' ' }
|
||||||
|
tietBrainKey.setText(trimmedBrainKey)
|
||||||
|
|
||||||
|
tilPin.isErrorEnabled = false
|
||||||
|
tilPinConfirmation.isErrorEnabled = false
|
||||||
|
tilBrainKey.isErrorEnabled = false
|
||||||
|
|
||||||
|
if (tietPin.text!!.length < Constants.MIN_PIN_LENGTH)
|
||||||
|
tilPin.error = getString(R.string.error__pin_too_short)
|
||||||
|
else if (tietPin.text.toString() != tietPinConfirmation.text.toString())
|
||||||
|
tilPinConfirmation.error = getString(R.string.error__pin_mismatch)
|
||||||
|
else if (tietBrainKey.text!!.isEmpty() || !tietBrainKey.text.toString().contains(" "))
|
||||||
|
tilBrainKey.error = getString(R.string.error__enter_correct_brainkey)
|
||||||
|
else {
|
||||||
|
val brainKey = tietBrainKey.text.toString().split(" ")
|
||||||
|
if (brainKey.size in 12..16) {
|
||||||
|
// TODO verify brainkey
|
||||||
|
} else
|
||||||
|
tilBrainKey.error = getString(R.string.error__enter_correct_brainkey)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,14 +1,12 @@
|
||||||
package cy.agorise.bitsybitshareswallet.utils
|
package cy.agorise.bitsybitshareswallet.utils
|
||||||
|
|
||||||
import android.app.Activity
|
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
import android.os.Bundle
|
|
||||||
import cy.agorise.graphenej.api.ApiAccess
|
import cy.agorise.graphenej.api.ApiAccess
|
||||||
import cy.agorise.graphenej.api.android.NetworkServiceManager
|
import cy.agorise.graphenej.api.android.NetworkServiceManager
|
||||||
|
|
||||||
class BitsyApplication : Application(), Application.ActivityLifecycleCallbacks {
|
class BitsyApplication : Application() {
|
||||||
|
|
||||||
val BITSHARES_NODE_URLS = arrayOf(
|
private val BITSHARES_NODE_URLS = arrayOf(
|
||||||
// PP private nodes
|
// PP private nodes
|
||||||
"wss://nl.palmpay.io/ws",
|
"wss://nl.palmpay.io/ws",
|
||||||
"wss://mx.palmpay.io/ws",
|
"wss://mx.palmpay.io/ws",
|
||||||
|
@ -53,13 +51,6 @@ class BitsyApplication : Application(), Application.ActivityLifecycleCallbacks {
|
||||||
* better estimate when the user has left the app and it is safe to disconnect the websocket connection
|
* better estimate when the user has left the app and it is safe to disconnect the websocket connection
|
||||||
*/
|
*/
|
||||||
registerActivityLifecycleCallbacks(networkManager)
|
registerActivityLifecycleCallbacks(networkManager)
|
||||||
|
|
||||||
/*
|
|
||||||
* Registering this class as a listener to all activity's callback cycle events, in order to
|
|
||||||
* better estimate when the user has left the app and it is safe to disconnect the WebSocket connection
|
|
||||||
* TODO is it necessary??
|
|
||||||
*/
|
|
||||||
registerActivityLifecycleCallbacks(this)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupNodes(): String {
|
private fun setupNodes(): String {
|
||||||
|
@ -70,26 +61,4 @@ class BitsyApplication : Application(), Application.ActivityLifecycleCallbacks {
|
||||||
stringBuilder.replace(stringBuilder.length - 1, stringBuilder.length, "")
|
stringBuilder.replace(stringBuilder.length - 1, stringBuilder.length, "")
|
||||||
return stringBuilder.toString()
|
return stringBuilder.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onActivityCreated(activity: Activity?, savedInstanceState: Bundle?) {
|
|
||||||
//TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onActivityStarted(activity: Activity?) {
|
|
||||||
//TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onActivityResumed(activity: Activity?) {
|
|
||||||
//TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onActivityPaused(activity: Activity?) {
|
|
||||||
//TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onActivityStopped(activity: Activity?) { }
|
|
||||||
|
|
||||||
override fun onActivitySaveInstanceState(activity: Activity?, outState: Bundle?) { }
|
|
||||||
|
|
||||||
override fun onActivityDestroyed(activity: Activity?) { }
|
|
||||||
}
|
}
|
|
@ -9,6 +9,9 @@ object Constants {
|
||||||
/** Version of the currently used license */
|
/** Version of the currently used license */
|
||||||
const val CURRENT_LICENSE_VERSION = 1
|
const val CURRENT_LICENSE_VERSION = 1
|
||||||
|
|
||||||
|
/** The minimum required length for a PIN number */
|
||||||
|
const val MIN_PIN_LENGTH = 6
|
||||||
|
|
||||||
/** Key used to store if the initial setup is already done or not */
|
/** Key used to store if the initial setup is already done or not */
|
||||||
const val KEY_INITIAL_SETUP_DONE = "key_initial_setup_done"
|
const val KEY_INITIAL_SETUP_DONE = "key_initial_setup_done"
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
tools:context=".activities.ImportBrainkeyActivity">
|
tools:context=".activities.ImportBrainkeyActivity">
|
||||||
|
|
||||||
<com.google.android.material.textfield.TextInputLayout
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
|
android:id="@+id/tilPin"
|
||||||
style="@style/Widget.Bitsy.TextInputLayout"
|
style="@style/Widget.Bitsy.TextInputLayout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -29,6 +30,7 @@
|
||||||
</com.google.android.material.textfield.TextInputLayout>
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
|
|
||||||
<com.google.android.material.textfield.TextInputLayout
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
|
android:id="@+id/tilPinConfirmation"
|
||||||
style="@style/Widget.Bitsy.TextInputLayout"
|
style="@style/Widget.Bitsy.TextInputLayout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -48,6 +50,7 @@
|
||||||
</com.google.android.material.textfield.TextInputLayout>
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
|
|
||||||
<com.google.android.material.textfield.TextInputLayout
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
|
android:id="@+id/tilBrainKey"
|
||||||
style="@style/Widget.Bitsy.TextInputLayout"
|
style="@style/Widget.Bitsy.TextInputLayout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -63,7 +66,8 @@
|
||||||
android:inputType="textMultiLine"
|
android:inputType="textMultiLine"
|
||||||
android:gravity="top"
|
android:gravity="top"
|
||||||
android:lines="4"
|
android:lines="4"
|
||||||
android:maxLines="4"/>
|
android:scrollHorizontally="false"
|
||||||
|
android:imeOptions="actionDone"/>
|
||||||
</com.google.android.material.textfield.TextInputLayout>
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
|
|
||||||
<com.google.android.material.button.MaterialButton
|
<com.google.android.material.button.MaterialButton
|
||||||
|
|
|
@ -9,8 +9,11 @@
|
||||||
|
|
||||||
<!-- Import Brainkey Activity -->
|
<!-- Import Brainkey Activity -->
|
||||||
<string name="text_field__6_digit_pin">6+ digits PIN</string>
|
<string name="text_field__6_digit_pin">6+ digits PIN</string>
|
||||||
|
<string name="error__pin_too_short">PIN too short</string>
|
||||||
<string name="text_field__confirm_pin">Confirm PIN</string>
|
<string name="text_field__confirm_pin">Confirm PIN</string>
|
||||||
|
<string name="error__pin_mismatch">PIN mismatch</string>
|
||||||
<string name="text__brain_key">BrainKey</string>
|
<string name="text__brain_key">BrainKey</string>
|
||||||
|
<string name="error__enter_correct_brainkey">Please enter correct brainkey, it should have between 12 and 16 words.</string>
|
||||||
<string name="button__import">Import</string>
|
<string name="button__import">Import</string>
|
||||||
<string name="button__create">Create</string>
|
<string name="button__create">Create</string>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue