summaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/net/taler/wallet/PromptPayment.kt7
-rw-r--r--app/src/main/java/net/taler/wallet/WalletViewModel.kt49
-rw-r--r--app/src/main/java/net/taler/wallet/backend/WalletBackendApi.kt7
-rw-r--r--app/src/main/java/net/taler/wallet/backend/WalletBackendService.kt1
4 files changed, 51 insertions, 13 deletions
diff --git a/app/src/main/java/net/taler/wallet/PromptPayment.kt b/app/src/main/java/net/taler/wallet/PromptPayment.kt
index 42a9b39..f5d4bce 100644
--- a/app/src/main/java/net/taler/wallet/PromptPayment.kt
+++ b/app/src/main/java/net/taler/wallet/PromptPayment.kt
@@ -87,12 +87,14 @@ class PromptPayment : Fragment() {
private fun showPayStatus(view: View, payStatus: PayStatus) {
val promptPaymentDetails = view.findViewById<View>(R.id.prompt_payment_details)
val balanceInsufficientWarning = view.findViewById<View>(R.id.balance_insufficient_warning)
+ val errorTextView = view.findViewById<TextView>(R.id.pay_error_text)
val confirmPaymentButton = view.findViewById<Button>(R.id.button_confirm_payment)
when (payStatus) {
is PayStatus.Prepared -> {
fillOrderInfo(view, payStatus.contractTerms, payStatus.totalFees)
promptPaymentDetails.visibility = View.VISIBLE
balanceInsufficientWarning.visibility = View.GONE
+ errorTextView.visibility = View.GONE
confirmPaymentButton.isEnabled = true
confirmPaymentButton.setOnClickListener {
@@ -104,6 +106,7 @@ class PromptPayment : Fragment() {
fillOrderInfo(view, payStatus.contractTerms, null)
promptPaymentDetails.visibility = View.VISIBLE
balanceInsufficientWarning.visibility = View.VISIBLE
+ errorTextView.visibility = View.GONE
confirmPaymentButton.isEnabled = false
}
is PayStatus.Success -> {
@@ -114,6 +117,10 @@ class PromptPayment : Fragment() {
activity!!.findNavController(R.id.nav_host_fragment).navigate(R.id.action_promptPayment_to_alreadyPaid)
model.payStatus.value = PayStatus.None()
}
+ is PayStatus.Error -> {
+ errorTextView.visibility = View.VISIBLE
+ errorTextView.text = "Error: ${payStatus.error}"
+ }
is PayStatus.None -> {
// No payment active.
}
diff --git a/app/src/main/java/net/taler/wallet/WalletViewModel.kt b/app/src/main/java/net/taler/wallet/WalletViewModel.kt
index 9e93fcf..13fa28e 100644
--- a/app/src/main/java/net/taler/wallet/WalletViewModel.kt
+++ b/app/src/main/java/net/taler/wallet/WalletViewModel.kt
@@ -20,6 +20,7 @@ import android.app.Application
import android.util.Log
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.MutableLiveData
+import com.google.android.material.snackbar.Snackbar
import net.taler.wallet.backend.WalletBackendApi
import org.json.JSONObject
@@ -174,8 +175,11 @@ class WalletViewModel(val app: Application) : AndroidViewModel(app) {
return
}
activeGetBalance++
- walletBackendApi.sendRequest("getBalances", null) { result ->
+ walletBackendApi.sendRequest("getBalances", null) { isError, result ->
activeGetBalance--
+ if (isError) {
+ return@sendRequest
+ }
val balanceList = mutableListOf<BalanceEntry>()
val byCurrency = result.getJSONObject("byCurrency")
val currencyList = byCurrency.keys().asSequence().toList().sorted()
@@ -197,8 +201,12 @@ class WalletViewModel(val app: Application) : AndroidViewModel(app) {
return
}
activeGetPending++
- walletBackendApi.sendRequest("getPendingOperations", null) { result ->
+ walletBackendApi.sendRequest("getPendingOperations", null) { isError, result ->
activeGetPending--
+ if (isError) {
+ Log.i(TAG, "got getPending error result")
+ return@sendRequest
+ }
Log.i(TAG, "got getPending result")
val pendingList = mutableListOf<PendingOperationInfo>()
val pendingJson = result.getJSONArray("pendingOperations")
@@ -213,7 +221,10 @@ class WalletViewModel(val app: Application) : AndroidViewModel(app) {
}
fun getHistory(cb: (r: HistoryResult) -> Unit) {
- walletBackendApi.sendRequest("getHistory", null) { result ->
+ walletBackendApi.sendRequest("getHistory", null) { isError, result ->
+ if (isError) {
+ return@sendRequest
+ }
val historyEntries = mutableListOf<HistoryEntry>()
val historyList = result.getJSONArray("history")
for (i in 0 until historyList.length()) {
@@ -232,7 +243,7 @@ class WalletViewModel(val app: Application) : AndroidViewModel(app) {
fun withdrawTestkudos() {
testWithdrawalInProgress.value = true
- walletBackendApi.sendRequest("withdrawTestkudos", null) {
+ walletBackendApi.sendRequest("withdrawTestkudos", null) { _, _ ->
testWithdrawalInProgress.postValue(false)
}
}
@@ -246,7 +257,12 @@ class WalletViewModel(val app: Application) : AndroidViewModel(app) {
val myPayRequestId = this.currentPayRequestId
this.payStatus.value = PayStatus.Loading()
- walletBackendApi.sendRequest("preparePay", args) { result ->
+ walletBackendApi.sendRequest("preparePay", args) { isError, result ->
+ if (isError) {
+ Log.v(TAG, "got preparePay error result")
+ payStatus.value = PayStatus.Error(result.toString(0))
+ return@sendRequest
+ }
Log.v(TAG, "got preparePay result")
if (myPayRequestId != this.currentPayRequestId) {
Log.v(TAG, "preparePay result was for old request")
@@ -292,7 +308,7 @@ class WalletViewModel(val app: Application) : AndroidViewModel(app) {
val args = JSONObject()
args.put("proposalId", proposalId)
- walletBackendApi.sendRequest("confirmPay", args) {
+ walletBackendApi.sendRequest("confirmPay", args) { isError, result ->
payStatus.postValue(PayStatus.Success())
}
}
@@ -325,7 +341,10 @@ class WalletViewModel(val app: Application) : AndroidViewModel(app) {
this.currentWithdrawRequestId++
val myWithdrawRequestId = this.currentWithdrawRequestId
- walletBackendApi.sendRequest("getWithdrawDetailsForUri", args) { result ->
+ walletBackendApi.sendRequest("getWithdrawDetailsForUri", args) { isError, result ->
+ if (isError) {
+ return@sendRequest
+ }
if (myWithdrawRequestId != this.currentWithdrawRequestId) {
return@sendRequest
}
@@ -351,7 +370,10 @@ class WalletViewModel(val app: Application) : AndroidViewModel(app) {
this.currentWithdrawRequestId++
val myWithdrawRequestId = this.currentWithdrawRequestId
- walletBackendApi.sendRequest("getWithdrawDetailsForUri", args) { result ->
+ walletBackendApi.sendRequest("getWithdrawDetailsForUri", args) { isError, result ->
+ if (isError) {
+ return@sendRequest
+ }
if (myWithdrawRequestId != this.currentWithdrawRequestId) {
return@sendRequest
}
@@ -397,7 +419,11 @@ class WalletViewModel(val app: Application) : AndroidViewModel(app) {
withdrawStatus.value = WithdrawStatus.Withdrawing(talerWithdrawUri)
- walletBackendApi.sendRequest("acceptWithdrawal", args) {
+ walletBackendApi.sendRequest("acceptWithdrawal", args) { isError, _ ->
+ if (isError) {
+ Log.v(TAG, "got acceptWithdrawal error result")
+ return@sendRequest
+ }
Log.v(TAG, "got acceptWithdrawal result")
val status = withdrawStatus.value
if (status !is WithdrawStatus.Withdrawing) {
@@ -425,7 +451,10 @@ class WalletViewModel(val app: Application) : AndroidViewModel(app) {
val args = JSONObject()
args.put("exchangeBaseUrl", s.exchangeBaseUrl)
args.put("etag", s.tosEtag)
- walletBackendApi.sendRequest("acceptExchangeTermsOfService", args) {
+ walletBackendApi.sendRequest("acceptExchangeTermsOfService", args) { isError, _ ->
+ if (isError) {
+ return@sendRequest
+ }
// Try withdrawing again with accepted ToS
getWithdrawalInfo(s.talerWithdrawUri)
}
diff --git a/app/src/main/java/net/taler/wallet/backend/WalletBackendApi.kt b/app/src/main/java/net/taler/wallet/backend/WalletBackendApi.kt
index 36795f5..0d078a9 100644
--- a/app/src/main/java/net/taler/wallet/backend/WalletBackendApi.kt
+++ b/app/src/main/java/net/taler/wallet/backend/WalletBackendApi.kt
@@ -33,7 +33,7 @@ class WalletBackendApi(private val app: Application) {
private var walletBackendMessenger: Messenger? = null
private val queuedMessages = LinkedList<Message>()
- private val handlers = SparseArray<(message: JSONObject) -> Unit>()
+ private val handlers = SparseArray<(isError: Boolean, message: JSONObject) -> Unit>()
private var nextRequestID = 1
var notificationHandler: (() -> Unit)? = null
var connectedHandler: (() -> Unit)? = null
@@ -78,8 +78,9 @@ class WalletBackendApi(private val app: Application) {
Log.e(TAG, "response did not contain response payload")
return
}
+ val isError = msg.data.getBoolean("isError")
val json = JSONObject(response)
- h(json)
+ h(isError, json)
}
WalletBackendService.MSG_NOTIFY -> {
val nh = api.notificationHandler
@@ -110,7 +111,7 @@ class WalletBackendApi(private val app: Application) {
fun sendRequest(
operation: String,
args: JSONObject?,
- onResponse: (message: JSONObject) -> Unit = { }
+ onResponse: (isError: Boolean, message: JSONObject) -> Unit = { _, _ -> }
) {
val requestID = nextRequestID++
Log.i(TAG, "sending request for operation $operation ($requestID)")
diff --git a/app/src/main/java/net/taler/wallet/backend/WalletBackendService.kt b/app/src/main/java/net/taler/wallet/backend/WalletBackendService.kt
index 297f0f7..6ae77cc 100644
--- a/app/src/main/java/net/taler/wallet/backend/WalletBackendService.kt
+++ b/app/src/main/java/net/taler/wallet/backend/WalletBackendService.kt
@@ -220,6 +220,7 @@ class WalletBackendService : Service() {
} else {
b.putString("response", "{}")
}
+ b.putBoolean("isError", message.getBoolean("isError"))
b.putInt("requestID", rd.clientRequestID)
b.putString("operation", operation)
rd.messenger.send(m)