aboutsummaryrefslogtreecommitdiff
path: root/wallet/src/main/java/net/taler
diff options
context:
space:
mode:
Diffstat (limited to 'wallet/src/main/java/net/taler')
-rw-r--r--wallet/src/main/java/net/taler/wallet/MainActivity.kt25
-rw-r--r--wallet/src/main/java/net/taler/wallet/MainViewModel.kt2
-rw-r--r--wallet/src/main/java/net/taler/wallet/refund/RefundManager.kt35
-rw-r--r--wallet/src/main/java/net/taler/wallet/transactions/TransactionDetailFragment.kt7
-rw-r--r--wallet/src/main/java/net/taler/wallet/transactions/TransactionManager.kt2
-rw-r--r--wallet/src/main/java/net/taler/wallet/transactions/Transactions.kt7
6 files changed, 54 insertions, 24 deletions
diff --git a/wallet/src/main/java/net/taler/wallet/MainActivity.kt b/wallet/src/main/java/net/taler/wallet/MainActivity.kt
index c7c31ca..838ed2d 100644
--- a/wallet/src/main/java/net/taler/wallet/MainActivity.kt
+++ b/wallet/src/main/java/net/taler/wallet/MainActivity.kt
@@ -163,15 +163,7 @@ class MainActivity : AppCompatActivity(), OnNavigationItemSelectedListener,
}
url.toLowerCase(ROOT).startsWith("taler://refund/") -> {
model.showProgressBar.value = true
- model.refundManager.refund(url).observe(this, Observer { status ->
- model.showProgressBar.value = false
- val res = when (status) {
- is RefundStatus.Error -> R.string.refund_error
- // TODO once wallet-core exposes currency, navigate to its transaction list
- is RefundStatus.Success -> R.string.refund_success
- }
- Snackbar.make(nav_view, res, LENGTH_LONG).show()
- })
+ model.refundManager.refund(url).observe(this, Observer(::onRefundResponse))
}
else -> {
Snackbar.make(
@@ -183,6 +175,21 @@ class MainActivity : AppCompatActivity(), OnNavigationItemSelectedListener,
}
}
+ private fun onRefundResponse(status: RefundStatus) {
+ model.showProgressBar.value = false
+ when (status) {
+ is RefundStatus.Error -> {
+ Snackbar.make(nav_view, R.string.refund_error, LENGTH_LONG).show()
+ }
+ is RefundStatus.Success -> {
+ val amount = status.response.amountRefundGranted
+ model.showTransactions(amount.currency)
+ val str = getString(R.string.refund_success, amount.amountStr)
+ Snackbar.make(nav_view, str, LENGTH_LONG).show()
+ }
+ }
+ }
+
private val triggerPaymentReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
if (nav.currentDestination?.id == R.id.promptPayment) return
diff --git a/wallet/src/main/java/net/taler/wallet/MainViewModel.kt b/wallet/src/main/java/net/taler/wallet/MainViewModel.kt
index 24a8f1e..6249551 100644
--- a/wallet/src/main/java/net/taler/wallet/MainViewModel.kt
+++ b/wallet/src/main/java/net/taler/wallet/MainViewModel.kt
@@ -102,7 +102,7 @@ class MainViewModel(val app: Application) : AndroidViewModel(app) {
val paymentManager = PaymentManager(api, viewModelScope, mapper)
val pendingOperationsManager: PendingOperationsManager = PendingOperationsManager(api)
val transactionManager: TransactionManager = TransactionManager(api, viewModelScope, mapper)
- val refundManager = RefundManager(api)
+ val refundManager = RefundManager(api, viewModelScope)
val exchangeManager: ExchangeManager = ExchangeManager(api, mapper)
private val mTransactionsEvent = MutableLiveData<Event<String>>()
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 5593486..fdacb0d 100644
--- a/wallet/src/main/java/net/taler/wallet/refund/RefundManager.kt
+++ b/wallet/src/main/java/net/taler/wallet/refund/RefundManager.kt
@@ -19,28 +19,43 @@ package net.taler.wallet.refund
import android.util.Log
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
+import kotlinx.coroutines.CoroutineScope
+import kotlinx.coroutines.launch
+import kotlinx.serialization.Serializable
+import net.taler.common.Amount
import net.taler.wallet.TAG
import net.taler.wallet.backend.WalletBackendApi
-import org.json.JSONObject
sealed class RefundStatus {
object Error : RefundStatus()
- object Success : RefundStatus()
+ data class Success(val response: RefundResponse) : RefundStatus()
}
-class RefundManager(private val walletBackendApi: WalletBackendApi) {
+@Serializable
+data class RefundResponse(
+ val amountEffectivePaid: Amount,
+ val amountRefundGranted: Amount,
+ val amountRefundGone: Amount,
+ val pendingAtExchange: Boolean
+)
+
+class RefundManager(
+ private val api: WalletBackendApi,
+ private val scope: CoroutineScope
+) {
fun refund(refundUri: String): LiveData<RefundStatus> {
val liveData = MutableLiveData<RefundStatus>()
- val args = JSONObject().also { it.put("talerRefundUri", refundUri) }
- walletBackendApi.sendRequest("applyRefund", args) { isError, result ->
- if (isError) {
- Log.e(TAG, "Refund Error: $result")
+ scope.launch {
+ api.request("applyRefund", RefundResponse.serializer()) {
+ put("talerRefundUri", refundUri)
+ }.onError {
+ Log.e(TAG, "Refund Error: $it")
// TODO show error string
liveData.postValue(RefundStatus.Error)
- } else {
- Log.e(TAG, "Refund Success: $result")
- liveData.postValue(RefundStatus.Success)
+ }.onSuccess {
+ Log.e(TAG, "Refund Success: $it")
+ liveData.postValue(RefundStatus.Success(it))
}
}
return liveData
diff --git a/wallet/src/main/java/net/taler/wallet/transactions/TransactionDetailFragment.kt b/wallet/src/main/java/net/taler/wallet/transactions/TransactionDetailFragment.kt
index 0142978..be83b09 100644
--- a/wallet/src/main/java/net/taler/wallet/transactions/TransactionDetailFragment.kt
+++ b/wallet/src/main/java/net/taler/wallet/transactions/TransactionDetailFragment.kt
@@ -55,7 +55,8 @@ class TransactionDetailFragment : Fragment() {
}
override fun onCreateView(
- inflater: LayoutInflater, container: ViewGroup?,
+ inflater: LayoutInflater,
+ container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return inflater.inflate(transaction.detailPageLayout, container, false)
@@ -96,7 +97,9 @@ class TransactionDetailFragment : Fragment() {
private fun bind(t: TransactionWithdrawal) {
effectiveAmountLabel.text = getString(R.string.withdraw_total)
effectiveAmountView.text = t.amountEffective.toString()
- if (t.pending && t.withdrawalDetails is TalerBankIntegrationApi && !t.confirmed && t.withdrawalDetails.bankConfirmationUrl != null) {
+ if (t.pending && t.withdrawalDetails is TalerBankIntegrationApi &&
+ !t.confirmed && t.withdrawalDetails.bankConfirmationUrl != null
+ ) {
val i = Intent().apply {
data = Uri.parse(t.withdrawalDetails.bankConfirmationUrl)
}
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 b9f86b3..d398f57 100644
--- a/wallet/src/main/java/net/taler/wallet/transactions/TransactionManager.kt
+++ b/wallet/src/main/java/net/taler/wallet/transactions/TransactionManager.kt
@@ -94,7 +94,7 @@ class TransactionManager(
val transactions: LinkedList<Transaction> = mapper.readValue(transactionsArray)
// TODO remove when fixed in wallet-core
transactions.sortWith(compareBy({ it.pending }, { it.timestamp.ms }, { it.transactionId }))
- transactions.reverse() // show latest first
+ transactions.reverse() // show latest first
mProgress.postValue(false)
liveData.postValue(TransactionsResult.Success(transactions))
// update all transactions on UiThread if there was a currency
diff --git a/wallet/src/main/java/net/taler/wallet/transactions/Transactions.kt b/wallet/src/main/java/net/taler/wallet/transactions/Transactions.kt
index 1ba7e79..08f02fc 100644
--- a/wallet/src/main/java/net/taler/wallet/transactions/Transactions.kt
+++ b/wallet/src/main/java/net/taler/wallet/transactions/Transactions.kt
@@ -188,9 +188,14 @@ class TransactionRefund(
pending: Boolean,
val refundedTransactionId: String,
val info: TransactionInfo,
- val amountInvalid: Amount,
+ /**
+ * Part of the refund that couldn't be applied because the refund permissions were expired
+ */
+ val amountInvalid: Amount? = null,
error: TransactionError? = null,
+ @JsonProperty("amountEffective") // TODO remove when fixed in wallet-core
amountRaw: Amount,
+ @JsonProperty("amountRaw") // TODO remove when fixed in wallet-core
amountEffective: Amount
) : Transaction(transactionId, timestamp, pending, error, amountRaw, amountEffective) {
override val icon = R.drawable.transaction_refund