Search in sources :

Example 6 with Lock

use of osmosis.lockup.Lock in project cosmostation-android by cosmostation.

the class EarningMyHolder method onBindView.

public void onBindView(Context c, BaseActivity activity, BaseData baseData, BalancerPoolOuterClass.BalancerPool pool, ArrayList<Lock.PeriodLock> lockups, ArrayList<GaugeOuterClass.Gauge> gauges) {
    Coin coin0 = new Coin(pool.getPoolAssets(0).getToken().getDenom(), pool.getPoolAssets(0).getToken().getAmount());
    Coin coin1 = new Coin(pool.getPoolAssets(1).getToken().getDenom(), pool.getPoolAssets(1).getToken().getAmount());
    BigDecimal lpCoinPrice = WUtil.getOsmoLpTokenPerUsdPrice(baseData, pool);
    BigDecimal apr = WUtil.getPoolArp(baseData, pool, gauges, 2);
    BigDecimal totalShare = new BigDecimal(pool.getTotalShares().getAmount());
    itemPoolId.setText("#" + pool.getId() + " MY EARNING");
    itemPoolCoinPair.setText(WUtil.dpOsmosisTokenName(baseData, coin0.denom) + " / " + WUtil.dpOsmosisTokenName(baseData, coin1.denom));
    itemPoolApr.setText(WDp.getPercentDp(apr));
    // pool incentives
    BigDecimal incentive1Day = WUtil.getNextIncentiveAmount(gauges, 0);
    BigDecimal incentive7Day = WUtil.getNextIncentiveAmount(gauges, 1);
    BigDecimal incentive14Day = WUtil.getNextIncentiveAmount(gauges, 2);
    // display lock
    BigDecimal bondedAmount = BigDecimal.ZERO;
    BigDecimal unbondingAmount = BigDecimal.ZERO;
    BigDecimal unbondedAmount = BigDecimal.ZERO;
    BigDecimal myRewards = BigDecimal.ZERO;
    for (Lock.PeriodLock lockup : lockups) {
        Coin lpCoin = new Coin(lockup.getCoins(0).getDenom(), lockup.getCoins(0).getAmount());
        BigDecimal myShare = new BigDecimal(lpCoin.amount);
        BigDecimal myShareRate = myShare.divide(totalShare, 24, RoundingMode.DOWN);
        long now = new Date().getTime();
        long day7 = now + 604800000;
        long endTime = lockup.getEndTime().getSeconds() * 1000;
        if (endTime == -62135596800000l) {
            bondedAmount = bondedAmount.add(new BigDecimal(lpCoin.amount));
            if (lockup.getDuration().getSeconds() == 86400) {
                myRewards = myRewards.add(myShareRate.multiply(incentive1Day));
            } else if (lockup.getDuration().getSeconds() == 604800) {
                myRewards = myRewards.add(myShareRate.multiply(incentive7Day));
            } else if (lockup.getDuration().getSeconds() == 1209600) {
                myRewards = myRewards.add(myShareRate.multiply(incentive14Day));
            }
        } else if (endTime > now) {
            unbondingAmount = unbondingAmount.add(new BigDecimal(lpCoin.amount));
            if (lockup.getEndTime().getSeconds() > day7) {
                myRewards = myRewards.add(myShareRate.multiply(incentive7Day));
            } else {
                myRewards = myRewards.add(myShareRate.multiply(incentive1Day));
            }
        } else {
            unbondedAmount = unbondedAmount.add(new BigDecimal(lpCoin.amount));
            myRewards = myRewards.add(myShareRate.multiply(incentive1Day));
        }
    }
    itemBondedAmount.setText(WDp.getDpAmount2(c, bondedAmount, 18, 6));
    itemBondedDenom.setText("GAMM-" + pool.getId());
    itemUnBondingAmount.setText(WDp.getDpAmount2(c, unbondingAmount, 18, 6));
    itemUnBondingDenom.setText("GAMM-" + pool.getId());
    itemUnBondedAmount.setText(WDp.getDpAmount2(c, unbondedAmount, 18, 6));
    itemUnBondedDenom.setText("GAMM-" + pool.getId());
    BigDecimal bonedCoinValue = bondedAmount.multiply(lpCoinPrice).movePointLeft(18).setScale(2, RoundingMode.DOWN);
    itemBondedValue.setText(WDp.getDpRawDollor(c, bonedCoinValue, 2));
    BigDecimal unbondingCoinValue = unbondingAmount.multiply(lpCoinPrice).movePointLeft(18).setScale(2, RoundingMode.DOWN);
    itemUnBondingValue.setText(WDp.getDpRawDollor(c, unbondingCoinValue, 2));
    BigDecimal unbondedCoinValue = unbondedAmount.multiply(lpCoinPrice).movePointLeft(18).setScale(2, RoundingMode.DOWN);
    itemUnBondedValue.setText(WDp.getDpRawDollor(c, unbondedCoinValue, 2));
    // display available
    BigDecimal availableAmount = baseData.getAvailable("gamm/pool/" + pool.getId());
    BigDecimal availableValue = availableAmount.multiply(lpCoinPrice).movePointLeft(18).setScale(2, RoundingMode.DOWN);
    itemAvailableAmount.setText(WDp.getDpAmount2(c, availableAmount, 18, 6));
    itemAvailableDenom.setText("GAMM-" + pool.getId());
    itemAvailableValue.setText(WDp.getDpRawDollor(c, availableValue, 2));
    // display reward
    itemRewardAmount.setText(WDp.getDpAmount2(c, myRewards, 6, 6));
    itemRoot.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Intent intent = new Intent(activity, EarningDetailActivity.class);
            intent.putExtra("osmosisPool", pool.toByteArray());
            OsmosisGaugeWrapper gaugesWrapper = new OsmosisGaugeWrapper(gauges);
            intent.putExtra("osmosisGauges", gaugesWrapper);
            OsmosisPeriodLockWrapper lockupsWrapper = new OsmosisPeriodLockWrapper(lockups);
            intent.putExtra("osmosislockups", lockupsWrapper);
            activity.startActivity(intent);
        }
    });
}
Also used : EarningDetailActivity(wannabit.io.cosmostaion.activities.chains.osmosis.EarningDetailActivity) Intent(android.content.Intent) TextView(android.widget.TextView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) CardView(androidx.cardview.widget.CardView) BigDecimal(java.math.BigDecimal) Date(java.util.Date) Lock(osmosis.lockup.Lock) Coin(wannabit.io.cosmostaion.model.type.Coin) OsmosisGaugeWrapper(wannabit.io.cosmostaion.utils.OsmosisGaugeWrapper) OsmosisPeriodLockWrapper(wannabit.io.cosmostaion.utils.OsmosisPeriodLockWrapper)

Aggregations

Lock (osmosis.lockup.Lock)6 OsmosisPeriodLockWrapper (wannabit.io.cosmostaion.utils.OsmosisPeriodLockWrapper)6 View (android.view.View)4 TextView (android.widget.TextView)4 BigDecimal (java.math.BigDecimal)4 ArrayList (java.util.ArrayList)4 Intent (android.content.Intent)2 Button (android.widget.Button)2 CardView (androidx.cardview.widget.CardView)2 RecyclerView (androidx.recyclerview.widget.RecyclerView)2 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)2 Date (java.util.Date)2 EarningDetailActivity (wannabit.io.cosmostaion.activities.chains.osmosis.EarningDetailActivity)2 Coin (wannabit.io.cosmostaion.model.type.Coin)2 OsmosisGaugeWrapper (wannabit.io.cosmostaion.utils.OsmosisGaugeWrapper)2