aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTorsten Grote <t@grobox.de>2023-04-11 11:00:40 -0300
committerTorsten Grote <t@grobox.de>2023-04-11 11:00:40 -0300
commitf5aced13fda3132d5ee3a6947fe95f7b7b22b98a (patch)
treefe3f89cc2f43a5c87cc154a9e9f706bc5bd56b8f
parente6f87a0a63e8692bbde182877366719e4ea9ab94 (diff)
downloadtaler-android-f5aced13fda3132d5ee3a6947fe95f7b7b22b98a.tar.gz
taler-android-f5aced13fda3132d5ee3a6947fe95f7b7b22b98a.tar.bz2
taler-android-f5aced13fda3132d5ee3a6947fe95f7b7b22b98a.zip
[wallet] Validate IBAN with wallet core when making deposits
-rw-r--r--wallet/src/main/java/net/taler/wallet/deposit/DepositManager.kt33
-rw-r--r--wallet/src/main/java/net/taler/wallet/deposit/DepositState.kt1
-rw-r--r--wallet/src/main/java/net/taler/wallet/deposit/MakeDepositComposable.kt24
-rw-r--r--wallet/src/main/res/values/strings.xml1
4 files changed, 52 insertions, 7 deletions
diff --git a/wallet/src/main/java/net/taler/wallet/deposit/DepositManager.kt b/wallet/src/main/java/net/taler/wallet/deposit/DepositManager.kt
index 0f10b5f..91f7ad5 100644
--- a/wallet/src/main/java/net/taler/wallet/deposit/DepositManager.kt
+++ b/wallet/src/main/java/net/taler/wallet/deposit/DepositManager.kt
@@ -47,6 +47,32 @@ class DepositManager(
@UiThread
fun onDepositButtonClicked(amount: Amount, receiverName: String, iban: String, bic: String) {
+ if (depositState.value is DepositState.FeesChecked) {
+ // fees already checked, so IBAN was validated, can make deposit directly
+ makeIbanDeposit(amount, receiverName, iban, bic)
+ } else {
+ // validate IBAN first
+ mDepositState.value = DepositState.CheckingFees
+ scope.launch {
+ api.request("validateIban", ValidateIbanResponse.serializer()) {
+ put("iban", iban)
+ }.onError {
+ Log.e(TAG, "Error validateIban $it")
+ mDepositState.value = DepositState.Error(it.userFacingMsg)
+ }.onSuccess { response ->
+ if (response.valid) {
+ // only prepare/make deposit, if IBAN is valid
+ makeIbanDeposit(amount, receiverName, iban, bic)
+ } else {
+ mDepositState.value = DepositState.IbanInvalid
+ }
+ }
+ }
+ }
+ }
+
+ @UiThread
+ private fun makeIbanDeposit(amount: Amount, receiverName: String, iban: String, bic: String) {
val paytoUri: String = PaytoUriIban(
iban = iban,
bic = bic,
@@ -66,7 +92,7 @@ class DepositManager(
}
private fun makeDeposit(amount: Amount, uri: String) {
- if (depositState.value.showFees) makeDeposit(
+ if (depositState.value is DepositState.FeesChecked) makeDeposit(
paytoUri = uri,
amount = amount,
totalDepositCost = depositState.value.totalDepositCost
@@ -126,6 +152,11 @@ class DepositManager(
}
@Serializable
+data class ValidateIbanResponse(
+ val valid: Boolean,
+)
+
+@Serializable
data class PrepareDepositResponse(
val totalDepositCost: Amount,
val effectiveDepositAmount: Amount,
diff --git a/wallet/src/main/java/net/taler/wallet/deposit/DepositState.kt b/wallet/src/main/java/net/taler/wallet/deposit/DepositState.kt
index 918d74c..a019757 100644
--- a/wallet/src/main/java/net/taler/wallet/deposit/DepositState.kt
+++ b/wallet/src/main/java/net/taler/wallet/deposit/DepositState.kt
@@ -26,6 +26,7 @@ sealed class DepositState {
object Start : DepositState()
object CheckingFees : DepositState()
+ object IbanInvalid : DepositState()
class FeesChecked(
override val totalDepositCost: Amount,
override val effectiveDepositAmount: Amount,
diff --git a/wallet/src/main/java/net/taler/wallet/deposit/MakeDepositComposable.kt b/wallet/src/main/java/net/taler/wallet/deposit/MakeDepositComposable.kt
index becb8c3..176ff97 100644
--- a/wallet/src/main/java/net/taler/wallet/deposit/MakeDepositComposable.kt
+++ b/wallet/src/main/java/net/taler/wallet/deposit/MakeDepositComposable.kt
@@ -91,6 +91,7 @@ fun MakeDepositComposable(
LaunchedEffect(Unit) {
focusRequester.requestFocus()
}
+ val ibanError = state is DepositState.IbanInvalid
OutlinedTextField(
modifier = Modifier
.padding(16.dp),
@@ -99,11 +100,20 @@ fun MakeDepositComposable(
onValueChange = { input ->
iban = input.uppercase()
},
- isError = iban.isBlank(),
+ isError = ibanError,
+ supportingText = {
+ if (ibanError) {
+ Text(
+ modifier = Modifier.fillMaxWidth(),
+ text = stringResource(R.string.send_deposit_iban_error),
+ color = MaterialTheme.colorScheme.error
+ )
+ }
+ },
label = {
Text(
text = stringResource(R.string.send_deposit_iban),
- color = if (iban.isBlank()) {
+ color = if (ibanError) {
MaterialTheme.colorScheme.error
} else Color.Unspecified,
)
@@ -190,10 +200,12 @@ fun MakeDepositComposable(
onMakeDeposit(amount, name, iban, bic)
},
) {
- Text(text = stringResource(
- if (state.showFees) R.string.send_deposit_create_button
- else R.string.send_deposit_check_fees_button
- ))
+ Text(
+ text = stringResource(
+ if (state is DepositState.FeesChecked) R.string.send_deposit_create_button
+ else R.string.send_deposit_check_fees_button
+ )
+ )
}
}
}
diff --git a/wallet/src/main/res/values/strings.xml b/wallet/src/main/res/values/strings.xml
index 67d2033..cc0a31c 100644
--- a/wallet/src/main/res/values/strings.xml
+++ b/wallet/src/main/res/values/strings.xml
@@ -136,6 +136,7 @@ GNU Taler is immune against many types of fraud, such as phishing of credit card
<string name="send_deposit_bitcoin">To a Bitcoin wallet</string>
<string name="send_deposit_title">Deposit to a bank account</string>
<string name="send_deposit_iban">IBAN</string>
+ <string name="send_deposit_iban_error">IBAN is invalid</string>
<string name="send_deposit_bic">BIC/SWIFT</string>
<string name="send_deposit_name">Account holder</string>
<string name="send_deposit_bitcoin_address">Bitcoin address</string>