Search in sources :

Example 11 with Coin

use of wannabit.io.cosmostaion.model.type.Coin in project cosmostation-android by cosmostation.

the class ResTxInfo method simpleDeposits.

public ArrayList<Coin> simpleDeposits() {
    ArrayList<Coin> result = new ArrayList<>();
    if (logs != null && logs.get(0) != null && logs.get(0).events != null) {
        for (Event event : logs.get(0).events) {
            if (event.type.equals("swap_deposit")) {
                for (EventAttribute attr : event.attributes) {
                    if (attr.key.equalsIgnoreCase("amount")) {
                        String value = attr.value;
                        String[] splits = value.split(",");
                        for (String split : splits) {
                            Coin depositCoin = new Coin(split.replaceAll("[0-9]", ""), split.replaceAll("[^0-9]", ""));
                            result.add(depositCoin);
                        }
                    }
                }
            }
        }
    }
    return result;
}
Also used : Coin(wannabit.io.cosmostaion.model.type.Coin) ArrayList(java.util.ArrayList)

Example 12 with Coin

use of wannabit.io.cosmostaion.model.type.Coin in project cosmostation-android by cosmostation.

the class ResTxInfo method simpleWithdraws.

public ArrayList<Coin> simpleWithdraws() {
    ArrayList<Coin> result = new ArrayList<>();
    if (logs != null && logs.get(0) != null && logs.get(0).events != null) {
        for (Event event : logs.get(0).events) {
            if (event.type.equals("swap_withdraw")) {
                for (EventAttribute attr : event.attributes) {
                    if (attr.key.equalsIgnoreCase("amount")) {
                        String value = attr.value;
                        String[] splits = value.split(",");
                        for (String split : splits) {
                            Coin depositCoin = new Coin(split.replaceAll("[0-9]", ""), split.replaceAll("[^0-9]", ""));
                            result.add(depositCoin);
                        }
                    }
                }
            }
        }
    }
    return result;
}
Also used : Coin(wannabit.io.cosmostaion.model.type.Coin) ArrayList(java.util.ArrayList)

Example 13 with Coin

use of wannabit.io.cosmostaion.model.type.Coin in project cosmostation-android by cosmostation.

the class ResTxInfo method simpleSwapInCoin.

public Coin simpleSwapInCoin() {
    Coin coin = new Coin();
    if (logs != null && logs.get(0) != null && logs.get(0).events != null) {
        for (Event event : logs.get(0).events) {
            if (event.type.equals("swap_trade")) {
                for (EventAttribute attr : event.attributes) {
                    if (attr.key.equalsIgnoreCase("input")) {
                        String value = attr.value;
                        String denom = value.replaceAll("[0-9]", "");
                        String amount = value.replaceAll("[^0-9]", "");
                        coin.denom = denom;
                        coin.amount = amount;
                    }
                }
            }
        }
    }
    return coin;
}
Also used : Coin(wannabit.io.cosmostaion.model.type.Coin)

Example 14 with Coin

use of wannabit.io.cosmostaion.model.type.Coin in project cosmostation-android by cosmostation.

the class ResTxInfo method simpleSwapCoin.

public Coin simpleSwapCoin() {
    Coin coin = new Coin();
    if (logs != null && logs.get(0) != null && logs.get(0).events != null) {
        for (Event event : logs.get(0).events) {
            if (event.type.equals("transfer")) {
                for (EventAttribute attr : event.attributes) {
                    if (attr.key.equals("amount")) {
                        String value = attr.value;
                        String denom = value.replaceAll("[0-9]", "");
                        String amount = value.replaceAll("[^0-9]", "");
                        coin.denom = denom;
                        coin.amount = amount;
                    }
                }
            }
        }
    }
    return coin;
}
Also used : Coin(wannabit.io.cosmostaion.model.type.Coin)

Example 15 with Coin

use of wannabit.io.cosmostaion.model.type.Coin in project cosmostation-android by cosmostation.

the class ResApiNewTxListCustom method getDpCoin.

public Coin getDpCoin(BaseChain chain) {
    // display staking reward amount
    if (getMsgCnt() > 0) {
        boolean allReward = true;
        for (int i = 0; i < getMsgs().length(); i++) {
            String msgType = "";
            try {
                msgType = getMsgs().getJSONObject(0).getString("@type");
            } catch (Exception e) {
            }
            try {
                msgType = getMsgs().getJSONObject(0).getString("type");
            } catch (Exception e) {
            }
            if (!msgType.contains("MsgWithdrawDelegatorReward")) {
                allReward = false;
                break;
            }
        }
        if (allReward) {
            if (data != null && data.logs != null) {
                BigDecimal totalRewardSum = BigDecimal.ZERO;
                for (int i = 0; i < data.logs.size(); i++) {
                    try {
                        for (int j = 0; j < new JSONArray(data.logs).getJSONObject(i).getJSONArray("events").length(); j++) {
                            if (new JSONArray(data.logs).getJSONObject(i).getJSONArray("events").getJSONObject(j).getString("type").equalsIgnoreCase("transfer")) {
                                String value = new JSONArray(data.logs).getJSONObject(i).getJSONArray("events").getJSONObject(j).getJSONArray("attributes").getJSONObject(2).getString("value");
                                for (String rawCoin : value.split(",")) {
                                    if (rawCoin.contains(WDp.mainDenom(chain))) {
                                        totalRewardSum = totalRewardSum.add(new BigDecimal(rawCoin.replaceAll("[^0-9]", "")));
                                    }
                                }
                            }
                        }
                    } catch (Exception e) {
                    }
                }
                return new Coin(WDp.mainDenom(chain), totalRewardSum.toString());
            }
        }
    }
    // display re-invset amount
    if (getMsgCnt() == 2) {
        String msgType0 = "";
        String msgType1 = "";
        try {
            msgType0 = getMsgs().getJSONObject(0).getString("@type");
        } catch (Exception e) {
        }
        try {
            msgType0 = getMsgs().getJSONObject(0).getString("type");
        } catch (Exception e) {
        }
        try {
            msgType1 = getMsgs().getJSONObject(1).getString("@type");
        } catch (Exception e) {
        }
        try {
            msgType1 = getMsgs().getJSONObject(1).getString("type");
        } catch (Exception e) {
        }
        if (msgType0.contains("MsgWithdrawDelegatorReward") && msgType1.contains("MsgDelegate") || msgType0.contains("MsgWithdrawDelegationReward") && msgType1.contains("MsgDelegate")) {
            String denom = "";
            String amount = "";
            try {
                denom = getMsgs().getJSONObject(1).getJSONObject("amount").getString("denom");
                amount = getMsgs().getJSONObject(1).getJSONObject("amount").getString("amount");
            } catch (JSONException e) {
                e.printStackTrace();
            }
            try {
                denom = getMsgs().getJSONObject(1).getJSONObject("value").getJSONObject("amount").getString("denom");
                amount = getMsgs().getJSONObject(1).getJSONObject("value").getJSONObject("amount").getString("amount");
            } catch (JSONException e) {
                e.printStackTrace();
            }
            return new Coin(denom, amount);
        }
    }
    if (getMsgCnt() == 0 || getMsgCnt() > 1) {
        return null;
    }
    String msgType = "";
    try {
        msgType = getMsgs().getJSONObject(0).getString("@type");
    } catch (Exception e) {
    }
    try {
        msgType = getMsgs().getJSONObject(0).getString("type");
    } catch (Exception e) {
    }
    String denom = "";
    String amount = "";
    if (msgType.contains("MsgSendToEth")) {
    } else if (msgType.contains("MsgSend")) {
        try {
            denom = getMsgs().getJSONObject(0).getJSONArray("amount").getJSONObject(0).getString("denom");
            amount = getMsgs().getJSONObject(0).getJSONArray("amount").getJSONObject(0).getString("amount");
        } catch (JSONException e) {
        }
        try {
            denom = getMsgs().getJSONObject(0).getJSONObject("value").getJSONArray("amount").getJSONObject(0).getString("denom");
            amount = getMsgs().getJSONObject(0).getJSONObject("value").getJSONArray("amount").getJSONObject(0).getString("amount");
        } catch (JSONException e) {
        }
        return new Coin(denom, amount);
    } else if (msgType.contains("MsgDelegate") || msgType.contains("MsgUndelegate") || msgType.contains("MsgBeginRedelegate")) {
        try {
            denom = getMsgs().getJSONObject(0).getJSONObject("amount").getString("denom");
            amount = getMsgs().getJSONObject(0).getJSONObject("amount").getString("amount");
        } catch (JSONException e) {
        }
        try {
            denom = getMsgs().getJSONObject(0).getJSONObject("value").getJSONObject("amount").getString("denom");
            amount = getMsgs().getJSONObject(0).getJSONObject("value").getJSONObject("amount").getString("amount");
        } catch (JSONException e) {
        }
        return new Coin(denom, amount);
    } else if (msgType.contains("ibc") && msgType.contains("MsgTransfer")) {
        try {
            denom = getMsgs().getJSONObject(0).getJSONObject("token").getString("denom");
            amount = getMsgs().getJSONObject(0).getJSONObject("token").getString("amount");
        } catch (JSONException e) {
        }
        return new Coin(denom, amount);
    }
    return null;
}
Also used : Coin(wannabit.io.cosmostaion.model.type.Coin) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) JSONException(org.json.JSONException) BigDecimal(java.math.BigDecimal)

Aggregations

Coin (wannabit.io.cosmostaion.model.type.Coin)126 BigDecimal (java.math.BigDecimal)85 ArrayList (java.util.ArrayList)28 TextView (android.widget.TextView)27 CardView (androidx.cardview.widget.CardView)27 View (android.view.View)25 RecyclerView (androidx.recyclerview.widget.RecyclerView)17 Intent (android.content.Intent)15 Abci (cosmos.base.abci.v1beta1.Abci)13 ImageView (android.widget.ImageView)12 Matcher (java.util.regex.Matcher)12 Pattern (java.util.regex.Pattern)12 CoinOuterClass (cosmos.base.v1beta1.CoinOuterClass)9 SpannableString (android.text.SpannableString)6 Balance (wannabit.io.cosmostaion.dao.Balance)6 Date (java.util.Date)5 IbcToken (wannabit.io.cosmostaion.dao.IbcToken)5 Fee (wannabit.io.cosmostaion.model.type.Fee)5 Bundle (android.os.Bundle)4 Lock (osmosis.lockup.Lock)4