Search in sources :

Example 6 with Cw20Assets

use of wannabit.io.cosmostaion.dao.Cw20Assets in project cosmostation-android by cosmostation.

the class WDp method allAssetToUserCurrency.

public static BigDecimal allAssetToUserCurrency(BaseChain baseChain, BaseData baseData) {
    BigDecimal totalValue = BigDecimal.ZERO;
    if (isGRPC(baseChain)) {
        for (Coin coin : baseData.mGrpcBalance) {
            if (coin.denom.equals(mainDenom(baseChain))) {
                BigDecimal amount = baseData.getAllMainAsset(mainDenom(baseChain));
                BigDecimal assetValue = userCurrencyValue(baseData, coin.denom, amount, mainDivideDecimal(baseChain));
                totalValue = totalValue.add(assetValue);
            } else if (baseChain.equals(COSMOS_MAIN) && coin.denom.startsWith("pool")) {
                BigDecimal amount = baseData.getAvailable(coin.denom);
                BigDecimal assetValue = userCurrencyValue(baseData, coin.denom, amount, 6);
                totalValue = totalValue.add(assetValue);
            } else if (baseChain.equals(OSMOSIS_MAIN) && coin.denom.equals(TOKEN_ION) || baseChain.equals(CRESCENT_MAIN) && coin.denom.equals(TOKEN_BCRE) || baseChain.equals(NYX_MAIN) && coin.denom.equals(TOKEN_NYM)) {
                BigDecimal amount = baseData.getAvailable(coin.denom);
                BigDecimal assetValue = userCurrencyValue(baseData, coin.denom, amount, 6);
                totalValue = totalValue.add(assetValue);
            } else if (baseChain.equals(OSMOSIS_MAIN) && coin.denom.contains("gamm/pool")) {
                BigDecimal amount = baseData.getAvailable(coin.denom);
                BigDecimal assetValue = userCurrencyValue(baseData, coin.denom, amount, 18);
                totalValue = totalValue.add(assetValue);
            } else if (baseChain.equals(SIF_MAIN) && coin.denom.startsWith("c")) {
                BigDecimal amount = baseData.getAvailable(coin.denom);
                int decimal = WUtil.getSifCoinDecimal(baseData, coin.denom);
                BigDecimal assetValue = userCurrencyValue(baseData, coin.denom.substring(1), amount, decimal);
                totalValue = totalValue.add(assetValue);
            } else if (baseChain.equals(EMONEY_MAIN) || coin.denom.startsWith("e")) {
                BigDecimal available = baseData.getAvailable(coin.denom);
                totalValue = totalValue.add(userCurrencyValue(baseData, coin.denom, available, 6));
            } else if (baseChain.equals(KAVA_MAIN) && !coin.isIbc()) {
                BigDecimal amount = baseData.getAvailable(coin.denom);
                amount = amount.add(baseData.getVesting(coin.denom));
                String kavaDenom = WDp.getKavaBaseDenom(coin.denom);
                int kavaDecimal = WUtil.getKavaCoinDecimal(baseData, coin.denom);
                BigDecimal assetValue = userCurrencyValue(baseData, kavaDenom, amount, kavaDecimal);
                totalValue = totalValue.add(assetValue);
            } else if (baseChain.equals(GRABRIDGE_MAIN) && coin.denom.startsWith("gravity")) {
                Assets assets = baseData.getAsset(coin.denom);
                BigDecimal available = baseData.getAvailable(assets.denom);
                totalValue = totalValue.add(userCurrencyValue(baseData, assets.origin_symbol, available, assets.decimal));
            } else if (baseChain.equals(INJ_MAIN) && coin.denom.startsWith("peggy")) {
                Assets assets = baseData.getAsset(coin.denom);
                BigDecimal available = baseData.getAvailable(assets.denom);
                totalValue = totalValue.add(userCurrencyValue(baseData, assets.origin_symbol, available, assets.decimal));
            } else if (coin.isIbc()) {
                BigDecimal amount = baseData.getAvailable(coin.denom);
                IbcToken ibcToken = baseData.getIbcToken(coin.denom);
                if (ibcToken != null && ibcToken.auth) {
                    BigDecimal assetValue = userCurrencyValue(baseData, ibcToken.base_denom, amount, ibcToken.decimal);
                    totalValue = totalValue.add(assetValue);
                }
            }
        }
        if (baseData.getCw20sGrpc(baseChain).size() > 0) {
            for (Cw20Assets assets : baseData.getCw20sGrpc(baseChain)) {
                BigDecimal amount = assets.getAmount();
                totalValue = totalValue.add(userCurrencyValue(baseData, assets.denom, amount, assets.decimal));
            }
        }
    } else if (baseChain.equals(BNB_MAIN)) {
        for (Balance balance : baseData.mBalances) {
            if (balance.symbol.equals(mainDenom(baseChain))) {
                BigDecimal amount = baseData.getAllBnbTokenAmount(balance.symbol);
                BigDecimal assetValue = userCurrencyValue(baseData, TOKEN_BNB, amount, mainDivideDecimal(baseChain));
                totalValue = totalValue.add(assetValue);
            } else {
                BigDecimal amount = baseData.getAllBnbTokenAmount(balance.symbol);
                BigDecimal convertAmount = WUtil.getBnbConvertAmount(baseData, balance.symbol, amount);
                BigDecimal assetValue = userCurrencyValue(baseData, TOKEN_BNB, convertAmount, mainDivideDecimal(baseChain));
                totalValue = totalValue.add(assetValue);
            }
        }
    } else if (baseChain.equals(OKEX_MAIN)) {
        for (Balance balance : baseData.mBalances) {
            if (balance.symbol.equals(mainDenom(baseChain))) {
                BigDecimal amount = baseData.getAllExToken(balance.symbol);
                BigDecimal assetValue = userCurrencyValue(baseData, TOKEN_OK, amount, mainDivideDecimal(baseChain));
                totalValue = totalValue.add(assetValue);
            } else {
                BigDecimal convertAmount = convertTokenToOkt(baseData, balance.symbol);
                BigDecimal assetValue = userCurrencyValue(baseData, TOKEN_OK, convertAmount, mainDivideDecimal(baseChain));
                totalValue = totalValue.add(assetValue);
            }
        }
    } else {
        for (Balance balance : baseData.mBalances) {
            if (balance.symbol.equals(mainDenom(baseChain))) {
                BigDecimal amount = baseData.getAllMainAssetOld(balance.symbol);
                BigDecimal assetValue = userCurrencyValue(baseData, balance.symbol, amount, mainDivideDecimal(baseChain));
                totalValue = totalValue.add(assetValue);
            } else {
            }
        }
    }
    return totalValue;
}
Also used : Coin(wannabit.io.cosmostaion.model.type.Coin) IbcToken(wannabit.io.cosmostaion.dao.IbcToken) Assets(wannabit.io.cosmostaion.dao.Assets) Cw20Assets(wannabit.io.cosmostaion.dao.Cw20Assets) Cw20Assets(wannabit.io.cosmostaion.dao.Cw20Assets) SpannableString(android.text.SpannableString) Balance(wannabit.io.cosmostaion.dao.Balance) BigDecimal(java.math.BigDecimal)

Aggregations

Cw20Assets (wannabit.io.cosmostaion.dao.Cw20Assets)6 SpannableString (android.text.SpannableString)4 IbcToken (wannabit.io.cosmostaion.dao.IbcToken)4 BalancerPool (osmosis.gamm.poolmodels.balancer.BalancerPool)2 Balance (wannabit.io.cosmostaion.dao.Balance)2 Coin (wannabit.io.cosmostaion.model.type.Coin)2 Intent (android.content.Intent)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 CardView (androidx.cardview.widget.CardView)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 Any (com.google.protobuf2.Any)1 CoinOuterClass (cosmos.base.v1beta1.CoinOuterClass)1 Distribution (cosmos.distribution.v1beta1.Distribution)1 Staking (cosmos.staking.v1beta1.Staking)1 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 QueryOuterClass (kava.pricefeed.v1beta1.QueryOuterClass)1