use of wannabit.io.cosmostaion.model.type.Coin in project cosmostation-android by cosmostation.
the class ResLcdVestingAccountInfo method getCalcurateAmount.
public BigDecimal getCalcurateAmount(String denom, int position) {
BigDecimal result = BigDecimal.ZERO;
VestingPeriod period = getCalcurateVestingByDenom(denom).get(position);
for (Coin coin : period.amount) {
if (coin.denom.equals(denom)) {
result = new BigDecimal(coin.amount);
}
}
return result;
}
use of wannabit.io.cosmostaion.model.type.Coin 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.model.type.Coin 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.model.type.Coin in project cosmostation-android by cosmostation.
the class HtlcResultActivity method onUpdateClaimView.
private void onUpdateClaimView() {
CardView cardClaim = findViewById(R.id.card_claim);
ImageView iconImg = cardClaim.findViewById(R.id.claim_icon);
ImageView statusImg = cardClaim.findViewById(R.id.claim_status_img);
TextView statusTv = cardClaim.findViewById(R.id.claim_status);
TextView errorTv = cardClaim.findViewById(R.id.claim_fail_msg);
TextView blockHeightTv = cardClaim.findViewById(R.id.claim_block_height);
TextView txHashTv = cardClaim.findViewById(R.id.claim_hash);
TextView memoTv = cardClaim.findViewById(R.id.claim_tx_memo);
TextView claimAmount = cardClaim.findViewById(R.id.claim_amount);
TextView claimDenom = cardClaim.findViewById(R.id.claim_amount_denom);
TextView feeAmount = cardClaim.findViewById(R.id.claim_fee);
TextView feeDenom = cardClaim.findViewById(R.id.claim_fee_denom);
TextView claimerTv = cardClaim.findViewById(R.id.claimer_addr);
TextView randomNumberTv = cardClaim.findViewById(R.id.claim_random_number);
TextView swapIdTv = cardClaim.findViewById(R.id.claim_swap_id);
iconImg.setColorFilter(WDp.getChainColor(getBaseContext(), mRecipientChain), android.graphics.PorterDuff.Mode.SRC_IN);
if (mRecipientChain.equals(BaseChain.BNB_MAIN) && mResReceiveBnbTxInfo != null) {
final Msg msg = mResReceiveBnbTxInfo.tx.value.msg.get(0);
if (mResReceiveBnbTxInfo.ok) {
statusImg.setImageDrawable(getResources().getDrawable(R.drawable.success_ic));
statusTv.setText(R.string.str_success_c);
} else {
statusImg.setImageDrawable(getResources().getDrawable(R.drawable.fail_ic));
statusTv.setText(R.string.str_failed_c);
errorTv.setText(mResReceiveBnbTxInfo.log);
errorTv.setVisibility(View.VISIBLE);
}
blockHeightTv.setText(mResReceiveBnbTxInfo.height);
txHashTv.setText(mResReceiveBnbTxInfo.hash);
memoTv.setText(mResReceiveBnbTxInfo.tx.value.memo);
claimDenom.setText("");
claimAmount.setText("");
WDp.DpMainDenom(getBaseContext(), mRecipientChain.getChain(), feeDenom);
feeAmount.setText(WDp.getDpAmount2(getBaseContext(), new BigDecimal(FEE_BNB_SEND), 0, 8));
claimerTv.setText(msg.value.from);
randomNumberTv.setText(msg.value.random_number);
swapIdTv.setText(msg.value.swap_id);
} else if (mResReceiveTxInfo != null) {
if (mRecipientChain.equals(BaseChain.KAVA_MAIN)) {
final Msg msg = mResReceiveTxInfo.tx.value.msg.get(0);
if (mResReceiveTxInfo.isSuccess()) {
statusImg.setImageDrawable(getResources().getDrawable(R.drawable.success_ic));
statusTv.setText(R.string.str_success_c);
} else {
statusImg.setImageDrawable(getResources().getDrawable(R.drawable.fail_ic));
statusTv.setText(R.string.str_failed_c);
errorTv.setText(mResReceiveTxInfo.failMessage());
errorTv.setVisibility(View.VISIBLE);
}
blockHeightTv.setText(mResReceiveTxInfo.height);
txHashTv.setText(mResReceiveTxInfo.txhash);
memoTv.setText(mResReceiveTxInfo.tx.value.memo);
Coin receiveCoin = mResReceiveTxInfo.simpleSwapCoin();
try {
if (!TextUtils.isEmpty(receiveCoin.denom)) {
WDp.showCoinDp(getBaseContext(), getBaseDao(), receiveCoin, claimDenom, claimAmount, mRecipientChain);
} else {
claimDenom.setText("");
claimAmount.setText("");
}
} catch (Exception e) {
claimDenom.setText("");
claimAmount.setText("");
}
WDp.DpMainDenom(getBaseContext(), mRecipientChain.getChain(), feeDenom);
feeAmount.setText(WDp.getDpAmount2(getBaseContext(), mResReceiveTxInfo.simpleFee(), 6, 6));
claimerTv.setText(msg.value.from);
randomNumberTv.setText(msg.value.random_number);
swapIdTv.setText(msg.value.swap_id);
}
}
}
use of wannabit.io.cosmostaion.model.type.Coin in project cosmostation-android by cosmostation.
the class HtlcResultActivity method onUpdateSendView.
private void onUpdateSendView() {
CardView cardSend = findViewById(R.id.card_send);
ImageView iconImg = cardSend.findViewById(R.id.send_icon);
ImageView statusImg = cardSend.findViewById(R.id.send_status_img);
TextView statusTv = cardSend.findViewById(R.id.send_status);
TextView errorTv = cardSend.findViewById(R.id.send_fail_msg);
TextView blockHeightTv = cardSend.findViewById(R.id.send_block_height);
TextView txHashTv = cardSend.findViewById(R.id.send_hash);
TextView memoTv = cardSend.findViewById(R.id.send_tx_memo);
TextView sendAmount = cardSend.findViewById(R.id.send_amount);
TextView sendDenom = cardSend.findViewById(R.id.send_amount_denom);
TextView feeAmount = cardSend.findViewById(R.id.send_fee);
TextView feeDenom = cardSend.findViewById(R.id.send_fee_denom);
TextView senderTv = cardSend.findViewById(R.id.sender_addr);
TextView relayRecipientTv = cardSend.findViewById(R.id.relay_recipient_addr);
TextView relaySenderTv = cardSend.findViewById(R.id.relay_sender_addr);
TextView recipientTv = cardSend.findViewById(R.id.recipient_addr);
TextView randomHashTv = cardSend.findViewById(R.id.random_hash);
iconImg.setColorFilter(WDp.getChainColor(getBaseContext(), mBaseChain), android.graphics.PorterDuff.Mode.SRC_IN);
if (mBaseChain.equals(BaseChain.BNB_MAIN) && mResSendBnbTxInfo != null) {
final Msg msg = mResSendBnbTxInfo.tx.value.msg.get(0);
if (mResSendBnbTxInfo.ok) {
statusImg.setImageDrawable(getResources().getDrawable(R.drawable.success_ic));
statusTv.setText(R.string.str_success_c);
} else {
statusImg.setImageDrawable(getResources().getDrawable(R.drawable.fail_ic));
statusTv.setText(R.string.str_failed_c);
errorTv.setText(mResSendBnbTxInfo.log);
errorTv.setVisibility(View.VISIBLE);
}
blockHeightTv.setText(mResSendBnbTxInfo.height);
txHashTv.setText(mResSendBnbTxInfo.hash);
memoTv.setText(mResSendBnbTxInfo.tx.value.memo);
Coin sendCoin = WDp.getCoins(msg.value.amount).get(0);
WDp.showCoinDp(getBaseContext(), getBaseDao(), sendCoin, sendDenom, sendAmount, mBaseChain);
WDp.DpMainDenom(getBaseContext(), mBaseChain.getChain(), feeDenom);
feeAmount.setText(WDp.getDpAmount2(getBaseContext(), new BigDecimal(FEE_BNB_SEND), 0, 8));
senderTv.setText(msg.value.from);
relayRecipientTv.setText(msg.value.to);
relaySenderTv.setText(msg.value.sender_other_chain);
recipientTv.setText(msg.value.recipient_other_chain);
randomHashTv.setText(msg.value.random_number_hash);
} else if ((mBaseChain.equals(BaseChain.KAVA_MAIN)) && mResSendTxInfo != null) {
final Msg msg = mResSendTxInfo.tx.value.msg.get(0);
if (mResSendTxInfo.isSuccess()) {
statusImg.setImageDrawable(getResources().getDrawable(R.drawable.success_ic));
statusTv.setText(R.string.str_success_c);
} else {
statusImg.setImageDrawable(getResources().getDrawable(R.drawable.fail_ic));
statusTv.setText(R.string.str_failed_c);
errorTv.setText(mResSendTxInfo.failMessage());
errorTv.setVisibility(View.VISIBLE);
}
blockHeightTv.setText(mResSendTxInfo.height);
txHashTv.setText(mResSendTxInfo.txhash);
memoTv.setText(mResSendTxInfo.tx.value.memo);
Coin sendCoin = WDp.getCoins(msg.value.amount).get(0);
sendDenom.setText(sendCoin.denom.toUpperCase());
sendAmount.setText(WDp.getDpAmount2(this, new BigDecimal(sendCoin.amount), WUtil.getKavaCoinDecimal(getBaseDao(), sendCoin.denom), WUtil.getKavaCoinDecimal(getBaseDao(), sendCoin.denom)));
WDp.DpMainDenom(getBaseContext(), mBaseChain.getChain(), feeDenom);
feeAmount.setText(WDp.getDpAmount2(getBaseContext(), mResSendTxInfo.simpleFee(), 6, 6));
senderTv.setText(msg.value.from);
relayRecipientTv.setText(msg.value.to);
relaySenderTv.setText(msg.value.sender_other_chain);
recipientTv.setText(msg.value.recipient_other_chain);
randomHashTv.setText(msg.value.random_number_hash);
}
}
Aggregations