Skip to content

Commit 7041750

Browse files
committed
fix(tokens): reflect receiving USD Reserves when selling
Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent b432ef4 commit 7041750

4 files changed

Lines changed: 42 additions & 32 deletions

File tree

apps/flipcash/core/src/main/res/values/strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,4 +412,7 @@
412412
<string name="subtitle_wasAddedToYourWallet">was added to your Flipcash wallet</string>
413413
<string name="label_ofToken">of %1s</string>
414414

415+
<string name="label_sellAmount">Sell Amount</string>
416+
<string name="label_percentFee">%1$d Fee</string>
417+
415418
</resources>

apps/flipcash/features/tokens/src/main/kotlin/com/flipcash/app/tokens/internal/TokenSellReceiptScreen.kt

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,9 @@ import androidx.compose.foundation.layout.navigationBarsPadding
1212
import androidx.compose.foundation.layout.padding
1313
import androidx.compose.material.Text
1414
import androidx.compose.runtime.Composable
15-
import androidx.compose.runtime.derivedStateOf
1615
import androidx.compose.runtime.getValue
17-
import androidx.compose.runtime.remember
1816
import androidx.compose.ui.Alignment
1917
import androidx.compose.ui.Modifier
20-
import androidx.compose.ui.graphics.Color
21-
import androidx.compose.ui.graphics.compositeOver
2218
import androidx.compose.ui.res.stringResource
2319
import androidx.compose.ui.text.style.TextAlign
2420
import androidx.compose.ui.unit.dp
@@ -30,13 +26,9 @@ import com.flipcash.app.tokens.BuySellSwapTokenViewModel
3026
import com.flipcash.features.tokens.R
3127
import com.getcode.opencode.model.financial.Fiat
3228
import com.getcode.opencode.model.financial.TokenWithBalance
33-
import com.getcode.opencode.model.financial.minus
34-
import com.getcode.opencode.model.financial.times
3529
import com.getcode.theme.CodeTheme
3630
import com.getcode.theme.White05
37-
import com.getcode.theme.White08
3831
import com.getcode.theme.bolded
39-
import com.getcode.theme.inputColors
4032
import com.getcode.ui.theme.ButtonState
4133
import com.getcode.ui.theme.CodeButton
4234
import com.getcode.ui.theme.CodeScaffold
@@ -101,10 +93,11 @@ private fun TokenSellReceiptScreen(
10193
)
10294
) {
10395
SellReceipt(
104-
tokenWithBalance = state.tokenWithBalance!!.copy(
105-
balance = state.amountEntryState.selectedAmount.nativeAmount
106-
),
107-
fee = state.sellFee,
96+
grossTransferAmount = state.enteredAmount,
97+
netTransferAmount = state.netTransferAmount,
98+
feeAmount = state.feeAmount,
99+
feePercentage = state.sellFee,
100+
tokenWithBalance = state.tokenWithBalance!!,
108101
)
109102
}
110103
}
@@ -113,7 +106,10 @@ private fun TokenSellReceiptScreen(
113106
@Composable
114107
private fun SellReceipt(
115108
tokenWithBalance: TokenWithBalance,
116-
fee: Double?,
109+
grossTransferAmount: Fiat,
110+
netTransferAmount: Fiat,
111+
feePercentage: Double?,
112+
feeAmount: Fiat,
117113
modifier: Modifier = Modifier,
118114
) {
119115
Column(
@@ -133,33 +129,20 @@ private fun SellReceipt(
133129
verticalArrangement = Arrangement.spacedBy(CodeTheme.dimens.grid.x6),
134130
horizontalAlignment = Alignment.CenterHorizontally
135131
) {
136-
val feeAmount by remember(fee, tokenWithBalance.balance) {
137-
derivedStateOf {
138-
if (fee == null) return@derivedStateOf Fiat.Zero
139-
tokenWithBalance.balance * (fee / 100.0)
140-
}
141-
}
142-
143-
val netTransferAmount by remember(tokenWithBalance.balance, feeAmount) {
144-
derivedStateOf {
145-
tokenWithBalance.balance - feeAmount
146-
}
147-
}
148-
149132
Column(
150133
modifier = modifier,
151134
verticalArrangement = Arrangement.spacedBy(CodeTheme.dimens.grid.x3),
152135
) {
153136
ReceiptLineItem(
154137
modifier = Modifier.fillMaxWidth(),
155-
label = "Sell amount",
156-
amount = tokenWithBalance.balance.formatted(),
138+
label = stringResource(R.string.label_sellAmount),
139+
amount = grossTransferAmount.formatted(),
157140
)
158141

159-
if (fee != null) {
142+
if (feePercentage != null) {
160143
ReceiptLineItem(
161144
modifier = Modifier.fillMaxWidth(),
162-
label = "${fee.roundToInt()}% Fee",
145+
label = stringResource(R.string.label_percentFee, feePercentage.roundToInt()),
163146
amount = feeAmount.formatted(
164147
extraPrefix = if (feeAmount.decimalValue != 1.0) "~" else null,
165148
),

apps/flipcash/features/tokens/src/main/kotlin/com/flipcash/app/tokens/internal/TokenTxProcessingScreen.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,13 @@ private fun TokenTxProcessingScreen(
182182
LoadingSuccessState.State.Error -> stringResource(R.string.error_title_buySellFailed)
183183
LoadingSuccessState.State.Idle -> ""
184184
LoadingSuccessState.State.Loading -> stringResource(R.string.title_processingYourTransaction)
185-
LoadingSuccessState.State.Success -> state.enteredAmount.formatted(suffix = stringResource(R.string.label_ofToken, state.tokenName))
185+
LoadingSuccessState.State.Success -> {
186+
val name = when (state.purpose) {
187+
is TokenSwapPurpose.BalanceIncrease -> state.tokenName
188+
else -> stringResource(R.string.title_cashReserves)
189+
}
190+
state.netTransferAmount.formatted(suffix = stringResource(R.string.label_ofToken, name))
191+
}
186192
},
187193
style = CodeTheme.typography.textLarge,
188194
color = CodeTheme.colors.textMain,

apps/flipcash/shared/tokens/src/main/kotlin/BuySellSwapTokenViewModel.kt

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.flipcash.app.tokens
22

3+
import androidx.compose.runtime.derivedStateOf
4+
import androidx.compose.runtime.getValue
5+
import androidx.compose.runtime.remember
36
import androidx.lifecycle.viewModelScope
47
import com.flipcash.app.activityfeed.ActivityFeedCoordinator
58
import com.flipcash.app.core.extensions.onResult
@@ -24,6 +27,8 @@ import com.getcode.opencode.model.financial.SendLimit
2427
import com.getcode.opencode.model.financial.Token
2528
import com.getcode.opencode.model.financial.TokenWithBalance
2629
import com.getcode.opencode.model.financial.TokenWithLocalizedBalance
30+
import com.getcode.opencode.model.financial.minus
31+
import com.getcode.opencode.model.financial.times
2732
import com.getcode.opencode.model.financial.toFiat
2833
import com.getcode.opencode.model.financial.usdf
2934
import com.getcode.opencode.model.transactions.SwapState
@@ -93,7 +98,8 @@ class BuySellSwapTokenViewModel @Inject constructor(
9398
}
9499

95100
val tokenName: String
96-
get() = tokenWithBalance?.token?.name.orEmpty()
101+
get() = tokenWithBalance?.displayName.orEmpty()
102+
97103
val canTransact: Boolean
98104
get() = (amountEntryState.amountAnimatedModel.amountData.amount) > 0.00 && buyProgress.isIdle && sellProgress.isIdle && processingProgress.isIdle
99105

@@ -123,6 +129,18 @@ class BuySellSwapTokenViewModel @Inject constructor(
123129
currencyCode = tokenBalance.currencyCode
124130
)
125131

132+
val feeAmount: Fiat
133+
get() {
134+
val fee = sellFee ?: return Fiat.Zero
135+
return enteredAmount * (fee / 100.0)
136+
}
137+
138+
val netTransferAmount: Fiat
139+
get() = when (purpose) {
140+
is TokenSwapPurpose.BalanceIncrease -> enteredAmount
141+
else -> enteredAmount - feeAmount
142+
}
143+
126144
val transactionLimit: Fiat
127145
get() {
128146
return when (purpose) {

0 commit comments

Comments
 (0)