Skip to content

Commit cfff436

Browse files
committed
chore: properly balance cap relative to rate only during buy with reserves
Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent d950205 commit cfff436

2 files changed

Lines changed: 4 additions & 5 deletions

File tree

apps/flipcash/shared/tokens/src/main/kotlin/com/flipcash/app/tokens/ui/BuySellSwapTokenViewModel.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class BuySellSwapTokenViewModel @Inject constructor(
134134
val netTransferAmount: Fiat
135135
get() = when (purpose) {
136136
is TokenSwapPurpose.BalanceIncrease -> enteredAmount
137-
else -> enteredAmount - feeAmount
137+
else -> Fiat(fiat = enteredAmount.decimalValue - feeAmount.decimalValue, currencyCode = enteredAmount.currencyCode)
138138
}
139139

140140
val transactionLimit: Fiat
@@ -473,7 +473,7 @@ class BuySellSwapTokenViewModel @Inject constructor(
473473
val amountFiat = LocalFiat.valueExchangeIn(
474474
amount = Fiat(data.amountData.amount, rate.currency),
475475
token = Token.usdf,
476-
balance = stateFlow.value.reservesBalance,
476+
balance = stateFlow.value.reservesBalance.convertingToUsdIfNeeded(rate),
477477
rate = rate
478478
)
479479

services/opencode/src/main/kotlin/com/getcode/opencode/model/financial/LocalFiat.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,10 @@ data class LocalFiat(
114114
debug: Boolean = BuildConfig.DEBUG,
115115
trace: Boolean = true,
116116
): LocalFiat {
117-
val usdBalance = balance?.convertingToUsdIfNeeded(rate)
118117
val usdValue = amount.convertingToUsdIfNeeded(rate)
119118
// cap the entered amount as well, since our display rounds HALF_UP
120119
// e,g entered 0.02 USD, but balance is 0.016 USD
121-
val cappedValue = usdBalance?.let { min(it, usdValue) } ?: usdValue
120+
val cappedValue = balance?.let { min(it, usdValue) } ?: usdValue
122121

123122
if (token.address == Mint.usdf) {
124123
// this doesn't need a calculated value exchange since we are USDC
@@ -155,7 +154,7 @@ data class LocalFiat(
155154
rate = rate,
156155
amount = amount,
157156
usdValue = usdValue,
158-
balance = usdBalance,
157+
balance = balance,
159158
cappedValue = cappedValue,
160159
token = token,
161160
supply = supply,

0 commit comments

Comments
 (0)