summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTorsten Grote <t@grobox.de>2020-03-06 12:56:55 -0300
committerTorsten Grote <t@grobox.de>2020-03-06 12:56:55 -0300
commitd9a578ad4a0b64f87c81d825d784ce14ce5778b2 (patch)
treeb17540ef2cc33d9772564026be156089776bf35b
parent826c0167e37d25c2437d67d1d893586e9b9dadd5 (diff)
downloadwallet-android-d9a578ad4a0b64f87c81d825d784ce14ce5778b2.tar.gz
wallet-android-d9a578ad4a0b64f87c81d825d784ce14ce5778b2.tar.bz2
wallet-android-d9a578ad4a0b64f87c81d825d784ce14ce5778b2.zip
Show error screen when withdrawal fails
-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
-rw-r--r--app/src/main/res/drawable/ic_error.xml25
-rw-r--r--app/src/main/res/layout/fragment_error.xml97
-rw-r--r--app/src/main/res/layout/fragment_withdraw_successful.xml3
-rw-r--r--app/src/main/res/navigation/nav_graph.xml9
-rw-r--r--app/src/main/res/values/strings.xml4
8 files changed, 215 insertions, 8 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
}
}
diff --git a/app/src/main/res/drawable/ic_error.xml b/app/src/main/res/drawable/ic_error.xml
new file mode 100644
index 0000000..1f705af
--- /dev/null
+++ b/app/src/main/res/drawable/ic_error.xml
@@ -0,0 +1,25 @@
+<!--
+ ~ 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/>
+ -->
+
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24.0"
+ android:viewportHeight="24.0">
+ <path
+ android:fillColor="#FF000000"
+ android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM13,17h-2v-2h2v2zM13,13h-2L11,7h2v6z"/>
+</vector>
diff --git a/app/src/main/res/layout/fragment_error.xml b/app/src/main/res/layout/fragment_error.xml
new file mode 100644
index 0000000..3d977dd
--- /dev/null
+++ b/app/src/main/res/layout/fragment_error.xml
@@ -0,0 +1,97 @@
+<?xml version="1.0" encoding="utf-8"?><!--
+ ~ 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/>
+ -->
+
+<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ tools:context=".withdraw.ErrorFragment">
+
+ <ImageView
+ android:id="@+id/errorImageView"
+ android:layout_width="0dp"
+ android:layout_height="0dp"
+ android:layout_margin="16dp"
+ android:alpha="0.56"
+ android:src="@drawable/ic_error"
+ android:tint="@color/red"
+ app:layout_constraintBottom_toTopOf="@+id/errorTitle"
+ app:layout_constraintDimensionRatio="1:1"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toTopOf="parent"
+ app:layout_constraintVertical_bias="0.0"
+ app:layout_constraintVertical_chainStyle="packed"
+ tools:ignore="ContentDescription" />
+
+ <TextView
+ android:id="@+id/errorTitle"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_margin="16dp"
+ android:gravity="center_horizontal|top"
+ android:minHeight="64dp"
+ android:textColor="@color/red"
+ app:autoSizeMaxTextSize="40sp"
+ app:autoSizeTextType="uniform"
+ app:layout_constraintBottom_toTopOf="@+id/errorMessage"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toBottomOf="@+id/errorImageView"
+ tools:text="@string/withdraw_error_title" />
+
+ <TextView
+ android:id="@+id/errorMessage"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_margin="16dp"
+ android:gravity="center"
+ android:textAppearance="@style/TextAppearance.AppCompat.Medium"
+ app:layout_constraintBottom_toTopOf="@+id/errorDevMessage"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toBottomOf="@+id/errorTitle"
+ tools:text="@string/withdraw_error_message" />
+
+ <TextView
+ android:id="@+id/errorDevMessage"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_margin="16dp"
+ android:fontFamily="monospace"
+ android:gravity="center"
+ android:textColor="@color/red"
+ android:textIsSelectable="true"
+ android:visibility="gone"
+ app:layout_constraintBottom_toTopOf="@+id/backButton"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toBottomOf="@+id/errorMessage"
+ tools:text="Error: Fetching keys failed: unexpected status for keys: 502"
+ tools:visibility="visible" />
+
+ <Button
+ android:id="@+id/backButton"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_margin="16dp"
+ android:text="@string/button_back"
+ app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintStart_toStartOf="parent" />
+
+</androidx.constraintlayout.widget.ConstraintLayout>
diff --git a/app/src/main/res/layout/fragment_withdraw_successful.xml b/app/src/main/res/layout/fragment_withdraw_successful.xml
index d1b9c90..2b7c308 100644
--- a/app/src/main/res/layout/fragment_withdraw_successful.xml
+++ b/app/src/main/res/layout/fragment_withdraw_successful.xml
@@ -43,6 +43,7 @@
android:layout_margin="16dp"
android:text="@string/withdraw_success_info"
android:textAlignment="center"
+ android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintBottom_toTopOf="@+id/backButton"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
@@ -53,7 +54,7 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="16dp"
- android:text="@string/button_back"
+ android:text="@string/button_continue"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
diff --git a/app/src/main/res/navigation/nav_graph.xml b/app/src/main/res/navigation/nav_graph.xml
index e540c12..549ca01 100644
--- a/app/src/main/res/navigation/nav_graph.xml
+++ b/app/src/main/res/navigation/nav_graph.xml
@@ -81,6 +81,10 @@
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" />
</fragment>
<fragment
@@ -104,6 +108,11 @@
android:name="net.taler.wallet.pending.PendingOperationsFragment"
android:label="Pending Operations"
tools:layout="@layout/fragment_pending_operations" />
+ <fragment
+ android:id="@+id/errorFragment"
+ android:name="net.taler.wallet.withdraw.ErrorFragment"
+ android:label="@string/nav_error"
+ tools:layout="@layout/fragment_error" />
<action
android:id="@+id/action_global_promptPayment"
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index b8f41fb..5120492 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -23,9 +23,11 @@
<string name="nav_prompt_withdraw">Withdraw Digital Cash</string>
<string name="nav_exchange_tos">Exchange\'s Terms of Service</string>
+ <string name="nav_error">Error</string>
<string name="button_back">Go Back</string>
<string name="button_cancel">Cancel</string>
+ <string name="button_continue">Continue</string>
<string name="button_scan_qr_code">Scan Taler QR Code</string>
<string name="menu_history">History</string>
@@ -84,6 +86,8 @@
<string name="withdraw_exchange">Using the exchange provider</string>
<string name="withdraw_button_testkudos">Withdraw TESTKUDOS</string>
<string name="withdraw_button_confirm">Confirm Withdraw</string>
+ <string name="withdraw_error_title">Withdrawal Error</string>
+ <string name="withdraw_error_message">Withdrawing is currently not possible. Please try again later!</string>
<string name="pending_operations_title">Pending Operations</string>
<string name="pending_operations_refuse">Refuse Proposal</string>