aboutsummaryrefslogtreecommitdiff
path: root/wallet/src/main/java/net/taler
diff options
context:
space:
mode:
authorTorsten Grote <t@grobox.de>2020-04-02 13:48:33 -0300
committerTorsten Grote <t@grobox.de>2020-04-02 13:48:33 -0300
commita6e5a8d9f210618d779d43c859234b94827bf172 (patch)
tree77ea746665a3d32b2f3e68e33f2f586ea7b8d2e3 /wallet/src/main/java/net/taler
parentc3f777e6154d33d26b2431fa886678edf029dd34 (diff)
downloadtaler-android-a6e5a8d9f210618d779d43c859234b94827bf172.tar.gz
taler-android-a6e5a8d9f210618d779d43c859234b94827bf172.tar.bz2
taler-android-a6e5a8d9f210618d779d43c859234b94827bf172.zip
[wallet] Show withdraw summary before ToS and do one-click accept
Diffstat (limited to 'wallet/src/main/java/net/taler')
-rw-r--r--wallet/src/main/java/net/taler/wallet/withdraw/PromptWithdrawFragment.kt62
-rw-r--r--wallet/src/main/java/net/taler/wallet/withdraw/ReviewExchangeTosFragment.kt11
-rw-r--r--wallet/src/main/java/net/taler/wallet/withdraw/WithdrawManager.kt68
3 files changed, 70 insertions, 71 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 61aed4a..875a9c4 100644
--- a/wallet/src/main/java/net/taler/wallet/withdraw/PromptWithdrawFragment.kt
+++ b/wallet/src/main/java/net/taler/wallet/withdraw/PromptWithdrawFragment.kt
@@ -25,6 +25,7 @@ import androidx.fragment.app.activityViewModels
import androidx.lifecycle.Observer
import androidx.navigation.fragment.findNavController
import kotlinx.android.synthetic.main.fragment_prompt_withdraw.*
+import net.taler.common.Amount
import net.taler.common.fadeIn
import net.taler.common.fadeOut
import net.taler.wallet.R
@@ -48,34 +49,23 @@ class PromptWithdrawFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
- confirmWithdrawButton.setOnClickListener {
- val status = withdrawManager.withdrawStatus.value
- if (status !is WithdrawStatus.ReceivedDetails) throw AssertionError()
- it.fadeOut()
- confirmProgressBar.fadeIn()
- withdrawManager.acceptWithdrawal(status.talerWithdrawUri, status.suggestedExchange)
- }
-
withdrawManager.withdrawStatus.observe(viewLifecycleOwner, Observer {
showWithdrawStatus(it)
})
}
- private fun showWithdrawStatus(status: WithdrawStatus?) = when (status) {
+ private fun showWithdrawStatus(status: WithdrawStatus?): Any = when (status) {
is WithdrawStatus.ReceivedDetails -> {
- model.showProgressBar.value = false
- progressBar.fadeOut()
-
- introView.fadeIn()
- withdrawAmountView.text = status.amount.toString()
- withdrawAmountView.fadeIn()
- feeView.fadeIn()
-
- exchangeIntroView.fadeIn()
- withdrawExchangeUrl.text = status.suggestedExchange
- withdrawExchangeUrl.fadeIn()
-
- confirmWithdrawButton.isEnabled = true
+ showContent(status.amount, status.suggestedExchange)
+ confirmWithdrawButton.apply {
+ text = getString(R.string.withdraw_button_confirm)
+ setOnClickListener {
+ it.fadeOut()
+ confirmProgressBar.fadeIn()
+ withdrawManager.acceptWithdrawal(status.talerWithdrawUri, status.suggestedExchange)
+ }
+ isEnabled = true
+ }
}
is WithdrawStatus.Success -> {
model.showProgressBar.value = false
@@ -89,8 +79,14 @@ class PromptWithdrawFragment : Fragment() {
model.showProgressBar.value = true
}
is TermsOfServiceReviewRequired -> {
- model.showProgressBar.value = false
- findNavController().navigate(R.id.action_promptWithdraw_to_reviewExchangeTOS)
+ showContent(status.amount, status.suggestedExchange)
+ confirmWithdrawButton.apply {
+ text = getString(R.string.withdraw_button_tos)
+ setOnClickListener {
+ findNavController().navigate(R.id.action_promptWithdraw_to_reviewExchangeTOS)
+ }
+ isEnabled = true
+ }
}
is WithdrawStatus.Error -> {
model.showProgressBar.value = false
@@ -99,4 +95,22 @@ class PromptWithdrawFragment : Fragment() {
null -> model.showProgressBar.value = false
}
+ private fun showContent(amount: Amount, exchange: String) {
+ model.showProgressBar.value = false
+ progressBar.fadeOut()
+
+ introView.fadeIn()
+ withdrawAmountView.text = amount.toString()
+ withdrawAmountView.fadeIn()
+ feeView.fadeIn()
+
+ exchangeIntroView.fadeIn()
+ withdrawExchangeUrl.text = exchange.let {
+ if (it.startsWith("https://")) it.substring(8) else it
+ }.trimEnd('/')
+ withdrawExchangeUrl.fadeIn()
+
+ withdrawCard.fadeIn()
+ }
+
}
diff --git a/wallet/src/main/java/net/taler/wallet/withdraw/ReviewExchangeTosFragment.kt b/wallet/src/main/java/net/taler/wallet/withdraw/ReviewExchangeTosFragment.kt
index d998e5d..af76971 100644
--- a/wallet/src/main/java/net/taler/wallet/withdraw/ReviewExchangeTosFragment.kt
+++ b/wallet/src/main/java/net/taler/wallet/withdraw/ReviewExchangeTosFragment.kt
@@ -47,14 +47,7 @@ class ReviewExchangeTosFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
acceptTosCheckBox.isChecked = false
- acceptTosCheckBox.setOnCheckedChangeListener { _, isChecked ->
- acceptTosButton.isEnabled = isChecked
- }
-// abortTosButton.setOnClickListener {
-// withdrawManager.cancelCurrentWithdraw()
-// findNavController().navigateUp()
-// }
- acceptTosButton.setOnClickListener {
+ acceptTosCheckBox.setOnCheckedChangeListener { _, _ ->
withdrawManager.acceptCurrentTermsOfService()
}
withdrawManager.withdrawStatus.observe(viewLifecycleOwner, Observer {
@@ -71,8 +64,6 @@ class ReviewExchangeTosFragment : Fragment() {
is WithdrawStatus.ReceivedDetails -> {
findNavController().navigate(R.id.action_reviewExchangeTOS_to_promptWithdraw)
}
- else -> {
- }
}
})
}
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 d686465..e252627 100644
--- a/wallet/src/main/java/net/taler/wallet/withdraw/WithdrawManager.kt
+++ b/wallet/src/main/java/net/taler/wallet/withdraw/WithdrawManager.kt
@@ -21,6 +21,7 @@ import androidx.lifecycle.MutableLiveData
import net.taler.common.Amount
import net.taler.wallet.TAG
import net.taler.wallet.backend.WalletBackendApi
+import net.taler.wallet.withdraw.WithdrawStatus.ReceivedDetails
import org.json.JSONObject
sealed class WithdrawStatus {
@@ -62,9 +63,9 @@ class WithdrawManager(private val walletBackendApi: WalletBackendApi) {
}
fun getWithdrawalInfo(talerWithdrawUri: String) {
- val args = JSONObject()
- args.put("talerWithdrawUri", talerWithdrawUri)
-
+ val args = JSONObject().apply {
+ put("talerWithdrawUri", talerWithdrawUri)
+ }
withdrawStatus.value = WithdrawStatus.Loading(talerWithdrawUri)
this.currentWithdrawRequestId++
@@ -97,12 +98,13 @@ class WithdrawManager(private val walletBackendApi: WalletBackendApi) {
}
private fun getWithdrawalInfoWithExchange(talerWithdrawUri: String, selectedExchange: String) {
- val args = JSONObject()
- args.put("talerWithdrawUri", talerWithdrawUri)
- args.put("selectedExchange", selectedExchange)
+ val args = JSONObject().apply {
+ put("talerWithdrawUri", talerWithdrawUri)
+ put("selectedExchange", selectedExchange)
+ }
- this.currentWithdrawRequestId++
- val myWithdrawRequestId = this.currentWithdrawRequestId
+ currentWithdrawRequestId++
+ val myWithdrawRequestId = currentWithdrawRequestId
walletBackendApi.sendRequest("getWithdrawDetailsForUri", args) { isError, result ->
if (isError) {
@@ -111,15 +113,15 @@ class WithdrawManager(private val walletBackendApi: WalletBackendApi) {
withdrawStatus.postValue(WithdrawStatus.Error(message))
return@sendRequest
}
- if (myWithdrawRequestId != this.currentWithdrawRequestId) {
- val mismatch = "$myWithdrawRequestId != ${this.currentWithdrawRequestId}"
+ if (myWithdrawRequestId != currentWithdrawRequestId) {
+ val mismatch = "$myWithdrawRequestId != $currentWithdrawRequestId"
Log.w(TAG, "Got withdraw result for different request id $mismatch")
return@sendRequest
}
Log.v(TAG, "got getWithdrawDetailsForUri result (with exchange details)")
val status = withdrawStatus.value
if (status !is WithdrawStatus.Loading) {
- Log.v(TAG, "ignoring withdrawal info result, not loading.")
+ Log.w(TAG, "ignoring withdrawal info result, not loading.")
return@sendRequest
}
val wi = result.getJSONObject("bankWithdrawDetails")
@@ -145,7 +147,7 @@ class WithdrawManager(private val walletBackendApi: WalletBackendApi) {
)
} else {
withdrawStatus.postValue(
- WithdrawStatus.ReceivedDetails(
+ ReceivedDetails(
status.talerWithdrawUri,
amount,
suggestedExchange
@@ -162,15 +164,16 @@ class WithdrawManager(private val walletBackendApi: WalletBackendApi) {
withdrawStatus.value = WithdrawStatus.Withdrawing(talerWithdrawUri)
- walletBackendApi.sendRequest("acceptWithdrawal", args) { isError, _ ->
+ walletBackendApi.sendRequest("acceptWithdrawal", args) { isError, result ->
if (isError) {
- Log.v(TAG, "got acceptWithdrawal error result")
+ Log.v(TAG, "got acceptWithdrawal error result: ${result.toString(4)}")
return@sendRequest
}
Log.v(TAG, "got acceptWithdrawal result")
val status = withdrawStatus.value
if (status !is WithdrawStatus.Withdrawing) {
- Log.v(TAG, "ignoring acceptWithdrawal result, invalid state")
+ Log.w(TAG, "ignoring acceptWithdrawal result, invalid state: $status")
+ return@sendRequest
}
withdrawStatus.postValue(WithdrawStatus.Success)
}
@@ -180,30 +183,21 @@ class WithdrawManager(private val walletBackendApi: WalletBackendApi) {
* Accept the currently displayed terms of service.
*/
fun acceptCurrentTermsOfService() {
- when (val s = withdrawStatus.value) {
- is WithdrawStatus.TermsOfServiceReviewRequired -> {
- val args = JSONObject()
- args.put("exchangeBaseUrl", s.exchangeBaseUrl)
- args.put("etag", s.tosEtag)
- walletBackendApi.sendRequest("acceptExchangeTermsOfService", args) { isError, _ ->
- if (isError) {
- return@sendRequest
- }
- withdrawStatus.postValue(
- WithdrawStatus.ReceivedDetails(
- s.talerWithdrawUri,
- s.amount,
- s.suggestedExchange
- )
- )
- }
+ val s = withdrawStatus.value
+ check(s is WithdrawStatus.TermsOfServiceReviewRequired)
+
+ val args = JSONObject().apply {
+ put("exchangeBaseUrl", s.exchangeBaseUrl)
+ put("etag", s.tosEtag)
+ }
+ walletBackendApi.sendRequest("acceptExchangeTermsOfService", args) { isError, result ->
+ if (isError) {
+ Log.e(TAG, "Error acceptExchangeTermsOfService ${result.toString(4)}")
+ return@sendRequest
}
+ val status = ReceivedDetails(s.talerWithdrawUri, s.amount, s.suggestedExchange)
+ withdrawStatus.postValue(status)
}
}
- fun cancelCurrentWithdraw() {
- currentWithdrawRequestId++
- withdrawStatus.value = null
- }
-
}