aboutsummaryrefslogtreecommitdiff
path: root/wallet/src
diff options
context:
space:
mode:
Diffstat (limited to 'wallet/src')
-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
-rw-r--r--wallet/src/main/res/layout/fragment_prompt_withdraw.xml14
-rw-r--r--wallet/src/main/res/layout/fragment_review_exchange_tos.xml36
-rw-r--r--wallet/src/main/res/navigation/nav_graph.xml7
-rw-r--r--wallet/src/main/res/values/strings.xml7
7 files changed, 94 insertions, 111 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
- }
-
}
diff --git a/wallet/src/main/res/layout/fragment_prompt_withdraw.xml b/wallet/src/main/res/layout/fragment_prompt_withdraw.xml
index fe64bad..b03ee03 100644
--- a/wallet/src/main/res/layout/fragment_prompt_withdraw.xml
+++ b/wallet/src/main/res/layout/fragment_prompt_withdraw.xml
@@ -29,7 +29,7 @@
android:layout_marginEnd="16dp"
android:layout_marginBottom="8dp"
android:gravity="center"
- android:text="@string/withdraw_do_you_want"
+ android:text="@string/withdraw_total"
android:visibility="invisible"
app:layout_constraintBottom_toTopOf="@+id/withdrawAmountView"
app:layout_constraintEnd_toEndOf="parent"
@@ -97,13 +97,13 @@
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:gravity="center"
- android:textSize="25sp"
+ android:textSize="24sp"
android:visibility="invisible"
app:layout_constraintBottom_toTopOf="@+id/withdrawCard"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/exchangeIntroView"
- tools:text="(exchange base url)"
+ tools:text="long.exchange.demo.taler.net"
tools:visibility="visible" />
<ProgressBar
@@ -121,9 +121,11 @@
style="@style/BottomCard"
android:layout_width="0dp"
android:layout_height="wrap_content"
+ android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintStart_toStartOf="parent">
+ app:layout_constraintStart_toStartOf="parent"
+ tools:visibility="visible">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
@@ -140,7 +142,9 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
- app:layout_constraintStart_toStartOf="parent" />
+ app:layout_constraintStart_toStartOf="parent"
+ tools:enabled="true"
+ tools:text="@string/withdraw_button_tos" />
<ProgressBar
android:id="@+id/confirmProgressBar"
diff --git a/wallet/src/main/res/layout/fragment_review_exchange_tos.xml b/wallet/src/main/res/layout/fragment_review_exchange_tos.xml
index 9c7d7a1..2587c1a 100644
--- a/wallet/src/main/res/layout/fragment_review_exchange_tos.xml
+++ b/wallet/src/main/res/layout/fragment_review_exchange_tos.xml
@@ -60,35 +60,15 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
- <androidx.constraintlayout.widget.ConstraintLayout
- android:layout_width="match_parent"
+ <CheckBox
+ android:id="@+id/acceptTosCheckBox"
+ android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:padding="8dp">
-
- <CheckBox
- android:id="@+id/acceptTosCheckBox"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:text="@string/exchange_tos_accept"
- android:visibility="invisible"
- app:layout_constraintBottom_toTopOf="@+id/acceptTosButton"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintStart_toStartOf="parent"
- tools:visibility="visible" />
-
- <Button
- android:id="@+id/acceptTosButton"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:backgroundTint="@color/green"
- android:enabled="false"
- android:text="@string/exchange_tos_button_continue"
- app:layout_constraintBottom_toBottomOf="parent"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintHorizontal_bias="1.0"
- app:layout_constraintStart_toStartOf="parent" />
-
- </androidx.constraintlayout.widget.ConstraintLayout>
+ android:layout_marginStart="8dp"
+ android:layout_marginEnd="8dp"
+ android:text="@string/exchange_tos_accept"
+ android:visibility="invisible"
+ tools:visibility="visible" />
</com.google.android.material.card.MaterialCardView>
diff --git a/wallet/src/main/res/navigation/nav_graph.xml b/wallet/src/main/res/navigation/nav_graph.xml
index 39aa182..9875b8a 100644
--- a/wallet/src/main/res/navigation/nav_graph.xml
+++ b/wallet/src/main/res/navigation/nav_graph.xml
@@ -74,14 +74,13 @@
android:label="@string/nav_prompt_withdraw"
tools:layout="@layout/fragment_prompt_withdraw">
<action
+ android:id="@+id/action_promptWithdraw_to_reviewExchangeTOS"
+ app:destination="@id/reviewExchangeTOS" />
+ <action
android:id="@+id/action_promptWithdraw_to_withdrawSuccessful"
app:destination="@id/withdrawSuccessful"
app:popUpTo="@id/showBalance" />
<action
- android:id="@+id/action_promptWithdraw_to_reviewExchangeTOS"
- app:destination="@id/reviewExchangeTOS"
- app:popUpTo="@id/showBalance" />
- <action
android:id="@+id/action_promptWithdraw_to_errorFragment"
app:destination="@id/errorFragment"
app:popUpTo="@id/showBalance" />
diff --git a/wallet/src/main/res/values/strings.xml b/wallet/src/main/res/values/strings.xml
index b16808c..8cd2dd8 100644
--- a/wallet/src/main/res/values/strings.xml
+++ b/wallet/src/main/res/values/strings.xml
@@ -79,11 +79,12 @@
<string name="withdraw_accepted">Withdrawal accepted</string>
<string name="withdraw_success_info">The wire transfer now needs to be confirmed with the bank. Once the wire transfer is complete, the digital cash will automatically show in this wallet.</string>
- <string name="withdraw_do_you_want">Do you want to withdraw</string>
- <string name="withdraw_fees">(minus exchange fees not shown in this prototype)</string>
- <string name="withdraw_exchange">Using the exchange provider</string>
+ <string name="withdraw_total">Withdraw</string>
+ <string name="withdraw_fees">(minus exchange fees)</string>
+ <string name="withdraw_exchange">Exchange</string>
<string name="withdraw_button_testkudos">Withdraw TESTKUDOS</string>
<string name="withdraw_button_confirm">Confirm Withdraw</string>
+ <string name="withdraw_button_tos">Review Terms</string>
<string name="withdraw_error_title">Withdrawal Error</string>
<string name="withdraw_error_message">Withdrawing is currently not possible. Please try again later!</string>