diff --git a/common_wallet/src/main/java/jp/co/soramitsu/common_wallet/presentation/compose/util/PolkaswapFormulas.kt b/common_wallet/src/main/java/jp/co/soramitsu/common_wallet/presentation/compose/util/PolkaswapFormulas.kt index 33388672f..c961cc980 100644 --- a/common_wallet/src/main/java/jp/co/soramitsu/common_wallet/presentation/compose/util/PolkaswapFormulas.kt +++ b/common_wallet/src/main/java/jp/co/soramitsu/common_wallet/presentation/compose/util/PolkaswapFormulas.kt @@ -33,6 +33,7 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package jp.co.soramitsu.common_wallet.presentation.compose.util import java.math.BigDecimal +import jp.co.soramitsu.common.domain.OptionsProvider import jp.co.soramitsu.common.util.ext.Big100 import jp.co.soramitsu.common.util.ext.divideBy import jp.co.soramitsu.common.util.ext.equalTo @@ -133,6 +134,6 @@ object PolkaswapFormulas { amount: BigDecimal, amountPooled: BigDecimal, otherPooled: BigDecimal, - precision: Int - ): BigDecimal = amount.multiply(otherPooled).safeDivide(amountPooled).safeDivide(Big100, precision) + precision: Int? = OptionsProvider.defaultScale, + ): BigDecimal = amount.multiply(otherPooled).safeDivide(amountPooled, precision) } diff --git a/feature_polkaswap_impl/src/main/java/jp/co/soramitsu/feature_polkaswap_impl/presentation/screens/liquidityremove/LiquidityRemoveViewModel.kt b/feature_polkaswap_impl/src/main/java/jp/co/soramitsu/feature_polkaswap_impl/presentation/screens/liquidityremove/LiquidityRemoveViewModel.kt index c1275dbf7..ea6cbad60 100644 --- a/feature_polkaswap_impl/src/main/java/jp/co/soramitsu/feature_polkaswap_impl/presentation/screens/liquidityremove/LiquidityRemoveViewModel.kt +++ b/feature_polkaswap_impl/src/main/java/jp/co/soramitsu/feature_polkaswap_impl/presentation/screens/liquidityremove/LiquidityRemoveViewModel.kt @@ -320,7 +320,7 @@ class LiquidityRemoveViewModel @AssistedInject constructor( amount1, it.user.basePooled, it.user.targetPooled, - removeState.assetState2?.token?.precision ?: 18 + removeState.assetState2?.token?.precision ) percent = PolkaswapFormulas.calculateShareOfPoolFromAmount( amount1, @@ -346,7 +346,7 @@ class LiquidityRemoveViewModel @AssistedInject constructor( amount2, it.user.targetPooled, it.user.basePooled, - removeState.assetState1?.token?.precision ?: 18 + removeState.assetState1?.token?.precision ) percent = PolkaswapFormulas.calculateShareOfPoolFromAmount( amount1, diff --git a/feature_polkaswap_impl/src/test/java/jp/co/soramitsu/feature_polkaswap_impl/domain/PoolsInteractorTest.kt b/feature_polkaswap_impl/src/test/java/jp/co/soramitsu/feature_polkaswap_impl/domain/PoolsInteractorTest.kt index cf516afbf..d953eb513 100644 --- a/feature_polkaswap_impl/src/test/java/jp/co/soramitsu/feature_polkaswap_impl/domain/PoolsInteractorTest.kt +++ b/feature_polkaswap_impl/src/test/java/jp/co/soramitsu/feature_polkaswap_impl/domain/PoolsInteractorTest.kt @@ -148,6 +148,6 @@ class PoolsInteractorTest { assertEquals(BigDecimal("5.051548910147228600"), details.targetAmount) assertEquals(BigDecimal("1.979590849830759653"), details.perFirst) assertEquals(BigDecimal("0.505154891014722860"), details.perSecond) - assertEquals(BigDecimal("66.298112417815485325766582281222800"), details.shareOfPool) + assertEquals(BigDecimal("66.298112417815485325766582281222788"), details.shareOfPool) } } diff --git a/feature_polkaswap_impl/src/test/java/jp/co/soramitsu/feature_polkaswap_impl/presentation/polkaswap/liquidity/remove/RemoveLiquidityViewModelTest.kt b/feature_polkaswap_impl/src/test/java/jp/co/soramitsu/feature_polkaswap_impl/presentation/polkaswap/liquidity/remove/RemoveLiquidityViewModelTest.kt index ae226fc29..1999597b3 100644 --- a/feature_polkaswap_impl/src/test/java/jp/co/soramitsu/feature_polkaswap_impl/presentation/polkaswap/liquidity/remove/RemoveLiquidityViewModelTest.kt +++ b/feature_polkaswap_impl/src/test/java/jp/co/soramitsu/feature_polkaswap_impl/presentation/polkaswap/liquidity/remove/RemoveLiquidityViewModelTest.kt @@ -36,6 +36,7 @@ import androidx.arch.core.executor.testing.InstantTaskExecutorRule import jp.co.soramitsu.common.R import jp.co.soramitsu.common.resourses.ResourceManager import jp.co.soramitsu.common.util.NumbersFormatter +import jp.co.soramitsu.common.util.ext.equalTo import jp.co.soramitsu.feature_assets_api.domain.AssetsInteractor import jp.co.soramitsu.feature_assets_api.presentation.AssetsRouter import jp.co.soramitsu.feature_polkaswap_api.domain.interfaces.PoolsInteractor @@ -198,7 +199,7 @@ class RemoveLiquidityViewModelTest { advanceUntilIdle() assertEquals(BigDecimal(0.5), viewModel.removeState.assetState1?.amount) - assertEquals(BigDecimal(0.5), viewModel.removeState.assetState2?.amount) + assertTrue(viewModel.removeState.assetState2?.amount?.equalTo(BigDecimal(0.5)) == true) assertEquals("Remove", viewModel.removeState.btnState.text) assertTrue(viewModel.removeState.btnState.enabled) } @@ -212,7 +213,7 @@ class RemoveLiquidityViewModelTest { viewModel.onAmount2Change(BigDecimal("0.35")) advanceUntilIdle() - assertEquals(BigDecimal("0.35"), viewModel.removeState.assetState1?.amount) + assertTrue(viewModel.removeState.assetState1?.amount?.equalTo(amount) == true) assertEquals(BigDecimal("0.35"), viewModel.removeState.assetState2?.amount) assertTrue(viewModel.removeState.btnState.enabled) }