aboutsummaryrefslogtreecommitdiff
path: root/wallet/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'wallet/src/main/java')
-rw-r--r--wallet/src/main/java/net/taler/wallet/Utils.kt17
-rw-r--r--wallet/src/main/java/net/taler/wallet/payment/PaymentManager.kt8
-rw-r--r--wallet/src/main/java/net/taler/wallet/pending/PendingOperationsManager.kt2
-rw-r--r--wallet/src/main/java/net/taler/wallet/refund/RefundManager.kt1
-rw-r--r--wallet/src/main/java/net/taler/wallet/transactions/TransactionManager.kt5
-rw-r--r--wallet/src/main/java/net/taler/wallet/transactions/TransactionsFragment.kt4
-rw-r--r--wallet/src/main/java/net/taler/wallet/withdraw/WithdrawManager.kt4
7 files changed, 31 insertions, 10 deletions
diff --git a/wallet/src/main/java/net/taler/wallet/Utils.kt b/wallet/src/main/java/net/taler/wallet/Utils.kt
index e299245..ea01552 100644
--- a/wallet/src/main/java/net/taler/wallet/Utils.kt
+++ b/wallet/src/main/java/net/taler/wallet/Utils.kt
@@ -30,6 +30,7 @@ import android.widget.Toast
import android.widget.Toast.LENGTH_LONG
import androidx.annotation.RequiresApi
import com.google.zxing.integration.android.IntentIntegrator
+import org.json.JSONObject
fun scanQrCode(activity: Activity) {
IntentIntegrator(activity).apply {
@@ -90,6 +91,22 @@ private fun connectToWifiDeprecated(context: Context, ssid: String) {
}
}
+fun getErrorString(json: JSONObject): String {
+ return StringBuilder().apply {
+ append(json.getString("talerErrorCode"))
+ append(" ")
+ append(json.getString("message"))
+ json.optJSONObject("details")?.let { details ->
+ details.optJSONObject("errorResponse")?.let { errorResponse ->
+ append("\n\n")
+ append(errorResponse.optString("code"))
+ append(" ")
+ append(errorResponse.optString("hint"))
+ }
+ }
+ }.toString()
+}
+
fun cleanExchange(exchange: String) = exchange.let {
if (it.startsWith("https://")) it.substring(8) else it
}.trimEnd('/')
diff --git a/wallet/src/main/java/net/taler/wallet/payment/PaymentManager.kt b/wallet/src/main/java/net/taler/wallet/payment/PaymentManager.kt
index 2427afb..db21da4 100644
--- a/wallet/src/main/java/net/taler/wallet/payment/PaymentManager.kt
+++ b/wallet/src/main/java/net/taler/wallet/payment/PaymentManager.kt
@@ -26,6 +26,7 @@ import net.taler.common.Amount
import net.taler.common.ContractTerms
import net.taler.wallet.TAG
import net.taler.wallet.backend.WalletBackendApi
+import net.taler.wallet.getErrorString
import net.taler.wallet.payment.PayStatus.AlreadyPaid
import net.taler.wallet.payment.PayStatus.InsufficientBalance
import net.taler.wallet.payment.PreparePayResponse.AlreadyConfirmedResponse
@@ -71,7 +72,7 @@ class PaymentManager(
val args = JSONObject(mapOf("talerPayUri" to url))
walletBackendApi.sendRequest("preparePay", args) { isError, result ->
if (isError) {
- handleError("preparePay", result.toString(2))
+ handleError("preparePay", getErrorString(result))
return@sendRequest
}
val response: PreparePayResponse = mapper.readValue(result.toString())
@@ -84,6 +85,7 @@ class PaymentManager(
}
}
+ // TODO validate product images (or leave to wallet-core?)
private fun getContractTerms(json: JSONObject): ContractTerms {
val terms: ContractTerms = mapper.readValue(json.getString("contractTermsRaw"))
// validate product images
@@ -101,7 +103,7 @@ class PaymentManager(
val args = JSONObject(mapOf("proposalId" to proposalId))
walletBackendApi.sendRequest("confirmPay", args) { isError, result ->
if (isError) {
- handleError("preparePay", result.toString())
+ handleError("preparePay", getErrorString(result))
return@sendRequest
}
mPayStatus.postValue(PayStatus.Success(currency))
@@ -124,7 +126,7 @@ class PaymentManager(
walletBackendApi.sendRequest("abortProposal", args) { isError, result ->
if (isError) {
- handleError("abortProposal", result.toString(2))
+ handleError("abortProposal", getErrorString(result))
Log.e(TAG, "received error response to abortProposal")
return@sendRequest
}
diff --git a/wallet/src/main/java/net/taler/wallet/pending/PendingOperationsManager.kt b/wallet/src/main/java/net/taler/wallet/pending/PendingOperationsManager.kt
index 7027687..df778ed 100644
--- a/wallet/src/main/java/net/taler/wallet/pending/PendingOperationsManager.kt
+++ b/wallet/src/main/java/net/taler/wallet/pending/PendingOperationsManager.kt
@@ -34,7 +34,7 @@ class PendingOperationsManager(private val walletBackendApi: WalletBackendApi) {
internal fun getPending() {
walletBackendApi.sendRequest("getPendingOperations") { isError, result ->
if (isError) {
- Log.i(TAG, "got getPending error result: $result")
+ Log.i(TAG, "got getPending error result: ${result.toString(2)}")
return@sendRequest
}
Log.i(TAG, "got getPending result")
diff --git a/wallet/src/main/java/net/taler/wallet/refund/RefundManager.kt b/wallet/src/main/java/net/taler/wallet/refund/RefundManager.kt
index 21c634e..5593486 100644
--- a/wallet/src/main/java/net/taler/wallet/refund/RefundManager.kt
+++ b/wallet/src/main/java/net/taler/wallet/refund/RefundManager.kt
@@ -36,6 +36,7 @@ class RefundManager(private val walletBackendApi: WalletBackendApi) {
walletBackendApi.sendRequest("applyRefund", args) { isError, result ->
if (isError) {
Log.e(TAG, "Refund Error: $result")
+ // TODO show error string
liveData.postValue(RefundStatus.Error)
} else {
Log.e(TAG, "Refund Success: $result")
diff --git a/wallet/src/main/java/net/taler/wallet/transactions/TransactionManager.kt b/wallet/src/main/java/net/taler/wallet/transactions/TransactionManager.kt
index bd37b37..8ec3914 100644
--- a/wallet/src/main/java/net/taler/wallet/transactions/TransactionManager.kt
+++ b/wallet/src/main/java/net/taler/wallet/transactions/TransactionManager.kt
@@ -27,12 +27,13 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import net.taler.wallet.backend.WalletBackendApi
+import net.taler.wallet.getErrorString
import org.json.JSONObject
import java.util.HashMap
import java.util.LinkedList
sealed class TransactionsResult {
- object Error : TransactionsResult()
+ class Error(val msg: String) : TransactionsResult()
class Success(val transactions: List<Transaction>) : TransactionsResult()
}
@@ -72,7 +73,7 @@ class TransactionManager(
searchQuery?.let { request.put("search", it) }
walletBackendApi.sendRequest("getTransactions", request) { isError, result ->
if (isError) {
- liveData.postValue(TransactionsResult.Error)
+ liveData.postValue(TransactionsResult.Error(getErrorString(result)))
mProgress.postValue(false)
} else {
val currencyToUpdate = if (searchQuery == null) currency else null
diff --git a/wallet/src/main/java/net/taler/wallet/transactions/TransactionsFragment.kt b/wallet/src/main/java/net/taler/wallet/transactions/TransactionsFragment.kt
index 2ae58c3..8d47a3f 100644
--- a/wallet/src/main/java/net/taler/wallet/transactions/TransactionsFragment.kt
+++ b/wallet/src/main/java/net/taler/wallet/transactions/TransactionsFragment.kt
@@ -160,9 +160,9 @@ class TransactionsFragment : Fragment(), OnTransactionClickListener, ActionMode.
}
private fun onTransactionsResult(result: TransactionsResult) = when (result) {
- TransactionsResult.Error -> {
+ is TransactionsResult.Error -> {
list.fadeOut()
- emptyState.text = getString(R.string.transactions_error)
+ emptyState.text = getString(R.string.transactions_error, result.msg)
emptyState.fadeIn()
}
is TransactionsResult.Success -> {
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 e14a747..6fb9390 100644
--- a/wallet/src/main/java/net/taler/wallet/withdraw/WithdrawManager.kt
+++ b/wallet/src/main/java/net/taler/wallet/withdraw/WithdrawManager.kt
@@ -26,6 +26,7 @@ import net.taler.wallet.TAG
import net.taler.wallet.backend.WalletBackendApi
import net.taler.wallet.exchanges.ExchangeFees
import net.taler.wallet.exchanges.ExchangeItem
+import net.taler.wallet.getErrorString
import net.taler.wallet.withdraw.WithdrawStatus.ReceivedDetails
import org.json.JSONObject
@@ -196,8 +197,7 @@ class WithdrawManager(
@UiThread
private fun handleError(operation: String, result: JSONObject) {
Log.e(TAG, "Error $operation ${result.toString(2)}")
- val message = if (result.has("message")) result.getString("message") else null
- withdrawStatus.value = WithdrawStatus.Error(message)
+ withdrawStatus.value = WithdrawStatus.Error(getErrorString(result))
}
}