use of wannabit.io.cosmostaion.dao.Balance in project cosmostation-android by cosmostation.
the class WUtil method getBalancesFromKavaLcd.
public static ArrayList<Balance> getBalancesFromKavaLcd(long accountId, ResLcdKavaAccountInfo lcd) {
long time = System.currentTimeMillis();
ArrayList<Balance> result = new ArrayList<>();
if (lcd != null && lcd.result != null && lcd.height != null) {
if (lcd.result.type.equals(COSMOS_AUTH_TYPE_ACCOUNT)) {
if (lcd.result.value.coins != null && lcd.result.value.coins.size() > 0) {
for (Coin coin : lcd.result.value.coins) {
Balance temp = new Balance();
temp.accountId = accountId;
temp.symbol = coin.denom;
temp.balance = new BigDecimal(coin.amount);
temp.fetchTime = time;
result.add(temp);
}
}
return result;
} else if (lcd.result.type.equals(BaseConstant.COSMOS_AUTH_TYPE_VESTING_ACCOUNT) || lcd.result.type.equals(COSMOS_AUTH_TYPE_P_VESTING_ACCOUNT)) {
BigDecimal dpBalance = BigDecimal.ZERO;
BigDecimal dpVesting = BigDecimal.ZERO;
BigDecimal originalVesting = BigDecimal.ZERO;
BigDecimal remainVesting = BigDecimal.ZERO;
BigDecimal delegatedVesting = BigDecimal.ZERO;
if (lcd.result.value.coins != null && lcd.result.value.coins.size() > 0) {
for (Coin coin : lcd.result.value.coins) {
if (coin.denom.equals(TOKEN_KAVA)) {
dpBalance = BigDecimal.ZERO;
dpVesting = BigDecimal.ZERO;
originalVesting = BigDecimal.ZERO;
remainVesting = BigDecimal.ZERO;
delegatedVesting = BigDecimal.ZERO;
dpBalance = new BigDecimal(coin.amount);
if (lcd.result.value.original_vesting != null && lcd.result.value.original_vesting.size() > 0) {
for (Coin vesting : lcd.result.value.original_vesting) {
if (vesting.denom.equals(TOKEN_KAVA)) {
originalVesting = originalVesting.add(new BigDecimal(vesting.amount));
}
}
}
if (lcd.result.value.delegated_vesting != null && lcd.result.value.delegated_vesting.size() > 0) {
for (Coin vesting : lcd.result.value.delegated_vesting) {
if (vesting.denom.equals(TOKEN_KAVA)) {
delegatedVesting = delegatedVesting.add(new BigDecimal(vesting.amount));
}
}
}
WLog.w("kava dpBalance " + dpBalance);
WLog.w("kava originalVesting " + originalVesting);
WLog.w("kava delegatedVesting " + delegatedVesting);
remainVesting = lcd.result.value.getCalcurateVestingAmountSumByDenom(TOKEN_KAVA);
WLog.w("kava remainVesting " + remainVesting);
dpVesting = remainVesting.subtract(delegatedVesting);
WLog.w("kava dpVesting " + dpVesting);
if (dpVesting.compareTo(BigDecimal.ZERO) <= 0) {
dpVesting = BigDecimal.ZERO;
}
WLog.w("kava dpVesting1 " + dpVesting);
if (remainVesting.compareTo(delegatedVesting) > 0) {
dpBalance = dpBalance.subtract(remainVesting).add(delegatedVesting);
}
WLog.w("kava dpBalancee " + dpBalance);
Balance temp = new Balance();
temp.accountId = accountId;
temp.symbol = TOKEN_KAVA;
temp.balance = dpBalance;
temp.frozen = delegatedVesting;
temp.locked = dpVesting;
temp.fetchTime = time;
result.add(temp);
} else if (coin.denom.equals(TOKEN_HARD)) {
dpBalance = BigDecimal.ZERO;
dpVesting = BigDecimal.ZERO;
originalVesting = BigDecimal.ZERO;
remainVesting = BigDecimal.ZERO;
delegatedVesting = BigDecimal.ZERO;
dpBalance = new BigDecimal(coin.amount);
if (lcd.result.value.original_vesting != null && lcd.result.value.original_vesting.size() > 0) {
for (Coin vesting : lcd.result.value.original_vesting) {
if (vesting.denom.equals(TOKEN_HARD)) {
originalVesting = originalVesting.add(new BigDecimal(vesting.amount));
}
}
}
WLog.w("hard dpBalance " + dpBalance);
WLog.w("hard originalVesting " + originalVesting);
remainVesting = lcd.result.value.getCalcurateVestingAmountSumByDenom(TOKEN_HARD);
dpBalance = dpBalance.subtract(remainVesting);
WLog.w("hard dpBalancee " + dpBalance);
Balance temp = new Balance();
temp.accountId = accountId;
temp.symbol = coin.denom;
temp.balance = dpBalance;
temp.locked = remainVesting;
temp.fetchTime = time;
result.add(temp);
} else if (coin.denom.equals(TOKEN_SWP)) {
dpBalance = BigDecimal.ZERO;
dpVesting = BigDecimal.ZERO;
originalVesting = BigDecimal.ZERO;
remainVesting = BigDecimal.ZERO;
delegatedVesting = BigDecimal.ZERO;
dpBalance = new BigDecimal(coin.amount);
if (lcd.result.value.original_vesting != null && lcd.result.value.original_vesting.size() > 0) {
for (Coin vesting : lcd.result.value.original_vesting) {
if (vesting.denom.equals(TOKEN_SWP)) {
originalVesting = originalVesting.add(new BigDecimal(vesting.amount));
}
}
}
WLog.w("TOKEN_SWP dpBalance " + dpBalance);
WLog.w("TOKEN_SWP originalVesting " + originalVesting);
remainVesting = lcd.result.value.getCalcurateVestingAmountSumByDenom(TOKEN_SWP);
dpBalance = dpBalance.subtract(remainVesting);
WLog.w("TOKEN_SWP dpBalancee " + dpBalance);
Balance temp = new Balance();
temp.accountId = accountId;
temp.symbol = coin.denom;
temp.balance = dpBalance;
temp.locked = remainVesting;
temp.fetchTime = time;
result.add(temp);
} else {
Balance temp = new Balance();
temp.accountId = accountId;
temp.symbol = coin.denom;
temp.balance = new BigDecimal(coin.amount);
temp.fetchTime = time;
result.add(temp);
}
}
}
}
}
return result;
}
use of wannabit.io.cosmostaion.dao.Balance in project cosmostation-android by cosmostation.
the class WUtil method getBalancesFromOkLcd.
public static ArrayList<Balance> getBalancesFromOkLcd(long accountId, ResOkAccountToken lcd) {
long time = System.currentTimeMillis();
ArrayList<Balance> result = new ArrayList<>();
if (lcd.data != null && lcd.data.currencies != null && lcd.data.currencies.size() > 0) {
for (ResOkAccountToken.OkCurrency currency : lcd.data.currencies) {
Balance temp = new Balance();
temp.accountId = accountId;
temp.symbol = currency.symbol;
temp.balance = new BigDecimal(currency.available);
temp.locked = new BigDecimal(currency.locked);
temp.fetchTime = time;
result.add(temp);
}
}
return result;
}
use of wannabit.io.cosmostaion.dao.Balance in project cosmostation-android by cosmostation.
the class WDp method allAssetToBtc.
public static BigDecimal allAssetToBtc(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 btcValue = btcValue(baseData, coin.denom, amount, mainDivideDecimal(baseChain));
totalValue = totalValue.add(btcValue);
} else if (baseChain.equals(OSMOSIS_MAIN) && coin.denom.equals(TOKEN_ION)) {
BigDecimal amount = baseData.getAvailable(coin.denom);
BigDecimal btcValue = btcValue(baseData, coin.denom, amount, 6);
totalValue = totalValue.add(btcValue);
} else if (baseChain.equals(SIF_MAIN) && coin.denom.startsWith("c")) {
BigDecimal amount = baseData.getAvailable(coin.denom);
int decimal = WUtil.getSifCoinDecimal(baseData, coin.denom);
BigDecimal btcValue = btcValue(baseData, coin.denom.substring(1), amount, decimal);
totalValue = totalValue.add(btcValue);
} else if (baseChain.equals(KAVA_MAIN)) {
if (coin.denom.equals(mainDenom(baseChain))) {
BigDecimal amount = baseData.getAllMainAsset(coin.denom);
BigDecimal btcValue = btcValue(baseData, TOKEN_KAVA, amount, mainDivideDecimal(baseChain));
totalValue = totalValue.add(btcValue);
} else {
BigDecimal convertAmount = convertTokenToKava(baseData, coin.denom);
BigDecimal btcValue = btcValue(baseData, TOKEN_KAVA, convertAmount, mainDivideDecimal(baseChain));
totalValue = totalValue.add(btcValue);
}
} else if (coin.denom.startsWith("ibc/")) {
BigDecimal amount = baseData.getAvailable(coin.denom);
IbcToken ibcToken = baseData.getIbcToken(coin.denom);
if (ibcToken != null && ibcToken.auth) {
BigDecimal btcValue = btcValue(baseData, ibcToken.base_denom, amount, ibcToken.decimal);
totalValue = totalValue.add(btcValue);
}
}
}
} else if (baseChain.equals(BNB_MAIN)) {
for (Balance balance : baseData.mBalances) {
if (balance.symbol.equals(mainDenom(baseChain))) {
BigDecimal amount = baseData.getAllBnbTokenAmount(balance.symbol);
BigDecimal btcValue = btcValue(baseData, TOKEN_BNB, amount, mainDivideDecimal(baseChain));
totalValue = totalValue.add(btcValue);
} else {
BigDecimal amount = baseData.getAllBnbTokenAmount(balance.symbol);
BigDecimal convertAmount = WUtil.getBnbConvertAmount(baseData, balance.symbol, amount);
BigDecimal btcValue = btcValue(baseData, TOKEN_BNB, convertAmount, mainDivideDecimal(baseChain));
totalValue = totalValue.add(btcValue);
}
}
} else if (baseChain.equals(OKEX_MAIN)) {
for (Balance balance : baseData.mBalances) {
if (balance.symbol.equals(mainDenom(baseChain))) {
BigDecimal amount = baseData.getAllExToken(balance.symbol);
BigDecimal btcValue = btcValue(baseData, TOKEN_OK, amount, mainDivideDecimal(baseChain));
totalValue = totalValue.add(btcValue);
} else {
BigDecimal convertAmount = convertTokenToOkt(baseData, balance.symbol);
BigDecimal btcValue = btcValue(baseData, TOKEN_OK, convertAmount, mainDivideDecimal(baseChain));
totalValue = totalValue.add(btcValue);
}
}
} else {
for (Balance balance : baseData.mBalances) {
if (balance.symbol.equals(mainDenom(baseChain))) {
BigDecimal amount = baseData.getAllMainAssetOld(balance.symbol);
BigDecimal btcValue = btcValue(baseData, balance.symbol, amount, mainDivideDecimal(baseChain));
totalValue = totalValue.add(btcValue);
} else {
}
}
}
return totalValue;
}
use of wannabit.io.cosmostaion.dao.Balance in project cosmostation-android by cosmostation.
the class MainTokensFragment method onUpdateView.
private void onUpdateView() {
final String mainDenom = WDp.mainDenom(getMainActivity().mBaseChain);
mCW20Grpc = getBaseDao().getCw20sGrpc(getMainActivity().mBaseChain);
mNativeGrpc.clear();
mIbcAuthedGrpc.clear();
mPoolGrpc.clear();
mEtherGrpc.clear();
mIbcUnknownGrpc.clear();
mGravityDexGrpc.clear();
mInjectivePoolGrpc.clear();
mKavaBep2Grpc.clear();
mEtcGrpc.clear();
mUnknownGrpc.clear();
for (Coin coin : getBaseDao().mGrpcBalance) {
if (coin.denom.equalsIgnoreCase(mainDenom)) {
mNativeGrpc.add(coin);
} else if (coin.isIbc()) {
final IbcToken ibcToken = getBaseDao().getIbcToken(coin.getIbcHash());
if (ibcToken != null && ibcToken.auth) {
mIbcAuthedGrpc.add(coin);
} else {
mIbcUnknownGrpc.add(coin);
}
} else if (getMainActivity().mBaseChain.equals(OSMOSIS_MAIN) && coin.osmosisAmm() || getMainActivity().mBaseChain.equals(CRESCENT_MAIN) && coin.crescnetPool()) {
mPoolGrpc.add(coin);
} else if (getMainActivity().mBaseChain.equals(OSMOSIS_MAIN) && coin.denom.equalsIgnoreCase(TOKEN_ION) || getMainActivity().mBaseChain.equals(EMONEY_MAIN) && coin.denom.startsWith("e") || getMainActivity().mBaseChain.equals(CRESCENT_MAIN) && coin.denom.equalsIgnoreCase(TOKEN_BCRE) || getMainActivity().mBaseChain.equals(NYX_MAIN) && coin.denom.equalsIgnoreCase(TOKEN_NYM)) {
mNativeGrpc.add(coin);
} else if (getMainActivity().mBaseChain.equals(SIF_MAIN) && coin.denom.startsWith("c") || getMainActivity().mBaseChain.equals(GRABRIDGE_MAIN) && coin.denom.startsWith("gravity") || getMainActivity().mBaseChain.equals(INJ_MAIN) && coin.denom.startsWith("peggy")) {
mEtherGrpc.add(coin);
} else if (getMainActivity().mBaseChain.equals(COSMOS_MAIN) && coin.denom.startsWith("pool")) {
mGravityDexGrpc.add(coin);
} else if (getMainActivity().mBaseChain.equals(INJ_MAIN) && coin.denom.startsWith("share")) {
mInjectivePoolGrpc.add(coin);
} else if (getMainActivity().mBaseChain.equals(KAVA_MAIN)) {
if (coin.denom.equals(TOKEN_HARD) || coin.denom.equalsIgnoreCase(TOKEN_USDX) || coin.denom.equalsIgnoreCase(TOKEN_SWP)) {
mNativeGrpc.add(coin);
} else if (coin.denom.equalsIgnoreCase(TOKEN_HTLC_KAVA_BNB) || coin.denom.equalsIgnoreCase(TOKEN_HTLC_KAVA_BTCB) || coin.denom.equalsIgnoreCase(TOKEN_HTLC_KAVA_XRPB) || coin.denom.equalsIgnoreCase(TOKEN_HTLC_KAVA_BUSD)) {
mKavaBep2Grpc.add(coin);
} else if (coin.denom.equalsIgnoreCase("btch") || coin.denom.equalsIgnoreCase("hbtc")) {
mEtcGrpc.add(coin);
}
} else {
mUnknownGrpc.add(coin);
}
}
mNative.clear();
mEtc.clear();
mUnKnown.clear();
for (Balance balance : getBaseDao().mBalances) {
if (balance.symbol.equalsIgnoreCase(mainDenom)) {
mNative.add(balance);
} else if (getMainActivity().mBaseChain.equals(BNB_MAIN)) {
mEtc.add(balance);
} else if (getMainActivity().mBaseChain.equals(OKEX_MAIN)) {
mEtc.add(balance);
} else {
mUnKnown.add(balance);
}
}
if (isGRPC(getMainActivity().mBaseChain)) {
WUtil.onSortingCoins(mNativeGrpc, getMainActivity().mBaseChain);
WUtil.onSortingGravityPool(mGravityDexGrpc, getBaseDao());
WUtil.onSortingOsmosisPool(getMainActivity().mBaseChain, mPoolGrpc);
WUtil.onSortingInjectivePool(mInjectivePoolGrpc);
} else if (getMainActivity().mBaseChain.equals(BNB_MAIN) || getMainActivity().mBaseChain.equals(OKEX_MAIN)) {
WUtil.onSortingNativeCoins(mEtc, getMainActivity().mBaseChain);
} else {
WUtil.onSortingNativeCoins(mNative, getMainActivity().mBaseChain);
}
if (isGRPC(getMainActivity().mBaseChain)) {
if (getBaseDao().mGrpcBalance != null && getBaseDao().mGrpcBalance.size() > 0) {
mTokensAdapter.notifyDataSetChanged();
mEmptyToken.setVisibility(View.GONE);
mRecyclerView.setVisibility(View.VISIBLE);
} else {
mEmptyToken.setVisibility(View.VISIBLE);
mRecyclerView.setVisibility(View.GONE);
}
} else {
if (getBaseDao().mBalances != null && getBaseDao().mBalances.size() > 0) {
mTokensAdapter.notifyDataSetChanged();
mEmptyToken.setVisibility(View.GONE);
mRecyclerView.setVisibility(View.VISIBLE);
} else {
mEmptyToken.setVisibility(View.VISIBLE);
mRecyclerView.setVisibility(View.GONE);
}
}
}
use of wannabit.io.cosmostaion.dao.Balance in project cosmostation-android by cosmostation.
the class MainTokensFragment method onBindNativeItem.
// with native tokens
private void onBindNativeItem(TokensAdapter.AssetHolder holder, int position) {
final Balance balance = mNative.get(position);
if (getMainActivity().mBaseChain.equals(BNB_MAIN)) {
final String denom = mNative.get(position).symbol;
final BigDecimal amount = getBaseDao().getAllBnbTokenAmount(denom);
final BnbToken bnbToken = getBaseDao().getBnbToken(denom);
if (bnbToken != null) {
holder.itemSymbol.setText(bnbToken.original_symbol.toUpperCase());
holder.itemInnerSymbol.setText("(" + bnbToken.symbol + ")");
holder.itemFullName.setText("Binance Chain Native Coin");
holder.itemImg.setImageDrawable(getResources().getDrawable(R.drawable.bnb_token_img));
holder.itemSymbol.setTextColor(WDp.getChainColor(getContext(), BNB_MAIN));
holder.itemBalance.setText(WDp.getDpAmount2(getContext(), amount, 0, 6));
holder.itemValue.setText(WDp.dpUserCurrencyValue(getBaseDao(), TOKEN_BNB, amount, 0));
}
holder.itemRoot.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getMainActivity(), StakingTokenDetailActivity.class);
startActivity(intent);
}
});
} else if (getMainActivity().mBaseChain.equals(OKEX_MAIN)) {
final OkToken okToken = getBaseDao().okToken(balance.symbol);
holder.itemSymbol.setText(okToken.original_symbol.toUpperCase());
holder.itemInnerSymbol.setText("(" + okToken.symbol + ")");
holder.itemFullName.setText("OKC Staking Coin");
if (balance.symbol.equals(TOKEN_OK)) {
holder.itemSymbol.setTextColor(WDp.getChainColor(getContext(), getMainActivity().mBaseChain));
holder.itemImg.setImageDrawable(getResources().getDrawable(R.drawable.token_okx));
BigDecimal totalAmount = getBaseDao().getAllExToken(balance.symbol);
holder.itemBalance.setText(WDp.getDpAmount2(getContext(), totalAmount, 0, 6));
holder.itemValue.setText(WDp.dpUserCurrencyValue(getBaseDao(), balance.symbol, totalAmount, 0));
}
holder.itemRoot.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getMainActivity(), StakingTokenDetailActivity.class);
startActivity(intent);
}
});
}
}
Aggregations