Skip to content

Commit 65b2a54

Browse files
committed
fix(ui): make Confirm In Phantom button react to button state for inline content label
Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent 15e92f4 commit 65b2a54

6 files changed

Lines changed: 41 additions & 23 deletions

File tree

apps/flipcash/core/src/main/kotlin/com/flipcash/app/core/onramp/ui/ConfirmInWalletButtonLabel.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ import androidx.compose.foundation.layout.fillMaxSize
66
import androidx.compose.foundation.layout.padding
77
import androidx.compose.foundation.text.InlineTextContent
88
import androidx.compose.foundation.text.appendInlineContent
9+
import androidx.compose.material.ButtonColors
910
import androidx.compose.runtime.Composable
11+
import androidx.compose.runtime.getValue
12+
import androidx.compose.runtime.key
13+
import androidx.compose.runtime.remember
14+
import androidx.compose.runtime.rememberUpdatedState
1015
import androidx.compose.ui.Alignment
1116
import androidx.compose.ui.Modifier
1217
import androidx.compose.ui.graphics.Color
@@ -21,19 +26,24 @@ import androidx.compose.ui.unit.sp
2126
import com.flipcash.core.R
2227
import com.flipcash.services.internal.model.thirdparty.OnRampProvider
2328
import com.getcode.theme.CodeTheme
29+
import com.getcode.ui.theme.ButtonState
2430

2531
@Composable
2632
fun buildExternalWalletButtonLabel(
2733
prefix: String,
2834
provider: OnRampProvider.UsesDeeplinks,
29-
iconColor: Color
35+
isEnabled: Boolean = true,
36+
colors: ButtonColors = ButtonState.Filled.colors(),
3037
): AnnotatedButtonLabel {
3138
val (title, icon) = when (provider) {
3239
OnRampProvider.Backpack -> stringResource(R.string.label_backpack) to painterResource(R.drawable.ic_backpack_wallet)
3340
OnRampProvider.Phantom -> stringResource(R.string.label_phantom) to painterResource(R.drawable.ic_phantom_wallet)
3441
OnRampProvider.Solflare -> stringResource(R.string.label_solflare) to painterResource(R.drawable.ic_solflare_wallet)
3542
}
3643

44+
val currentIsEnabled by rememberUpdatedState(isEnabled)
45+
val currentColors by rememberUpdatedState(colors)
46+
3747
return buildAnnotatedString {
3848
append(prefix)
3949
appendInlineContent("[icon]", alternateText = " ")
@@ -50,6 +60,7 @@ fun buildExternalWalletButtonLabel(
5060
modifier = Modifier.fillMaxSize(),
5161
contentAlignment = Alignment.Center
5262
) {
63+
val iconColor by currentColors.contentColor(currentIsEnabled)
5364
Image(
5465
modifier = Modifier.padding(
5566
start = CodeTheme.dimens.staticGrid.x1 + 2.dp,

apps/flipcash/core/src/main/kotlin/com/flipcash/app/core/onramp/ui/PhantomLabel.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.flipcash.app.core.onramp.ui
22

33
import androidx.compose.foundation.text.InlineTextContent
4+
import androidx.compose.material.ButtonColors
45
import androidx.compose.runtime.Composable
56
import androidx.compose.ui.graphics.Color
67
import androidx.compose.ui.text.AnnotatedString
@@ -12,7 +13,8 @@ typealias AnnotatedButtonLabel = Pair<AnnotatedString, Map<String, InlineTextCon
1213
@Composable
1314
fun buildPhantomButtonLabel(
1415
prefix: String,
15-
iconColor: Color = ButtonState.Filled.colors().contentColor(true).value,
16+
isEnabled: Boolean = true,
17+
colors: ButtonColors = ButtonState.Filled.colors(),
1618
): AnnotatedButtonLabel {
17-
return buildExternalWalletButtonLabel(prefix, OnRampProvider.Phantom, iconColor)
19+
return buildExternalWalletButtonLabel(prefix, OnRampProvider.Phantom, isEnabled = isEnabled, colors = colors)
1820
}

apps/flipcash/core/src/main/kotlin/com/flipcash/app/core/ui/ButtonPreviews.kt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ private fun Buttons() {
7171
buildExternalWalletButtonLabel(
7272
"Confirm in",
7373
provider = OnRampProvider.Phantom,
74-
Color.Black
7574
)
7675
) {
7776
CodeButton(
@@ -83,6 +82,23 @@ private fun Buttons() {
8382
)
8483
}
8584

85+
with(
86+
buildExternalWalletButtonLabel(
87+
"Confirm in",
88+
provider = OnRampProvider.Phantom,
89+
isEnabled = false,
90+
)
91+
) {
92+
CodeButton(
93+
modifier = Modifier.fillMaxWidth(),
94+
onClick = {},
95+
enabled = false,
96+
text = first,
97+
inlineContent = second,
98+
buttonState = ButtonState.Filled,
99+
)
100+
}
101+
86102
with(buildNotifyButtonLabel()) {
87103
CodeButton(
88104
modifier = Modifier.fillMaxWidth(),

apps/flipcash/features/onramp/src/main/kotlin/com/flipcash/app/onramp/internal/screens/OnRampAmountScreenContent.kt

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,15 @@
11
package com.flipcash.app.onramp.internal.screens
22

3-
import androidx.compose.foundation.Image
4-
import androidx.compose.foundation.layout.Box
53
import androidx.compose.foundation.layout.Column
64
import androidx.compose.foundation.layout.fillMaxSize
75
import androidx.compose.foundation.layout.fillMaxWidth
86
import androidx.compose.foundation.layout.navigationBarsPadding
97
import androidx.compose.foundation.layout.padding
10-
import androidx.compose.foundation.text.InlineTextContent
11-
import androidx.compose.foundation.text.appendInlineContent
128
import androidx.compose.runtime.Composable
139
import androidx.compose.runtime.getValue
14-
import androidx.compose.ui.Alignment
1510
import androidx.compose.ui.Modifier
16-
import androidx.compose.ui.graphics.Color
17-
import androidx.compose.ui.graphics.ColorFilter
18-
import androidx.compose.ui.res.painterResource
1911
import androidx.compose.ui.res.stringResource
2012
import androidx.compose.ui.text.AnnotatedString
21-
import androidx.compose.ui.text.Placeholder
22-
import androidx.compose.ui.text.PlaceholderVerticalAlign
23-
import androidx.compose.ui.text.buildAnnotatedString
24-
import androidx.compose.ui.unit.dp
25-
import androidx.compose.ui.unit.sp
2613
import androidx.lifecycle.compose.collectAsStateWithLifecycle
2714
import cafe.adriel.voyager.core.registry.ScreenRegistry
2815
import com.flipcash.app.core.AppRoute
@@ -38,8 +25,6 @@ import com.getcode.navigation.core.LocalCodeNavigator
3825
import com.getcode.theme.CodeTheme
3926
import com.getcode.ui.theme.ButtonState
4027
import com.getcode.ui.theme.CodeButton
41-
import kotlin.collections.emptyMap
42-
import kotlin.to
4328

4429
@Composable
4530
internal fun OnRampAmountScreen(
@@ -112,7 +97,6 @@ private fun ConfirmationButton(
11297
modifier: Modifier = Modifier,
11398
dispatchEvent: (OnRampViewModel.Event) -> Unit
11499
) {
115-
val buttonColors = ButtonState.Filled.colors()
116100
val (buttonText, assets) = when (provider) {
117101
is OnRampProvider.Coinbase -> when (provider.type) {
118102
// https://developers.google.com/pay/api/android/guides/brand-guidelines#using-pay-in-text
@@ -125,7 +109,7 @@ private fun ConfirmationButton(
125109
buildExternalWalletButtonLabel(
126110
prefix = stringResource(R.string.label_confirmIn),
127111
provider = provider,
128-
iconColor = buttonColors.contentColor(state.canAdd).value
112+
isEnabled = state.canAdd
129113
)
130114
}
131115

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,10 @@ internal fun BuySellTokenEntryScreen(
102102
Box(modifier = Modifier.fillMaxWidth()) {
103103
val (text, inlineContent) = when (state.purpose) {
104104
is TokenSwapPurpose.Buy -> AnnotatedString(stringResource(R.string.action_buy)) to emptyMap()
105-
is TokenSwapPurpose.FundWithWallet -> buildPhantomButtonLabel(prefix = stringResource(R.string.label_confirmIn))
105+
is TokenSwapPurpose.FundWithWallet -> buildPhantomButtonLabel(
106+
prefix = stringResource(R.string.label_confirmIn),
107+
isEnabled = state.canTransact
108+
)
106109
is TokenSwapPurpose.Sell -> AnnotatedString(stringResource(R.string.action_next)) to emptyMap()
107110
else -> AnnotatedString("") to emptyMap()
108111
}

ui/components/src/main/kotlin/com/getcode/ui/theme/CodeButton.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import androidx.compose.runtime.derivedStateOf
4242
import androidx.compose.runtime.getValue
4343
import androidx.compose.runtime.mutableStateOf
4444
import androidx.compose.runtime.remember
45+
import androidx.compose.runtime.rememberUpdatedState
4546
import androidx.compose.runtime.setValue
4647
import androidx.compose.ui.Alignment
4748
import androidx.compose.ui.Modifier
@@ -266,7 +267,8 @@ fun CodeButton(
266267
style = style,
267268
sizeKey = text
268269
) {
269-
Text(text = text, inlineContent = inlineContent)
270+
val updatedInlineContent by rememberUpdatedState(inlineContent)
271+
Text(text = text, inlineContent = updatedInlineContent)
270272
}
271273
}
272274

0 commit comments

Comments
 (0)