summaryrefslogtreecommitdiff
path: root/wallet/src/main/java/net/taler
diff options
context:
space:
mode:
authorTorsten Grote <t@grobox.de>2023-01-06 11:43:10 -0300
committerTorsten Grote <t@grobox.de>2023-01-06 11:43:10 -0300
commit905c63242ba6d80caece6c18b2b867cb300bbe7b (patch)
tree4fa9ac1249c498adba221892077cd1895a38f28e /wallet/src/main/java/net/taler
parent6f45cd9e9f4e25df5048854cc421178f1cd66a59 (diff)
downloadtaler-android-905c63242ba6d80caece6c18b2b867cb300bbe7b.tar.gz
taler-android-905c63242ba6d80caece6c18b2b867cb300bbe7b.tar.bz2
taler-android-905c63242ba6d80caece6c18b2b867cb300bbe7b.zip
[wallet] Allow to restrict coins to age when withdrawing
#0007352
Diffstat (limited to 'wallet/src/main/java/net/taler')
-rw-r--r--wallet/src/main/java/net/taler/wallet/withdraw/PromptWithdrawFragment.kt20
-rw-r--r--wallet/src/main/java/net/taler/wallet/withdraw/WithdrawManager.kt32
2 files changed, 41 insertions, 11 deletions
diff --git a/wallet/src/main/java/net/taler/wallet/withdraw/PromptWithdrawFragment.kt b/wallet/src/main/java/net/taler/wallet/withdraw/PromptWithdrawFragment.kt
index 3cd2f49..dbf901a 100644
--- a/wallet/src/main/java/net/taler/wallet/withdraw/PromptWithdrawFragment.kt
+++ b/wallet/src/main/java/net/taler/wallet/withdraw/PromptWithdrawFragment.kt
@@ -20,6 +20,7 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
+import android.widget.ArrayAdapter
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import androidx.navigation.fragment.findNavController
@@ -114,13 +115,18 @@ class PromptWithdrawFragment : Fragment() {
}
private fun onReceivedDetails(s: ReceivedDetails) {
- showContent(s.amountRaw, s.amountEffective, s.exchangeBaseUrl, s.talerWithdrawUri)
+ showContent(s.amountRaw, s.amountEffective, s.exchangeBaseUrl, s.talerWithdrawUri,
+ s.ageRestrictionOptions)
ui.confirmWithdrawButton.apply {
text = getString(R.string.withdraw_button_confirm)
setOnClickListener {
it.fadeOut()
ui.confirmProgressBar.fadeIn()
- withdrawManager.acceptWithdrawal()
+ val ageRestrict = (ui.ageSelector.selectedItem as String?)?.let { age ->
+ if (age == context.getString(R.string.withdraw_restrict_age_unrestricted)) null
+ else age.toIntOrNull()
+ }
+ withdrawManager.acceptWithdrawal(ageRestrict)
}
isEnabled = true
}
@@ -131,6 +137,7 @@ class PromptWithdrawFragment : Fragment() {
amountEffective: Amount,
exchange: String,
uri: String?,
+ ageRestrictionOptions: List<Int>? = null,
) {
model.showProgressBar.value = false
ui.progressBar.fadeOut()
@@ -160,6 +167,15 @@ class PromptWithdrawFragment : Fragment() {
}
}
+ if (ageRestrictionOptions != null) {
+ ui.ageLabel.fadeIn()
+ val context = requireContext()
+ val items = listOf(context.getString(R.string.withdraw_restrict_age_unrestricted)) +
+ ageRestrictionOptions.map { it.toString() }
+ ui.ageSelector.adapter = ArrayAdapter(context, R.layout.list_item_age, items)
+ ui.ageSelector.fadeIn()
+ }
+
ui.withdrawCard.fadeIn()
}
diff --git a/wallet/src/main/java/net/taler/wallet/withdraw/WithdrawManager.kt b/wallet/src/main/java/net/taler/wallet/withdraw/WithdrawManager.kt
index 6fdc916..1698a10 100644
--- a/wallet/src/main/java/net/taler/wallet/withdraw/WithdrawManager.kt
+++ b/wallet/src/main/java/net/taler/wallet/withdraw/WithdrawManager.kt
@@ -44,6 +44,7 @@ sealed class WithdrawStatus {
val exchangeBaseUrl: String,
val amountRaw: Amount,
val amountEffective: Amount,
+ val ageRestrictionOptions: List<Int>? = null,
val tosText: String,
val tosEtag: String,
val showImmediately: Event<Boolean>,
@@ -54,11 +55,12 @@ sealed class WithdrawStatus {
val exchangeBaseUrl: String,
val amountRaw: Amount,
val amountEffective: Amount,
+ val ageRestrictionOptions: List<Int>? = null,
) : WithdrawStatus()
object Withdrawing : WithdrawStatus()
data class Success(val currency: String) : WithdrawStatus()
- sealed class ManualTransferRequired: WithdrawStatus() {
+ sealed class ManualTransferRequired : WithdrawStatus() {
abstract val uri: Uri
abstract val transactionId: String?
}
@@ -103,6 +105,7 @@ data class WithdrawalDetails(
val tosAccepted: Boolean,
val amountRaw: Amount,
val amountEffective: Amount,
+ val ageRestrictionOptions: List<Int>? = null,
)
@Serializable
@@ -152,9 +155,12 @@ class WithdrawManager(
if (details.defaultExchangeBaseUrl == null) {
val exchangeSelection = ExchangeSelection(details.amount, uri)
withdrawStatus.value = WithdrawStatus.NeedsExchange(exchangeSelection.toEvent())
- } else {
- getWithdrawalDetails(details.defaultExchangeBaseUrl, details.amount, false, uri)
- }
+ } else getWithdrawalDetails(
+ exchangeBaseUrl = details.defaultExchangeBaseUrl,
+ amount = details.amount,
+ showTosImmediately = false,
+ uri = uri,
+ )
}
}
@@ -177,6 +183,7 @@ class WithdrawManager(
exchangeBaseUrl = exchangeBaseUrl,
amountRaw = details.amountRaw,
amountEffective = details.amountEffective,
+ ageRestrictionOptions = details.ageRestrictionOptions,
)
} else getExchangeTos(exchangeBaseUrl, details, showTosImmediately, uri)
}
@@ -198,6 +205,7 @@ class WithdrawManager(
exchangeBaseUrl = exchangeBaseUrl,
amountRaw = details.amountRaw,
amountEffective = details.amountEffective,
+ ageRestrictionOptions = details.ageRestrictionOptions,
tosText = it.content,
tosEtag = it.currentEtag,
showImmediately = showImmediately.toEvent(),
@@ -221,23 +229,28 @@ class WithdrawManager(
exchangeBaseUrl = s.exchangeBaseUrl,
amountRaw = s.amountRaw,
amountEffective = s.amountEffective,
+ ageRestrictionOptions = s.ageRestrictionOptions,
)
}
}
@UiThread
- fun acceptWithdrawal() = scope.launch {
+ fun acceptWithdrawal(restrictAge: Int? = null) = scope.launch {
val status = withdrawStatus.value as ReceivedDetails
withdrawStatus.value = WithdrawStatus.Withdrawing
if (status.talerWithdrawUri == null) {
- acceptManualWithdrawal(status)
+ acceptManualWithdrawal(status, restrictAge)
} else {
- acceptBankIntegratedWithdrawal(status)
+ acceptBankIntegratedWithdrawal(status, restrictAge)
}
}
- private suspend fun acceptBankIntegratedWithdrawal(status: ReceivedDetails) {
+ private suspend fun acceptBankIntegratedWithdrawal(
+ status: ReceivedDetails,
+ restrictAge: Int? = null,
+ ) {
api.request<Unit>("acceptBankIntegratedWithdrawal") {
+ restrictAge?.let { put("restrictAge", restrictAge) }
put("exchangeBaseUrl", status.exchangeBaseUrl)
put("talerWithdrawUri", status.talerWithdrawUri)
}.onError {
@@ -247,8 +260,9 @@ class WithdrawManager(
}
}
- private suspend fun acceptManualWithdrawal(status: ReceivedDetails) {
+ private suspend fun acceptManualWithdrawal(status: ReceivedDetails, restrictAge: Int? = null) {
api.request("acceptManualWithdrawal", AcceptManualWithdrawalResponse.serializer()) {
+ restrictAge?.let { put("restrictAge", restrictAge) }
put("exchangeBaseUrl", status.exchangeBaseUrl)
put("amount", status.amountRaw.toJSONString())
}.onError {