summaryrefslogtreecommitdiff
path: root/app/src/main/java/net/taler
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/net/taler')
-rw-r--r--app/src/main/java/net/taler/wallet/withdraw/ErrorFragment.kt64
-rw-r--r--app/src/main/java/net/taler/wallet/withdraw/PromptWithdrawFragment.kt8
-rw-r--r--app/src/main/java/net/taler/wallet/withdraw/WithdrawManager.kt13
3 files changed, 78 insertions, 7 deletions
diff --git a/app/src/main/java/net/taler/wallet/withdraw/ErrorFragment.kt b/app/src/main/java/net/taler/wallet/withdraw/ErrorFragment.kt
new file mode 100644
index 0000000..f0f6610
--- /dev/null
+++ b/app/src/main/java/net/taler/wallet/withdraw/ErrorFragment.kt
@@ -0,0 +1,64 @@
+/*
+ * This file is part of GNU Taler
+ * (C) 2020 Taler Systems S.A.
+ *
+ * GNU Taler is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+
+package net.taler.wallet.withdraw
+
+import android.os.Bundle
+import android.view.LayoutInflater
+import android.view.View
+import android.view.View.GONE
+import android.view.View.VISIBLE
+import android.view.ViewGroup
+import androidx.fragment.app.Fragment
+import androidx.fragment.app.activityViewModels
+import androidx.navigation.fragment.findNavController
+import kotlinx.android.synthetic.main.fragment_error.*
+import net.taler.wallet.R
+import net.taler.wallet.WalletViewModel
+
+class ErrorFragment : Fragment() {
+
+ private val model: WalletViewModel by activityViewModels()
+ private val withdrawManager by lazy { model.withdrawManager }
+
+ override fun onCreateView(
+ inflater: LayoutInflater, container: ViewGroup?,
+ savedInstanceState: Bundle?
+ ): View? {
+ return inflater.inflate(R.layout.fragment_error, container, false)
+ }
+
+ override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
+ super.onViewCreated(view, savedInstanceState)
+
+ errorTitle.setText(R.string.withdraw_error_title)
+ errorMessage.setText(R.string.withdraw_error_message)
+
+ // show dev error message if dev mode is on
+ val status = withdrawManager.withdrawStatus.value
+ if (model.devMode.value == true && status is WithdrawStatus.Error) {
+ errorDevMessage.visibility = VISIBLE
+ errorDevMessage.text = status.message
+ } else {
+ errorDevMessage.visibility = GONE
+ }
+
+ backButton.setOnClickListener {
+ findNavController().navigateUp()
+ }
+ }
+
+}
diff --git a/app/src/main/java/net/taler/wallet/withdraw/PromptWithdrawFragment.kt b/app/src/main/java/net/taler/wallet/withdraw/PromptWithdrawFragment.kt
index 0b14e32..454816b 100644
--- a/app/src/main/java/net/taler/wallet/withdraw/PromptWithdrawFragment.kt
+++ b/app/src/main/java/net/taler/wallet/withdraw/PromptWithdrawFragment.kt
@@ -67,7 +67,7 @@ class PromptWithdrawFragment : Fragment() {
})
}
- private fun showWithdrawStatus(status: WithdrawStatus) = when (status) {
+ private fun showWithdrawStatus(status: WithdrawStatus?) = when (status) {
is WithdrawStatus.ReceivedDetails -> {
model.showProgressBar.value = false
progressBar.fadeOut()
@@ -86,7 +86,7 @@ class PromptWithdrawFragment : Fragment() {
}
is WithdrawStatus.Success -> {
model.showProgressBar.value = false
- withdrawManager.withdrawStatus.value = WithdrawStatus.None
+ withdrawManager.withdrawStatus.value = null
findNavController().navigate(R.id.action_promptWithdraw_to_withdrawSuccessful)
}
is Loading -> {
@@ -99,9 +99,11 @@ class PromptWithdrawFragment : Fragment() {
model.showProgressBar.value = false
findNavController().navigate(R.id.action_promptWithdraw_to_reviewExchangeTOS)
}
- is WithdrawStatus.None -> {
+ is WithdrawStatus.Error -> {
model.showProgressBar.value = false
+ findNavController().navigate(R.id.action_promptWithdraw_to_errorFragment)
}
+ null -> model.showProgressBar.value = false
}
}
diff --git a/app/src/main/java/net/taler/wallet/withdraw/WithdrawManager.kt b/app/src/main/java/net/taler/wallet/withdraw/WithdrawManager.kt
index 8179d8d..e3af757 100644
--- a/app/src/main/java/net/taler/wallet/withdraw/WithdrawManager.kt
+++ b/app/src/main/java/net/taler/wallet/withdraw/WithdrawManager.kt
@@ -24,7 +24,6 @@ import net.taler.wallet.backend.WalletBackendApi
import org.json.JSONObject
sealed class WithdrawStatus {
- object None : WithdrawStatus()
data class Loading(val talerWithdrawUri: String) : WithdrawStatus()
data class TermsOfServiceReviewRequired(
val talerWithdrawUri: String,
@@ -35,7 +34,6 @@ sealed class WithdrawStatus {
val suggestedExchange: String
) : WithdrawStatus()
- object Success : WithdrawStatus()
data class ReceivedDetails(
val talerWithdrawUri: String,
val amount: Amount,
@@ -43,11 +41,14 @@ sealed class WithdrawStatus {
) : WithdrawStatus()
data class Withdrawing(val talerWithdrawUri: String) : WithdrawStatus()
+
+ object Success : WithdrawStatus()
+ data class Error(val message: String?) : WithdrawStatus()
}
class WithdrawManager(private val walletBackendApi: WalletBackendApi) {
- val withdrawStatus = MutableLiveData<WithdrawStatus>(WithdrawStatus.None)
+ val withdrawStatus = MutableLiveData<WithdrawStatus>()
val testWithdrawalInProgress = MutableLiveData(false)
private var currentWithdrawRequestId = 0
@@ -72,6 +73,8 @@ class WithdrawManager(private val walletBackendApi: WalletBackendApi) {
walletBackendApi.sendRequest("getWithdrawDetailsForUri", args) { isError, result ->
if (isError) {
Log.e(TAG, "Error getWithdrawDetailsForUri ${result.toString(4)}")
+ val message = if (result.has("message")) result.getString("message") else null
+ withdrawStatus.postValue(WithdrawStatus.Error(message))
return@sendRequest
}
if (myWithdrawRequestId != this.currentWithdrawRequestId) {
@@ -104,6 +107,8 @@ class WithdrawManager(private val walletBackendApi: WalletBackendApi) {
walletBackendApi.sendRequest("getWithdrawDetailsForUri", args) { isError, result ->
if (isError) {
Log.e(TAG, "Error getWithdrawDetailsForUri ${result.toString(4)}")
+ val message = if (result.has("message")) result.getString("message") else null
+ withdrawStatus.postValue(WithdrawStatus.Error(message))
return@sendRequest
}
if (myWithdrawRequestId != this.currentWithdrawRequestId) {
@@ -198,7 +203,7 @@ class WithdrawManager(private val walletBackendApi: WalletBackendApi) {
fun cancelCurrentWithdraw() {
currentWithdrawRequestId++
- withdrawStatus.value = WithdrawStatus.None
+ withdrawStatus.value = null
}
}