From 28240c4cd667f6f6df2973588f1fa1a22c9d12b1 Mon Sep 17 00:00:00 2001 From: Jeremy Lee <37092291+yogurtandjam@users.noreply.github.com> Date: Thu, 12 Sep 2024 14:25:35 -0400 Subject: [PATCH] display usd value for withdraw flow [OTE-783] (#645) --- .../calculator/TransferInputCalculator.kt | 3 +++ .../calculator/V2/TransferInputCalculatorV2.kt | 5 +++++ .../exchange.dydx.abacus/output/input/TransferInput.kt | 4 ++++ .../state/internalstate/InternalTransferInputState.kt | 1 + .../calculator/v2/TransferInputCalculatorV2Tests.kt | 3 +++ 5 files changed, 16 insertions(+) create mode 100644 src/commonTest/kotlin/exchange.dydx.abacus/calculator/v2/TransferInputCalculatorV2Tests.kt diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/calculator/TransferInputCalculator.kt b/src/commonMain/kotlin/exchange.dydx.abacus/calculator/TransferInputCalculator.kt index 7c8d9c39b..b2e6b11e5 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/calculator/TransferInputCalculator.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/calculator/TransferInputCalculator.kt @@ -223,6 +223,9 @@ internal class TransferInputCalculator(val parser: ParserProtocol) { val toAmountUSDC = parser.asDouble(parser.value(transfer, "route.toAmountUSDC")) summary.safeSet("toAmountUSDC", toAmountUSDC) + val toAmountUSD = parser.asDouble(parser.value(transfer, "route.toAmountUSD")) + summary.safeSet("toAmountUSD", toAmountUSD) + val aggregatePriceImpact = parser.asDouble(parser.value(transfer, "route.aggregatePriceImpact")) summary.safeSet( diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/calculator/V2/TransferInputCalculatorV2.kt b/src/commonMain/kotlin/exchange.dydx.abacus/calculator/V2/TransferInputCalculatorV2.kt index 71e673930..9fcf4590c 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/calculator/V2/TransferInputCalculatorV2.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/calculator/V2/TransferInputCalculatorV2.kt @@ -57,6 +57,7 @@ internal class TransferInputCalculatorV2( val toAmount = parser.asDouble(parser.value(route, "toAmount")) val toAmountMin = parser.asDouble(parser.value(route, "toAmountMin")) val toAmountUSDC = parser.asDouble(parser.value(route, "toAmountUSDC")) + val toAmountUSD = parser.asDouble(parser.value(route, "toAmountUSD")) var aggregatePriceImpact = parser.asDouble(parser.value(route, "aggregatePriceImpact")) aggregatePriceImpact = if (aggregatePriceImpact != null) aggregatePriceImpact / 100.0 else null @@ -80,6 +81,7 @@ internal class TransferInputCalculatorV2( toAmount = toAmount, toAmountMin = toAmountMin, toAmountUSDC = toAmountUSDC, + toAmountUSD = toAmountUSD, aggregatePriceImpact = aggregatePriceImpact, ) } @@ -98,6 +100,7 @@ internal class TransferInputCalculatorV2( val toAmount = parser.asDouble(parser.value(route, "toAmount")) val toAmountMin = parser.asDouble(parser.value(route, "toAmountMin")) val toAmountUSDC = parser.asDouble(parser.value(route, "toAmountUSDC")) + val toAmountUSD = parser.asDouble(parser.value(route, "toAmountUSD")) var aggregatePriceImpact = parser.asDouble(parser.value(route, "aggregatePriceImpact")) aggregatePriceImpact = if (aggregatePriceImpact != null) aggregatePriceImpact / 100.0 else null @@ -113,6 +116,7 @@ internal class TransferInputCalculatorV2( toAmount = toAmount, toAmountMin = toAmountMin, toAmountUSDC = toAmountUSDC, + toAmountUSD = toAmountUSD, aggregatePriceImpact = aggregatePriceImpact, ) } @@ -132,6 +136,7 @@ internal class TransferInputCalculatorV2( toAmount = null, toAmountMin = null, toAmountUSDC = null, + toAmountUSD = null, aggregatePriceImpact = null, ) } diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/output/input/TransferInput.kt b/src/commonMain/kotlin/exchange.dydx.abacus/output/input/TransferInput.kt index 15f6b6f57..ee01c3af2 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/output/input/TransferInput.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/output/input/TransferInput.kt @@ -360,6 +360,7 @@ data class TransferInputSummary( val toAmount: Double?, val toAmountMin: Double?, val toAmountUSDC: Double?, + val toAmountUSD: Double?, val aggregatePriceImpact: Double?, ) { companion object { @@ -382,6 +383,7 @@ data class TransferInputSummary( val toAmount = parser.asDouble(data["toAmount"]) val toAmountMin = parser.asDouble(data["toAmountMin"]) val toAmountUSDC = parser.asDouble(data["toAmountUSDC"]) + val toAmountUSD = parser.asDouble(data["toAmountUSD"]) val aggregatePriceImpact = parser.asDouble(data["aggregatePriceImpact"]) return if (existing?.usdcSize != usdcSize || @@ -395,6 +397,7 @@ data class TransferInputSummary( existing.toAmount != toAmount || existing.toAmountMin != toAmountMin || existing.toAmountUSDC != toAmountUSDC || + existing.toAmountUSD != toAmountUSD || existing.aggregatePriceImpact != aggregatePriceImpact ) { TransferInputSummary( @@ -409,6 +412,7 @@ data class TransferInputSummary( toAmount, toAmountMin, toAmountUSDC, + toAmountUSD, aggregatePriceImpact, ) } else { diff --git a/src/commonMain/kotlin/exchange.dydx.abacus/state/internalstate/InternalTransferInputState.kt b/src/commonMain/kotlin/exchange.dydx.abacus/state/internalstate/InternalTransferInputState.kt index 78b3f1735..2e6910d94 100644 --- a/src/commonMain/kotlin/exchange.dydx.abacus/state/internalstate/InternalTransferInputState.kt +++ b/src/commonMain/kotlin/exchange.dydx.abacus/state/internalstate/InternalTransferInputState.kt @@ -93,6 +93,7 @@ internal fun TransferInputSummary.Companion.safeCreate(existing: TransferInputSu toAmount = null, toAmountMin = null, toAmountUSDC = null, + toAmountUSD = null, aggregatePriceImpact = null, ) } diff --git a/src/commonTest/kotlin/exchange.dydx.abacus/calculator/v2/TransferInputCalculatorV2Tests.kt b/src/commonTest/kotlin/exchange.dydx.abacus/calculator/v2/TransferInputCalculatorV2Tests.kt new file mode 100644 index 000000000..7c42da5e5 --- /dev/null +++ b/src/commonTest/kotlin/exchange.dydx.abacus/calculator/v2/TransferInputCalculatorV2Tests.kt @@ -0,0 +1,3 @@ +package exchange.dydx.abacus.calculator.v2 + +class TransferInputCalculatorV2Tests