diff options
author | Torsten Grote <t@grobox.de> | 2021-12-08 15:46:15 -0300 |
---|---|---|
committer | Torsten Grote <t@grobox.de> | 2021-12-08 15:46:15 -0300 |
commit | 5c525667c77d945abb85e5f0b2469fb5af376fce (patch) | |
tree | 4c73e785f64664e1b045be2ce6736dbb299cbc8d /wallet/src | |
parent | 71be094780464c2b97a4cb6b33dd7f465647c082 (diff) | |
download | taler-android-5c525667c77d945abb85e5f0b2469fb5af376fce.tar.gz taler-android-5c525667c77d945abb85e5f0b2469fb5af376fce.tar.bz2 taler-android-5c525667c77d945abb85e5f0b2469fb5af376fce.zip |
Add a button to cancel manual withdrawal
Diffstat (limited to 'wallet/src')
5 files changed, 47 insertions, 7 deletions
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 6b5a79b..ea257a8 100644 --- a/wallet/src/main/java/net/taler/wallet/transactions/TransactionManager.kt +++ b/wallet/src/main/java/net/taler/wallet/transactions/TransactionManager.kt @@ -16,12 +16,14 @@ package net.taler.wallet.transactions +import android.util.Log import androidx.annotation.UiThread import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.switchMap import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.launch +import net.taler.wallet.TAG import net.taler.wallet.backend.WalletBackendApi import java.util.HashMap import java.util.LinkedList @@ -33,7 +35,7 @@ sealed class TransactionsResult { class TransactionManager( private val api: WalletBackendApi, - private val scope: CoroutineScope + private val scope: CoroutineScope, ) { private val mProgress = MutableLiveData<Boolean>() @@ -88,4 +90,14 @@ class TransactionManager( } } + fun deleteTransaction(transactionId: String) = scope.launch { + api.request<Unit>("deleteTransaction") { + put("transactionId", transactionId) + }.onError { + Log.e(TAG, "Error deleteTransaction $it") + }.onSuccess { + // no op + } + } + } diff --git a/wallet/src/main/java/net/taler/wallet/transactions/TransactionWithdrawalFragment.kt b/wallet/src/main/java/net/taler/wallet/transactions/TransactionWithdrawalFragment.kt index 319aa7e..a11f8ba 100644 --- a/wallet/src/main/java/net/taler/wallet/transactions/TransactionWithdrawalFragment.kt +++ b/wallet/src/main/java/net/taler/wallet/transactions/TransactionWithdrawalFragment.kt @@ -69,6 +69,7 @@ class TransactionWithdrawalFragment : TransactionDetailFragment() { exchangeBaseUrl = t.exchangeBaseUrl, // TODO what if there's more than one or no URI? uriStr = t.withdrawalDetails.exchangePaytoUris[0], + transactionId = t.transactionId, ) withdrawManager.viewManualWithdrawal(status) findNavController().navigate(R.id.action_nav_transactions_detail_withdrawal_to_nav_exchange_manual_withdrawal_success) diff --git a/wallet/src/main/java/net/taler/wallet/withdraw/ManualWithdrawSuccessFragment.kt b/wallet/src/main/java/net/taler/wallet/withdraw/ManualWithdrawSuccessFragment.kt index cb22c04..4ea3e73 100644 --- a/wallet/src/main/java/net/taler/wallet/withdraw/ManualWithdrawSuccessFragment.kt +++ b/wallet/src/main/java/net/taler/wallet/withdraw/ManualWithdrawSuccessFragment.kt @@ -35,6 +35,7 @@ import androidx.compose.foundation.layout.wrapContentWidth import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll import androidx.compose.material.Button +import androidx.compose.material.ButtonDefaults import androidx.compose.material.Icon import androidx.compose.material.IconButton import androidx.compose.material.MaterialTheme @@ -44,6 +45,7 @@ import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.ContentCopy import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment.Companion.CenterHorizontally +import androidx.compose.ui.Alignment.Companion.End import androidx.compose.ui.Modifier import androidx.compose.ui.draw.alpha import androidx.compose.ui.platform.ComposeView @@ -56,6 +58,7 @@ import androidx.compose.ui.unit.dp import androidx.core.content.getSystemService import androidx.fragment.app.Fragment import androidx.fragment.app.activityViewModels +import androidx.navigation.fragment.findNavController import com.google.android.material.composethemeadapter.MdcTheme import net.taler.common.startActivitySafe import net.taler.lib.common.Amount @@ -64,6 +67,7 @@ import net.taler.wallet.R class ManualWithdrawSuccessFragment : Fragment() { private val model: MainViewModel by activityViewModels() + private val transactionManager by lazy { model.transactionManager } private val withdrawManager by lazy { model.withdrawManager } override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, @@ -78,10 +82,16 @@ class ManualWithdrawSuccessFragment : Fragment() { val onBankAppClick = if (componentName == null) null else { { startActivitySafe(intent) } } + val onCancelClick = if (status.transactionId == null) null else { + { + transactionManager.deleteTransaction(status.transactionId) + findNavController().navigate(R.id.action_nav_exchange_manual_withdrawal_success_to_nav_main) + } + } setContent { MdcTheme { Surface { - Screen(status, onBankAppClick) + Screen(status, onBankAppClick, onCancelClick) } } } @@ -97,6 +107,7 @@ class ManualWithdrawSuccessFragment : Fragment() { private fun Screen( status: WithdrawStatus.ManualTransferRequired, bankAppClick: (() -> Unit)?, + onCancelClick: (() -> Unit)?, ) { val scrollState = rememberScrollState() Column(modifier = Modifier @@ -146,6 +157,17 @@ private fun Screen( Text(text = stringResource(R.string.withdraw_manual_ready_bank_button)) } } + if (onCancelClick != null) { + Button( + onClick = onCancelClick, + colors = ButtonDefaults.buttonColors(backgroundColor = colorResource(R.color.red)), + modifier = Modifier + .padding(vertical = 16.dp) + .align(End), + ) { + Text(text = stringResource(R.string.withdraw_manual_ready_cancel)) + } + } } } @@ -171,7 +193,7 @@ fun DetailRow(label: String, content: String, copy: Boolean = true) { text = content, style = MaterialTheme.typography.body1, modifier = Modifier - .padding(vertical = 8.dp) + .padding(bottom = 8.dp) .weight(0.7f) .then(if (copy) Modifier else Modifier.alpha(0.7f)) ) @@ -187,8 +209,9 @@ fun PreviewScreen() { uri = Uri.parse("https://taler.net"), iban = "ASDQWEASDZXCASDQWE", subject = "Taler Withdrawal P2T19EXRBY4B145JRNZ8CQTD7TCS03JE9VZRCEVKVWCP930P56WG", - amountRaw = Amount("KUDOS", 10, 0) - )) {} + amountRaw = Amount("KUDOS", 10, 0), + transactionId = "", + ), {}) {} } } 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 858d63e..fbb5c18 100644 --- a/wallet/src/main/java/net/taler/wallet/withdraw/WithdrawManager.kt +++ b/wallet/src/main/java/net/taler/wallet/withdraw/WithdrawManager.kt @@ -63,6 +63,7 @@ sealed class WithdrawStatus { val iban: String, val subject: String, val amountRaw: Amount, + val transactionId: String?, ) : WithdrawStatus() data class Error(val message: String?) : WithdrawStatus() @@ -241,8 +242,7 @@ class WithdrawManager( amount = status.amountRaw, exchangeBaseUrl = status.exchangeBaseUrl, // TODO what if there's more than one or no URI? - uriStr = "payto://iban/ASDQWEASDZXCASDQWE?amount=KUDOS%3A10&message=Taler+Withdrawal+P2T19EXRBY4B145JRNZ8CQTD7TCS03JE9VZRCEVKVWCP930P56WG", // response.exchangePaytoUris[0], - // "payto://x-taler-bank/bank.demo.taler.net/Exchange?amount=KUDOS%3A10&message=Taler+Withdrawal+P2T19EXRBY4B145JRNZ8CQTD7TCS03JE9VZRCEVKVWCP930P56WG" + uriStr = response.exchangePaytoUris[0], ) } } @@ -258,6 +258,7 @@ class WithdrawManager( * Don't call this from ongoing withdrawal processes as it destroys state. */ fun viewManualWithdrawal(status: WithdrawStatus.ManualTransferRequired) { + require(status.transactionId != null) { "No transaction ID given" } withdrawStatus.value = status } @@ -267,6 +268,7 @@ fun createManualTransferRequired( amount: Amount, exchangeBaseUrl: String, uriStr: String, + transactionId: String? = null, ): WithdrawStatus.ManualTransferRequired { val uri = Uri.parse(uriStr) return WithdrawStatus.ManualTransferRequired( @@ -275,5 +277,6 @@ fun createManualTransferRequired( iban = uri.lastPathSegment!!, subject = uri.getQueryParameter("message")!!, amountRaw = amount, + transactionId = transactionId, ) } diff --git a/wallet/src/main/res/values/strings.xml b/wallet/src/main/res/values/strings.xml index d2f181c..7595060 100644 --- a/wallet/src/main/res/values/strings.xml +++ b/wallet/src/main/res/values/strings.xml @@ -122,6 +122,7 @@ GNU Taler is immune against many types of fraud, such as phishing of credit card <string name="withdraw_manual_ready_iban">IBAN</string> <string name="withdraw_manual_ready_subject">Subject</string> <string name="withdraw_manual_ready_bank_button">Open in banking app</string> + <string name="withdraw_manual_ready_cancel">Cancel withdrawal</string> <string name="withdraw_manual_ready_warning">Make sure to use the correct subject, otherwise the money will not arrive in this wallet.</string> <string name="withdraw_error_title">Withdrawal Error</string> <string name="withdraw_error_message">Withdrawing is currently not possible. Please try again later!</string> |