Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## [Unreleased]

### Fixed

- Not warning about insufficient funds at disposal to pay the transaction fee
when configuring earning

## [1.9.0] - 2025-04-17

### Removed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class BakerRegisterAmountActivity : BaseDelegationBakerRegisterAmountActivity(
maximumValue = viewModel.getStakeInputMax(),
oldStakedAmount = viewModel.bakerDelegationData.oldStakedAmount,
balance = viewModel.bakerDelegationData.account.balance,
atDisposal = viewModel.atDisposal(),
atDisposal = viewModel.bakerDelegationData.account.balanceAtDisposal,
currentPool = viewModel.bakerDelegationData.bakerPoolStatus?.delegatedCapital,
poolLimit = null,
previouslyStakedInPool = viewModel.bakerDelegationData.account.delegation?.stakedAmount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,10 @@ class BakerRegistrationConfirmationActivity : BaseDelegationBakerActivity(
}

private fun onContinueClicked() {
if (viewModel.atDisposal() < (viewModel.bakerDelegationData.cost ?: BigInteger.ZERO)) {
showNotEnoughFunds()
if (viewModel.bakerDelegationData.account.balanceAtDisposal <
(viewModel.bakerDelegationData.cost ?: BigInteger.ZERO)
) {
showNotEnoughFundsForFee()
return
}
viewModel.prepareTransaction()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import com.concordium.wallet.data.model.BakerDelegationData
import com.concordium.wallet.data.util.CurrencyUtil
import com.concordium.wallet.extension.showSingle
import com.concordium.wallet.ui.bakerdelegation.dialog.NoChangeDialog
import com.concordium.wallet.ui.bakerdelegation.dialog.NotEnoughFundsDialog
import com.concordium.wallet.ui.bakerdelegation.dialog.NotEnoughFundsForFeeDialog
import com.concordium.wallet.ui.base.BaseActivity
import com.concordium.wallet.ui.common.delegates.AuthDelegate
import com.concordium.wallet.ui.common.delegates.AuthDelegateImpl
Expand Down Expand Up @@ -88,8 +88,8 @@ abstract class BaseDelegationBakerActivity(
}
}

protected fun showNotEnoughFunds() {
NotEnoughFundsDialog().showSingle(supportFragmentManager, NotEnoughFundsDialog.TAG)
protected fun showNotEnoughFundsForFee() {
NotEnoughFundsForFeeDialog().showSingle(supportFragmentManager, NotEnoughFundsForFeeDialog.TAG)
}

protected fun showNoChange() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,17 +235,6 @@ class DelegationBakerViewModel(application: Application) : AndroidViewModel(appl
return (!bakerDelegationData.isBakerPool && !bakerDelegationData.isLPool)
}

fun atDisposal(): BigInteger {
var staked: BigInteger = BigInteger.ZERO
bakerDelegationData.account.delegation?.let {
staked = it.stakedAmount
}
bakerDelegationData.account.baker?.let {
staked = it.stakedAmount
}
return bakerDelegationData.account.balance - staked
}

fun selectBakerPool() {
this.bakerDelegationData.isLPool = false
this.bakerDelegationData.isBakerPool = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,16 @@ class StakeAmountInputValidator(
private val previouslyStakedInPool: BigInteger?,
private val isInCoolDown: Boolean?,
private val oldPoolId: Long?,
private val newPoolId: String?
private val newPoolId: String?,
) {
enum class StakeError {
OK, NOT_ENOUGH_FUND, MINIMUM, MAXIMUM, POOL_LIMIT_REACHED, POOL_LIMIT_REACHED_COOLDOWN, UNKNOWN
OK,
NOT_ENOUGH_FUND,
NOT_ENOUGH_FUND_FOR_FEE,
MINIMUM, MAXIMUM,
POOL_LIMIT_REACHED,
POOL_LIMIT_REACHED_COOLDOWN,
UNKNOWN,
}

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

fun getErrorText(context: Context, stakeError: StakeError): String {
return when (stakeError) {
StakeError.NOT_ENOUGH_FUND -> context.getString(R.string.delegation_register_delegation_not_enough_funds)
StakeError.MINIMUM -> context.getString(
fun getErrorText(
context: Context,
stakeError: StakeError,
): String = when (stakeError) {

StakeError.NOT_ENOUGH_FUND ->
context.getString(R.string.delegation_register_delegation_not_enough_funds)

StakeError.NOT_ENOUGH_FUND_FOR_FEE ->
context.getString(R.string.delegation_register_delegation_not_enough_funds_for_fee)

StakeError.MINIMUM ->
context.getString(
R.string.delegation_register_delegation_minimum,
CurrencyUtil.formatGTU(minimumValue ?: BigInteger.ZERO)
)

StakeError.MAXIMUM -> context.getString(
StakeError.MAXIMUM ->
context.getString(
R.string.delegation_register_delegation_maximum,
CurrencyUtil.formatGTU(maximumValue ?: BigInteger.ZERO)
)

StakeError.POOL_LIMIT_REACHED -> context.getString(R.string.delegation_register_delegation_pool_limit_will_be_breached)
StakeError.POOL_LIMIT_REACHED_COOLDOWN -> context.getString(R.string.delegation_amount_too_large_while_in_cooldown)
StakeError.UNKNOWN -> context.getString(R.string.app_error_general)
else -> ""
}
StakeError.POOL_LIMIT_REACHED ->
context.getString(R.string.delegation_register_delegation_pool_limit_will_be_breached)

StakeError.POOL_LIMIT_REACHED_COOLDOWN ->
context.getString(R.string.delegation_amount_too_large_while_in_cooldown)

StakeError.UNKNOWN ->
context.getString(R.string.app_error_general)

StakeError.OK ->
""
}

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

private fun checkBalance(amount: BigInteger, estimatedFee: BigInteger?): StakeError = when {
balance == null || atDisposal == null -> StakeError.UNKNOWN
private fun checkBalance(
amount: BigInteger,
estimatedFee: BigInteger?,
): StakeError = when {

balance == null || atDisposal == null ->
StakeError.UNKNOWN

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

(estimatedFee ?: BigInteger.ZERO) > atDisposal -> StakeError.NOT_ENOUGH_FUND
atDisposal < (estimatedFee ?: BigInteger.ZERO) ->
StakeError.NOT_ENOUGH_FUND_FOR_FEE

else -> StakeError.OK
else ->
StakeError.OK
}

private fun checkPoolLimit(amount: BigInteger): StakeError {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ class DelegationRegisterAmountActivity : BaseDelegationBakerRegisterAmountActivi
maximumValue = null,
oldStakedAmount = null,
balance = viewModel.bakerDelegationData.account.balance,
atDisposal = viewModel.atDisposal(),
atDisposal = viewModel.bakerDelegationData.account.balanceAtDisposal,
currentPool = viewModel.bakerDelegationData.bakerPoolStatus?.delegatedCapital,
poolLimit = viewModel.bakerDelegationData.bakerPoolStatus?.delegatedCapitalCap,
previouslyStakedInPool = viewModel.bakerDelegationData.account.delegation?.stakedAmount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ class DelegationRemoveActivity : BaseDelegationBakerActivity(
}

private fun validate() {
if (viewModel.atDisposal() < (viewModel.bakerDelegationData.cost ?: BigInteger.ZERO)) {
showNotEnoughFunds()
if (viewModel.bakerDelegationData.account.balanceAtDisposal <
(viewModel.bakerDelegationData.cost ?: BigInteger.ZERO)
) {
showNotEnoughFundsForFee()
} else {
if (viewModel.bakerDelegationData.isBakerPool) {
viewModel.bakerDelegationData.account.delegation?.delegationTarget?.bakerId?.let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@ import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatDialogFragment
import com.concordium.wallet.R
import com.concordium.wallet.databinding.DialogNotEnoughFundsBinding
import com.concordium.wallet.databinding.DialogNotEnoughFundsForFeeBinding
import com.concordium.wallet.ui.MainActivity

class NotEnoughFundsDialog : AppCompatDialogFragment() {
class NotEnoughFundsForFeeDialog : AppCompatDialogFragment() {

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

private lateinit var binding: DialogNotEnoughFundsBinding
private lateinit var binding: DialogNotEnoughFundsForFeeBinding

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
binding = DialogNotEnoughFundsBinding.inflate(inflater, container, false)
binding = DialogNotEnoughFundsForFeeBinding.inflate(inflater, container, false)
return binding.root
}

Expand All @@ -36,6 +36,6 @@ class NotEnoughFundsDialog : AppCompatDialogFragment() {
}

companion object {
const val TAG = "NotEnoughFundsDialog"
const val TAG = "NotEnoughFundsForFeeDialog"
}
}
}
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,7 @@
<string name="delegation_register_delegation_minimum">Minimum stake: Ͼ%1$s</string>
<string name="delegation_register_delegation_maximum">Current maximum: Ͼ%1$s</string>
<string name="delegation_register_delegation_not_enough_funds">@string/insufficient_funds</string>
<string name="delegation_register_delegation_not_enough_funds_for_fee">Insufficient funds at disposal to pay the fee</string>
<string name="delegation_register_delegation_pool_limit_will_be_breached">Pool limit will be breached</string>
<plurals name="delegation_register_delegation_confirmation_desc">
<item quantity="one">This will lock your delegation amount. Amount is released after %d day from the time you remove or decrease your delegation.</item>
Expand Down