Skip to content

Commit 49b0d1e

Browse files
authored
Warn about insufficient funds at disposal to pay the transaction fee when configuring earning (#275)
* Use correct at disposal balance for earn amount validation * Use separate message for insufficient funds to pay the fee * Update the changelog
1 parent 2ba8a6f commit 49b0d1e

File tree

11 files changed

+72
-42
lines changed

11 files changed

+72
-42
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## [Unreleased]
4+
5+
### Fixed
6+
7+
- Not warning about insufficient funds at disposal to pay the transaction fee
8+
when configuring earning
9+
310
## [1.9.0] - 2025-04-17
411

512
### Removed

app/src/main/java/com/concordium/wallet/ui/bakerdelegation/baker/BakerRegisterAmountActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ class BakerRegisterAmountActivity : BaseDelegationBakerRegisterAmountActivity(
205205
maximumValue = viewModel.getStakeInputMax(),
206206
oldStakedAmount = viewModel.bakerDelegationData.oldStakedAmount,
207207
balance = viewModel.bakerDelegationData.account.balance,
208-
atDisposal = viewModel.atDisposal(),
208+
atDisposal = viewModel.bakerDelegationData.account.balanceAtDisposal,
209209
currentPool = viewModel.bakerDelegationData.bakerPoolStatus?.delegatedCapital,
210210
poolLimit = null,
211211
previouslyStakedInPool = viewModel.bakerDelegationData.account.delegation?.stakedAmount,

app/src/main/java/com/concordium/wallet/ui/bakerdelegation/baker/BakerRegistrationConfirmationActivity.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,10 @@ class BakerRegistrationConfirmationActivity : BaseDelegationBakerActivity(
387387
}
388388

389389
private fun onContinueClicked() {
390-
if (viewModel.atDisposal() < (viewModel.bakerDelegationData.cost ?: BigInteger.ZERO)) {
391-
showNotEnoughFunds()
390+
if (viewModel.bakerDelegationData.account.balanceAtDisposal <
391+
(viewModel.bakerDelegationData.cost ?: BigInteger.ZERO)
392+
) {
393+
showNotEnoughFundsForFee()
392394
return
393395
}
394396
viewModel.prepareTransaction()

app/src/main/java/com/concordium/wallet/ui/bakerdelegation/common/BaseDelegationBakerActivity.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import com.concordium.wallet.data.model.BakerDelegationData
1010
import com.concordium.wallet.data.util.CurrencyUtil
1111
import com.concordium.wallet.extension.showSingle
1212
import com.concordium.wallet.ui.bakerdelegation.dialog.NoChangeDialog
13-
import com.concordium.wallet.ui.bakerdelegation.dialog.NotEnoughFundsDialog
13+
import com.concordium.wallet.ui.bakerdelegation.dialog.NotEnoughFundsForFeeDialog
1414
import com.concordium.wallet.ui.base.BaseActivity
1515
import com.concordium.wallet.ui.common.delegates.AuthDelegate
1616
import com.concordium.wallet.ui.common.delegates.AuthDelegateImpl
@@ -88,8 +88,8 @@ abstract class BaseDelegationBakerActivity(
8888
}
8989
}
9090

91-
protected fun showNotEnoughFunds() {
92-
NotEnoughFundsDialog().showSingle(supportFragmentManager, NotEnoughFundsDialog.TAG)
91+
protected fun showNotEnoughFundsForFee() {
92+
NotEnoughFundsForFeeDialog().showSingle(supportFragmentManager, NotEnoughFundsForFeeDialog.TAG)
9393
}
9494

9595
protected fun showNoChange() {

app/src/main/java/com/concordium/wallet/ui/bakerdelegation/common/DelegationBakerViewModel.kt

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -235,17 +235,6 @@ class DelegationBakerViewModel(application: Application) : AndroidViewModel(appl
235235
return (!bakerDelegationData.isBakerPool && !bakerDelegationData.isLPool)
236236
}
237237

238-
fun atDisposal(): BigInteger {
239-
var staked: BigInteger = BigInteger.ZERO
240-
bakerDelegationData.account.delegation?.let {
241-
staked = it.stakedAmount
242-
}
243-
bakerDelegationData.account.baker?.let {
244-
staked = it.stakedAmount
245-
}
246-
return bakerDelegationData.account.balance - staked
247-
}
248-
249238
fun selectBakerPool() {
250239
this.bakerDelegationData.isLPool = false
251240
this.bakerDelegationData.isBakerPool = true

app/src/main/java/com/concordium/wallet/ui/bakerdelegation/common/StakeAmountInputValidator.kt

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,16 @@ class StakeAmountInputValidator(
1616
private val previouslyStakedInPool: BigInteger?,
1717
private val isInCoolDown: Boolean?,
1818
private val oldPoolId: Long?,
19-
private val newPoolId: String?
19+
private val newPoolId: String?,
2020
) {
2121
enum class StakeError {
22-
OK, NOT_ENOUGH_FUND, MINIMUM, MAXIMUM, POOL_LIMIT_REACHED, POOL_LIMIT_REACHED_COOLDOWN, UNKNOWN
22+
OK,
23+
NOT_ENOUGH_FUND,
24+
NOT_ENOUGH_FUND_FOR_FEE,
25+
MINIMUM, MAXIMUM,
26+
POOL_LIMIT_REACHED,
27+
POOL_LIMIT_REACHED_COOLDOWN,
28+
UNKNOWN,
2329
}
2430

2531
fun validate(amount: BigInteger?, estimatedFee: BigInteger?): StakeError {
@@ -45,24 +51,40 @@ class StakeAmountInputValidator(
4551
return StakeError.OK
4652
}
4753

48-
fun getErrorText(context: Context, stakeError: StakeError): String {
49-
return when (stakeError) {
50-
StakeError.NOT_ENOUGH_FUND -> context.getString(R.string.delegation_register_delegation_not_enough_funds)
51-
StakeError.MINIMUM -> context.getString(
54+
fun getErrorText(
55+
context: Context,
56+
stakeError: StakeError,
57+
): String = when (stakeError) {
58+
59+
StakeError.NOT_ENOUGH_FUND ->
60+
context.getString(R.string.delegation_register_delegation_not_enough_funds)
61+
62+
StakeError.NOT_ENOUGH_FUND_FOR_FEE ->
63+
context.getString(R.string.delegation_register_delegation_not_enough_funds_for_fee)
64+
65+
StakeError.MINIMUM ->
66+
context.getString(
5267
R.string.delegation_register_delegation_minimum,
5368
CurrencyUtil.formatGTU(minimumValue ?: BigInteger.ZERO)
5469
)
5570

56-
StakeError.MAXIMUM -> context.getString(
71+
StakeError.MAXIMUM ->
72+
context.getString(
5773
R.string.delegation_register_delegation_maximum,
5874
CurrencyUtil.formatGTU(maximumValue ?: BigInteger.ZERO)
5975
)
6076

61-
StakeError.POOL_LIMIT_REACHED -> context.getString(R.string.delegation_register_delegation_pool_limit_will_be_breached)
62-
StakeError.POOL_LIMIT_REACHED_COOLDOWN -> context.getString(R.string.delegation_amount_too_large_while_in_cooldown)
63-
StakeError.UNKNOWN -> context.getString(R.string.app_error_general)
64-
else -> ""
65-
}
77+
StakeError.POOL_LIMIT_REACHED ->
78+
context.getString(R.string.delegation_register_delegation_pool_limit_will_be_breached)
79+
80+
StakeError.POOL_LIMIT_REACHED_COOLDOWN ->
81+
context.getString(R.string.delegation_amount_too_large_while_in_cooldown)
82+
83+
StakeError.UNKNOWN ->
84+
context.getString(R.string.app_error_general)
85+
86+
StakeError.OK ->
87+
""
6688
}
6789

6890
private fun checkMaximum(amount: BigInteger): StakeError {
@@ -81,15 +103,22 @@ class StakeAmountInputValidator(
81103
return StakeError.OK
82104
}
83105

84-
private fun checkBalance(amount: BigInteger, estimatedFee: BigInteger?): StakeError = when {
85-
balance == null || atDisposal == null -> StakeError.UNKNOWN
106+
private fun checkBalance(
107+
amount: BigInteger,
108+
estimatedFee: BigInteger?,
109+
): StakeError = when {
110+
111+
balance == null || atDisposal == null ->
112+
StakeError.UNKNOWN
86113

87114
balance < amount + (estimatedFee ?: BigInteger.ZERO) ->
88115
StakeError.NOT_ENOUGH_FUND
89116

90-
(estimatedFee ?: BigInteger.ZERO) > atDisposal -> StakeError.NOT_ENOUGH_FUND
117+
atDisposal < (estimatedFee ?: BigInteger.ZERO) ->
118+
StakeError.NOT_ENOUGH_FUND_FOR_FEE
91119

92-
else -> StakeError.OK
120+
else ->
121+
StakeError.OK
93122
}
94123

95124
private fun checkPoolLimit(amount: BigInteger): StakeError {

app/src/main/java/com/concordium/wallet/ui/bakerdelegation/delegation/DelegationRegisterAmountActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ class DelegationRegisterAmountActivity : BaseDelegationBakerRegisterAmountActivi
241241
maximumValue = null,
242242
oldStakedAmount = null,
243243
balance = viewModel.bakerDelegationData.account.balance,
244-
atDisposal = viewModel.atDisposal(),
244+
atDisposal = viewModel.bakerDelegationData.account.balanceAtDisposal,
245245
currentPool = viewModel.bakerDelegationData.bakerPoolStatus?.delegatedCapital,
246246
poolLimit = viewModel.bakerDelegationData.bakerPoolStatus?.delegatedCapitalCap,
247247
previouslyStakedInPool = viewModel.bakerDelegationData.account.delegation?.stakedAmount,

app/src/main/java/com/concordium/wallet/ui/bakerdelegation/delegation/DelegationRemoveActivity.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,10 @@ class DelegationRemoveActivity : BaseDelegationBakerActivity(
8181
}
8282

8383
private fun validate() {
84-
if (viewModel.atDisposal() < (viewModel.bakerDelegationData.cost ?: BigInteger.ZERO)) {
85-
showNotEnoughFunds()
84+
if (viewModel.bakerDelegationData.account.balanceAtDisposal <
85+
(viewModel.bakerDelegationData.cost ?: BigInteger.ZERO)
86+
) {
87+
showNotEnoughFundsForFee()
8688
} else {
8789
if (viewModel.bakerDelegationData.isBakerPool) {
8890
viewModel.bakerDelegationData.account.delegation?.delegationTarget?.bakerId?.let {

app/src/main/java/com/concordium/wallet/ui/bakerdelegation/dialog/NotEnoughFundsDialog.kt renamed to app/src/main/java/com/concordium/wallet/ui/bakerdelegation/dialog/NotEnoughFundsForFeeDialog.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@ import android.view.View
77
import android.view.ViewGroup
88
import androidx.appcompat.app.AppCompatDialogFragment
99
import com.concordium.wallet.R
10-
import com.concordium.wallet.databinding.DialogNotEnoughFundsBinding
10+
import com.concordium.wallet.databinding.DialogNotEnoughFundsForFeeBinding
1111
import com.concordium.wallet.ui.MainActivity
1212

13-
class NotEnoughFundsDialog : AppCompatDialogFragment() {
13+
class NotEnoughFundsForFeeDialog : AppCompatDialogFragment() {
1414

1515
override fun getTheme(): Int = R.style.CCX_Dialog
1616

17-
private lateinit var binding: DialogNotEnoughFundsBinding
17+
private lateinit var binding: DialogNotEnoughFundsForFeeBinding
1818

1919
override fun onCreateView(
2020
inflater: LayoutInflater,
2121
container: ViewGroup?,
2222
savedInstanceState: Bundle?
2323
): View {
24-
binding = DialogNotEnoughFundsBinding.inflate(inflater, container, false)
24+
binding = DialogNotEnoughFundsForFeeBinding.inflate(inflater, container, false)
2525
return binding.root
2626
}
2727

@@ -36,6 +36,6 @@ class NotEnoughFundsDialog : AppCompatDialogFragment() {
3636
}
3737

3838
companion object {
39-
const val TAG = "NotEnoughFundsDialog"
39+
const val TAG = "NotEnoughFundsForFeeDialog"
4040
}
41-
}
41+
}

app/src/main/res/layout/dialog_not_enough_funds.xml renamed to app/src/main/res/layout/dialog_not_enough_funds_for_fee.xml

File renamed without changes.

0 commit comments

Comments
 (0)