Display tx info

NOTE: This commit still logs seed phrases for development purposes
This commit is contained in:
pokkst 2022-09-07 17:46:53 -05:00
parent c051c2aee9
commit ae232d1a92
No known key found for this signature in database
GPG key ID: 90C2ED85E67A50FF
3 changed files with 96 additions and 9 deletions

View file

@ -16,6 +16,8 @@
package com.m2049r.xmrwallet.adapter;
import static com.m2049r.xmrwallet.util.DateHelper.DATETIME_FORMATTER;
import android.content.Context;
import android.text.Html;
import android.text.Spanned;
@ -36,6 +38,7 @@ import com.m2049r.xmrwallet.R;
import com.m2049r.xmrwallet.data.Crypto;
import com.m2049r.xmrwallet.data.UserNotes;
import com.m2049r.xmrwallet.model.TransactionInfo;
import com.m2049r.xmrwallet.model.Wallet;
import com.m2049r.xmrwallet.util.Helper;
import com.m2049r.xmrwallet.util.ThemeHelper;
@ -60,17 +63,107 @@ public class TransactionInfoAdapter extends RecyclerView.Adapter<TransactionInfo
* (custom ViewHolder).
*/
public static class ViewHolder extends RecyclerView.ViewHolder {
private final int outboundColour;
private final int inboundColour;
private final int pendingColour;
private final int failedColour;
private TxInfoAdapterListener listener = null;
private TextView amountTextView = null;
public ViewHolder(TxInfoAdapterListener listener, View view) {
super(view);
inboundColour = ThemeHelper.getThemedColor(view.getContext(), R.attr.positiveColor);
outboundColour = ThemeHelper.getThemedColor(view.getContext(), R.attr.negativeColor);
pendingColour = ThemeHelper.getThemedColor(view.getContext(), R.attr.neutralColor);
failedColour = ThemeHelper.getThemedColor(view.getContext(), R.attr.neutralColor);
this.listener = listener;
Calendar cal = Calendar.getInstance();
TimeZone tz = cal.getTimeZone(); //get the local time zone.
DATETIME_FORMATTER.setTimeZone(tz);
}
public void bind(TransactionInfo txInfo) {
String displayAmount = Helper.getDisplayAmount(txInfo.amount, Helper.DISPLAY_DIGITS_INFO);
TextView confirmationsTextView = ((TextView)itemView.findViewById(R.id.tvConfirmations));
CircularProgressIndicator confirmationsProgressBar = ((CircularProgressIndicator)itemView.findViewById(R.id.pbConfirmations));
this.amountTextView = ((TextView)itemView.findViewById(R.id.tx_amount));
((TextView)itemView.findViewById(R.id.tx_failed)).setVisibility(View.GONE);
if(txInfo.isFailed) {
((TextView)itemView.findViewById(R.id.tx_amount)).setText(itemView.getContext().getString(R.string.tx_list_amount_negative, displayAmount));
((TextView)itemView.findViewById(R.id.tx_failed)).setVisibility(View.VISIBLE);
setTxColour(failedColour);
confirmationsTextView.setVisibility(View.GONE);
confirmationsProgressBar.setVisibility(View.GONE);
} else if(txInfo.isPending) {
setTxColour(pendingColour);
confirmationsProgressBar.setVisibility(View.GONE);
confirmationsProgressBar.setIndeterminate(true);
confirmationsProgressBar.setVisibility(View.VISIBLE);
confirmationsTextView.setVisibility(View.GONE);
} else if (txInfo.direction == TransactionInfo.Direction.Direction_In) {
setTxColour(inboundColour);
if (!txInfo.isConfirmed()) {
confirmationsProgressBar.setVisibility(View.VISIBLE);
final int confirmations = (int) txInfo.confirmations;
confirmationsProgressBar.setProgressCompat(confirmations, true);
final String confCount = Integer.toString(confirmations);
confirmationsTextView.setText(confCount);
if (confCount.length() == 1) // we only have space for character in the progress circle
confirmationsTextView.setVisibility(View.VISIBLE);
else
confirmationsTextView.setVisibility(View.GONE);
} else {
confirmationsProgressBar.setVisibility(View.GONE);
confirmationsTextView.setVisibility(View.GONE);
}
} else {
setTxColour(outboundColour);
confirmationsProgressBar.setVisibility(View.GONE);
confirmationsTextView.setVisibility(View.GONE);
}
if (txInfo.direction == TransactionInfo.Direction.Direction_Out) {
((TextView)itemView.findViewById(R.id.tx_amount)).setText(itemView.getContext().getString(R.string.tx_list_amount_negative, displayAmount));
} else {
((TextView)itemView.findViewById(R.id.tx_amount)).setText(itemView.getContext().getString(R.string.tx_list_amount_positive, displayAmount));
}
TextView paymentIdTextView = ((TextView)itemView.findViewById(R.id.tx_paymentid));
String tag = null;
String info = "";
UserNotes userNotes = new UserNotes(txInfo.notes);
if ((txInfo.addressIndex != 0) && (txInfo.direction == TransactionInfo.Direction.Direction_In))
tag = txInfo.getDisplayLabel();
if ((userNotes.note.isEmpty())) {
if (!txInfo.paymentId.equals("0000000000000000")) {
info = txInfo.paymentId;
}
} else {
info = userNotes.note;
}
if (tag == null) {
paymentIdTextView.setText(info);
} else {
Spanned label = Html.fromHtml(itemView.getContext().getString(R.string.tx_details_notes,
Integer.toHexString(ThemeHelper.getThemedColor(itemView.getContext(), R.attr.positiveColor) & 0xFFFFFF),
Integer.toHexString(ThemeHelper.getThemedColor(itemView.getContext(), android.R.attr.colorBackground) & 0xFFFFFF),
tag, info.isEmpty() ? "" : ("&nbsp; " + info)));
paymentIdTextView.setText(label);
}
((TextView)itemView.findViewById(R.id.tx_datetime)).setText(getDateTime(txInfo.timestamp));
itemView.setOnClickListener(view -> {
listener.onClickTransaction(txInfo);
});
}
private void setTxColour(int clr) {
amountTextView.setTextColor(clr);
}
private String getDateTime(long time) {
return DATETIME_FORMATTER.format(new Date(time * 1000));
}
}
/**

View file

@ -17,6 +17,8 @@
package com.m2049r.xmrwallet.service;
import static com.m2049r.xmrwallet.model.Wallet.SWEEP_ALL;
import com.m2049r.xmrwallet.data.DefaultNodes;
import com.m2049r.xmrwallet.data.Node;
import com.m2049r.xmrwallet.data.TxData;
@ -97,7 +99,7 @@ public class MoneroHandlerThread extends Thread implements WalletListener {
public boolean sendTx(String address, String amountStr) {
long amount = Wallet.getAmountFromString(amountStr);
PendingTransaction pendingTx = wallet.createTransaction(new TxData(address, amount, 0, PendingTransaction.Priority.Priority_Default));
PendingTransaction pendingTx = wallet.createTransaction(new TxData(address, SWEEP_ALL, 0, PendingTransaction.Priority.Priority_Default));
return pendingTx.commit("", true);
}

View file

@ -28,14 +28,6 @@
android:layout_height="wrap_content"
android:layout_gravity="center">
<ImageView
android:id="@+id/ivTxType"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_gravity="center"
android:src="@drawable/ic_xmrto_btc"
android:visibility="visible" />
<com.google.android.material.progressindicator.CircularProgressIndicator
android:id="@+id/pbConfirmations"
android:layout_width="0dp"