Skip to content

Commit da1fe8e

Browse files
committed
chore(flipcash/withdrawal): disconnect onWithdraw event from Confirm to split event handling
Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent 6cd1a19 commit da1fe8e

2 files changed

Lines changed: 15 additions & 19 deletions

File tree

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,10 @@
124124
<string name="error_title_destinationAccountNotInitialized">Destination Account Not Initialized\nPlease make sure the address you’re withdrawing to has been initialized by your wallet provider. A quick way to do this is to make sure there is already some USDC in the address you’re trying to withdraw to</string>
125125
<string name="error_title_invalidAddress">Invalid address</string>
126126

127-
<string name="action_withdraw">Yes, Withdraw</string>
127+
<string name="action_withdraw">Withdraw</string>
128+
<string name="action_confirmWithdraw">Yes, Withdraw</string>
128129
<string name="prompt_title_confirmWithdrawal">Are You Sure?</string>
130+
129131
<string name="prompt_description_confirmWithdrawal">Withdrawals are irreversible and cannot be undone once initiated</string>
130132
<string name="prompt_title_learnAboutWithdrawalFee">What Is This Fee?</string>
131133
<string name="prompt_description_learnAboutWithdrawalFee">The account you’re trying to withdraw to requires a one time account creation fee. This fee will be deducted from the amount you’re withdrawing</string>

apps/flipcash/features/withdrawal/src/main/kotlin/com/flipcash/app/withdrawal/WithdrawalViewModel.kt

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ internal class WithdrawalViewModel @Inject constructor(
138138
data object OnWithdrawalTooSmall : Event
139139

140140
data object OnWithdraw : Event
141+
data object ConfirmWithdrawal : Event
141142
data object OnWithdrawalConfirmed : Event
142143
data object OnWithdrawSuccessful : Event
143144
}
@@ -343,25 +344,16 @@ internal class WithdrawalViewModel @Inject constructor(
343344
val fee = withdrawalChecks?.feeAmount
344345
if (amount.usdc - (fee ?: Fiat.Zero) < Fiat.Zero) {
345346
dispatchEvent(Event.UpdateWithdrawalState(loading = false))
346-
BottomBarManager.showMessage(
347-
BottomBarManager.BottomBarMessage(
348-
title = resources.getString(R.string.error_title_withdrawalTooSmall),
349-
subtitle = resources.getString(R.string.error_description_withdrawalTooSmall),
350-
showScrim = false,
351-
showCancel = false,
352-
actions = buildList {
353-
add(
354-
BottomBarAction(
355-
text = resources.getString(R.string.action_ok),
356-
onClick = { dispatchEvent(Event.OnWithdrawalTooSmall) }
357-
)
358-
)
359-
}
360-
)
361-
)
347+
dispatchEvent(Event.OnWithdrawalTooSmall)
362348
return@onEach
363349
}
364350

351+
dispatchEvent(Event.ConfirmWithdrawal)
352+
}.launchIn(viewModelScope)
353+
354+
eventFlow
355+
.filterIsInstance<Event.ConfirmWithdrawal>()
356+
.onEach {
365357
BottomBarManager.showMessage(
366358
BottomBarManager.BottomBarMessage(
367359
title = resources.getString(R.string.prompt_title_confirmWithdrawal),
@@ -370,15 +362,16 @@ internal class WithdrawalViewModel @Inject constructor(
370362
actions = buildList {
371363
add(
372364
BottomBarAction(
373-
text = resources.getString(R.string.action_withdraw),
365+
text = resources.getString(R.string.action_confirmWithdraw),
374366
onClick = { dispatchEvent(Event.OnWithdrawalConfirmed) }
375367
)
376368
)
377369
},
378370
showCancel = true
379371
)
380372
)
381-
}.launchIn(viewModelScope)
373+
}
374+
.launchIn(viewModelScope)
382375

383376
eventFlow
384377
.filterIsInstance<Event.OnWithdrawalConfirmed>()
@@ -448,6 +441,7 @@ internal class WithdrawalViewModel @Inject constructor(
448441

449442
Event.OnLearnAboutFee,
450443
Event.OnWithdrawalTooSmall,
444+
Event.ConfirmWithdrawal,
451445
Event.OnWithdrawalConfirmed,
452446
Event.OnWithdrawSuccessful,
453447
Event.PasteFromClipboard,

0 commit comments

Comments
 (0)