display correct label and amount for tip unlocks in tx history

This commit is contained in:
Akinwale Ariwodola 2020-05-24 00:08:14 +01:00
parent cf6d567193
commit 238f59ad71
6 changed files with 51 additions and 9 deletions

View file

@ -168,6 +168,10 @@ public class RewardListAdapter extends RecyclerView.Adapter<RewardListAdapter.Vi
return; return;
} }
if (vh.inputCustomCode != null && !vh.inputCustomCode.hasFocus()) {
vh.inputCustomCode.requestFocus();
}
if (clickListener != null) { if (clickListener != null) {
clickListener.onRewardClicked(reward, vh.loading); clickListener.onRewardClicked(reward, vh.loading);
} }

View file

@ -72,7 +72,9 @@ public class TransactionListAdapter extends RecyclerView.Adapter<TransactionList
vh.claimView.setText(item.getClaim()); vh.claimView.setText(item.getClaim());
vh.feeView.setText(context.getString(R.string.tx_list_fee, TX_LIST_AMOUNT_FORMAT.format(item.getFee().doubleValue()))); vh.feeView.setText(context.getString(R.string.tx_list_fee, TX_LIST_AMOUNT_FORMAT.format(item.getFee().doubleValue())));
vh.txidLinkView.setText(item.getTxid().substring(0, 7)); vh.txidLinkView.setText(item.getTxid().substring(0, 7));
vh.dateView.setText(TX_LIST_DATE_FORMAT.format(item.getTxDate())); vh.dateView.setVisibility(item.getConfirmations() > 0 ? View.VISIBLE : View.GONE);
vh.dateView.setText(item.getConfirmations() > 0 ? TX_LIST_DATE_FORMAT.format(item.getTxDate()) : null);
vh.pendingView.setVisibility(item.getConfirmations() == 0 ? View.VISIBLE : View.GONE);
vh.infoFeeContainer.setVisibility(!Helper.isNullOrEmpty(item.getClaim()) || Math.abs(item.getFee().doubleValue()) > 0 ? vh.infoFeeContainer.setVisibility(!Helper.isNullOrEmpty(item.getClaim()) || Math.abs(item.getFee().doubleValue()) > 0 ?
View.VISIBLE : View.GONE); View.VISIBLE : View.GONE);
@ -111,6 +113,7 @@ public class TransactionListAdapter extends RecyclerView.Adapter<TransactionList
protected TextView feeView; protected TextView feeView;
protected TextView txidLinkView; protected TextView txidLinkView;
protected TextView dateView; protected TextView dateView;
protected TextView pendingView;
protected View infoFeeContainer; protected View infoFeeContainer;
public ViewHolder(View v) { public ViewHolder(View v) {
@ -121,6 +124,7 @@ public class TransactionListAdapter extends RecyclerView.Adapter<TransactionList
feeView = v.findViewById(R.id.transaction_fee); feeView = v.findViewById(R.id.transaction_fee);
txidLinkView = v.findViewById(R.id.transaction_id_link); txidLinkView = v.findViewById(R.id.transaction_id_link);
dateView = v.findViewById(R.id.transaction_date); dateView = v.findViewById(R.id.transaction_date);
pendingView = v.findViewById(R.id.transaction_pending_text);
infoFeeContainer = v.findViewById(R.id.transaction_info_fee_container); infoFeeContainer = v.findViewById(R.id.transaction_info_fee_container);
} }
} }

View file

@ -5,7 +5,9 @@ import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List;
import io.lbry.browser.R; import io.lbry.browser.R;
import io.lbry.browser.exceptions.LbryUriException; import io.lbry.browser.exceptions.LbryUriException;
@ -53,13 +55,22 @@ public class Transaction {
int descStringId = -1; int descStringId = -1;
TransactionInfo info = null; TransactionInfo info = null;
List<TransactionInfo> infos = new ArrayList<>();
try { try {
if (jsonObject.has("abandon_info")) { if (jsonObject.has("abandon_info")) {
JSONArray array = jsonObject.getJSONArray("abandon_info"); JSONArray array = jsonObject.getJSONArray("abandon_info");
if (array.length() > 0) { if (array.length() > 0) {
if (array.length() == 1) {
info = TransactionInfo.fromJSONObject(array.getJSONObject(0)); info = TransactionInfo.fromJSONObject(array.getJSONObject(0));
descStringId = R.string.abandon; descStringId = info.getBalanceDelta().doubleValue() == info.getAmount().doubleValue() ? R.string.unlock : R.string.abandon;
transaction.setAbandonInfo(info); transaction.setAbandonInfo(info);
} else {
// multiple abandon infos (txo_spend unlock tip)
descStringId = R.string.unlock;
for (int i = 0; i < array.length(); i++) {
infos.add(TransactionInfo.fromJSONObject(array.getJSONObject(i)));
}
}
} }
} }
if (info == null && jsonObject.has("claim_info")) { if (info == null && jsonObject.has("claim_info")) {
@ -94,8 +105,18 @@ public class Transaction {
// pass // pass
} }
if (transaction.getValue().doubleValue() == 0 && info != null && info.getBalanceDelta().doubleValue() != 0) {
if (transaction.getValue().doubleValue() == 0) {
if (info != null && info.getBalanceDelta().doubleValue() != 0) {
transaction.setValue(info.getBalanceDelta()); transaction.setValue(info.getBalanceDelta());
} else if (infos.size() > 0) {
BigDecimal total = new BigDecimal(0);
for (TransactionInfo txInfo : infos) {
total = total.add(txInfo.getAmount());
}
transaction.setValue(total);
}
} }
if (descStringId == -1) { if (descStringId == -1) {

View file

@ -20,7 +20,7 @@ public class WalletBalanceTask extends AsyncTask<Void, Void, WalletBalance> {
} }
protected WalletBalance doInBackground(Void... params) { protected WalletBalance doInBackground(Void... params) {
WalletBalance balance = new WalletBalance(); WalletBalance balance;
try { try {
JSONObject json = (JSONObject) Lbry.genericApiCall(Lbry.METHOD_WALLET_BALANCE); JSONObject json = (JSONObject) Lbry.genericApiCall(Lbry.METHOD_WALLET_BALANCE);
balance = WalletBalance.fromJSONObject(json); balance = WalletBalance.fromJSONObject(json);

View file

@ -28,7 +28,8 @@
android:fontFamily="@font/inter" android:fontFamily="@font/inter"
android:textSize="14sp" android:textSize="14sp"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" /> android:layout_height="wrap_content"
android:imeOptions="actionNext" />
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
<RelativeLayout <RelativeLayout

View file

@ -102,6 +102,18 @@
android:singleLine="true" android:singleLine="true"
android:textColor="@color/lightGrey" android:textColor="@color/lightGrey"
android:textSize="12sp" android:textSize="12sp"
android:textFontWeight="300" /> android:textFontWeight="300"
android:visibility="gone" />
<TextView
android:id="@+id/transaction_pending_text"
android:gravity="right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/inter"
android:text="@string/pending"
android:textSize="12sp"
android:textStyle="italic"
android:textFontWeight="300"
android:visibility="gone" />
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>