-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Features/mob 400 adjust margin screen bottom (#87)
* Margin type and leverage screens skeleton * MOB-356 MOB-358 Margin mode screen * Change bg color * MOB-360 rough UX for target leverage screen * Fixed PR * move modifier to param * In the middle of coding * lint * There is no longer InputFieldScarfold * Put back InputFieldScaffold * More placeholder code and it compiles * rough amount input * Formatting "Add Margin" and "Remove Margin" * MOB-400 placeholder for bottom * Adjust margin receipt area * MOB-400 rearranging receipt data * MOB-400 liquidation price * Fix copy and modified code * PR review * spotless * fix build
- Loading branch information
Showing
15 changed files
with
1,334 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
...e/dydx/trading/feature/receipt/components/freecollateral/DydxReceiptFreeCollateralView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package exchange.dydx.trading.feature.receipt.components.buyingpower | ||
|
||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.Spacer | ||
import androidx.compose.material.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.text.TextStyle | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.hilt.navigation.compose.hiltViewModel | ||
import exchange.dydx.abacus.protocols.LocalizerProtocol | ||
import exchange.dydx.platformui.components.changes.PlatformAmountChange | ||
import exchange.dydx.platformui.components.changes.PlatformDirection | ||
import exchange.dydx.platformui.designSystem.theme.ThemeColor | ||
import exchange.dydx.platformui.designSystem.theme.ThemeFont | ||
import exchange.dydx.platformui.designSystem.theme.dydxDefault | ||
import exchange.dydx.platformui.designSystem.theme.themeColor | ||
import exchange.dydx.platformui.designSystem.theme.themeFont | ||
import exchange.dydx.trading.common.component.DydxComponent | ||
import exchange.dydx.trading.common.compose.collectAsStateWithLifecycle | ||
import exchange.dydx.trading.common.theme.DydxThemedPreviewSurface | ||
import exchange.dydx.trading.common.theme.MockLocalizer | ||
import exchange.dydx.trading.feature.shared.views.AmountText | ||
|
||
@Preview | ||
@Composable | ||
fun Preview_DydxReceiptFreeCollateralView() { | ||
DydxThemedPreviewSurface { | ||
DydxReceiptFreeCollateralView.Content( | ||
Modifier, | ||
DydxReceiptFreeCollateralView.ViewState.preview, | ||
) | ||
} | ||
} | ||
|
||
object DydxReceiptFreeCollateralView : DydxComponent { | ||
data class ViewState( | ||
val localizer: LocalizerProtocol, | ||
val before: AmountText.ViewState? = null, | ||
val after: AmountText.ViewState? = null, | ||
|
||
) { | ||
companion object { | ||
val preview = ViewState( | ||
localizer = MockLocalizer(), | ||
before = AmountText.ViewState.preview, | ||
after = AmountText.ViewState.preview, | ||
) | ||
} | ||
} | ||
|
||
@Composable | ||
override fun Content(modifier: Modifier) { | ||
val viewModel: DydxReceiptFreeCollateralViewModel = hiltViewModel() | ||
|
||
val state = viewModel.state.collectAsStateWithLifecycle(initialValue = null).value | ||
Content(modifier, state) | ||
} | ||
|
||
@Composable | ||
fun Content(modifier: Modifier, state: ViewState?) { | ||
if (state == null) return | ||
|
||
Row( | ||
modifier = modifier, | ||
verticalAlignment = Alignment.CenterVertically, | ||
) { | ||
Text( | ||
text = state.localizer.localize("APP.GENERAL.FREE_COLLATERAL"), | ||
style = TextStyle.dydxDefault | ||
.themeFont(fontSize = ThemeFont.FontSize.small) | ||
.themeColor(ThemeColor.SemanticColor.text_tertiary), | ||
) | ||
|
||
Spacer(modifier = Modifier.weight(0.1f)) | ||
|
||
PlatformAmountChange( | ||
modifier = Modifier.weight(1f), | ||
before = if (state.before != null) { | ||
{ | ||
AmountText.Content( | ||
state = state.before, | ||
textStyle = TextStyle.dydxDefault | ||
.themeFont( | ||
fontType = ThemeFont.FontType.number, | ||
fontSize = ThemeFont.FontSize.small, | ||
) | ||
.themeColor(ThemeColor.SemanticColor.text_tertiary), | ||
) | ||
} | ||
} else { | ||
null | ||
}, | ||
after = if (state.after != null) { | ||
{ | ||
AmountText.Content( | ||
state = state.after, | ||
textStyle = TextStyle.dydxDefault | ||
.themeFont( | ||
fontType = ThemeFont.FontType.number, | ||
fontSize = ThemeFont.FontSize.small, | ||
) | ||
.themeColor(ThemeColor.SemanticColor.text_primary), | ||
) | ||
} | ||
} else { | ||
null | ||
}, | ||
direction = PlatformDirection.from(state.before?.amount, state.after?.amount), | ||
textStyle = TextStyle.dydxDefault | ||
.themeFont(fontSize = ThemeFont.FontSize.small) | ||
.themeColor(ThemeColor.SemanticColor.text_tertiary), | ||
) | ||
} | ||
} | ||
} |
120 changes: 120 additions & 0 deletions
120
...x/trading/feature/receipt/components/freecollateral/DydxReceiptFreeCollateralViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package exchange.dydx.trading.feature.receipt.components.buyingpower | ||
|
||
import androidx.lifecycle.ViewModel | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import exchange.dydx.abacus.output.Subaccount | ||
import exchange.dydx.abacus.output.SubaccountPosition | ||
import exchange.dydx.abacus.output.input.TradeInput | ||
import exchange.dydx.abacus.output.input.TransferInput | ||
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.receipt.ReceiptType | ||
import exchange.dydx.trading.feature.shared.views.AmountText | ||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.combine | ||
import kotlinx.coroutines.flow.distinctUntilChanged | ||
import kotlinx.coroutines.flow.flatMapLatest | ||
import kotlinx.coroutines.flow.flowOf | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class DydxReceiptFreeCollateralViewModel @Inject constructor( | ||
private val localizer: LocalizerProtocol, | ||
private val abacusStateManager: AbacusStateManagerProtocol, | ||
private val formatter: DydxFormatter, | ||
private val receiptTypeFlow: Flow<@JvmSuppressWildcards ReceiptType?>, | ||
) : ViewModel(), DydxViewModel { | ||
|
||
@OptIn(ExperimentalCoroutinesApi::class) | ||
val state: Flow<DydxReceiptFreeCollateralView.ViewState?> = | ||
receiptTypeFlow | ||
.flatMapLatest { receiptType -> | ||
when (receiptType) { | ||
is ReceiptType.Trade -> { | ||
combine( | ||
abacusStateManager.state.selectedSubaccountPositions, | ||
abacusStateManager.state.tradeInput, | ||
) { positions, tradeInput -> | ||
createViewState(positions, tradeInput) | ||
} | ||
} | ||
is ReceiptType.Transfer -> { | ||
combine( | ||
abacusStateManager.state.selectedSubaccount, | ||
abacusStateManager.state.transferInput, | ||
) { subaccount, transferInput -> | ||
createViewState(subaccount, transferInput) | ||
} | ||
} | ||
else -> flowOf() | ||
} | ||
} | ||
.distinctUntilChanged() | ||
|
||
private fun createViewState( | ||
positions: List<SubaccountPosition>?, | ||
tradeInput: TradeInput?, | ||
): DydxReceiptFreeCollateralView.ViewState { | ||
val marketId = tradeInput?.marketId ?: "ETH-USD" | ||
val position = positions?.firstOrNull { it.id == marketId } | ||
return DydxReceiptFreeCollateralView.ViewState( | ||
localizer = localizer, | ||
before = if (position?.freeCollateral?.current != null) { | ||
AmountText.ViewState( | ||
localizer = localizer, | ||
formatter = formatter, | ||
amount = position.freeCollateral?.current, | ||
tickSize = 0, | ||
requiresPositive = true, | ||
) | ||
} else { | ||
null | ||
}, | ||
after = if (position?.freeCollateral?.postOrder != null) { | ||
AmountText.ViewState( | ||
localizer = localizer, | ||
formatter = formatter, | ||
amount = position.freeCollateral?.postOrder, | ||
tickSize = 0, | ||
requiresPositive = true, | ||
) | ||
} else { | ||
null | ||
}, | ||
) | ||
} | ||
|
||
private fun createViewState( | ||
subaccount: Subaccount?, | ||
transferInput: TransferInput?, | ||
): DydxReceiptFreeCollateralView.ViewState { | ||
return DydxReceiptFreeCollateralView.ViewState( | ||
localizer = localizer, | ||
before = if (subaccount?.freeCollateral?.current != null) { | ||
AmountText.ViewState( | ||
localizer = localizer, | ||
formatter = formatter, | ||
amount = subaccount.freeCollateral?.current, | ||
tickSize = 0, | ||
requiresPositive = true, | ||
) | ||
} else { | ||
null | ||
}, | ||
after = if (subaccount?.freeCollateral?.postOrder != null) { | ||
AmountText.ViewState( | ||
localizer = localizer, | ||
formatter = formatter, | ||
amount = subaccount.freeCollateral?.postOrder, | ||
tickSize = 0, | ||
requiresPositive = true, | ||
) | ||
} else { | ||
null | ||
}, | ||
) | ||
} | ||
} |
Oops, something went wrong.