Skip to content

Commit

Permalink
Bump Abacus, update AGP version and fix transfer fee display (#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruixhuang authored Nov 5, 2024
1 parent 69f3832 commit 39c27c1
Show file tree
Hide file tree
Showing 15 changed files with 116 additions and 20 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
buildscript {
ext.ktlintVersion = '0.48.0'
ext.kotlinVersion = '1.9.24'
ext.androidApplicationVersion = '8.7.1'
ext.androidApplicationVersion = '8.7.2'

repositories {
google()
Expand Down
2 changes: 1 addition & 1 deletion v4/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ ext {
compileSdkVersion = 34

// App dependencies
abacusVersion = '1.13.17'
abacusVersion = '1.13.18'
carteraVersion = '0.1.15'
kollectionsVersion = '2.0.16'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import exchange.dydx.trading.feature.receipt.components.expectedprice.DydxReceip
import exchange.dydx.trading.feature.receipt.components.fee.DydxReceiptBridgeFeeView
import exchange.dydx.trading.feature.receipt.components.fee.DydxReceiptFeeView
import exchange.dydx.trading.feature.receipt.components.fee.DydxReceiptGasFeeView
import exchange.dydx.trading.feature.receipt.components.fee.DydxReceiptTransferFeeView
import exchange.dydx.trading.feature.receipt.components.isolatedmargin.DydxReceiptIsolatedPositionMarginUsageView
import exchange.dydx.trading.feature.receipt.components.leverage.DydxReceiptPositionLeverageView
import exchange.dydx.trading.feature.receipt.components.liquidationprice.DydxReceiptLiquidationPriceView
Expand All @@ -61,6 +62,7 @@ object DydxReceiptView : DydxComponent {
Fee,
GasFee,
BridgeFee,
TransferFee,
ExpectedPrice,
Rewards,
Equity,
Expand Down Expand Up @@ -193,6 +195,10 @@ object DydxReceiptView : DydxComponent {
ReceiptLineType.LiquidationPrice -> {
DydxReceiptLiquidationPriceView.Content(Modifier.animateItemPlacement())
}

ReceiptLineType.TransferFee -> {
DydxReceiptTransferFeeView.Content(Modifier.animateItemPlacement())
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ private fun ReceiptLine.toType(): DydxReceiptView.ReceiptLineType? {
ReceiptLine.PositionMargin -> DydxReceiptView.ReceiptLineType.PositionMargin
ReceiptLine.PositionLeverage -> DydxReceiptView.ReceiptLineType.PositionLeverage
ReceiptLine.LiquidationPrice -> DydxReceiptView.ReceiptLineType.LiquidationPrice
ReceiptLine.TransferFee -> DydxReceiptView.ReceiptLineType.TransferFee
ReceiptLine.Total -> null
ReceiptLine.WalletBalance -> null
ReceiptLine.CrossFreeCollateral -> null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ 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
Expand All @@ -27,6 +28,7 @@ class DydxReceiptBuyingPowerViewModel @Inject constructor(
private val receiptTypeFlow: Flow<@JvmSuppressWildcards ReceiptType?>,
) : ViewModel(), DydxViewModel {

@OptIn(ExperimentalCoroutinesApi::class)
val state: Flow<DydxReceiptBuyingPowerView.ViewState?> =
receiptTypeFlow
.flatMapLatest { receiptType ->
Expand Down Expand Up @@ -64,7 +66,7 @@ class DydxReceiptBuyingPowerViewModel @Inject constructor(
AmountText.ViewState(
localizer = localizer,
formatter = formatter,
amount = position?.buyingPower?.current,
amount = position.buyingPower.current,
tickSize = 0,
requiresPositive = true,
)
Expand All @@ -75,7 +77,7 @@ class DydxReceiptBuyingPowerViewModel @Inject constructor(
AmountText.ViewState(
localizer = localizer,
formatter = formatter,
amount = position?.buyingPower?.postOrder,
amount = position.buyingPower.postOrder,
tickSize = 0,
requiresPositive = true,
)
Expand All @@ -95,7 +97,7 @@ class DydxReceiptBuyingPowerViewModel @Inject constructor(
AmountText.ViewState(
localizer = localizer,
formatter = formatter,
amount = subaccount?.buyingPower?.current,
amount = subaccount.buyingPower?.current,
tickSize = 0,
requiresPositive = true,
)
Expand All @@ -106,7 +108,7 @@ class DydxReceiptBuyingPowerViewModel @Inject constructor(
AmountText.ViewState(
localizer = localizer,
formatter = formatter,
amount = subaccount?.buyingPower?.postOrder,
amount = subaccount.buyingPower?.postOrder,
tickSize = 0,
requiresPositive = true,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class DydxReceiptEquityViewModel @Inject constructor(
AmountText.ViewState(
localizer = localizer,
formatter = formatter,
amount = subaccount?.equity?.current,
amount = subaccount.equity?.current,
tickSize = 2,
)
} else {
Expand All @@ -46,7 +46,7 @@ class DydxReceiptEquityViewModel @Inject constructor(
AmountText.ViewState(
localizer = localizer,
formatter = formatter,
amount = subaccount?.equity?.postOrder,
amount = subaccount.equity?.postOrder,
tickSize = 2,
)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,26 @@ class DydxReceiptExchangeReceivedViewModel @Inject constructor(
transferInput: TransferInput?
): String? {
val exchangeRate = transferInput?.summary?.exchangeRate ?: return null
val type = transferInput?.type ?: return null
val token = transferInput?.token ?: return null
val type = transferInput.type ?: return null
val token = transferInput.token ?: return null
val symbol =
transferInput?.resources?.tokenResources?.toMap()?.get(token)?.symbol ?: return null
transferInput.resources?.tokenResources?.toMap()?.get(token)?.symbol ?: return null
when (type) {
TransferType.deposit -> {
val usdcSize = transferInput?.summary?.usdcSize ?: return null
val usdcSize = transferInput.summary?.usdcSize ?: return null
val converted = formatter.raw(usdcSize, 2) ?: return null
return "$converted USDC"
}

TransferType.withdrawal -> {
val toAmount = transferInput?.summary?.toAmount
val toAmount = transferInput.summary?.toAmount
if (toAmount != null) {
val decimals = transferInput?.resources?.tokenResources?.toMap()?.get(token)?.decimals ?: return null
val decimals = transferInput.resources?.tokenResources?.toMap()?.get(token)?.decimals ?: return null
val size = toAmount.toDouble() / 10.0.pow(decimals)
val converted = formatter.raw(size, 4) ?: return null
return "$converted $symbol"
} else {
val usdcSize = transferInput?.summary?.usdcSize ?: return null
val usdcSize = transferInput.summary?.usdcSize ?: return null
if (exchangeRate > 0) {
val converted = formatter.raw(usdcSize * exchangeRate, 2) ?: return null
return "$converted $symbol"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class DydxReceiptExpectedPriceViewModel @Inject constructor(
title = localizer.localize("APP.TRADE.EXPECTED_PRICE"),
value = if (tradeSummary?.price != null) {
formatter.dollar(
tradeSummary?.price ?: 0.0,
tradeSummary.price ?: 0.0,
market.configs?.displayTickSizeDecimals ?: 0,
)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ class DydxReceiptFeeViewModel @Inject constructor(
feeType = localizer.localize("APP.TRADE.TAKER"),
feeFont = if (tradeSummary?.fee == null) {
null
} else if (tradeSummary?.fee ?: 0.0 > 0.0) {
} else if ((tradeSummary.fee ?: 0.0) > 0.0) {
DydxReceiptBaseFeeView.FeeFont.Number(
formatter.dollar(tradeSummary?.fee ?: 0.0, 2) ?: "",
formatter.dollar(tradeSummary.fee ?: 0.0, 2) ?: "",
)
} else {
DydxReceiptBaseFeeView.FeeFont.String(localizer.localize("APP.GENERAL.FREE"))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package exchange.dydx.trading.feature.receipt.components.fee

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.platformui.compose.collectAsStateWithLifecycle
import exchange.dydx.platformui.theme.DydxThemedPreviewSurface
import exchange.dydx.trading.common.component.DydxComponent
import exchange.dydx.trading.feature.receipt.components.fee.DydxReceiptBaseFeeView.ViewState

@Preview
@Composable
fun Preview_DydxReceiptTransferFeeView() {
DydxThemedPreviewSurface {
DydxReceiptTransferFeeView.Content(Modifier, ViewState.preview)
}
}

object DydxReceiptTransferFeeView : DydxReceiptBaseFeeView(), DydxComponent {

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

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

@Composable
fun Content(modifier: Modifier, state: ViewState?) {
DydxReceiptBaseFeeView.Content(modifier, state)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package exchange.dydx.trading.feature.receipt.components.fee

import androidx.lifecycle.ViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
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 kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.map
import javax.inject.Inject

@HiltViewModel
class DydxReceiptTransferFeeViewModel @Inject constructor(
private val localizer: LocalizerProtocol,
private val abacusStateManager: AbacusStateManagerProtocol,
private val formatter: DydxFormatter,
) : ViewModel(), DydxViewModel {

val state: Flow<DydxReceiptBaseFeeView.ViewState?> =
abacusStateManager.state.transferInput
.map {
createViewState(it)
}
.distinctUntilChanged()

private fun createViewState(
transferInput: TransferInput?
): DydxReceiptBaseFeeView.ViewState {
val gasFee = transferInput?.summary?.gasFee
return DydxReceiptBaseFeeView.ViewState(
localizer = localizer,
feeType = "Gas",
feeFont = if (gasFee == null) {
null
} else if (gasFee > 0.0) {
DydxReceiptBaseFeeView.FeeFont.Number(
formatter.dollar(gasFee, 2) ?: "",
)
} else {
DydxReceiptBaseFeeView.FeeFont.String(localizer.localize("APP.GENERAL.FREE"))
},
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import exchange.dydx.dydxstatemanager.AbacusStateManagerProtocol
import exchange.dydx.trading.common.DydxViewModel
import exchange.dydx.trading.common.formatter.DydxFormatter
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
Expand All @@ -24,6 +25,7 @@ class DydxReceiptFreeCollateralViewModel @Inject constructor(
private val formatter: DydxFormatter,
) : ViewModel(), DydxViewModel {

@OptIn(ExperimentalCoroutinesApi::class)
val state: Flow<DydxReceiptFreeCollateralView.ViewState?> =
abacusStateManager.marketId
.filterNotNull()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ 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 kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged
Expand All @@ -24,6 +25,7 @@ class DydxReceiptIsolatedPositionMarginUsageViewModel @Inject constructor(
private val formatter: DydxFormatter,
) : ViewModel(), DydxViewModel {

@OptIn(ExperimentalCoroutinesApi::class)
val state: Flow<DydxReceiptIsolatedPositionMarginUsageView.ViewState?> =
abacusStateManager.marketId
.filterNotNull()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import exchange.dydx.dydxstatemanager.AbacusStateManagerProtocol
import exchange.dydx.trading.common.DydxViewModel
import exchange.dydx.trading.common.formatter.DydxFormatter
import exchange.dydx.trading.feature.shared.views.LeverageView
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged
Expand All @@ -24,6 +25,7 @@ class DydxReceiptPositionLeverageViewModel @Inject constructor(
private val formatter: DydxFormatter,
) : ViewModel(), DydxViewModel {

@OptIn(ExperimentalCoroutinesApi::class)
val state: Flow<DydxReceiptPositionLeverageView.ViewState?> =
abacusStateManager.marketId
.filterNotNull()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class DydxReceiptMarginUsageViewModel @Inject constructor(
MarginUsageView.ViewState(
localizer = localizer,
displayOption = MarginUsageView.DisplayOption.IconAndValue,
percent = subaccount?.marginUsage?.current ?: 0.0,
percent = subaccount.marginUsage?.current ?: 0.0,
)
} else {
null
Expand All @@ -46,7 +46,7 @@ class DydxReceiptMarginUsageViewModel @Inject constructor(
MarginUsageView.ViewState(
localizer = localizer,
displayOption = MarginUsageView.DisplayOption.IconAndValue,
percent = subaccount?.marginUsage?.postOrder ?: 0.0,
percent = subaccount.marginUsage?.postOrder ?: 0.0,
)
} else {
null
Expand Down

0 comments on commit 39c27c1

Please sign in to comment.