Skip to content

Commit 4e5962b

Browse files
committed
chore(ocp): rename formatting param to rule for Fiat#formatted
Signed-off-by: Brandon McAnsh <[email protected]>
1 parent 87cd497 commit 4e5962b

File tree

14 files changed

+77
-51
lines changed

14 files changed

+77
-51
lines changed

apps/flipcash/core/src/main/kotlin/com/flipcash/app/core/money/FormatUtils.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ fun Int.withCommas(): String {
4040
return this.toString().reversed().chunked(3).joinToString(",").reversed()
4141
}
4242

43-
fun LocalFiat.formatted(formatting: Fiat.Formatting = Fiat.Formatting.None): String {
44-
return nativeAmount.formatted(formatting = formatting)
43+
fun LocalFiat.formatted(formatting: Fiat.FormattingRule = Fiat.FormattingRule.None): String {
44+
return nativeAmount.formatted(rule = formatting)
4545
}

apps/flipcash/features/pools/src/main/kotlin/com/flipcash/app/pools/internal/betting/components/BidOptions.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,12 @@ import androidx.compose.ui.text.SpanStyle
4646
import androidx.compose.ui.text.buildAnnotatedString
4747
import androidx.compose.ui.text.rememberTextMeasurer
4848
import androidx.compose.ui.text.style.TextAlign
49-
import androidx.compose.ui.text.style.TextDecoration
5049
import androidx.compose.ui.unit.dp
5150
import androidx.compose.ui.util.fastForEach
5251
import com.flipcash.app.core.pools.PoolBetOutcome
5352
import com.flipcash.app.core.pools.PoolResolution
5453
import com.flipcash.app.core.pools.label
5554
import com.flipcash.app.core.pools.winningOutcome
56-
import com.flipcash.app.core.ui.FlagWithFiat
5755
import com.flipcash.features.pools.R
5856
import com.getcode.opencode.model.financial.Fiat
5957
import com.getcode.theme.CodeTheme
@@ -215,7 +213,7 @@ internal fun BidOptions(
215213

216214
if (canBid && selectedOutcome == null) {
217215
val buyInAmount = buyIn.formatted(
218-
formatting = Fiat.Formatting.Truncated
216+
rule = Fiat.FormattingRule.Truncated
219217
)
220218

221219
val label = stringResource(R.string.subtitle_poolNotYetBet, buyInAmount)

apps/flipcash/features/pools/src/main/kotlin/com/flipcash/app/pools/internal/list/components/CompletedPoolStatusRow.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ internal fun CompletedPoolStatusRow(
6161
stringResource(
6262
R.string.subtitle_wonPool,
6363
summary.amountWon.formatted(
64-
formatting = Fiat.Formatting.Truncated
64+
rule = Fiat.FormattingRule.Truncated
6565
)
6666
),
6767
style = CodeTheme.typography.textSmall,
@@ -80,7 +80,7 @@ internal fun CompletedPoolStatusRow(
8080
stringResource(
8181
R.string.subtitle_lostPool,
8282
summary.amount.formatted(
83-
formatting = Fiat.Formatting.Truncated
83+
rule = Fiat.FormattingRule.Truncated
8484
)
8585
),
8686
style = CodeTheme.typography.textSmall,

apps/flipcash/features/pools/src/main/kotlin/com/flipcash/app/pools/internal/list/components/PoolSummaryRow.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ internal fun PoolSummaryRow(
8787
text = stringResource(
8888
R.string.subtitle_totalInPool,
8989
pool.totalPoolAmount.formatted(
90-
formatting = Fiat.Formatting.Truncated
90+
rule = Fiat.FormattingRule.Truncated
9191
)
9292
),
9393
style = CodeTheme.typography.textSmall,

apps/flipcash/features/purchase/src/main/kotlin/com/flipcash/app/purchase/internal/PurchaseAccountViewModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ internal class PurchaseAccountViewModel @Inject constructor(
131131
stateFlow
132132
.mapNotNull { it.costOfAccount }
133133
.map { (amount, currency) -> Fiat(amount, currency) }
134-
.onEach { dispatchEvent(Event.OnPriceFormatted(it.formatted(formatting = Fiat.Formatting.Truncated))) }
134+
.onEach { dispatchEvent(Event.OnPriceFormatted(it.formatted(rule = Fiat.FormattingRule.Truncated))) }
135135
.launchIn(viewModelScope)
136136

137137
eventFlow

apps/flipcash/features/transactions/src/main/kotlin/com/flipcash/app/transactions/internal/components/FeedItemDetails.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import androidx.compose.ui.graphics.Color
1616
import androidx.compose.ui.graphics.compositeOver
1717
import androidx.compose.ui.text.font.FontWeight.Companion.W600
1818
import androidx.compose.ui.text.style.TextOverflow
19-
import com.flipcash.app.core.feed.ActivityFeedMessage
2019
import com.flipcash.app.core.feed.ActivityFeedMessageWithToken
2120
import com.getcode.opencode.model.financial.Fiat
2221
import com.getcode.solana.keys.Mint
@@ -91,7 +90,7 @@ internal fun FeedItemDetails(
9190
modifier = Modifier.weight(1f),
9291
label = "USDC",
9392
value = usdcAmount.formatted(
94-
formatting = Fiat.Formatting.Length(
93+
rule = Fiat.FormattingRule.Length(
9594
token?.decimals ?: 6
9695
)
9796
),

apps/flipcash/shared/bill-customization/src/main/kotlin/com/flipcash/app/bill/customization/BillPlaygroundController.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import com.getcode.opencode.model.financial.Token
99
import com.getcode.ui.utils.hexToColor
1010
import kotlinx.coroutines.flow.MutableStateFlow
1111
import kotlinx.coroutines.flow.StateFlow
12+
import java.util.UUID
1213

1314
interface BillPlaygroundController {
1415
val state: StateFlow<State>
@@ -26,6 +27,7 @@ enum class PlaygroundMode {
2627
data class ColorStore(
2728
val committed: Color,
2829
val transition: Color? = null,
30+
val id: String = UUID.randomUUID().toString(),
2931
) {
3032
constructor(color: Color): this (color, null)
3133
constructor(color: String): this (hexToColor(color))
@@ -69,10 +71,10 @@ sealed interface Event {
6971
data object Undo: Event
7072
}
7173

72-
private const val MaxGradientColors = 3
74+
internal const val MaxGradientColors = 3
7375

7476
@OptIn(ExperimentalStdlibApi::class)
75-
private val PresetColorOptions: List<BillBackground.Solid> = listOf(
77+
internal val PresetColorOptions: List<BillBackground.Solid> = listOf(
7678
BillBackground.Solid("#FFFF453A"), // Red
7779
BillBackground.Solid("#FFFF9F0A"), // Orange
7880
BillBackground.Solid("#FFFFD60A"), // Yellow
@@ -87,7 +89,7 @@ private val PresetColorOptions: List<BillBackground.Solid> = listOf(
8789
BillBackground.Solid("#FF8B4513"), // Brown
8890
)
8991

90-
private val PresetGradients: List<BillBackground.Gradient> = listOf(
92+
internal val PresetGradients: List<BillBackground.Gradient> = listOf(
9193
BillBackground.Gradient(listOf("#FFE2EAF3", "#FF5487C1")),
9294
BillBackground.Gradient(listOf("#FFCDB3FF", "#FFECE0E5", "#FFFB9655")),
9395
BillBackground.Gradient(listOf("#FFFFD5E7", "#FF31D9AA")),
@@ -96,7 +98,7 @@ private val PresetGradients: List<BillBackground.Gradient> = listOf(
9698
BillBackground.Gradient(listOf("#FF4F63FC", "#FF31D9AA"))
9799
)
98100

99-
private fun buildGradient(): List<ColorStore> {
101+
internal fun buildGradient(): List<ColorStore> {
100102
val swatches = PresetColorOptions
101103

102104
// return a random 3 color gradient
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.flipcash.app.bill.customization.internal
2+
3+
import com.flipcash.app.bill.customization.ColorStore
4+
import com.flipcash.app.bill.customization.MaxGradientColors
5+
import com.flipcash.app.bill.customization.PlaygroundMode
6+
import com.flipcash.app.bill.customization.PresetColorOptions
7+
import com.flipcash.app.bill.customization.PresetGradients
8+
import com.flipcash.app.bill.customization.State
9+
import com.flipcash.app.bill.customization.buildGradient
10+
import com.getcode.opencode.model.financial.BillBackground
11+
import kotlinx.coroutines.flow.MutableStateFlow
12+
import kotlinx.coroutines.flow.StateFlow
13+
import kotlinx.coroutines.flow.asStateFlow
14+
import javax.inject.Inject
15+
16+
class BackgroundController @Inject constructor() {
17+
18+
private val _state = MutableStateFlow(ColorState())
19+
val state: StateFlow<ColorState>
20+
get() = _state.asStateFlow()
21+
22+
23+
}
24+
25+
data class ColorState(
26+
val mode: PlaygroundMode = PlaygroundMode.Presets,
27+
val selectedSlot: Int = 0,
28+
val maxSlots: Int = MaxGradientColors,
29+
val selectedColors: List<ColorStore> = buildGradient(),
30+
val colorOptions: List<BillBackground.Solid> = PresetColorOptions,
31+
val gradientOptions: List<BillBackground.Gradient> = PresetGradients,
32+
)

apps/flipcash/shared/bill-customization/src/main/kotlin/com/flipcash/app/bill/customization/internal/InternalBillPlaygroundController.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import com.getcode.opencode.model.financial.BillBackground
1616
import com.getcode.opencode.model.financial.LocalFiat
1717
import com.getcode.opencode.model.financial.Token
1818
import com.getcode.opencode.model.financial.toFiat
19+
import com.getcode.opencode.model.financial.usdc
1920
import com.getcode.opencode.utils.nonce
2021
import com.getcode.ui.utils.hexToColor
2122
import kotlinx.coroutines.flow.MutableSharedFlow
@@ -45,10 +46,8 @@ class InternalBillPlaygroundController(
4546

4647
override fun customizeFor(token: Token) {
4748
// create amount for the bill
48-
val demoAmount = LocalFiat.valueExchangeIn(
49-
amount = 5.toFiat(),
50-
token = token,
51-
rate = exchange.rateForUsd()
49+
val demoAmount = LocalFiat(
50+
usdc = 5.toFiat(),
5251
)
5352

5453
// provide bill "data" to render the scan code

apps/flipcash/shared/onramp/common/src/main/kotlin/com/flipcash/app/onramp/OnRampAmountSelectionModal.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ private fun PresetAmount(
122122
onClick: () -> Unit
123123
) {
124124
ClickableCell(
125-
text = amount.formatted(formatting = Fiat.Formatting.Truncated),
125+
text = amount.formatted(rule = Fiat.FormattingRule.Truncated),
126126
isSelected = isSelected,
127127
modifier = modifier,
128128
onClick = onClick

0 commit comments

Comments
 (0)