Skip to content

Commit ef19f74

Browse files
committed
chore(currency-creator): wire up purchase controller (phase 1)
Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent 69aa1a4 commit ef19f74

3 files changed

Lines changed: 26 additions & 3 deletions

File tree

apps/flipcash/features/currency-creator/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ android {
99
dependencies {
1010
implementation(project(":apps:flipcash:features:bill-customization"))
1111
implementation(project(":apps:flipcash:shared:bills"))
12+
implementation(project(":apps:flipcash:shared:payments"))
1213
implementation(project(":apps:flipcash:shared:userflags"))
1314
implementation(project(":libs:messaging"))
1415

apps/flipcash/features/currency-creator/src/main/kotlin/com/flipcash/app/currencycreator/internal/CurrencyCreatorViewModel.kt

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import android.net.Uri
44
import androidx.compose.foundation.text.input.TextFieldState
55
import androidx.core.text.trimmedLength
66
import androidx.lifecycle.viewModelScope
7+
import com.flipcash.app.core.AppRoute
78
import com.flipcash.app.core.bill.Bill
89
import com.flipcash.app.core.tokens.CurrencyCreatorStep
910
import com.flipcash.app.currencycreator.internal.components.CurrencyCreatorTopBarController
@@ -15,6 +16,9 @@ import com.getcode.opencode.model.financial.toFiat
1516
import com.getcode.opencode.model.ui.TokenBillCustomizations
1617
import com.flipcash.app.core.data.Loadable
1718
import com.flipcash.app.core.data.isLoaded
19+
import com.flipcash.app.core.tokens.SwapPurpose
20+
import com.flipcash.app.payments.PurchaseMethod
21+
import com.flipcash.app.payments.PurchaseMethodController
1822
import com.getcode.util.resources.ContentReader
1923
import com.getcode.view.BaseViewModel2
2024
import com.getcode.view.LoadingSuccessState
@@ -33,6 +37,7 @@ internal class CurrencyCreatorViewModel @Inject constructor(
3337
dispatchers: DispatcherProvider,
3438
userFlags: UserFlagsCoordinator,
3539
val contentReader: ContentReader,
40+
val purchaseMethodController: PurchaseMethodController,
3641
) : BaseViewModel2<CurrencyCreatorViewModel.State, CurrencyCreatorViewModel.Event>(
3742
initialState = State(),
3843
updateStateForEvent = updateStateForEvent,
@@ -119,7 +124,25 @@ internal class CurrencyCreatorViewModel @Inject constructor(
119124

120125
eventFlow
121126
.filterIsInstance<Event.Purchase>()
122-
.onEach { }
127+
.onEach { purchaseMethodController.present() }
128+
.launchIn(viewModelScope)
129+
130+
purchaseMethodController.selections
131+
.onEach { (method, metadata) ->
132+
when (method) {
133+
PurchaseMethod.CoinbaseOnRamp -> {
134+
val mint = metadata.mint ?: return@onEach
135+
}
136+
is PurchaseMethod.CashReserves -> {
137+
val mint = metadata.mint ?: return@onEach
138+
139+
}
140+
PurchaseMethod.PhantomWallet -> {
141+
142+
}
143+
}
144+
}
145+
.launchIn(viewModelScope)
123146
}
124147

125148
/**
@@ -139,7 +162,6 @@ internal class CurrencyCreatorViewModel @Inject constructor(
139162

140163
internal companion object {
141164
val updateStateForEvent: (Event) -> (State.() -> State) = { event ->
142-
println("Event: $event")
143165
when (event) {
144166
is Event.OnStepChanged -> { state ->
145167
state.copy(currentStep = event.step)

apps/flipcash/features/currency-creator/src/main/kotlin/com/flipcash/app/currencycreator/internal/screens/ReviewAndPurchaseScreen.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ internal fun ReviewAndPurchaseContent(
6363
),
6464
enabled = state.hasName,
6565
onClick = {
66-
66+
dispatch(CurrencyCreatorViewModel.Event.Purchase)
6767
},
6868
)
6969
}

0 commit comments

Comments
 (0)