From 8d1003e567a4845d64a93aa01e05ff0a35d5b234 Mon Sep 17 00:00:00 2001 From: arvifox Date: Tue, 25 Jun 2024 17:43:04 +0300 Subject: [PATCH] mwr-824 --- .../jp/co/soramitsu/common/domain/Asset.kt | 2 +- .../compose/components/AssetAmount.kt | 2 +- .../common/util/ext/BigDecimalExt.kt | 103 ------------------ .../compose/util/PolkaswapFormulas.kt | 8 +- .../presentation/PolkaswapFormulasTest.kt | 8 +- .../demeter/data/DemeterFarmingRepository.kt | 2 +- .../data/AssetsRepository.kt | 3 + .../domain/AssetsInteractor.kt | 7 ++ .../data/AssetsRepositoryImpl.kt | 7 ++ .../domain/AssetsInteractorImpl.kt | 15 ++- .../assetdetails/AssetDetailsViewModel.kt | 2 +- .../screens/send/TransferAmountViewModel.kt | 6 +- .../qr/QrCodeFlowViewModelTest.kt | 2 +- .../send/TransferAmountViewModelTest.kt | 2 +- .../data/BlockExplorerManager.kt | 3 +- .../domain/EcoSystemPoolsInteractor.kt | 2 +- .../domain/EcoSystemTokensInteractor.kt | 2 +- .../editfarm/EditFarmViewModel.kt | 4 +- .../presentation/explore/ExploreViewModel.kt | 2 +- .../domain/PoolsInteractorImpl.kt | 4 +- .../domain/SwapInteractorImpl.kt | 2 +- .../liquidityadd/LiquidityAddViewModel.kt | 6 +- .../LiquidityRemoveViewModel.kt | 36 +++++- .../screens/swap/SwapViewModel.kt | 6 +- .../add/AddLiquidityViewModelTest.kt | 2 +- .../remove/RemoveLiquidityViewModelTest.kt | 2 +- .../presentation/ReferralViewModel.kt | 2 +- 27 files changed, 98 insertions(+), 144 deletions(-) delete mode 100644 common/src/main/java/jp/co/soramitsu/common/util/ext/BigDecimalExt.kt diff --git a/common/src/main/java/jp/co/soramitsu/common/domain/Asset.kt b/common/src/main/java/jp/co/soramitsu/common/domain/Asset.kt index 9b88c775c..6230995b9 100644 --- a/common/src/main/java/jp/co/soramitsu/common/domain/Asset.kt +++ b/common/src/main/java/jp/co/soramitsu/common/domain/Asset.kt @@ -34,9 +34,9 @@ package jp.co.soramitsu.common.domain import android.os.Parcelable import java.math.BigDecimal +import jp.co.soramitsu.androidfoundation.format.equalTo import jp.co.soramitsu.common.R import jp.co.soramitsu.common.util.NumbersFormatter -import jp.co.soramitsu.common.util.ext.equalTo import kotlinx.parcelize.IgnoredOnParcel import kotlinx.parcelize.Parcelize diff --git a/common/src/main/java/jp/co/soramitsu/common/presentation/compose/components/AssetAmount.kt b/common/src/main/java/jp/co/soramitsu/common/presentation/compose/components/AssetAmount.kt index a17c14621..ba3b6404e 100644 --- a/common/src/main/java/jp/co/soramitsu/common/presentation/compose/components/AssetAmount.kt +++ b/common/src/main/java/jp/co/soramitsu/common/presentation/compose/components/AssetAmount.kt @@ -65,12 +65,12 @@ import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import java.math.BigDecimal +import jp.co.soramitsu.androidfoundation.format.orZero import jp.co.soramitsu.common.R import jp.co.soramitsu.common.domain.AssetAmountInputState import jp.co.soramitsu.common.domain.OptionsProvider import jp.co.soramitsu.common.presentation.compose.TokenIcon import jp.co.soramitsu.common.presentation.compose.theme.SoraAppTheme -import jp.co.soramitsu.common.util.ext.orZero import jp.co.soramitsu.common.util.testTagAsId import jp.co.soramitsu.ui_core.component.button.properties.Size import jp.co.soramitsu.ui_core.component.input.number.BasicNumberInput diff --git a/common/src/main/java/jp/co/soramitsu/common/util/ext/BigDecimalExt.kt b/common/src/main/java/jp/co/soramitsu/common/util/ext/BigDecimalExt.kt deleted file mode 100644 index 14533194a..000000000 --- a/common/src/main/java/jp/co/soramitsu/common/util/ext/BigDecimalExt.kt +++ /dev/null @@ -1,103 +0,0 @@ -/* -This file is part of the SORA network and Polkaswap app. - -Copyright (c) 2020, 2021, Polka Biome Ltd. All rights reserved. -SPDX-License-Identifier: BSD-4-Clause - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - -Redistributions of source code must retain the above copyright notice, this list -of conditions and the following disclaimer. -Redistributions in binary form must reproduce the above copyright notice, this -list of conditions and the following disclaimer in the documentation and/or other -materials provided with the distribution. - -All advertising materials mentioning features or use of this software must display -the following acknowledgement: This product includes software developed by Polka Biome -Ltd., SORA, and Polkaswap. - -Neither the name of the Polka Biome Ltd. nor the names of its contributors may be used -to endorse or promote products derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY Polka Biome Ltd. AS IS AND ANY EXPRESS OR IMPLIED WARRANTIES, -INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Polka Biome Ltd. BE LIABLE FOR ANY -DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE -USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -package jp.co.soramitsu.common.util.ext - -import java.math.BigDecimal -import java.math.BigInteger -import java.math.RoundingMode -import jp.co.soramitsu.common.domain.OptionsProvider -import kotlin.math.max - -val Big100 = BigDecimal.valueOf(100) - -fun compareNullDesc(o1: BigDecimal?, o2: BigDecimal?): Int = - when { - o1 == null && o2 == null -> 0 - o1 != null && o2 != null -> o2.compareTo(o1) - o1 == null -> 1 - else -> -1 - } - -fun compareNullDesc(o1: Double?, o2: Double?): Int = - when { - o1 == null && o2 == null -> 0 - o1 != null && o2 != null -> o2.compareTo(o1) - o1 == null -> 1 - else -> -1 - } - -fun BigInteger.isZero(): Boolean = this.compareTo(BigInteger.ZERO) == 0 -fun BigDecimal.isZero(): Boolean = this.compareTo(BigDecimal.ZERO) == 0 - -fun BigDecimal?.multiplyNullable(decimal: BigDecimal?): BigDecimal? = - if (this != null && decimal != null) this.multiply(decimal) else null - -fun BigDecimal.toDoubleInfinite() = this.toDouble().takeIf { converted -> - converted != Double.NEGATIVE_INFINITY && converted != Double.POSITIVE_INFINITY -} ?: 0.0 - -fun BigDecimal.equalTo(a: BigDecimal) = this.compareTo(a) == 0 - -fun BigDecimal.greaterThan(a: BigDecimal) = this.compareTo(a) == 1 - -fun BigDecimal?.orZero(): BigDecimal = this ?: BigDecimal.ZERO - -fun BigDecimal.nullZero(): BigDecimal? = if (this.isZero()) null else this - -fun BigDecimal.divideBy( - divisor: BigDecimal, - scale: Int? = null, -): BigDecimal { - return if (scale == null) { - val maxScale = max(this.scale(), divisor.scale()).coerceAtMost(OptionsProvider.defaultScale) - - if (maxScale != 0) { - this.divide(divisor, maxScale, RoundingMode.HALF_EVEN) - } else { - this.divide(divisor, OptionsProvider.defaultScale, RoundingMode.HALF_EVEN) - } - } else { - this.divide(divisor, scale, RoundingMode.HALF_EVEN) - } -} - -fun BigDecimal.safeDivide( - divisor: BigDecimal, - scale: Int? = null, -): BigDecimal { - return if (divisor.isZero()) { - BigDecimal.ZERO - } else { - divideBy(divisor, scale) - } -} 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 af38a1233..59e2f353c 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,11 +33,11 @@ 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.androidfoundation.format.Big100 +import jp.co.soramitsu.androidfoundation.format.divideBy +import jp.co.soramitsu.androidfoundation.format.equalTo +import jp.co.soramitsu.androidfoundation.format.safeDivide 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 -import jp.co.soramitsu.common.util.ext.safeDivide import jp.co.soramitsu.common_wallet.domain.model.WithDesired object PolkaswapFormulas { diff --git a/common_wallet/src/test/java/jp/co/soramitsu/common_wallet/presentation/PolkaswapFormulasTest.kt b/common_wallet/src/test/java/jp/co/soramitsu/common_wallet/presentation/PolkaswapFormulasTest.kt index 41753c97e..2e49dd35b 100644 --- a/common_wallet/src/test/java/jp/co/soramitsu/common_wallet/presentation/PolkaswapFormulasTest.kt +++ b/common_wallet/src/test/java/jp/co/soramitsu/common_wallet/presentation/PolkaswapFormulasTest.kt @@ -33,10 +33,10 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package jp.co.soramitsu.common_wallet.presentation import java.math.BigDecimal -import jp.co.soramitsu.common.util.ext.Big100 -import jp.co.soramitsu.common.util.ext.divideBy -import jp.co.soramitsu.common.util.ext.equalTo -import jp.co.soramitsu.common.util.ext.safeDivide +import jp.co.soramitsu.androidfoundation.format.Big100 +import jp.co.soramitsu.androidfoundation.format.divideBy +import jp.co.soramitsu.androidfoundation.format.equalTo +import jp.co.soramitsu.androidfoundation.format.safeDivide import jp.co.soramitsu.common_wallet.domain.model.WithDesired import jp.co.soramitsu.common_wallet.presentation.compose.util.PolkaswapFormulas import org.junit.Assert.assertEquals diff --git a/demeter/src/main/java/jp/co/soramitsu/demeter/data/DemeterFarmingRepository.kt b/demeter/src/main/java/jp/co/soramitsu/demeter/data/DemeterFarmingRepository.kt index 5b7afd8b0..d51a04b83 100644 --- a/demeter/src/main/java/jp/co/soramitsu/demeter/data/DemeterFarmingRepository.kt +++ b/demeter/src/main/java/jp/co/soramitsu/demeter/data/DemeterFarmingRepository.kt @@ -35,9 +35,9 @@ package jp.co.soramitsu.demeter.data import java.math.BigDecimal import java.math.BigInteger import java.util.concurrent.ConcurrentHashMap +import jp.co.soramitsu.androidfoundation.format.isZero import jp.co.soramitsu.androidfoundation.format.safeCast import jp.co.soramitsu.common.domain.OptionsProvider -import jp.co.soramitsu.common.util.ext.isZero import jp.co.soramitsu.common.util.mapBalance import jp.co.soramitsu.common_wallet.data.AssetLocalToAssetMapper import jp.co.soramitsu.core_db.AppDatabase diff --git a/feature_assets_api/src/main/java/jp/co/soramitsu/feature_assets_api/data/AssetsRepository.kt b/feature_assets_api/src/main/java/jp/co/soramitsu/feature_assets_api/data/AssetsRepository.kt index 97750d5a8..27bdc0a67 100644 --- a/feature_assets_api/src/main/java/jp/co/soramitsu/feature_assets_api/data/AssetsRepository.kt +++ b/feature_assets_api/src/main/java/jp/co/soramitsu/feature_assets_api/data/AssetsRepository.kt @@ -33,6 +33,7 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package jp.co.soramitsu.feature_assets_api.data import java.math.BigDecimal +import java.math.BigInteger import jp.co.soramitsu.common.account.SoraAccount import jp.co.soramitsu.common.domain.Asset import jp.co.soramitsu.common.domain.Token @@ -121,4 +122,6 @@ interface AssetsRepository { suspend fun updateBalancesVisibleAssets(address: String) suspend fun updateWhitelistBalances(address: String) + + suspend fun fetchBalance(address: String, ids: List): List } diff --git a/feature_assets_api/src/main/java/jp/co/soramitsu/feature_assets_api/domain/AssetsInteractor.kt b/feature_assets_api/src/main/java/jp/co/soramitsu/feature_assets_api/domain/AssetsInteractor.kt index 79f98c78c..59c5c501f 100644 --- a/feature_assets_api/src/main/java/jp/co/soramitsu/feature_assets_api/domain/AssetsInteractor.kt +++ b/feature_assets_api/src/main/java/jp/co/soramitsu/feature_assets_api/domain/AssetsInteractor.kt @@ -35,6 +35,7 @@ package jp.co.soramitsu.feature_assets_api.domain import java.math.BigDecimal import jp.co.soramitsu.common.account.SoraAccount import jp.co.soramitsu.common.domain.Asset +import jp.co.soramitsu.common.domain.OptionsProvider import jp.co.soramitsu.common.domain.Token import jp.co.soramitsu.common_wallet.data.XorAssetBalance import kotlinx.coroutines.flow.Flow @@ -94,4 +95,10 @@ interface AssetsInteractor { suspend fun updateWhitelistBalances() suspend fun updateBalanceVisibleAssets() + + suspend fun fetchBalance( + address: String, + ids: List, + precision: Int = OptionsProvider.defaultScale, + ): List } diff --git a/feature_assets_impl/src/main/java/jp/co/soramitsu/feature_assets_impl/data/AssetsRepositoryImpl.kt b/feature_assets_impl/src/main/java/jp/co/soramitsu/feature_assets_impl/data/AssetsRepositoryImpl.kt index b6a8a8606..128de4f89 100644 --- a/feature_assets_impl/src/main/java/jp/co/soramitsu/feature_assets_impl/data/AssetsRepositoryImpl.kt +++ b/feature_assets_impl/src/main/java/jp/co/soramitsu/feature_assets_impl/data/AssetsRepositoryImpl.kt @@ -432,6 +432,13 @@ class AssetsRepositoryImpl @Inject constructor( return balances to xorBalance } + override suspend fun fetchBalance( + address: String, + ids: List, + ): List { + return substrateCalls.fetchBalances(address, ids) + } + private suspend fun checkDefaultNeed(address: String, code: String) { if (db.assetDao().getAssetsWhitelist(address, code) .all { it.assetLocal == null } diff --git a/feature_assets_impl/src/main/java/jp/co/soramitsu/feature_assets_impl/domain/AssetsInteractorImpl.kt b/feature_assets_impl/src/main/java/jp/co/soramitsu/feature_assets_impl/domain/AssetsInteractorImpl.kt index ea4aaa1d2..2447227b5 100644 --- a/feature_assets_impl/src/main/java/jp/co/soramitsu/feature_assets_impl/domain/AssetsInteractorImpl.kt +++ b/feature_assets_impl/src/main/java/jp/co/soramitsu/feature_assets_impl/domain/AssetsInteractorImpl.kt @@ -34,6 +34,8 @@ package jp.co.soramitsu.feature_assets_impl.domain import java.math.BigDecimal import java.util.Date +import jp.co.soramitsu.androidfoundation.format.isZero +import jp.co.soramitsu.androidfoundation.format.orZero import jp.co.soramitsu.common.account.SoraAccount import jp.co.soramitsu.common.domain.Asset import jp.co.soramitsu.common.domain.AssetHolder @@ -41,8 +43,7 @@ import jp.co.soramitsu.common.domain.CoroutineManager import jp.co.soramitsu.common.domain.Token import jp.co.soramitsu.common.util.BuildUtils import jp.co.soramitsu.common.util.Flavor -import jp.co.soramitsu.common.util.ext.isZero -import jp.co.soramitsu.common.util.ext.orZero +import jp.co.soramitsu.common.util.mapBalance import jp.co.soramitsu.common_wallet.data.XorAssetBalance import jp.co.soramitsu.feature_account_api.domain.interfaces.CredentialsRepository import jp.co.soramitsu.feature_account_api.domain.interfaces.UserRepository @@ -211,6 +212,16 @@ class AssetsInteractorImpl constructor( assetsRepository.updateBalancesVisibleAssets(soraAccount.substrateAddress) } + override suspend fun fetchBalance( + address: String, + ids: List, + precision: Int, + ): List { + return assetsRepository.fetchBalance(address, ids).map { + mapBalance(it, precision) + } + } + override suspend fun updateWhitelistBalances() { val soraAccount = userRepository.getCurSoraAccount() assetsRepository.updateWhitelistBalances(soraAccount.substrateAddress) diff --git a/feature_assets_impl/src/main/java/jp/co/soramitsu/feature_assets_impl/presentation/screens/assetdetails/AssetDetailsViewModel.kt b/feature_assets_impl/src/main/java/jp/co/soramitsu/feature_assets_impl/presentation/screens/assetdetails/AssetDetailsViewModel.kt index ded9587a9..97175dbb0 100644 --- a/feature_assets_impl/src/main/java/jp/co/soramitsu/feature_assets_impl/presentation/screens/assetdetails/AssetDetailsViewModel.kt +++ b/feature_assets_impl/src/main/java/jp/co/soramitsu/feature_assets_impl/presentation/screens/assetdetails/AssetDetailsViewModel.kt @@ -41,6 +41,7 @@ import dagger.assisted.Assisted import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject import java.math.BigDecimal +import jp.co.soramitsu.androidfoundation.format.isZero import jp.co.soramitsu.androidfoundation.fragment.SingleLiveEvent import jp.co.soramitsu.androidfoundation.fragment.trigger import jp.co.soramitsu.androidfoundation.phone.BasicClipboardManager @@ -57,7 +58,6 @@ import jp.co.soramitsu.common.presentation.compose.components.initSmallTitle2 import jp.co.soramitsu.common.presentation.viewmodel.BaseViewModel import jp.co.soramitsu.common.util.NumbersFormatter import jp.co.soramitsu.common.util.StringPair -import jp.co.soramitsu.common.util.ext.isZero import jp.co.soramitsu.common_wallet.data.XorAssetBalance import jp.co.soramitsu.common_wallet.domain.model.fiatSymbol import jp.co.soramitsu.common_wallet.presentation.compose.states.mapPoolsData diff --git a/feature_assets_impl/src/main/java/jp/co/soramitsu/feature_assets_impl/presentation/screens/send/TransferAmountViewModel.kt b/feature_assets_impl/src/main/java/jp/co/soramitsu/feature_assets_impl/presentation/screens/send/TransferAmountViewModel.kt index 0ace82019..5c8e7fb74 100644 --- a/feature_assets_impl/src/main/java/jp/co/soramitsu/feature_assets_impl/presentation/screens/send/TransferAmountViewModel.kt +++ b/feature_assets_impl/src/main/java/jp/co/soramitsu/feature_assets_impl/presentation/screens/send/TransferAmountViewModel.kt @@ -38,6 +38,9 @@ import dagger.assisted.Assisted import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject import java.math.BigDecimal +import jp.co.soramitsu.androidfoundation.format.isZero +import jp.co.soramitsu.androidfoundation.format.nullZero +import jp.co.soramitsu.androidfoundation.format.orZero import jp.co.soramitsu.androidfoundation.fragment.SingleLiveEvent import jp.co.soramitsu.androidfoundation.fragment.trigger import jp.co.soramitsu.androidfoundation.phone.BasicClipboardManager @@ -52,9 +55,6 @@ import jp.co.soramitsu.common.domain.subtractFee import jp.co.soramitsu.common.presentation.compose.components.initSmallTitle2 import jp.co.soramitsu.common.presentation.viewmodel.BaseViewModel import jp.co.soramitsu.common.util.NumbersFormatter -import jp.co.soramitsu.common.util.ext.isZero -import jp.co.soramitsu.common.util.ext.nullZero -import jp.co.soramitsu.common.util.ext.orZero import jp.co.soramitsu.common.view.ViewHelper import jp.co.soramitsu.common_wallet.presentation.compose.util.PolkaswapFormulas import jp.co.soramitsu.feature_assets_api.domain.AssetsInteractor diff --git a/feature_assets_impl/src/test/java/jp/co/soramitsu/feature_assets_impl/presentation/qr/QrCodeFlowViewModelTest.kt b/feature_assets_impl/src/test/java/jp/co/soramitsu/feature_assets_impl/presentation/qr/QrCodeFlowViewModelTest.kt index f856035b4..631f959cd 100644 --- a/feature_assets_impl/src/test/java/jp/co/soramitsu/feature_assets_impl/presentation/qr/QrCodeFlowViewModelTest.kt +++ b/feature_assets_impl/src/test/java/jp/co/soramitsu/feature_assets_impl/presentation/qr/QrCodeFlowViewModelTest.kt @@ -44,6 +44,7 @@ import io.mockk.mockk import io.mockk.mockkStatic import io.mockk.verify import java.util.StringJoiner +import jp.co.soramitsu.androidfoundation.format.Big100 import jp.co.soramitsu.androidfoundation.phone.BasicClipboardManager import jp.co.soramitsu.androidfoundation.resource.ResourceManager import jp.co.soramitsu.common.account.AccountAvatarGenerator @@ -53,7 +54,6 @@ import jp.co.soramitsu.common.domain.CoroutineManager import jp.co.soramitsu.common.io.FileManager import jp.co.soramitsu.common.util.NumbersFormatter import jp.co.soramitsu.common.util.QrCodeGenerator -import jp.co.soramitsu.common.util.ext.Big100 import jp.co.soramitsu.feature_assets_api.domain.AssetsInteractor import jp.co.soramitsu.feature_assets_api.domain.QrCodeInteractor import jp.co.soramitsu.feature_assets_impl.presentation.screens.receiverequest.QRCodeFlowViewModel diff --git a/feature_assets_impl/src/test/java/jp/co/soramitsu/feature_assets_impl/presentation/send/TransferAmountViewModelTest.kt b/feature_assets_impl/src/test/java/jp/co/soramitsu/feature_assets_impl/presentation/send/TransferAmountViewModelTest.kt index 4c3b2e9e4..2fa37351e 100644 --- a/feature_assets_impl/src/test/java/jp/co/soramitsu/feature_assets_impl/presentation/send/TransferAmountViewModelTest.kt +++ b/feature_assets_impl/src/test/java/jp/co/soramitsu/feature_assets_impl/presentation/send/TransferAmountViewModelTest.kt @@ -40,12 +40,12 @@ import io.mockk.every import io.mockk.impl.annotations.MockK import io.mockk.junit4.MockKRule import java.math.BigDecimal +import jp.co.soramitsu.androidfoundation.format.equalTo import jp.co.soramitsu.androidfoundation.phone.BasicClipboardManager import jp.co.soramitsu.androidfoundation.resource.ResourceManager import jp.co.soramitsu.common.R import jp.co.soramitsu.common.account.AccountAvatarGenerator 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_assets_impl.presentation.screens.send.TransferAmountViewModel diff --git a/feature_blockexplorer_api/src/main/java/jp/co/soramitsu/feature_blockexplorer_api/data/BlockExplorerManager.kt b/feature_blockexplorer_api/src/main/java/jp/co/soramitsu/feature_blockexplorer_api/data/BlockExplorerManager.kt index 65c477826..82ccc68cd 100644 --- a/feature_blockexplorer_api/src/main/java/jp/co/soramitsu/feature_blockexplorer_api/data/BlockExplorerManager.kt +++ b/feature_blockexplorer_api/src/main/java/jp/co/soramitsu/feature_blockexplorer_api/data/BlockExplorerManager.kt @@ -37,12 +37,11 @@ import java.math.BigDecimal import java.util.concurrent.TimeUnit import javax.inject.Inject import javax.inject.Singleton +import jp.co.soramitsu.androidfoundation.format.toDoubleInfinite import jp.co.soramitsu.common.config.BuildConfigWrapper import jp.co.soramitsu.common.domain.AppStateProvider import jp.co.soramitsu.common.domain.RetryStrategyBuilder -import jp.co.soramitsu.common.domain.fiatChange import jp.co.soramitsu.common.logger.FirebaseWrapper -import jp.co.soramitsu.common.util.ext.toDoubleInfinite import jp.co.soramitsu.common.util.mapBalance import jp.co.soramitsu.core_db.AppDatabase import jp.co.soramitsu.core_db.model.FiatTokenPriceLocal diff --git a/feature_ecosystem_impl/src/main/java/jp/co/soramitsu/feature_ecosystem_impl/domain/EcoSystemPoolsInteractor.kt b/feature_ecosystem_impl/src/main/java/jp/co/soramitsu/feature_ecosystem_impl/domain/EcoSystemPoolsInteractor.kt index 40f2d3290..bafe16d0c 100644 --- a/feature_ecosystem_impl/src/main/java/jp/co/soramitsu/feature_ecosystem_impl/domain/EcoSystemPoolsInteractor.kt +++ b/feature_ecosystem_impl/src/main/java/jp/co/soramitsu/feature_ecosystem_impl/domain/EcoSystemPoolsInteractor.kt @@ -32,7 +32,7 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package jp.co.soramitsu.feature_ecosystem_impl.domain -import jp.co.soramitsu.common.util.ext.compareNullDesc +import jp.co.soramitsu.androidfoundation.format.compareNullDesc import jp.co.soramitsu.feature_polkaswap_api.domain.interfaces.PolkaswapRepository import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.map diff --git a/feature_ecosystem_impl/src/main/java/jp/co/soramitsu/feature_ecosystem_impl/domain/EcoSystemTokensInteractor.kt b/feature_ecosystem_impl/src/main/java/jp/co/soramitsu/feature_ecosystem_impl/domain/EcoSystemTokensInteractor.kt index 48b7f1b22..fe9ba2594 100644 --- a/feature_ecosystem_impl/src/main/java/jp/co/soramitsu/feature_ecosystem_impl/domain/EcoSystemTokensInteractor.kt +++ b/feature_ecosystem_impl/src/main/java/jp/co/soramitsu/feature_ecosystem_impl/domain/EcoSystemTokensInteractor.kt @@ -32,7 +32,7 @@ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package jp.co.soramitsu.feature_ecosystem_impl.domain -import jp.co.soramitsu.common.util.ext.compareNullDesc +import jp.co.soramitsu.androidfoundation.format.compareNullDesc import jp.co.soramitsu.feature_assets_api.data.AssetsRepository import jp.co.soramitsu.feature_blockexplorer_api.data.BlockExplorerManager import kotlinx.coroutines.flow.Flow diff --git a/feature_ecosystem_impl/src/main/java/jp/co/soramitsu/feature_ecosystem_impl/presentation/editfarm/EditFarmViewModel.kt b/feature_ecosystem_impl/src/main/java/jp/co/soramitsu/feature_ecosystem_impl/presentation/editfarm/EditFarmViewModel.kt index 15bda00f6..a698b62ef 100644 --- a/feature_ecosystem_impl/src/main/java/jp/co/soramitsu/feature_ecosystem_impl/presentation/editfarm/EditFarmViewModel.kt +++ b/feature_ecosystem_impl/src/main/java/jp/co/soramitsu/feature_ecosystem_impl/presentation/editfarm/EditFarmViewModel.kt @@ -37,6 +37,8 @@ import dagger.assisted.Assisted import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject import java.math.BigDecimal +import jp.co.soramitsu.androidfoundation.format.Big100 +import jp.co.soramitsu.androidfoundation.format.divideBy import jp.co.soramitsu.androidfoundation.resource.ResourceManager import jp.co.soramitsu.common.R import jp.co.soramitsu.common.domain.Asset @@ -44,8 +46,6 @@ import jp.co.soramitsu.common.presentation.viewmodel.BaseViewModel import jp.co.soramitsu.common.util.NumbersFormatter import jp.co.soramitsu.common.util.StringPair import jp.co.soramitsu.common.util.StringTriple -import jp.co.soramitsu.common.util.ext.Big100 -import jp.co.soramitsu.common.util.ext.divideBy import jp.co.soramitsu.common_wallet.domain.model.CommonUserPoolData import jp.co.soramitsu.common_wallet.presentation.compose.util.PolkaswapFormulas import jp.co.soramitsu.demeter.domain.DemeterFarmingInteractor diff --git a/feature_ecosystem_impl/src/main/java/jp/co/soramitsu/feature_ecosystem_impl/presentation/explore/ExploreViewModel.kt b/feature_ecosystem_impl/src/main/java/jp/co/soramitsu/feature_ecosystem_impl/presentation/explore/ExploreViewModel.kt index 439687c1d..46762eda5 100644 --- a/feature_ecosystem_impl/src/main/java/jp/co/soramitsu/feature_ecosystem_impl/presentation/explore/ExploreViewModel.kt +++ b/feature_ecosystem_impl/src/main/java/jp/co/soramitsu/feature_ecosystem_impl/presentation/explore/ExploreViewModel.kt @@ -35,6 +35,7 @@ package jp.co.soramitsu.feature_ecosystem_impl.presentation.explore import androidx.lifecycle.viewModelScope import dagger.hilt.android.lifecycle.HiltViewModel import javax.inject.Inject +import jp.co.soramitsu.androidfoundation.format.compareNullDesc import jp.co.soramitsu.androidfoundation.format.formatFiatSuffix import jp.co.soramitsu.androidfoundation.resource.ResourceManager import jp.co.soramitsu.common.domain.iconUri @@ -44,7 +45,6 @@ import jp.co.soramitsu.common.presentation.viewmodel.BaseViewModel import jp.co.soramitsu.common.util.NumbersFormatter import jp.co.soramitsu.common.util.StringPair import jp.co.soramitsu.common.util.StringTriple -import jp.co.soramitsu.common.util.ext.compareNullDesc import jp.co.soramitsu.common_wallet.domain.model.isFilterMatch import jp.co.soramitsu.common_wallet.presentation.compose.BasicFarmListItemState import jp.co.soramitsu.common_wallet.presentation.compose.BasicPoolListItemState diff --git a/feature_polkaswap_impl/src/main/java/jp/co/soramitsu/feature_polkaswap_impl/domain/PoolsInteractorImpl.kt b/feature_polkaswap_impl/src/main/java/jp/co/soramitsu/feature_polkaswap_impl/domain/PoolsInteractorImpl.kt index bef8fd03e..21f9db660 100644 --- a/feature_polkaswap_impl/src/main/java/jp/co/soramitsu/feature_polkaswap_impl/domain/PoolsInteractorImpl.kt +++ b/feature_polkaswap_impl/src/main/java/jp/co/soramitsu/feature_polkaswap_impl/domain/PoolsInteractorImpl.kt @@ -34,12 +34,12 @@ package jp.co.soramitsu.feature_polkaswap_impl.domain import java.math.BigDecimal import java.util.Date +import jp.co.soramitsu.androidfoundation.format.isZero +import jp.co.soramitsu.androidfoundation.format.safeDivide import jp.co.soramitsu.common.account.SoraAccount import jp.co.soramitsu.common.domain.LiquidityDetails import jp.co.soramitsu.common.domain.Token import jp.co.soramitsu.common.util.StringPair -import jp.co.soramitsu.common.util.ext.isZero -import jp.co.soramitsu.common.util.ext.safeDivide import jp.co.soramitsu.common_wallet.domain.model.BasicPoolData import jp.co.soramitsu.common_wallet.domain.model.CommonPoolData import jp.co.soramitsu.common_wallet.domain.model.CommonUserPoolData diff --git a/feature_polkaswap_impl/src/main/java/jp/co/soramitsu/feature_polkaswap_impl/domain/SwapInteractorImpl.kt b/feature_polkaswap_impl/src/main/java/jp/co/soramitsu/feature_polkaswap_impl/domain/SwapInteractorImpl.kt index 6c85355c3..f252286d7 100644 --- a/feature_polkaswap_impl/src/main/java/jp/co/soramitsu/feature_polkaswap_impl/domain/SwapInteractorImpl.kt +++ b/feature_polkaswap_impl/src/main/java/jp/co/soramitsu/feature_polkaswap_impl/domain/SwapInteractorImpl.kt @@ -36,10 +36,10 @@ import java.math.BigDecimal import java.math.RoundingMode import java.util.Date import jp.co.soramitsu.androidfoundation.coroutine.SuspendableProperty +import jp.co.soramitsu.androidfoundation.format.isZero import jp.co.soramitsu.common.domain.Market import jp.co.soramitsu.common.domain.PoolDex import jp.co.soramitsu.common.domain.Token -import jp.co.soramitsu.common.util.ext.isZero import jp.co.soramitsu.common_wallet.domain.model.WithDesired import jp.co.soramitsu.feature_account_api.domain.interfaces.CredentialsRepository import jp.co.soramitsu.feature_account_api.domain.interfaces.UserRepository diff --git a/feature_polkaswap_impl/src/main/java/jp/co/soramitsu/feature_polkaswap_impl/presentation/screens/liquidityadd/LiquidityAddViewModel.kt b/feature_polkaswap_impl/src/main/java/jp/co/soramitsu/feature_polkaswap_impl/presentation/screens/liquidityadd/LiquidityAddViewModel.kt index e2aa92da1..2666e3fed 100644 --- a/feature_polkaswap_impl/src/main/java/jp/co/soramitsu/feature_polkaswap_impl/presentation/screens/liquidityadd/LiquidityAddViewModel.kt +++ b/feature_polkaswap_impl/src/main/java/jp/co/soramitsu/feature_polkaswap_impl/presentation/screens/liquidityadd/LiquidityAddViewModel.kt @@ -38,6 +38,9 @@ import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject import java.math.BigDecimal import jp.co.soramitsu.androidfoundation.coroutine.SuspendableProperty +import jp.co.soramitsu.androidfoundation.format.isZero +import jp.co.soramitsu.androidfoundation.format.nullZero +import jp.co.soramitsu.androidfoundation.format.orZero import jp.co.soramitsu.androidfoundation.resource.ResourceManager import jp.co.soramitsu.common.R import jp.co.soramitsu.common.domain.Asset @@ -48,10 +51,7 @@ import jp.co.soramitsu.common.domain.printFiat import jp.co.soramitsu.common.presentation.compose.states.ButtonState import jp.co.soramitsu.common.presentation.viewmodel.BaseViewModel import jp.co.soramitsu.common.util.NumbersFormatter -import jp.co.soramitsu.common.util.ext.isZero import jp.co.soramitsu.common.util.ext.lazyAsync -import jp.co.soramitsu.common.util.ext.nullZero -import jp.co.soramitsu.common.util.ext.orZero import jp.co.soramitsu.common.view.ViewHelper import jp.co.soramitsu.common_wallet.domain.model.LiquidityData import jp.co.soramitsu.common_wallet.domain.model.WithDesired 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 51d10eec2..1f145f2ca 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 @@ -40,6 +40,9 @@ import dagger.assisted.Assisted import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject import java.math.BigDecimal +import jp.co.soramitsu.androidfoundation.format.isZero +import jp.co.soramitsu.androidfoundation.format.nullZero +import jp.co.soramitsu.androidfoundation.format.orZero import jp.co.soramitsu.androidfoundation.resource.ResourceManager import jp.co.soramitsu.common.R import jp.co.soramitsu.common.domain.Asset @@ -49,8 +52,6 @@ import jp.co.soramitsu.common.presentation.compose.states.ButtonState import jp.co.soramitsu.common.presentation.viewmodel.BaseViewModel import jp.co.soramitsu.common.util.NumbersFormatter import jp.co.soramitsu.common.util.ext.lazyAsync -import jp.co.soramitsu.common.util.ext.nullZero -import jp.co.soramitsu.common.util.ext.orZero import jp.co.soramitsu.common.view.ViewHelper import jp.co.soramitsu.common_wallet.domain.model.CommonUserPoolData import jp.co.soramitsu.common_wallet.presentation.compose.util.AmountFormat @@ -264,7 +265,7 @@ class LiquidityRemoveViewModel @AssistedInject constructor( poolDataLocal.user.poolProvidersBalance, ) } - if (maxPercent != null && !maxPercent.isNaN()) { + var fixedPoolData: CommonUserPoolData? = if (maxPercent != null && !maxPercent.isNaN()) { poolInFarming = true val usablePercent = 100 - maxPercent poolDataLocal.copy( @@ -289,6 +290,35 @@ class LiquidityRemoveViewModel @AssistedInject constructor( } else { poolDataLocal } + fixedPoolData = if (fixedPoolData != null && token2Id == SubstrateOptionsProvider.ethTokenId) { + if (token1Id == SubstrateOptionsProvider.feeAssetId || token1Id == SubstrateOptionsProvider.kxorTokenId) { + val kxorBalance = assetsInteractor + .fetchBalance(poolDataLocal.basic.reserveAccount, listOf(SubstrateOptionsProvider.kxorTokenId)) + .getOrElse(0) { BigDecimal.ZERO } + if (kxorBalance.isZero()) { + fixedPoolData + } else { + if (token1Id == SubstrateOptionsProvider.feeAssetId) { + fixedPoolData.copy( + user = fixedPoolData.user.copy( + basePooled = fixedPoolData.user.basePooled.minus(kxorBalance) + ) + ) + } else { + fixedPoolData.copy( + user = fixedPoolData.user.copy( + basePooled = kxorBalance + ) + ) + } + } + } else { + fixedPoolData + } + } else { + fixedPoolData + } + fixedPoolData } else { null } diff --git a/feature_polkaswap_impl/src/main/java/jp/co/soramitsu/feature_polkaswap_impl/presentation/screens/swap/SwapViewModel.kt b/feature_polkaswap_impl/src/main/java/jp/co/soramitsu/feature_polkaswap_impl/presentation/screens/swap/SwapViewModel.kt index eb0923163..69aeef3d5 100644 --- a/feature_polkaswap_impl/src/main/java/jp/co/soramitsu/feature_polkaswap_impl/presentation/screens/swap/SwapViewModel.kt +++ b/feature_polkaswap_impl/src/main/java/jp/co/soramitsu/feature_polkaswap_impl/presentation/screens/swap/SwapViewModel.kt @@ -43,6 +43,9 @@ import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject import java.math.BigDecimal import jp.co.soramitsu.androidfoundation.coroutine.SuspendableProperty +import jp.co.soramitsu.androidfoundation.format.isZero +import jp.co.soramitsu.androidfoundation.format.nullZero +import jp.co.soramitsu.androidfoundation.format.orZero import jp.co.soramitsu.androidfoundation.fragment.SingleLiveEvent import jp.co.soramitsu.androidfoundation.fragment.trigger import jp.co.soramitsu.androidfoundation.resource.ResourceManager @@ -57,10 +60,7 @@ import jp.co.soramitsu.common.domain.subtractFee import jp.co.soramitsu.common.presentation.compose.states.ButtonState import jp.co.soramitsu.common.presentation.viewmodel.BaseViewModel import jp.co.soramitsu.common.util.NumbersFormatter -import jp.co.soramitsu.common.util.ext.isZero import jp.co.soramitsu.common.util.ext.lazyAsync -import jp.co.soramitsu.common.util.ext.nullZero -import jp.co.soramitsu.common.util.ext.orZero import jp.co.soramitsu.common.view.ViewHelper import jp.co.soramitsu.common_wallet.domain.model.WithDesired import jp.co.soramitsu.common_wallet.presentation.compose.util.AmountFormat diff --git a/feature_polkaswap_impl/src/test/java/jp/co/soramitsu/feature_polkaswap_impl/presentation/polkaswap/liquidity/add/AddLiquidityViewModelTest.kt b/feature_polkaswap_impl/src/test/java/jp/co/soramitsu/feature_polkaswap_impl/presentation/polkaswap/liquidity/add/AddLiquidityViewModelTest.kt index a0dfe801c..f04a0a01d 100644 --- a/feature_polkaswap_impl/src/test/java/jp/co/soramitsu/feature_polkaswap_impl/presentation/polkaswap/liquidity/add/AddLiquidityViewModelTest.kt +++ b/feature_polkaswap_impl/src/test/java/jp/co/soramitsu/feature_polkaswap_impl/presentation/polkaswap/liquidity/add/AddLiquidityViewModelTest.kt @@ -35,12 +35,12 @@ package jp.co.soramitsu.feature_polkaswap_impl.presentation.polkaswap.liquidity. import androidx.arch.core.executor.testing.InstantTaskExecutorRule import io.mockk.mockkObject import java.math.BigDecimal +import jp.co.soramitsu.androidfoundation.format.equalTo import jp.co.soramitsu.androidfoundation.resource.ResourceManager import jp.co.soramitsu.common.R import jp.co.soramitsu.common.domain.CoroutineManager import jp.co.soramitsu.common.logger.FirebaseWrapper import jp.co.soramitsu.common.util.NumbersFormatter -import jp.co.soramitsu.common.util.ext.equalTo import jp.co.soramitsu.common_wallet.domain.model.LiquidityData import jp.co.soramitsu.feature_assets_api.domain.AssetsInteractor import jp.co.soramitsu.feature_assets_api.presentation.AssetsRouter 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 9735cc7d5..db0d8c859 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 @@ -34,10 +34,10 @@ package jp.co.soramitsu.feature_polkaswap_impl.presentation.polkaswap.liquidity. import androidx.arch.core.executor.testing.InstantTaskExecutorRule import java.math.BigDecimal +import jp.co.soramitsu.androidfoundation.format.equalTo import jp.co.soramitsu.androidfoundation.resource.ResourceManager import jp.co.soramitsu.common.R 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 diff --git a/feature_referral_impl/src/main/java/jp/co/soramitsu/feature_referral_impl/presentation/ReferralViewModel.kt b/feature_referral_impl/src/main/java/jp/co/soramitsu/feature_referral_impl/presentation/ReferralViewModel.kt index 1b2156358..ca939b342 100644 --- a/feature_referral_impl/src/main/java/jp/co/soramitsu/feature_referral_impl/presentation/ReferralViewModel.kt +++ b/feature_referral_impl/src/main/java/jp/co/soramitsu/feature_referral_impl/presentation/ReferralViewModel.kt @@ -38,6 +38,7 @@ import androidx.lifecycle.viewModelScope import dagger.hilt.android.lifecycle.HiltViewModel import java.math.BigDecimal import javax.inject.Inject +import jp.co.soramitsu.androidfoundation.format.orZero import jp.co.soramitsu.androidfoundation.fragment.SingleLiveEvent import jp.co.soramitsu.androidfoundation.resource.ResourceManager import jp.co.soramitsu.common.R @@ -48,7 +49,6 @@ import jp.co.soramitsu.common.presentation.compose.components.initSmallTitle2 import jp.co.soramitsu.common.presentation.viewmodel.BaseViewModel import jp.co.soramitsu.common.util.NumbersFormatter import jp.co.soramitsu.common.util.ext.lazyAsync -import jp.co.soramitsu.common.util.ext.orZero import jp.co.soramitsu.feature_assets_api.domain.AssetsInteractor import jp.co.soramitsu.feature_assets_api.presentation.AssetsRouter import jp.co.soramitsu.feature_main_api.launcher.MainRouter