Skip to content

Commit

Permalink
Fixing vault input parsing issue with non-US locale (#274)
Browse files Browse the repository at this point in the history
Also updating Abacus to show the correct APR
  • Loading branch information
ruixhuang authored Nov 20, 2024
1 parent 26dfd13 commit 613eb99
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion v4/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ android {
minSdkVersion parent.minSdkVersion
targetSdkVersion parent.targetSdkVersion
versionCode 10000
versionName "1.12.0"
versionName "1.12.1"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

Expand Down
2 changes: 1 addition & 1 deletion v4/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ ext {
compileSdkVersion = 34

// App dependencies
abacusVersion = '1.13.31'
abacusVersion = '1.13.34'
carteraVersion = '0.1.15'
kollectionsVersion = '2.0.16'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,12 @@ class DydxFormatter @Inject constructor() {
xxxxx.yyyyy
*/
fun decimalLocaleAgnostic(number: Double?, digits: Int?): String? {
return raw(number = number, digits = digits, locale = Locale.US)
fun decimalLocaleAgnostic(
number: Double?,
digits: Int?,
rounding: RoundingMode = RoundingMode.HALF_UP,
): String? {
return raw(number = number, digits = digits, locale = Locale.US, rounding = rounding)
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,24 @@ class DydxVaultDepositViewModel @Inject constructor(
subaccount: Subaccount?,
result: VaultFormValidationResult?
): DydxVaultDepositView.ViewState {
val roundedFreeCollateral = formatter.raw(subaccount?.freeCollateral?.current, digits = 2, rounding = RoundingMode.DOWN)
val roundedFreeCollateral = formatter.decimalLocaleAgnostic(subaccount?.freeCollateral?.current, digits = 2, rounding = RoundingMode.DOWN)
return DydxVaultDepositView.ViewState(
localizer = localizer,
transferAmount = VaultAmountBox.ViewState(
localizer = localizer,
formatter = formatter,
parser = parser,
value = parser.asString(inputState.amount.value),
maxAmount = roundedFreeCollateral?.toDouble(),
maxAmount = parser.asDouble(roundedFreeCollateral),
maxAction = {
inputState.amount.value = roundedFreeCollateral?.toDouble()
inputState.amount.value = parser.asDouble(roundedFreeCollateral)
},
title = localizer.localize("APP.VAULTS.ENTER_AMOUNT_TO_DEPOSIT"),
footer = localizer.localize("APP.GENERAL.CROSS_FREE_COLLATERAL"),
footerBefore = AmountText.ViewState(
localizer = localizer,
formatter = formatter,
amount = roundedFreeCollateral?.toDouble(),
amount = parser.asDouble(roundedFreeCollateral),
tickSize = 2,
requiresPositive = true,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,25 +61,25 @@ class DydxVaultWithdrawViewModel @Inject constructor(
vault: Vault?,
result: VaultFormValidationResult?
): DydxVaultWithdrawView.ViewState {
val roundedWithdrawableUsdc = formatter.raw(vault?.account?.withdrawableUsdc, digits = 2, rounding = RoundingMode.DOWN)
val roundedWithdrawableUsdc = formatter.decimalLocaleAgnostic(vault?.account?.withdrawableUsdc, digits = 2, rounding = RoundingMode.DOWN)
return DydxVaultWithdrawView.ViewState(
localizer = localizer,
transferAmount = VaultAmountBox.ViewState(
localizer = localizer,
formatter = formatter,
parser = parser,
value = parser.asString(inputState.amount.value),
maxAmount = roundedWithdrawableUsdc?.toDouble(),
maxAmount = parser.asDouble(roundedWithdrawableUsdc),
maxAction = {
val amount = roundedWithdrawableUsdc?.toDouble()
val amount = parser.asDouble(roundedWithdrawableUsdc)
updateAmount(value = amount, vaultAccount = vault?.account)
},
title = localizer.localize("APP.VAULTS.ENTER_AMOUNT_TO_WITHDRAW"),
footer = localizer.localize("APP.VAULTS.YOUR_VAULT_BALANCE"),
footerBefore = AmountText.ViewState(
localizer = localizer,
formatter = formatter,
amount = roundedWithdrawableUsdc?.toDouble(),
amount = parser.asDouble(roundedWithdrawableUsdc),
tickSize = 2,
requiresPositive = true,
),
Expand Down

0 comments on commit 613eb99

Please sign in to comment.