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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations