diff --git a/README.md b/README.md index e21682b..714807e 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ **NOTE**: _This app is a prototype. While it seems to work reasonably well and stable, the UI has not received any thought yet. It is fine to use but keep in mind that there isn't much error reporting, no progress indicators and some screens are crammed with info_ -Keycard Connect's main function is to enable using the Keycard with dApps outside of a web3 browser using WalletConnect. The dApp must of course support WalletConnect for this to work. Additionally, this app is a little toolbox for Keycardm allowing things like changing PIN, initializing cards, changing seed etc. +Keycard Connect's main function is to enable using the Keycard with dApps outside of a web3 browser using WalletConnect. The dApp must of course support WalletConnect for this to work. Additionally, this app is a little toolbox for Keycard, allowing things like changing PIN, initializing cards, changing seed etc. ## What works diff --git a/app/src/main/java/im/status/keycard/connect/data/PINUtils.kt b/app/src/main/java/im/status/keycard/connect/data/PINUtils.kt new file mode 100644 index 0000000..b11c7e1 --- /dev/null +++ b/app/src/main/java/im/status/keycard/connect/data/PINUtils.kt @@ -0,0 +1,4 @@ +package im.status.keycard.connect.data + +fun isValidPIN(pin: String) : Boolean = pin.length == 6 && pin.all { it.isDigit() } +fun isValidPUK(puk: String) : Boolean = puk.length == 12 && puk.all { it.isDigit() } diff --git a/app/src/main/java/im/status/keycard/connect/net/EthereumRPC.kt b/app/src/main/java/im/status/keycard/connect/net/EthereumRPC.kt index 0a52027..a9db78d 100644 --- a/app/src/main/java/im/status/keycard/connect/net/EthereumRPC.kt +++ b/app/src/main/java/im/status/keycard/connect/net/EthereumRPC.kt @@ -18,7 +18,7 @@ class EthereumRPC(endpointURL: String) { init { val moshi = Moshi.Builder().build() val type: Type = Types.newParameterizedType(Map::class.java, String::class.java, Any::class.java) - ethplorerJSONAdapter = moshi.adapter>(type) + ethplorerJSONAdapter = moshi.adapter(type) } fun changeEndpoint(endpointURL: String) { diff --git a/app/src/main/java/im/status/keycard/connect/ui/ChangePINActivity.kt b/app/src/main/java/im/status/keycard/connect/ui/ChangePINActivity.kt index c2f458c..c056ca3 100644 --- a/app/src/main/java/im/status/keycard/connect/ui/ChangePINActivity.kt +++ b/app/src/main/java/im/status/keycard/connect/ui/ChangePINActivity.kt @@ -2,18 +2,25 @@ package im.status.keycard.connect.ui import android.os.Bundle import android.view.View +import android.widget.Button import android.widget.EditText import androidx.appcompat.app.AppCompatActivity +import androidx.core.widget.doAfterTextChanged import im.status.keycard.connect.R import im.status.keycard.connect.Registry import im.status.keycard.connect.card.ChangePINCommand import im.status.keycard.connect.card.scriptWithAuthentication +import im.status.keycard.connect.data.isValidPIN class ChangePINActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { - //TODO: pin validation and confirmation super.onCreate(savedInstanceState) setContentView(R.layout.activity_change_pin) + + val pinText = findViewById(R.id.newPINText) + val pinConfirmation = findViewById(R.id.pinConfirmation) + pinText.doAfterTextChanged { validatePIN() } + pinConfirmation.doAfterTextChanged { validatePIN() } } fun ok(@Suppress("UNUSED_PARAMETER") view: View) { @@ -26,4 +33,11 @@ class ChangePINActivity : AppCompatActivity() { fun cancel(@Suppress("UNUSED_PARAMETER") view: View) { finish() } + + private fun validatePIN() { + val pinText = findViewById(R.id.newPINText).text.toString() + val pinConfirmation = findViewById(R.id.pinConfirmation).text.toString() + val button = findViewById