Skip to content

Commit

Permalink
Fixed incorrect value when updating delegation and validation state (#…
Browse files Browse the repository at this point in the history
…226)

* Fix incorrect value when user is updating the stakes as a delegator and validator

* Update imports
  • Loading branch information
zaiatsartem authored Dec 10, 2024
1 parent 29edfba commit 6c78b30
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ object CurrencyUtil {
return formatGTU(value, withGStroke, decimals)
}

fun formatGTU(value: BigInteger, withGStroke: Boolean = false, decimals: Int = 6): String {
fun formatGTU(
value: BigInteger,
withGStroke: Boolean = false,
decimals: Int = 6,
withCommas: Boolean = true
): String {
if (value == BigInteger.ZERO) return ZERO_AMOUNT
if (decimals <= 0) return value.toString()

Expand Down Expand Up @@ -70,7 +75,9 @@ object CurrencyUtil {
strBuilder.insert(0, "-")
}

return formatGTUWithCommas(strBuilder.toString().removeSuffix(separator.toString()))
val formattedString = strBuilder.toString().removeSuffix(separator.toString())

return if (withCommas) formatGTUWithCommas(formattedString) else formattedString
}

fun formatAndRoundGTU(value: BigInteger, roundDecimals: Int): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ class BakerRegisterAmountActivity : BaseDelegationBakerRegisterAmountActivity(
viewModel.bakerDelegationData.account?.baker?.restakeEarnings
binding.amount.setText(
CurrencyUtil.formatGTU(
viewModel.bakerDelegationData.account?.baker?.stakedAmount
value = viewModel.bakerDelegationData.account?.baker?.stakedAmount
?: BigInteger.ZERO,
true
withGStroke = true,
withCommas = false
)
)
binding.amountDesc.text = getString(R.string.baker_update_enter_new_stake)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,9 @@ class DelegationRegisterAmountActivity : BaseDelegationBakerRegisterAmountActivi
getString(R.string.delegation_update_delegation_amount_enter_amount)
binding.amount.setText(viewModel.bakerDelegationData.account?.delegation?.stakedAmount?.let {
CurrencyUtil.formatGTU(
it,
false
value = it,
withGStroke = false,
withCommas = false
)
})
}
Expand Down

0 comments on commit 6c78b30

Please sign in to comment.