Skip to content

Commit 9635de7

Browse files
committed
fix(flipcash): close phantom flow properly
Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent 5284148 commit 9635de7

3 files changed

Lines changed: 87 additions & 66 deletions

File tree

apps/flipcash/app/src/main/kotlin/com/flipcash/app/internal/ui/App.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ internal fun App(
130130
val codeNavigator = LocalCodeNavigator.current
131131
PhantomOnRampHandler(
132132
state = LocalPhantomDepositState.current,
133+
navigator = codeNavigator,
133134
router = router,
134135
deepLink = deepLink
135136
) {

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

Lines changed: 69 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -96,62 +96,76 @@ private fun OnRampAmountScreenContent(
9696
onDecimal = { dispatchEvent(OnRampViewModel.Event.OnDecimalPressed) }
9797
)
9898

99-
Box(modifier = Modifier.fillMaxWidth()) {
100-
val buttonColors = getButtonColors(state.canAdd, ButtonState.Filled, Color.Unspecified)
101-
val (buttonText, assets) = when (provider) {
102-
is OnRampProvider.Coinbase -> when (provider.type) {
103-
// https://developers.google.com/pay/api/android/guides/brand-guidelines#using-pay-in-text
104-
OnRampType.Virtual -> AnnotatedString(stringResource(R.string.action_addCashWithGooglePay)) to emptyMap()
105-
OnRampType.PhysicalDebit -> AnnotatedString(stringResource(R.string.action_addCashWithDebitCard)) to emptyMap()
106-
OnRampType.PhysicalCredit -> AnnotatedString(stringResource(R.string.action_addCashWithCreditCard)) to emptyMap()
107-
}
99+
ConfirmationButton(
100+
modifier = Modifier
101+
.fillMaxWidth(),
102+
state = state,
103+
provider = provider,
104+
dispatchEvent = dispatchEvent
105+
)
106+
}
107+
}
108108

109-
OnRampProvider.Phantom -> buildAnnotatedString {
110-
append(stringResource(R.string.label_confirmIn))
111-
appendInlineContent("[icon]", alternateText = " ")
112-
append(stringResource(R.string.label_phantom))
113-
} to mapOf(
114-
"[icon]" to InlineTextContent(
115-
placeholder = Placeholder(
116-
width = 25.sp,
117-
height = 14.sp,
118-
placeholderVerticalAlign = PlaceholderVerticalAlign.TextCenter
119-
),
120-
children = {
121-
Box(
122-
modifier = Modifier.fillMaxSize(),
123-
contentAlignment = Alignment.Center
124-
) {
125-
Image(
126-
modifier = Modifier.padding(
127-
start = CodeTheme.dimens.staticGrid.x1 + 2.dp,
128-
end = CodeTheme.dimens.staticGrid.x1
129-
),
130-
painter = painterResource(R.drawable.ic_phantom),
131-
colorFilter = ColorFilter.tint(buttonColors.contentColor(state.canAdd).value),
132-
contentDescription = null
133-
)
134-
}
135-
}
136-
)
137-
)
138-
null -> AnnotatedString(stringResource(R.string.action_addCash)) to emptyMap<String, InlineTextContent>()
139-
}
140-
CodeButton(
141-
enabled = state.canAdd,
142-
modifier = Modifier
143-
.fillMaxWidth()
144-
.padding(horizontal = CodeTheme.dimens.inset)
145-
.padding(bottom = CodeTheme.dimens.grid.x2)
146-
.navigationBarsPadding(),
147-
buttonState = ButtonState.Filled,
148-
isLoading = state.confirmingAmount.loading,
149-
isSuccess = state.confirmingAmount.success,
150-
text = buttonText,
151-
inlineContent = assets,
152-
) {
153-
dispatchEvent(OnRampViewModel.Event.OnAmountConfirmed)
154-
}
109+
@Composable
110+
private fun ConfirmationButton(
111+
state: AmountEntryState,
112+
provider: OnRampProvider.ThirdParty?,
113+
modifier: Modifier = Modifier,
114+
dispatchEvent: (OnRampViewModel.Event) -> Unit
115+
) {
116+
val buttonColors = getButtonColors(state.canAdd, ButtonState.Filled, Color.Unspecified)
117+
val (buttonText, assets) = when (provider) {
118+
is OnRampProvider.Coinbase -> when (provider.type) {
119+
// https://developers.google.com/pay/api/android/guides/brand-guidelines#using-pay-in-text
120+
OnRampType.Virtual -> AnnotatedString(stringResource(R.string.action_addCashWithGooglePay)) to emptyMap()
121+
OnRampType.PhysicalDebit -> AnnotatedString(stringResource(R.string.action_addCashWithDebitCard)) to emptyMap()
122+
OnRampType.PhysicalCredit -> AnnotatedString(stringResource(R.string.action_addCashWithCreditCard)) to emptyMap()
155123
}
124+
125+
OnRampProvider.Phantom -> buildAnnotatedString {
126+
append(stringResource(R.string.label_confirmIn))
127+
appendInlineContent("[icon]", alternateText = " ")
128+
append(stringResource(R.string.label_phantom))
129+
} to mapOf(
130+
"[icon]" to InlineTextContent(
131+
placeholder = Placeholder(
132+
width = 25.sp,
133+
height = 14.sp,
134+
placeholderVerticalAlign = PlaceholderVerticalAlign.TextCenter
135+
),
136+
children = {
137+
Box(
138+
modifier = Modifier.fillMaxSize(),
139+
contentAlignment = Alignment.Center
140+
) {
141+
Image(
142+
modifier = Modifier.padding(
143+
start = CodeTheme.dimens.staticGrid.x1 + 2.dp,
144+
end = CodeTheme.dimens.staticGrid.x1
145+
),
146+
painter = painterResource(R.drawable.ic_phantom),
147+
colorFilter = ColorFilter.tint(buttonColors.contentColor(state.canAdd).value),
148+
contentDescription = null
149+
)
150+
}
151+
}
152+
)
153+
)
154+
155+
null -> AnnotatedString(stringResource(R.string.action_addCash)) to emptyMap<String, InlineTextContent>()
156+
}
157+
CodeButton(
158+
enabled = state.canAdd,
159+
modifier = modifier
160+
.padding(horizontal = CodeTheme.dimens.inset)
161+
.padding(bottom = CodeTheme.dimens.grid.x2)
162+
.navigationBarsPadding(),
163+
buttonState = ButtonState.Filled,
164+
isLoading = state.confirmingAmount.loading,
165+
isSuccess = state.confirmingAmount.success,
166+
text = buttonText,
167+
inlineContent = assets,
168+
) {
169+
dispatchEvent(OnRampViewModel.Event.OnAmountConfirmed)
156170
}
157171
}

apps/flipcash/shared/onramp/phantom/src/main/kotlin/com/flipcash/app/onramp/PhantomOnRampHandler.kt

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import com.flipcash.services.analytics.Action
2121
import com.flipcash.shared.onramp.phantom.R
2222
import com.getcode.manager.BottomBarAction
2323
import com.getcode.manager.BottomBarManager
24+
import com.getcode.navigation.core.CodeNavigator
2425
import com.getcode.navigation.core.LocalCodeNavigator
2526
import com.getcode.ui.utils.RepeatOnLifecycle
2627
import com.getcode.util.permissions.LocalPermissionChecker
@@ -37,31 +38,36 @@ import kotlin.to
3738
@Composable
3839
fun PhantomOnRampHandler(
3940
state: PhantomDepositState,
41+
navigator: CodeNavigator,
4042
router: Router,
4143
deepLink: DeepLink?,
4244
content: @Composable () -> Unit
4345
) {
44-
val navigator = LocalCodeNavigator.current
4546
val permissions = LocalPermissionChecker.current
47+
val composeScope = rememberCoroutineScope()
4648

47-
suspend fun close(exit: Boolean) {
49+
fun close(exit: Boolean) {
4850
if (exit) {
49-
delay(300)
50-
navigator.hide()
51+
composeScope.launch {
52+
delay(300)
53+
navigator.hide()
54+
}
5155
return
5256
}
5357

5458
state.origin?.let { screenProvider ->
5559
val screen = ScreenRegistry.get(screenProvider)
56-
delay(300)
57-
val popped = navigator.popUntil { it::class == screen::class }
58-
if (!popped) navigator.popAll()
60+
composeScope.launch {
61+
delay(300)
62+
val popped = navigator.popUntil { it::class == screen::class }
63+
if (!popped) navigator.popAll()
64+
}
5965
} ?: run { navigator.popAll() }
6066
}
6167
val uriHandler = LocalUriHandler.current
6268
val context = LocalContext.current
6369

64-
val composeScope = rememberCoroutineScope()
70+
6571
val onNotificationResult: (Boolean) -> Unit = { isGranted ->
6672
composeScope.launch { close(true) }
6773
}
@@ -91,7 +97,7 @@ fun PhantomOnRampHandler(
9197
title = title,
9298
message = message,
9399
) {
94-
launch { close(false) }
100+
close(false)
95101
state.reset()
96102
}
97103
}.launchIn(this)
@@ -206,7 +212,7 @@ fun PhantomOnRampHandler(
206212
BottomBarAction(
207213
text = context.getString(R.string.action_ok),
208214
) {
209-
launch { close(true) }
215+
close(true)
210216
}
211217
)
212218
} else {
@@ -223,7 +229,7 @@ fun PhantomOnRampHandler(
223229
text = context.getString(R.string.action_dismiss),
224230
style = BottomBarManager.BottomBarButtonStyle.Text
225231
) {
226-
launch { close(true) }
232+
close(true)
227233
}
228234
)
229235
}

0 commit comments

Comments
 (0)