aboutsummaryrefslogtreecommitdiff
path: root/wallet/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'wallet/src/main')
-rw-r--r--wallet/src/main/java/net/taler/wallet/deposit/DepositFragment.kt36
-rw-r--r--wallet/src/main/java/net/taler/wallet/deposit/DepositManager.kt20
-rw-r--r--wallet/src/main/java/net/taler/wallet/deposit/DepositState.kt3
-rw-r--r--wallet/src/main/res/navigation/nav_graph.xml4
4 files changed, 51 insertions, 12 deletions
diff --git a/wallet/src/main/java/net/taler/wallet/deposit/DepositFragment.kt b/wallet/src/main/java/net/taler/wallet/deposit/DepositFragment.kt
index 2793e56..31dc03d 100644
--- a/wallet/src/main/java/net/taler/wallet/deposit/DepositFragment.kt
+++ b/wallet/src/main/java/net/taler/wallet/deposit/DepositFragment.kt
@@ -51,8 +51,11 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
+import androidx.lifecycle.lifecycleScope
+import androidx.navigation.fragment.findNavController
import com.google.android.material.composethemeadapter.MdcTheme
import net.taler.common.Amount
+import net.taler.common.showError
import net.taler.wallet.MainViewModel
import net.taler.wallet.R
import net.taler.wallet.compose.collectAsStateLifecycleAware
@@ -94,6 +97,19 @@ class DepositFragment : Fragment() {
}
}
+ override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
+ super.onViewCreated(view, savedInstanceState)
+ lifecycleScope.launchWhenStarted {
+ depositManager.depositState.collect { state ->
+ if (state is DepositState.Error) {
+ showError(state.msg)
+ } else if (state is DepositState.Success) {
+ findNavController().navigate(R.id.action_nav_deposit_to_nav_main)
+ }
+ }
+ }
+ }
+
override fun onStart() {
super.onStart()
activity?.setTitle(R.string.send_deposit_title)
@@ -189,23 +205,30 @@ private fun MakeDepositComposable(
)
}
)
+ val amountTitle = if (state.effectiveDepositAmount == null) {
+ R.string.amount_chosen
+ } else R.string.send_deposit_amount_effective
Text(
modifier = Modifier.padding(horizontal = 16.dp),
- text = stringResource(id = R.string.amount_chosen),
+ text = stringResource(id = amountTitle),
)
+ val shownAmount = if (state.effectiveDepositAmount == null) amount else {
+ state.effectiveDepositAmount
+ }
Text(
modifier = Modifier.padding(16.dp),
fontSize = 24.sp,
color = colorResource(R.color.green),
- text = amount.toString(),
+ text = shownAmount.toString(),
)
AnimatedVisibility(visible = state.showFees) {
Column(
modifier = Modifier.fillMaxWidth(),
horizontalAlignment = Alignment.CenterHorizontally,
) {
- val effectiveAmount = state.effectiveDepositAmount
- val fee = amount - (effectiveAmount ?: Amount.zero(amount.currency))
+ val totalAmount = state.totalDepositCost ?: amount
+ val effectiveAmount = state.effectiveDepositAmount ?: Amount.zero(amount.currency)
+ val fee = totalAmount - effectiveAmount
Text(
modifier = Modifier.padding(horizontal = 16.dp),
text = stringResource(id = R.string.withdraw_fees),
@@ -222,13 +245,13 @@ private fun MakeDepositComposable(
)
Text(
modifier = Modifier.padding(horizontal = 16.dp),
- text = stringResource(id = R.string.send_deposit_amount_effective),
+ text = stringResource(id = R.string.send_amount),
)
Text(
modifier = Modifier.padding(16.dp),
fontSize = 24.sp,
color = colorResource(R.color.green),
- text = effectiveAmount.toString(),
+ text = totalAmount.toString(),
)
}
}
@@ -263,6 +286,7 @@ fun PreviewMakeDepositComposable() {
Surface {
val state = DepositState.FeesChecked(
effectiveDepositAmount = Amount.fromDouble("TESTKUDOS", 42.00),
+ totalDepositCost = Amount.fromDouble("TESTKUDOS", 42.23),
)
MakeDepositComposable(
state = state,
diff --git a/wallet/src/main/java/net/taler/wallet/deposit/DepositManager.kt b/wallet/src/main/java/net/taler/wallet/deposit/DepositManager.kt
index a207691..81124ec 100644
--- a/wallet/src/main/java/net/taler/wallet/deposit/DepositManager.kt
+++ b/wallet/src/main/java/net/taler/wallet/deposit/DepositManager.kt
@@ -53,11 +53,14 @@ class DepositManager(
params = mapOf("receiver-name" to receiverName),
).paytoUri
- if (depositState.value.showFees) {
- val effectiveDepositAmount = depositState.value.effectiveDepositAmount
- ?: Amount.zero(amount.currency)
- makeDeposit(paytoUri, amount, effectiveDepositAmount)
- } else {
+ if (depositState.value.showFees) makeDeposit(
+ paytoUri = paytoUri,
+ amount = amount,
+ totalDepositCost = depositState.value.totalDepositCost
+ ?: Amount.zero(amount.currency),
+ effectiveDepositAmount = depositState.value.effectiveDepositAmount
+ ?: Amount.zero(amount.currency),
+ ) else {
prepareDeposit(paytoUri, amount)
}
}
@@ -73,6 +76,7 @@ class DepositManager(
mDepositState.value = DepositState.Error(it.userFacingMsg)
}.onSuccess {
mDepositState.value = DepositState.FeesChecked(
+ totalDepositCost = it.totalDepositCost,
effectiveDepositAmount = it.effectiveDepositAmount,
)
}
@@ -82,9 +86,13 @@ class DepositManager(
private fun makeDeposit(
paytoUri: String,
amount: Amount,
+ totalDepositCost: Amount,
effectiveDepositAmount: Amount,
) {
- mDepositState.value = DepositState.MakingDeposit(effectiveDepositAmount)
+ mDepositState.value = DepositState.MakingDeposit(
+ totalDepositCost = totalDepositCost,
+ effectiveDepositAmount = effectiveDepositAmount,
+ )
scope.launch {
api.request("createDepositGroup", CreateDepositGroupResponse.serializer()) {
put("depositPaytoUri", paytoUri)
diff --git a/wallet/src/main/java/net/taler/wallet/deposit/DepositState.kt b/wallet/src/main/java/net/taler/wallet/deposit/DepositState.kt
index 1249155..918d74c 100644
--- a/wallet/src/main/java/net/taler/wallet/deposit/DepositState.kt
+++ b/wallet/src/main/java/net/taler/wallet/deposit/DepositState.kt
@@ -21,17 +21,20 @@ import net.taler.common.Amount
sealed class DepositState {
open val showFees: Boolean = false
+ open val totalDepositCost: Amount? = null
open val effectiveDepositAmount: Amount? = null
object Start : DepositState()
object CheckingFees : DepositState()
class FeesChecked(
+ override val totalDepositCost: Amount,
override val effectiveDepositAmount: Amount,
) : DepositState() {
override val showFees = true
}
class MakingDeposit(
+ override val totalDepositCost: Amount,
override val effectiveDepositAmount: Amount,
) : DepositState() {
override val showFees = true
diff --git a/wallet/src/main/res/navigation/nav_graph.xml b/wallet/src/main/res/navigation/nav_graph.xml
index 3d253af..f1d189f 100644
--- a/wallet/src/main/res/navigation/nav_graph.xml
+++ b/wallet/src/main/res/navigation/nav_graph.xml
@@ -161,6 +161,10 @@
android:defaultValue="@null"
app:argType="string"
app:nullable="true" />
+ <action
+ android:id="@+id/action_nav_deposit_to_nav_main"
+ app:destination="@id/nav_main"
+ app:popUpTo="@id/nav_main" />
</fragment>
<fragment