use of wannabit.io.cosmostaion.dao.Balance in project cosmostation-android by cosmostation.
the class BaseActivity method onTaskResponse.
@Override
public void onTaskResponse(TaskResult result) {
// WLog.w("onTaskResponse " + result.taskType + " " + mTaskCount);
if (isFinishing())
return;
if (result.taskType == BaseConstant.TASK_PUSH_STATUS_UPDATE) {
if (result.isSuccess) {
mAccount = getBaseDao().onUpdatePushEnabled(mAccount, (boolean) result.resultData);
}
invalidateOptionsMenu();
return;
} else if (result.taskType == BaseConstant.TASK_FETCH_PRICE_INFO) {
if (result.isSuccess && result.resultData != null) {
getBaseDao().mPrices.clear();
ArrayList<Price> tempPrice = new ArrayList<>();
tempPrice = (ArrayList<Price>) result.resultData;
for (Price price : tempPrice) {
getBaseDao().mPrices.add(price);
}
}
}
mTaskCount--;
if (result.taskType == BaseConstant.TASK_FETCH_ACCOUNT) {
mAccount = getBaseDao().onSelectAccount(getBaseDao().getLastUser());
getBaseDao().mBalances = getBaseDao().onSelectBalance(mAccount.id);
// WLog.w("getBaseDao().mBalances " + getBaseDao().mBalances.size());
} else if (result.taskType == TASK_FETCH_NODE_INFO) {
getBaseDao().mNodeInfo = (NodeInfo) result.resultData;
mTaskCount = mTaskCount + 1;
new StationParamInfoTask(getBaseApplication(), this, mBaseChain, getBaseDao().getChainId()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} else if (result.taskType == TASK_FETCH_OKEX_ALL_VALIDATORS) {
ArrayList<Validator> allValis = (ArrayList<Validator>) result.resultData;
if (allValis != null) {
getBaseDao().mAllValidators = allValis;
}
} else if (result.taskType == BaseConstant.TASK_FETCH_BNB_TOKENS) {
ArrayList<BnbToken> tempTokens = (ArrayList<BnbToken>) result.resultData;
if (tempTokens != null) {
for (BnbToken token : tempTokens) {
token.type = BnbToken.BNB_TOKEN_TYPE_BEP2;
getBaseDao().mBnbTokens.add(token);
}
}
} else if (result.taskType == BaseConstant.TASK_FETCH_BNB_MINI_TOKENS) {
ArrayList<BnbToken> tempTokens = (ArrayList<BnbToken>) result.resultData;
if (tempTokens != null) {
for (BnbToken token : tempTokens) {
token.type = BnbToken.BNB_TOKEN_TYPE_MINI;
getBaseDao().mBnbTokens.add(token);
}
}
} else if (result.taskType == TASK_FETCH_BNB_TICKER) {
ArrayList<BnbTicker> tempTickers = (ArrayList<BnbTicker>) result.resultData;
if (tempTickers != null) {
getBaseDao().mBnbTickers.addAll(tempTickers);
}
} else if (result.taskType == TASK_FETCH_BNB_MINI_TICKER) {
ArrayList<BnbTicker> tempTickers = (ArrayList<BnbTicker>) result.resultData;
if (tempTickers != null) {
getBaseDao().mBnbTickers.addAll(tempTickers);
}
} else if (result.taskType == TASK_FETCH_BNB_FEES) {
getBaseDao().mBnbFees.clear();
if (result.isSuccess && result.resultData != null) {
getBaseDao().mBnbFees = (ArrayList<ResBnbFee>) result.resultData;
}
} else if (result.taskType == TASK_FETCH_OK_ACCOUNT_BALANCE) {
if (result.isSuccess) {
getBaseDao().mBalances = getBaseDao().onSelectBalance(mAccount.id);
}
// WLog.w("getBaseDao().mBalances " + getBaseDao().mBalances.size());
} else if (result.taskType == TASK_FETCH_OK_STAKING_INFO) {
if (result.isSuccess && result.resultData != null) {
getBaseDao().mOkStaking = (ResOkStaking) result.resultData;
}
} else if (result.taskType == TASK_FETCH_OK_UNBONDING_INFO) {
if (result.isSuccess && result.resultData != null) {
getBaseDao().mOkUnbonding = ((ResOkUnbonding) result.resultData);
}
} else if (result.taskType == TASK_FETCH_OK_TOKEN_LIST) {
if (result.isSuccess && result.resultData != null) {
getBaseDao().mOkTokenList = ((ResOkTokenList) result.resultData);
}
} else if (result.taskType == TASK_FETCH_OK_DEX_TICKERS) {
if (result.isSuccess && result.resultData != null) {
getBaseDao().mOkTickersList = ((ResOkTickersList) result.resultData);
}
} else // gRPC callback
if (result.taskType == TASK_GRPC_FETCH_NODE_INFO) {
tendermint.p2p.Types.NodeInfo tempNodeInfo = (tendermint.p2p.Types.NodeInfo) result.resultData;
if (tempNodeInfo != null) {
getBaseDao().mGRpcNodeInfo = tempNodeInfo;
mTaskCount = mTaskCount + 5;
new StationParamInfoTask(getBaseApplication(), this, mBaseChain, getBaseDao().getChainIdGrpc()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new StationIbcPathsTask(getBaseApplication(), this, mBaseChain, getBaseDao().getChainIdGrpc()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new StationIbcTokensTask(getBaseApplication(), this, mBaseChain, getBaseDao().getChainIdGrpc()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new MintScanAssetsTask(getBaseApplication(), this, mBaseChain).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
new MintScanCw20AssetsTask(getBaseApplication(), this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
} else if (result.taskType == TASK_GRPC_FETCH_AUTH) {
Any tempAccount = (Any) result.resultData;
if (tempAccount != null) {
getBaseDao().mGRpcAccount = tempAccount;
}
} else if (result.taskType == TASK_GRPC_FETCH_BONDED_VALIDATORS) {
ArrayList<Staking.Validator> bonded = (ArrayList<Staking.Validator>) result.resultData;
if (bonded != null) {
getBaseDao().mGRpcTopValidators.addAll(bonded);
}
} else if (result.taskType == TASK_GRPC_FETCH_UNBONDED_VALIDATORS) {
ArrayList<Staking.Validator> unbonded = (ArrayList<Staking.Validator>) result.resultData;
if (unbonded != null) {
getBaseDao().mGRpcOtherValidators.addAll(unbonded);
}
} else if (result.taskType == TASK_GRPC_FETCH_UNBONDING_VALIDATORS) {
ArrayList<Staking.Validator> unbonding = (ArrayList<Staking.Validator>) result.resultData;
if (unbonding != null) {
getBaseDao().mGRpcOtherValidators.addAll(unbonding);
}
} else if (result.taskType == TASK_GRPC_FETCH_BALANCE) {
ArrayList<CoinOuterClass.Coin> balance = (ArrayList<CoinOuterClass.Coin>) result.resultData;
if (balance != null && balance.size() > 0) {
for (CoinOuterClass.Coin coin : balance) {
if (!coin.getAmount().equals("0")) {
getBaseDao().mGrpcBalance.add(new Coin(coin.getDenom(), coin.getAmount()));
} else {
if (coin.getDenom().equalsIgnoreCase(WDp.mainDenom(mBaseChain))) {
getBaseDao().mGrpcBalance.add(new Coin(coin.getDenom(), coin.getAmount()));
}
}
}
}
if (getBaseDao().mGrpcBalance.size() <= 0 || getBaseDao().getAvailable(WDp.mainDenom(mBaseChain)).compareTo(BigDecimal.ZERO) <= 0) {
getBaseDao().mGrpcBalance.add(new Coin(WDp.mainDenom(mBaseChain), "0"));
}
} else if (result.taskType == TASK_GRPC_FETCH_DELEGATIONS) {
ArrayList<Staking.DelegationResponse> delegations = (ArrayList<Staking.DelegationResponse>) result.resultData;
if (delegations != null) {
getBaseDao().mGrpcDelegations = delegations;
}
} else if (result.taskType == TASK_GRPC_FETCH_UNDELEGATIONS) {
ArrayList<Staking.UnbondingDelegation> undelegations = (ArrayList<Staking.UnbondingDelegation>) result.resultData;
if (undelegations != null) {
getBaseDao().mGrpcUndelegations = undelegations;
}
} else if (result.taskType == TASK_GRPC_FETCH_ALL_REWARDS) {
ArrayList<Distribution.DelegationDelegatorReward> rewards = (ArrayList<Distribution.DelegationDelegatorReward>) result.resultData;
if (rewards != null) {
getBaseDao().mGrpcRewards = rewards;
}
} else if (result.taskType == TASK_GRPC_FETCH_STARNAME_FEE) {
if (result.isSuccess && result.resultData != null) {
getBaseDao().mGrpcStarNameFee = ((starnamed.x.configuration.v1beta1.Types.Fees) result.resultData);
}
} else if (result.taskType == TASK_GRPC_FETCH_STARNAME_CONFIG) {
if (result.isSuccess && result.resultData != null) {
getBaseDao().mGrpcStarNameConfig = ((starnamed.x.configuration.v1beta1.Types.Config) result.resultData);
}
} else if (result.taskType == TASK_GRPC_FETCH_GRAVITY_POOL_LIST) {
if (result.isSuccess && result.resultData != null) {
List<Liquidity.Pool> pools = (List<Liquidity.Pool>) result.resultData;
getBaseDao().mGrpcGravityPools = new ArrayList<Liquidity.Pool>(pools);
}
} else if (result.taskType == TASK_GRPC_FETCH_OSMOSIS_POOL_LIST) {
if (result.isSuccess && result.resultData != null) {
List<BalancerPool.Pool> pools = (List<BalancerPool.Pool>) result.resultData;
getBaseDao().mGrpcOsmosisPool = new ArrayList<BalancerPool.Pool>(pools);
}
} else // kava
if (result.taskType == TASK_FETCH_KAVA_INCENTIVE_PARAM) {
if (result.isSuccess && result.resultData != null) {
getBaseDao().mIncentiveParam5 = (IncentiveParam) result.resultData;
}
} else if (result.taskType == TASK_FETCH_KAVA_INCENTIVE_REWARD) {
if (result.isSuccess && result.resultData != null) {
getBaseDao().mIncentiveRewards = (IncentiveReward) result.resultData;
}
} else if (result.taskType == TASK_GRPC_FETCH_KAVA_PRICES) {
if (result.isSuccess && result.resultData != null) {
ArrayList<QueryOuterClass.CurrentPriceResponse> currentPrices = (ArrayList<QueryOuterClass.CurrentPriceResponse>) result.resultData;
if (currentPrices != null) {
for (QueryOuterClass.CurrentPriceResponse response : currentPrices) {
getBaseDao().mKavaTokenPrice.put(response.getMarketId(), response);
}
}
}
} else // mintscan
if (result.taskType == TASK_FETCH_MINTSCAN_CW20_ASSETS) {
if (result.isSuccess && result.resultData != null) {
getBaseDao().mCw20Assets = (ArrayList<Cw20Assets>) result.resultData;
if (getBaseDao().mCw20Assets != null && getBaseDao().mCw20Assets.size() > 0) {
for (Cw20Assets assets : getBaseDao().mCw20Assets) {
if (assets.chain.equalsIgnoreCase(WDp.getChainNameByBaseChain(mBaseChain))) {
mTaskCount = mTaskCount + 1;
new Cw20BalanceGrpcTask(getBaseApplication(), this, mBaseChain, mAccount, assets.contract_address).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
}
}
}
if (mTaskCount == 0) {
if (isGRPC(mBaseChain)) {
getBaseDao().mGRpcAllValidators.addAll(getBaseDao().mGRpcTopValidators);
getBaseDao().mGRpcAllValidators.addAll(getBaseDao().mGRpcOtherValidators);
for (Staking.Validator validator : getBaseDao().mGRpcAllValidators) {
boolean already = false;
for (Staking.DelegationResponse delegation : getBaseDao().mGrpcDelegations) {
if (delegation.getDelegation().getValidatorAddress().equals(validator.getOperatorAddress())) {
already = true;
break;
}
}
for (Staking.UnbondingDelegation undelegation : getBaseDao().mGrpcUndelegations) {
if (undelegation.getValidatorAddress().equals(validator.getOperatorAddress())) {
already = true;
break;
}
}
if (already)
getBaseDao().mGRpcMyValidators.add(validator);
}
// WLog.w("mIbcTokens " + getBaseDao().mIbcTokens.size());
if (getBaseDao().mGRpcNodeInfo == null) {
Toast.makeText(getBaseContext(), R.string.error_network_error, Toast.LENGTH_SHORT).show();
} else {
// WLog.w("mGRpcAccount " + getBaseDao().mGRpcAccount.getTypeUrl());
if (getBaseDao().mGRpcAccount != null && !getBaseDao().mGRpcAccount.getTypeUrl().contains(Auth.BaseAccount.getDescriptor().getFullName())) {
WUtil.onParseVestingAccount(getBaseDao(), mBaseChain);
}
ArrayList<Balance> snapBalance = new ArrayList<>();
for (Coin coin : getBaseDao().mGrpcBalance) {
snapBalance.add(new Balance(mAccount.id, coin.denom, coin.amount, Calendar.getInstance().getTime().getTime(), "0", "0"));
}
getBaseDao().onUpdateBalances(mAccount.id, snapBalance);
// WLog.w("getBaseDao().mGRpcNodeInfo " + getBaseDao().mGRpcNodeInfo.getNetwork());
}
} else if (mBaseChain.equals(BNB_MAIN)) {
if (getBaseDao().mNodeInfo == null) {
Toast.makeText(getBaseContext(), R.string.error_network_error, Toast.LENGTH_SHORT).show();
}
// WLog.w("mBnbTokens " + getBaseDao().mBnbTokens.size());
// WLog.w("mBnbTickers " + getBaseDao().mBnbTickers.size());
} else if (mBaseChain.equals(OKEX_MAIN)) {
for (Validator all : getBaseDao().mAllValidators) {
if (all.status == Validator.BONDED) {
getBaseDao().mTopValidators.add(all);
} else {
getBaseDao().mOtherValidators.add(all);
}
}
if (getBaseDao().mOkStaking != null && getBaseDao().mOkStaking.validator_address != null) {
for (String valAddr : getBaseDao().mOkStaking.validator_address) {
for (Validator val : getBaseDao().mAllValidators) {
if (val.operator_address.equals(valAddr)) {
getBaseDao().mMyValidators.add(val);
}
}
}
}
if (getBaseDao().mNodeInfo == null) {
Toast.makeText(getBaseContext(), R.string.error_network_error, Toast.LENGTH_SHORT).show();
}
} else {
getBaseDao().mAllValidators.addAll(getBaseDao().mTopValidators);
getBaseDao().mAllValidators.addAll(getBaseDao().mOtherValidators);
for (Validator top : getBaseDao().mAllValidators) {
boolean already = false;
for (BondingInfo bond : getBaseDao().mMyDelegations) {
if (bond.validator_address.equals(top.operator_address)) {
already = true;
break;
}
}
for (UnbondingInfo unbond : getBaseDao().mMyUnbondings) {
if (unbond.validator_address.equals(top.operator_address) && !already) {
already = true;
break;
}
}
if (already)
getBaseDao().mMyValidators.add(top);
}
if (getBaseDao().mNodeInfo == null) {
Toast.makeText(getBaseContext(), R.string.error_network_error, Toast.LENGTH_SHORT).show();
}
}
new StationPriceInfoTask(getBaseApplication(), this, mBaseChain).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
// callback with delay fix gRPC timming issue
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
if (mFetchCallback != null) {
mFetchCallback.fetchFinished();
}
}
}, 300);
}
}
use of wannabit.io.cosmostaion.dao.Balance in project cosmostation-android by cosmostation.
the class WUtil method getBalancesFromBnbLcd.
public static ArrayList<Balance> getBalancesFromBnbLcd(long accountId, ResBnbAccountInfo lcd) {
long time = System.currentTimeMillis();
ArrayList<Balance> result = new ArrayList<>();
if (lcd.balances != null && lcd.balances.size() > 0) {
for (ResBnbAccountInfo.BnbBalance coin : lcd.balances) {
Balance temp = new Balance();
temp.accountId = accountId;
temp.symbol = coin.symbol;
temp.balance = new BigDecimal(coin.free);
temp.locked = new BigDecimal(coin.locked);
temp.frozen = new BigDecimal(coin.frozen);
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 getBalancesFromVestingLcd.
public static ArrayList<Balance> getBalancesFromVestingLcd(long accountId, ResLcdVestingAccountInfo 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);
}
}
} else if (lcd.result.type.equals(COSMOS_AUTH_TYPE_P_VESTING_ACCOUNT)) {
for (Coin coin : lcd.result.value.coins) {
String denom = coin.denom;
BigDecimal dpBalance = BigDecimal.ZERO;
BigDecimal dpVesting = BigDecimal.ZERO;
BigDecimal originalVesting = BigDecimal.ZERO;
BigDecimal remainVesting = BigDecimal.ZERO;
BigDecimal delegatedVesting = BigDecimal.ZERO;
dpBalance = new BigDecimal(coin.amount);
WLog.w("dpBalance " + denom + " " + dpBalance);
for (Coin vesting : lcd.result.value.original_vesting) {
if (vesting.denom.equals(denom)) {
originalVesting = originalVesting.add(new BigDecimal(vesting.amount));
}
}
WLog.w("originalVesting " + denom + " " + originalVesting);
for (Coin vesting : lcd.result.value.delegated_vesting) {
if (vesting.denom.equals(denom)) {
delegatedVesting = delegatedVesting.add(new BigDecimal(vesting.amount));
}
}
WLog.w("delegatedVesting " + denom + " " + delegatedVesting);
remainVesting = lcd.getCalcurateVestingAmountSumByDenom(denom);
WLog.w("remainVesting " + denom + " " + remainVesting);
dpVesting = remainVesting.subtract(delegatedVesting);
WLog.w("dpVestingA " + denom + " " + dpVesting);
dpVesting = dpVesting.compareTo(BigDecimal.ZERO) <= 0 ? BigDecimal.ZERO : dpVesting;
WLog.w("dpVestingB " + denom + " " + dpVesting);
if (remainVesting.compareTo(delegatedVesting) > 0) {
dpBalance = dpBalance.subtract(remainVesting).add(delegatedVesting);
}
WLog.w("final dpBalance " + denom + " " + dpBalance);
Balance temp = new Balance();
temp.accountId = accountId;
temp.symbol = denom;
temp.balance = dpBalance;
temp.frozen = delegatedVesting;
temp.locked = dpVesting;
temp.fetchTime = time;
result.add(temp);
}
} else if (lcd.result.type.equals(COSMOS_AUTH_TYPE_C_VESTING_ACCOUNT)) {
for (Coin coin : lcd.result.value.coins) {
String denom = coin.denom;
BigDecimal dpBalance = BigDecimal.ZERO;
BigDecimal dpVesting = BigDecimal.ZERO;
BigDecimal originalVesting = BigDecimal.ZERO;
BigDecimal remainVesting = BigDecimal.ZERO;
BigDecimal delegatedVesting = BigDecimal.ZERO;
dpBalance = new BigDecimal(coin.amount);
WLog.w("dpBalance " + denom + " " + dpBalance);
for (Coin vesting : lcd.result.value.original_vesting) {
if (vesting.denom.equals(denom)) {
originalVesting = originalVesting.add(new BigDecimal(vesting.amount));
}
}
WLog.w("originalVesting " + denom + " " + originalVesting);
for (Coin vesting : lcd.result.value.delegated_vesting) {
if (vesting.denom.equals(denom)) {
delegatedVesting = delegatedVesting.add(new BigDecimal(vesting.amount));
}
}
WLog.w("delegatedVesting " + denom + " " + delegatedVesting);
long cTime = Calendar.getInstance().getTime().getTime();
long vestingStart = lcd.result.value.getStartTime() * 1000;
long vestingEnd = lcd.result.value.getEndTime() * 1000;
if (cTime < vestingStart) {
remainVesting = originalVesting;
} else if (cTime > vestingEnd) {
remainVesting = BigDecimal.ZERO;
} else if (cTime < vestingEnd) {
float progress = ((float) (cTime - vestingStart) / (float) (vestingEnd - vestingStart));
remainVesting = originalVesting.multiply(new BigDecimal(1 - progress)).setScale(0, RoundingMode.UP);
}
WLog.w("remainVesting " + denom + " " + remainVesting);
dpVesting = remainVesting.subtract(delegatedVesting);
WLog.w("dpVestingA " + denom + " " + dpVesting);
dpVesting = dpVesting.compareTo(BigDecimal.ZERO) <= 0 ? BigDecimal.ZERO : dpVesting;
WLog.w("dpVestingB " + denom + " " + dpVesting);
if (remainVesting.compareTo(delegatedVesting) > 0) {
dpBalance = dpBalance.subtract(remainVesting).add(delegatedVesting);
}
WLog.w("final dpBalance " + denom + " " + dpBalance);
Balance temp = new Balance();
temp.accountId = accountId;
temp.symbol = denom;
temp.balance = dpBalance;
temp.frozen = delegatedVesting;
temp.locked = dpVesting;
temp.fetchTime = time;
result.add(temp);
}
} else if (lcd.result.type.equals(COSMOS_AUTH_TYPE_D_VESTING_ACCOUNT)) {
for (Coin coin : lcd.result.value.coins) {
String denom = coin.denom;
BigDecimal dpBalance = BigDecimal.ZERO;
BigDecimal dpVesting = BigDecimal.ZERO;
BigDecimal originalVesting = BigDecimal.ZERO;
BigDecimal remainVesting = BigDecimal.ZERO;
BigDecimal delegatedVesting = BigDecimal.ZERO;
dpBalance = new BigDecimal(coin.amount);
WLog.w("dpBalance " + denom + " " + dpBalance);
for (Coin vesting : lcd.result.value.original_vesting) {
if (vesting.denom.equals(denom)) {
originalVesting = originalVesting.add(new BigDecimal(vesting.amount));
}
}
WLog.w("originalVesting " + denom + " " + originalVesting);
for (Coin vesting : lcd.result.value.delegated_vesting) {
if (vesting.denom.equals(denom)) {
delegatedVesting = delegatedVesting.add(new BigDecimal(vesting.amount));
}
}
WLog.w("delegatedVesting " + denom + " " + delegatedVesting);
long cTime = Calendar.getInstance().getTime().getTime();
long vestingEnd = lcd.result.value.getEndTime() * 1000;
if (cTime < vestingEnd) {
remainVesting = originalVesting;
}
WLog.w("remainVesting " + denom + " " + remainVesting);
dpVesting = remainVesting.subtract(delegatedVesting);
WLog.w("dpVestingA " + denom + " " + dpVesting);
dpVesting = dpVesting.compareTo(BigDecimal.ZERO) <= 0 ? BigDecimal.ZERO : dpVesting;
WLog.w("dpVestingB " + denom + " " + dpVesting);
if (remainVesting.compareTo(delegatedVesting) > 0) {
dpBalance = dpBalance.subtract(remainVesting).add(delegatedVesting);
}
WLog.w("final dpBalance " + denom + " " + dpBalance);
Balance temp = new Balance();
temp.accountId = accountId;
temp.symbol = denom;
temp.balance = dpBalance;
temp.frozen = delegatedVesting;
temp.locked = dpVesting;
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 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;
}
use of wannabit.io.cosmostaion.dao.Balance in project cosmostation-android by cosmostation.
the class MainTokensFragment method onBindUnKnownCoin.
// with Unknown coin oec, bnb
private void onBindUnKnownCoin(TokensAdapter.AssetHolder holder, int position) {
final Balance balance = mUnKnown.get(position);
holder.itemSymbol.setText("UNKNOWN");
holder.itemSymbol.setTextColor(getResources().getColor(R.color.colorWhite));
holder.itemInnerSymbol.setText("");
holder.itemFullName.setText("");
holder.itemImg.setImageDrawable(getResources().getDrawable(R.drawable.token_ic));
holder.itemBalance.setText(WDp.getDpAmount2(getContext(), balance.balance, 6, 6));
holder.itemValue.setText(WDp.dpUserCurrencyValue(getBaseDao(), balance.symbol, BigDecimal.ZERO, 6));
}
Aggregations