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
Original file line number Diff line number Diff line change
@@ -1,78 +1,33 @@
package com.flipcash.app.core.ui

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.Dp
import com.getcode.opencode.compose.LocalExchange
import com.getcode.opencode.model.financial.Fiat
import com.getcode.opencode.model.financial.LocalFiat
import com.getcode.theme.CodeTheme

/**
* The amount column of an activity/transaction row: the entry in the viewer's own currency, and —
* only when the payment was denominated in someone else's — what actually moved, flagged, underneath.
* A tip of 7,500 pesos reads "-$5.00" to a viewer in dollars, with "-$7,500.00" under an Argentine
* flag below it.
* The amount column of an activity/transaction row: the entry in the viewer's own currency, the
* only currency the app shows. A tip of 7,500 pesos reads "-$5.00" to a viewer in dollars.
*
* Both lines carry [signPrefix], so a debit reads as one whichever line you look at — see [sign]
* for the amount that signs itself.
*
* @param showViewerFlag whether the top line is flagged too. The per-token transaction history flags
* every amount it shows, so it opts in; the wallet's activity rows leave the viewer's own currency
* unflagged and let the flag mark the foreign line alone.
* The amount carries [signPrefix] — see [sign] for the amount that signs itself.
*/
@Composable
fun ActivityAmount(
amount: LocalFiat,
modifier: Modifier = Modifier,
signPrefix: String? = null,
showViewerFlag: Boolean = false,
) {
val exchange = LocalExchange.current
// Observed rather than read once: the viewer can change their currency from a screen stacked
// over the list, and these rows are re-mapped only when a profile or token cache lands, so
// nothing else would bring the new currency back down here. Cross-rates for a non-USDF entry
// are a snapshot taken alongside it — see `forViewer`, which only needs them as a fallback.
val preferredRate by exchange.observePreferredRate().collectAsState(initial = exchange.preferredRate)
val amounts = amount.forViewer(preferredRate, exchange.rates())
val viewer = amount.inDisplayCurrency()

Column(
Text(
modifier = modifier,
horizontalAlignment = Alignment.End,
verticalArrangement = Arrangement.spacedBy(CodeTheme.dimens.grid.x1),
) {
if (showViewerFlag) {
FlagWithFiat(
fiat = amounts.viewer,
extraPrefix = amounts.viewer.sign(signPrefix),
spacing = FLAG_SPACING,
)
} else {
Text(
text = amounts.viewer.formatted(extraPrefix = amounts.viewer.sign(signPrefix)),
style = CodeTheme.typography.textMedium,
color = CodeTheme.colors.textMain,
maxLines = 1,
)
}

amounts.transferred?.let { transferred ->
FlagWithFiat(
fiat = transferred,
extraPrefix = transferred.sign(signPrefix),
iconSize = CodeTheme.dimens.staticGrid.x2,
spacing = FLAG_SPACING,
textStyle = CodeTheme.typography.textSmall,
textColor = CodeTheme.colors.textSecondary,
)
}
}
text = viewer.formatted(extraPrefix = viewer.sign(signPrefix)),
style = CodeTheme.typography.textMedium,
color = CodeTheme.colors.textMain,
maxLines = 1,
)
}

/**
Expand All @@ -83,9 +38,3 @@ fun ActivityAmount(
*/
internal fun Fiat.sign(prefix: String?): String? = prefix?.takeUnless { isNegative }

/**
* How far the flag sits from the figure it belongs to. Tighter than [FlagWithFiat]'s default, which
* is set for a lone amount rather than for two of them stacked.
*/
private val FLAG_SPACING: Dp
@Composable get() = CodeTheme.dimens.grid.x1
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,17 @@ fun AmountWithKeypad(
}

/**
* The default amount field: centred in its region at display-large, with an optional currency
* flag that doubles as the currency picker affordance.
* The default amount field: centred in its region at display-large. Carries no currency flag or
* picker — the amount is always in the viewer's preferred currency.
*/
@Composable
fun BoxScope.AmountEntryField(
amountAnimatedModel: AmountAnimatedInputUiModel,
prefix: String = "",
placeholder: String = "",
currencyFlag: Int? = null,
decimalPlaces: Int = 2,
hint: String = "",
isError: Boolean = false,
isClickable: Boolean = false,
onClick: () -> Unit = { },
) {
val networkObserver = LocalNetworkObserver.current
val networkState by networkObserver.state.collectAsStateWithLifecycle()
Expand All @@ -97,13 +94,12 @@ fun BoxScope.AmountEntryField(
amountText = "",
placeholder = placeholder,
captionText = hint,
currencyResId = currencyFlag,
currencyResId = null,
isAltCaptionKinIcon = false,
isAltCaption = isError,
uiModel = amountAnimatedModel,
isAnimated = true,
isClickable = isClickable,
onClick = onClick,
isClickable = false,
networkState = networkState,
textStyle = CodeTheme.typography.displayLarge,
decimalPlaces = decimalPlaces,
Expand All @@ -112,7 +108,7 @@ fun BoxScope.AmountEntryField(

/**
* v2 amount field: top-anchored and left-aligned at display-extra-large over an "$X available"
* line. Carries no currency flag or chevron — the currency is fixed for the flows that use it.
* line. Carries no currency flag or chevron, like [AmountEntryField].
*
* @param caption optional text rendered immediately under the amount. It belongs here rather than
* in [AmountWithKeypad]'s accessory strip: the strip sits at the bottom of the amount region, which
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@ import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.foundation.selection.selectable
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Check
import androidx.compose.material3.CircularProgressIndicator
Expand All @@ -21,7 +18,6 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.drawWithContent
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.painter.Painter
Expand All @@ -35,7 +31,6 @@ import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.flipcash.core.R
import com.getcode.opencode.compose.LocalExchange
import com.getcode.opencode.model.financial.Fiat
import com.getcode.opencode.model.financial.Token
import com.getcode.opencode.model.financial.TokenWithBalance
Expand Down Expand Up @@ -72,7 +67,6 @@ data class TokenBalanceRowStyling(
val nameTextStyle: TextStyle,
val balanceDisplayStyle: TokenBalanceStyle,
val iconSize: Dp,
val flagSize: Dp,
val selectionStyle: TokenSelectionStyle,
val disabledAlpha: Float,
val contentPadding: PaddingValues,
Expand All @@ -83,7 +77,6 @@ fun rememberTokenBalanceRowStyling(
nameTextStyle: TextStyle = CodeTheme.typography.screenTitle.copy(fontWeight = FontWeight.Bold),
balanceDisplayStyle: TokenBalanceStyle = TokenBalanceStyle.Large(),
iconSize: Dp = CodeTheme.dimens.staticGrid.x6,
flagSize: Dp = CodeTheme.dimens.staticGrid.x3,
selectionStyle: TokenSelectionStyle = TokenSelectionStyle.None,
disabledAlpha: Float = 0.8f,
contentPadding: PaddingValues = PaddingValues(vertical = CodeTheme.dimens.inset),
Expand All @@ -92,7 +85,6 @@ fun rememberTokenBalanceRowStyling(
nameTextStyle = nameTextStyle,
balanceDisplayStyle = balanceDisplayStyle,
iconSize = iconSize,
flagSize = flagSize,
selectionStyle = selectionStyle,
disabledAlpha = disabledAlpha,
contentPadding = contentPadding,
Expand All @@ -103,7 +95,6 @@ fun TokenBalanceRow(
tokenWithBalance: TokenWithLocalizedBalance,
modifier: Modifier = Modifier,
showName: Boolean = true,
showFlag: Boolean = false,
showLogo: Boolean = true,
isSelected: Boolean? = null,
isEnabled: Boolean = true,
Expand All @@ -119,15 +110,14 @@ fun TokenBalanceRow(
TokenBalanceRow(
token = token,
displayName = displayName,
balance = balance.nativeAmount,
balance = balance.inDisplayCurrency(),
iconOverride = iconOverride,
formattedBalance = formattedBalance,
isSelected = isSelected,
isEnabled = isEnabled,
isLoading = isLoading,
modifier = modifier,
showName = showName,
showFlag = showFlag,
showLogo = showLogo,
styling = styling,
horizontalArrangement = horizontalArrangement,
Expand All @@ -142,7 +132,6 @@ fun TokenBalanceRow(
modifier: Modifier = Modifier,
showName: Boolean = true,
showLogo: Boolean = true,
showFlag: Boolean = false,
isSelected: Boolean? = null,
isEnabled: Boolean = true,
isLoading: Boolean = false,
Expand All @@ -157,10 +146,9 @@ fun TokenBalanceRow(
TokenBalanceRow(
token = token,
displayName = displayName,
balance = balance,
balance = balance.inDisplayCurrency(),
showName = showName,
showLogo = showLogo,
showFlag = showFlag,
isSelected = isSelected,
isEnabled = isEnabled,
isLoading = isLoading,
Expand All @@ -183,7 +171,6 @@ fun TokenBalanceRow(
displayName: String = token.name,
showName: Boolean = true,
showLogo: Boolean = true,
showFlag: Boolean = false,
isSelected: Boolean? = null,
isEnabled: Boolean = true,
isLoading: Boolean = false,
Expand All @@ -194,7 +181,6 @@ fun TokenBalanceRow(
contentPadding: PaddingValues = styling.contentPadding,
onClick: (() -> Unit)? = null,
) {
val exchange = LocalExchange.current
val backgroundColor = CodeTheme.colors.background
// The checkbox mark is drawn, not announced, so the row carries the selection instead.
val selection = isSelected.takeIf {
Expand Down Expand Up @@ -267,7 +253,6 @@ fun TokenBalanceRow(

}

val flag = exchange.getFlagByCurrency(balance.currencyCode.name)
Row(
horizontalArrangement = Arrangement.spacedBy(CodeTheme.dimens.grid.x1),
verticalAlignment = Alignment.CenterVertically,
Expand All @@ -283,19 +268,6 @@ fun TokenBalanceRow(
)
}

if (showFlag) {
flag?.let {
Image(
modifier = Modifier
.height(styling.flagSize)
.width(styling.flagSize)
.clip(CircleShape),
painter = painterResource(it),
contentDescription = null
)
}
}

when (val displayStyle = styling.balanceDisplayStyle) {
is TokenBalanceStyle.Large -> {
val resolvedTextStyle = displayStyle.textStyle
Expand Down
Loading
Loading