Skip to content

Commit bba9fcc

Browse files
committed
chore(flipcash): include metadata on error modal when pool distributions fail
Signed-off-by: Brandon McAnsh <[email protected]>
1 parent 1dba5c9 commit bba9fcc

File tree

6 files changed

+73
-11
lines changed

6 files changed

+73
-11
lines changed

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,8 @@
226226
<string name="error_title_resolvePoolFailed">Something Went Wrong</string>
227227
<string name="error_description_resolvePoolFailed">We were unable to resolve your pool. Please try again</string>
228228

229-
<string name="error_title_resolvePoolDistributionsFailed">Pool Distributions Failed</string>
230-
<string name="error_description_resolvePoolDistributionsFailed">
231-
The distributions for this pool could not be completed. Please try again
232-
%1$s
233-
</string>
229+
<string name="error_title_resolvePoolDistributionsFailed">Pool Payouts Failed</string>
230+
<string name="error_description_resolvePoolDistributionsFailed">The payouts for this pool could not be completed. Please try again</string>
234231

235232

236233
<string name="action_swipeToBuyIn">Swipe to Buy In</string>

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,19 @@ internal class PoolBettingViewModel @Inject constructor(
460460
}.onEach { event ->
461461
when (event) {
462462
PaymentEvent.OnPaymentCancelled -> Unit
463-
is PaymentEvent.OnPaymentError -> Unit
463+
is PaymentEvent.OnPaymentError -> {
464+
when (val error = event.error) {
465+
is PaymentError.PoolDistributionFailed -> {
466+
BottomBarManager.showError(
467+
title = resources.getString(R.string.error_title_resolvePoolDistributionsFailed),
468+
message = resources.getString(R.string.error_description_resolvePoolDistributionsFailed),
469+
additionalInfo = error.state
470+
)
471+
}
472+
// other errors are handled internally
473+
else -> Unit
474+
}
475+
}
464476
is PaymentEvent.OnRpcFailure -> Unit
465477
is PaymentEvent.OnPaymentSuccess -> {
466478
event.acknowledge(true) {

apps/flipcash/shared/payments/src/main/kotlin/com/flipcash/app/payments/internal/InternalPaymentController.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ internal class InternalPaymentController(
220220
}
221221
is PaymentError.NoOwnerForDistribution -> presentPaymentFailedError()
222222
is PaymentError.NoPoolBalance -> presentPaymentFailedError()
223-
is PaymentError.PoolDistributionFailed -> presentPaymentFailedError()
223+
is PaymentError.PoolDistributionFailed -> Unit
224224
}
225225
}
226226

@@ -263,6 +263,7 @@ sealed interface PaymentError {
263263
data class NoPoolBalance(override val message: String? = "No pool balance") : PaymentError, Throwable(message)
264264

265265
data class PoolDistributionFailed(
266+
val state: Map<String, Any?> = emptyMap(),
266267
override val message: String = "Failed to distribute funds",
267268
override val cause: Throwable,
268269
): PaymentError, Throwable(

apps/flipcash/shared/payments/src/main/kotlin/com/flipcash/app/payments/internal/InternalPoolResolveDelegate.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,7 @@ class InternalPoolResolveDelegate @Inject constructor(
110110

111111
onError(
112112
error.copy(
113-
message = """
114-
---
115-
DEBUG: ${metadata.entries.joinToString()}
116-
""".trimIndent()
113+
state = metadata
117114
)
118115
)
119116
}

libs/messaging/src/main/kotlin/com/getcode/manager/BottomBarManager.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ object BottomBarManager {
2727
data class BottomBarMessage(
2828
val title: String = "",
2929
val subtitle: String = "",
30+
val additionalInfo: Map<String, Any?> = emptyMap(),
3031
val actions: List<BottomBarAction> = emptyList(),
3132
val showCancel: Boolean,
3233
val onClose: (selection: SelectedBottomBarAction) -> Unit = { },
@@ -130,13 +131,15 @@ object BottomBarManager {
130131
fun showError(
131132
title: String,
132133
message: String,
134+
additionalInfo: Map<String, Any?> = emptyMap(),
133135
additionalActions: List<BottomBarAction> = emptyList(),
134136
onDismiss: () -> Unit = { },
135137
) {
136138
showMessage(
137139
BottomBarMessage(
138140
title = title,
139141
subtitle = message,
142+
additionalInfo = additionalInfo,
140143
showCancel = false,
141144
actions = additionalActions,
142145
type = BottomBarMessageType.ERROR,

ui/components/src/main/kotlin/com/getcode/ui/components/bars/BottomBarContainer.kt

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ import androidx.compose.animation.slideInVertically
1010
import androidx.compose.animation.slideOutVertically
1111
import androidx.compose.animation.togetherWith
1212
import androidx.compose.foundation.background
13+
import androidx.compose.foundation.clickable
1314
import androidx.compose.foundation.interaction.MutableInteractionSource
1415
import androidx.compose.foundation.layout.Arrangement
1516
import androidx.compose.foundation.layout.Box
1617
import androidx.compose.foundation.layout.Column
18+
import androidx.compose.foundation.layout.Row
1719
import androidx.compose.foundation.layout.Spacer
1820
import androidx.compose.foundation.layout.WindowInsets
1921
import androidx.compose.foundation.layout.fillMaxSize
@@ -22,22 +24,27 @@ import androidx.compose.foundation.layout.navigationBars
2224
import androidx.compose.foundation.layout.padding
2325
import androidx.compose.foundation.layout.windowInsetsPadding
2426
import androidx.compose.foundation.shape.CornerSize
27+
import androidx.compose.material.Icon
2528
import androidx.compose.material.LocalContentColor
2629
import androidx.compose.material.Text
30+
import androidx.compose.material.icons.Icons
31+
import androidx.compose.material.icons.rounded.ExpandMore
2732
import androidx.compose.runtime.Composable
2833
import androidx.compose.runtime.CompositionLocalProvider
2934
import androidx.compose.runtime.LaunchedEffect
3035
import androidx.compose.runtime.collectAsState
3136
import androidx.compose.runtime.derivedStateOf
3237
import androidx.compose.runtime.getValue
3338
import androidx.compose.runtime.mutableLongStateOf
39+
import androidx.compose.runtime.mutableStateOf
3440
import androidx.compose.runtime.remember
3541
import androidx.compose.runtime.rememberCoroutineScope
3642
import androidx.compose.runtime.setValue
3743
import androidx.compose.ui.Alignment
3844
import androidx.compose.ui.Modifier
3945
import androidx.compose.ui.draw.alpha
4046
import androidx.compose.ui.draw.clipToBounds
47+
import androidx.compose.ui.draw.rotate
4148
import androidx.compose.ui.graphics.Color
4249
import androidx.compose.ui.res.stringResource
4350
import androidx.compose.ui.text.style.TextAlign
@@ -224,6 +231,51 @@ fun BottomBarView(
224231
}
225232
}
226233
}
234+
if (bottomBarMessage.additionalInfo.isNotEmpty()) {
235+
var isExpanded by remember { mutableStateOf(false) }
236+
237+
CompositionLocalProvider(LocalContentColor provides White) {
238+
Column {
239+
Row(
240+
modifier = Modifier.clickable { isExpanded = !isExpanded },
241+
verticalAlignment = Alignment.CenterVertically,
242+
) {
243+
val rotation by animateFloatAsState(if (isExpanded) 180f else 0f)
244+
val linkPrefix = if (isExpanded) "Hide" else "View"
245+
Text(
246+
text = "$linkPrefix Additional Information",
247+
style = CodeTheme.typography.caption,
248+
color = LocalContentColor.current.copy(alpha = 0.8f),
249+
)
250+
Icon(
251+
modifier = Modifier.rotate(rotation),
252+
imageVector = Icons.Rounded.ExpandMore,
253+
contentDescription = null,
254+
tint = LocalContentColor.current.copy(alpha = 0.8f),
255+
)
256+
}
257+
AnimatedContent(
258+
targetState = isExpanded,
259+
modifier = Modifier.fillMaxWidth(),
260+
transitionSpec = {
261+
slideInVertically { -it } togetherWith slideOutVertically { -it }
262+
}
263+
) { expanded ->
264+
if (expanded) {
265+
Text(
266+
modifier = Modifier.fillMaxWidth(),
267+
text = """
268+
${bottomBarMessage.additionalInfo.onEach { (k, v) -> "$k: $v" }}
269+
""".trimIndent(),
270+
style = CodeTheme.typography.textSmall,
271+
)
272+
} else {
273+
Spacer(modifier = Modifier.fillMaxWidth())
274+
}
275+
}
276+
}
277+
}
278+
}
227279
Column(verticalArrangement = Arrangement.spacedBy(CodeTheme.dimens.grid.x2)) {
228280
val okText = stringResource(R.string.action_ok)
229281
val actions by remember(bottomBarMessage.actions) {

0 commit comments

Comments
 (0)