Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI-653 Move Alerts to Profile and scaffolding the vault view #228

Merged
merged 2 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,4 @@ include ':v4:integration:web3'
include ':v4:integration:analytics'
include ':v4:integration:statsig'
include ':v4:integration:fcm'
include ':v4:feature:vault'
20 changes: 20 additions & 0 deletions v4/app/src/main/assets/features.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,26 @@
}
]
}
},
{
"title":{
"text":"Vault"
},
"field":{
"field":"vault_enabled",
"optional":true,
"type" : "text",
"options" : [
{
"text": "yes",
"value" : "1"
},
{
"text": "no",
"value" : "0"
}
]
}
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ enum class DydxFeatureFlag {
deployment_url,
force_mainnet,
abacus_static_typing,
vault_enabled,
}

class DydxFeatureFlags @Inject constructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ object ProfileRoutes {
const val debug_enable = "action/debug/enable"
const val report_issue = "settings/report_issue"
const val notifications = "settings/notifications"
const val alerts = "settings/alerts"
}

object NewsAlertsRoutes {
Expand All @@ -67,3 +68,7 @@ object TransferRoutes {
const val transfer_search = "transfer/search"
const val transfer_status = "transfer/status"
}

object VaultRoutes {
const val main = "vault"
}
1 change: 1 addition & 0 deletions v4/core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ dependencies {
implementation project(':v4:feature:newsalerts')
implementation project(':v4:feature:workers')
implementation project(':v4:feature:transfer')
implementation project(':v4:feature:vault')

/* Local Dependencies */
implementation "androidx.core:core:$androidKtxVersion"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import exchange.dydx.trading.feature.profile.profileGraph
import exchange.dydx.trading.feature.trade.tradeGraph
import exchange.dydx.trading.feature.transfer.transferGraph
import exchange.dydx.utilities.utils.Logging
import exchange.dydx.vault.vaultGraph

private const val TAG = "DydxNavGraph"

Expand Down Expand Up @@ -81,6 +82,11 @@ fun DydxNavGraph(
appRouter = appRouter,
logger = logger,
)

vaultGraph(
appRouter = appRouter,
logger = logger,
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ package exchange.dydx.trading.feature.newsalerts.alerts
import androidx.lifecycle.ViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import exchange.dydx.abacus.protocols.LocalizerProtocol
import exchange.dydx.dydxstatemanager.AbacusStateManagerProtocol
import exchange.dydx.trading.common.DydxViewModel
import exchange.dydx.trading.common.formatter.DydxFormatter
import exchange.dydx.trading.feature.newsalerts.alerts.alertprovider.DydxAlertsProvider
import exchange.dydx.trading.feature.newsalerts.alerts.alertprovider.DydxAlertsProviderItemProtocol
import kotlinx.coroutines.flow.Flow
Expand All @@ -16,8 +14,6 @@ import javax.inject.Inject
@HiltViewModel
class DydxAlertsViewModel @Inject constructor(
private val localizer: LocalizerProtocol,
private val abacusStateManager: AbacusStateManagerProtocol,
private val formatter: DydxFormatter,
private val alertsProvider: DydxAlertsProvider,
) : ViewModel(), DydxViewModel {

Expand Down
1 change: 1 addition & 0 deletions v4/feature/profile/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ dependencies {
implementation project(path: ':v4:platformUI')
implementation project(path: ':v4:feature:shared')
implementation project(path: ':v4:feature:portfolio')
implementation project(path: ':v4:feature:newsalerts')

/* Local Dependencies */

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import exchange.dydx.trading.common.navigation.ProfileRoutes
import exchange.dydx.trading.common.navigation.ProfileRoutes.debug_enable
import exchange.dydx.trading.common.navigation.dydxComposable
import exchange.dydx.trading.feature.profile.actions.debugenabled.DydxDebugEnableView
import exchange.dydx.trading.feature.profile.alerts.DydxAlertsContainerView
import exchange.dydx.trading.feature.profile.color.DydxDirectionColorPreferenceView
import exchange.dydx.trading.feature.profile.debug.DydxDebugView
import exchange.dydx.trading.feature.profile.featureflags.DydxFeatureFlagsView
Expand Down Expand Up @@ -190,4 +191,12 @@ fun NavGraphBuilder.profileGraph(
) { navBackStackEntry ->
DydxGasTokenView.Content(Modifier)
}

dydxComposable(
router = appRouter,
route = ProfileRoutes.alerts,
deepLinks = appRouter.deeplinks(ProfileRoutes.alerts),
) { navBackStackEntry ->
DydxAlertsContainerView.Content(Modifier)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import exchange.dydx.platformui.designSystem.theme.themeColor
import exchange.dydx.platformui.theme.DydxThemedPreviewSurface
import exchange.dydx.platformui.theme.MockLocalizer
import exchange.dydx.trading.common.component.DydxComponent
import exchange.dydx.trading.feature.profile.components.DydxProfileAlertsView
import exchange.dydx.trading.feature.profile.components.DydxProfileBalancesView
import exchange.dydx.trading.feature.profile.components.DydxProfileButtonsView
import exchange.dydx.trading.feature.profile.components.DydxProfileFeesView
Expand All @@ -43,10 +44,12 @@ fun Preview_DydxProfileView() {
object DydxProfileView : DydxComponent {
data class ViewState(
val localizer: LocalizerProtocol,
val hasAlerts: Boolean,
) {
companion object {
val preview = ViewState(
localizer = MockLocalizer(),
hasAlerts = true,
)
}
}
Expand Down Expand Up @@ -81,6 +84,11 @@ object DydxProfileView : DydxComponent {
item(key = "buttons") {
DydxProfileButtonsView.Content(Modifier.padding(horizontal = ThemeShapes.HorizontalPadding))
}
if (state?.hasAlerts == true) {
item(key = "vault") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think key should be alerts ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah.. that's right.. I will update in the next PR

DydxProfileAlertsView.Content(Modifier.padding(horizontal = ThemeShapes.HorizontalPadding))
}
}
item(key = "balances") {
DydxProfileBalancesView.Content(Modifier.padding(horizontal = ThemeShapes.HorizontalPadding))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,24 @@ import androidx.lifecycle.ViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import exchange.dydx.abacus.protocols.LocalizerProtocol
import exchange.dydx.trading.common.DydxViewModel
import exchange.dydx.trading.common.featureflags.DydxFeatureFlag
import exchange.dydx.trading.common.featureflags.DydxFeatureFlags
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOf
import javax.inject.Inject

@HiltViewModel
class DydxProfileViewModel @Inject constructor(
val localizer: LocalizerProtocol,
val featureFlags: DydxFeatureFlags,
) : ViewModel(), DydxViewModel {

val state: Flow<DydxProfileView.ViewState?> = flowOf(createViewState())

private fun createViewState(): DydxProfileView.ViewState {
return DydxProfileView.ViewState(
localizer = localizer,
hasAlerts = featureFlags.isFeatureEnabled(DydxFeatureFlag.vault_enabled, default = false),
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package exchange.dydx.trading.feature.profile.alerts

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.hilt.navigation.compose.hiltViewModel
import exchange.dydx.abacus.protocols.LocalizerProtocol
import exchange.dydx.platformui.compose.collectAsStateWithLifecycle
import exchange.dydx.platformui.designSystem.theme.ThemeColor
import exchange.dydx.platformui.designSystem.theme.themeColor
import exchange.dydx.platformui.theme.DydxThemedPreviewSurface
import exchange.dydx.platformui.theme.MockLocalizer
import exchange.dydx.trading.common.component.DydxComponent
import exchange.dydx.trading.feature.newsalerts.alerts.DydxAlertsView
import exchange.dydx.trading.feature.shared.views.HeaderView

@Preview
@Composable
fun Preview_DydxAlertsContainerView() {
DydxThemedPreviewSurface {
DydxAlertsContainerView.Content(Modifier, DydxAlertsContainerView.ViewState.preview)
}
}

object DydxAlertsContainerView : DydxComponent {
data class ViewState(
val localizer: LocalizerProtocol,
val backButtionAction: () -> Unit = {},
) {
companion object {
val preview = ViewState(
localizer = MockLocalizer(),
)
}
}

@Composable
override fun Content(modifier: Modifier) {
val viewModel: DydxAlertsContainerViewModel = hiltViewModel()

val state = viewModel.state.collectAsStateWithLifecycle(initialValue = null).value
Content(modifier, state)
}

@Composable
fun Content(modifier: Modifier, state: ViewState?) {
if (state == null) {
return
}

Column(
modifier = modifier
.fillMaxSize()
.themeColor(ThemeColor.SemanticColor.layer_2),
) {
HeaderView(
title = state.localizer.localize("APP.GENERAL.ALERTS"),
modifier = Modifier.fillMaxWidth(),
backAction = state.backButtionAction,
)

DydxAlertsView.Content(modifier = Modifier)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package exchange.dydx.trading.feature.profile.alerts

import androidx.lifecycle.ViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import exchange.dydx.abacus.protocols.LocalizerProtocol
import exchange.dydx.trading.common.DydxViewModel
import exchange.dydx.trading.common.navigation.DydxRouter
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOf
import javax.inject.Inject

@HiltViewModel
class DydxAlertsContainerViewModel @Inject constructor(
private val localizer: LocalizerProtocol,
private val router: DydxRouter,
) : ViewModel(), DydxViewModel {

val state: Flow<DydxAlertsContainerView.ViewState?> = flowOf(createViewState())

private fun createViewState(): DydxAlertsContainerView.ViewState {
return DydxAlertsContainerView.ViewState(
localizer = localizer,
backButtionAction = {
router.navigateBack()
},
)
}
}
Loading
Loading