Skip to content

Commit

Permalink
mwr-641
Browse files Browse the repository at this point in the history
  • Loading branch information
arvifox committed Sep 20, 2023
1 parent e88017d commit 3ecd39e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down

0 comments on commit 3ecd39e

Please sign in to comment.