aboutsummaryrefslogtreecommitdiff
path: root/cashier
diff options
context:
space:
mode:
authorTorsten Grote <t@grobox.de>2022-09-13 13:58:28 -0300
committerTorsten Grote <t@grobox.de>2022-09-13 14:04:01 -0300
commit83f0b43283b5313f9f8c00a02861cd703292ce59 (patch)
tree9a160d794153d484c6dafae69cc65fbbf28dd2f9 /cashier
parente91eeba93c0e6eaf444dd3d9664c1c6d4476771b (diff)
downloadtaler-android-83f0b43283b5313f9f8c00a02861cd703292ce59.tar.gz
taler-android-83f0b43283b5313f9f8c00a02861cd703292ce59.tar.bz2
taler-android-83f0b43283b5313f9f8c00a02861cd703292ce59.zip
[cashier] disable timeout when showing QR code
There's no need for a timeout. The withdrawal gets aborted when the user navigates away.
Diffstat (limited to 'cashier')
-rw-r--r--cashier/src/main/java/net/taler/cashier/config/ConfigManager.kt3
-rw-r--r--cashier/src/main/java/net/taler/cashier/withdraw/TransactionFragment.kt14
-rw-r--r--cashier/src/main/java/net/taler/cashier/withdraw/WithdrawManager.kt16
3 files changed, 17 insertions, 16 deletions
diff --git a/cashier/src/main/java/net/taler/cashier/config/ConfigManager.kt b/cashier/src/main/java/net/taler/cashier/config/ConfigManager.kt
index d850d27..c79fd12 100644
--- a/cashier/src/main/java/net/taler/cashier/config/ConfigManager.kt
+++ b/cashier/src/main/java/net/taler/cashier/config/ConfigManager.kt
@@ -55,7 +55,7 @@ private val TAG = ConfigManager::class.java.simpleName
class ConfigManager(
private val app: Application,
private val scope: CoroutineScope,
- private val httpClient: HttpClient
+ private val httpClient: HttpClient,
) {
val configDestination = ConfigFragmentDirections.actionGlobalConfigFragment()
@@ -112,6 +112,7 @@ class ConfigManager(
mConfigResult.postValue(result)
}
}
+
private suspend fun checkConfig(config: Config) = withContext(Dispatchers.IO) {
val url = "${config.bankUrl}/integration-api/config"
Log.d(TAG, "Checking config: $url")
diff --git a/cashier/src/main/java/net/taler/cashier/withdraw/TransactionFragment.kt b/cashier/src/main/java/net/taler/cashier/withdraw/TransactionFragment.kt
index ffb1539..0f606b8 100644
--- a/cashier/src/main/java/net/taler/cashier/withdraw/TransactionFragment.kt
+++ b/cashier/src/main/java/net/taler/cashier/withdraw/TransactionFragment.kt
@@ -50,21 +50,21 @@ class TransactionFragment : Fragment() {
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
- ): View? {
+ ): View {
ui = FragmentTransactionBinding.inflate(inflater, container, false)
return ui.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
- withdrawManager.withdrawAmount.observe(viewLifecycleOwner, { amount ->
+ withdrawManager.withdrawAmount.observe(viewLifecycleOwner) { amount ->
ui.amountView.text = amount?.toString()
- })
- withdrawManager.withdrawResult.observe(viewLifecycleOwner, { result ->
+ }
+ withdrawManager.withdrawResult.observe(viewLifecycleOwner) { result ->
onWithdrawResultReceived(result)
- })
- withdrawManager.withdrawStatus.observe(viewLifecycleOwner, { status ->
+ }
+ withdrawManager.withdrawStatus.observe(viewLifecycleOwner) { status ->
onWithdrawStatusChanged(status)
- })
+ }
// change intro text depending on whether NFC is available or not
val hasNfc = NfcManager.hasNfc(requireContext())
diff --git a/cashier/src/main/java/net/taler/cashier/withdraw/WithdrawManager.kt b/cashier/src/main/java/net/taler/cashier/withdraw/WithdrawManager.kt
index 601b59a..c6c39d0 100644
--- a/cashier/src/main/java/net/taler/cashier/withdraw/WithdrawManager.kt
+++ b/cashier/src/main/java/net/taler/cashier/withdraw/WithdrawManager.kt
@@ -38,17 +38,15 @@ import net.taler.common.Amount
import net.taler.common.QrCodeManager.makeQrCode
import net.taler.common.isOnline
import org.json.JSONObject
-import java.util.concurrent.TimeUnit.MINUTES
import java.util.concurrent.TimeUnit.SECONDS
private val TAG = WithdrawManager::class.java.simpleName
private val INTERVAL = SECONDS.toMillis(1)
-private val TIMEOUT = MINUTES.toMillis(2)
class WithdrawManager(
private val app: Application,
- private val viewModel: MainViewModel
+ private val viewModel: MainViewModel,
) {
private val scope
get() = viewModel.viewModelScope
@@ -83,7 +81,7 @@ class WithdrawManager(
if (balanceResult !is BalanceResult.Success) return false
return try {
balanceResult.amount.positive && amount <= balanceResult.amount.amount
- } catch (e : IllegalStateException) {
+ } catch (e: IllegalStateException) {
Log.e(TAG, "Error comparing amounts", e)
null
}
@@ -128,7 +126,7 @@ class WithdrawManager(
}
}
- private val timer: CountDownTimer = object : CountDownTimer(TIMEOUT, INTERVAL) {
+ private val timer: CountDownTimer = object : CountDownTimer(Long.MAX_VALUE, INTERVAL) {
override fun onTick(millisUntilFinished: Long) {
val result = withdrawResult.value
if (result is WithdrawResult.Success) {
@@ -155,7 +153,8 @@ class WithdrawManager(
}
private fun checkWithdrawStatus(withdrawalId: String) = scope.launch(Dispatchers.IO) {
- val url = "${config.bankUrl}/access-api/accounts/${config.username}/withdrawals/${withdrawalId}"
+ val url =
+ "${config.bankUrl}/access-api/accounts/${config.username}/withdrawals/${withdrawalId}"
Log.d(TAG, "Checking withdraw status at $url")
val response = makeJsonGetRequest(url, config)
if (response !is Success) return@launch // ignore errors and continue trying
@@ -206,7 +205,8 @@ class WithdrawManager(
}
private fun abort(withdrawalId: String) = scope.launch(Dispatchers.IO) {
- val url = "${config.bankUrl}/access-api/accounts/${config.username}/withdrawals/${withdrawalId}/abort"
+ val url =
+ "${config.bankUrl}/access-api/accounts/${config.username}/withdrawals/${withdrawalId}/abort"
Log.d(TAG, "Aborting withdrawal at $url")
makeJsonPostRequest(url, JSONObject(), config)
}
@@ -263,5 +263,5 @@ sealed class WithdrawStatus {
data class LastTransaction(
val withdrawAmount: Amount,
- val withdrawStatus: WithdrawStatus
+ val withdrawStatus: WithdrawStatus,
)