deal with pending transactions

This commit is contained in:
m2049r 2017-08-20 17:53:10 +02:00
parent 344eeb7a3b
commit 3a68802ae7
6 changed files with 44 additions and 6 deletions

View File

@ -132,6 +132,7 @@ public class TxFragment extends Fragment {
sb.append(getString(R.string.tx_paymentId)).append(": ");
sb.append(info.paymentId).append("\n");
sb.append(getString(R.string.tx_amount)).append(": ");
sb.append((info.direction == TransactionInfo.Direction.Direction_In ? "+" : "-"));
sb.append(Wallet.getDisplayAmount(info.amount)).append("\n");
sb.append(getString(R.string.tx_fee)).append(": ");
sb.append(Wallet.getDisplayAmount(info.fee)).append("\n");
@ -141,7 +142,13 @@ public class TxFragment extends Fragment {
sb.append(getString(R.string.tx_timestamp)).append(": ");
sb.append(TS_FORMATTER.format(new Date(info.timestamp * 1000))).append("\n");
sb.append(getString(R.string.tx_blockheight)).append(": ");
sb.append(info.blockheight).append("\n");
if (info.isPending) {
sb.append(getString(R.string.tx_pending)).append("\n");
} else if (info.isFailed) {
sb.append(getString(R.string.tx_failed)).append("\n");
} else {
sb.append(info.blockheight).append("\n");
}
sb.append(getString(R.string.tx_transfers)).append(": ");
if (info.transfers != null) {
boolean comma = false;
@ -162,7 +169,7 @@ public class TxFragment extends Fragment {
ClipData clip = ClipData.newPlainText(getString(R.string.tx_copy_label), sb.toString());
clipboardManager.setPrimaryClip(clip);
Toast.makeText(getActivity(), getString(R.string.tx_copy_message), Toast.LENGTH_SHORT).show();
Log.d(TAG, sb.toString());
//Log.d(TAG, sb.toString());
}
TransactionInfo info = null;
@ -185,8 +192,15 @@ public class TxFragment extends Fragment {
tvTxId.setText(info.hash);
tvTxKey.setText(info.txKey.isEmpty() ? "-" : info.txKey);
tvTxPaymentId.setText(info.paymentId);
tvTxBlockheight.setText("" + info.blockheight);
tvTxAmount.setText(Wallet.getDisplayAmount(info.amount));
if (info.isPending) {
tvTxBlockheight.setText(getString(R.string.tx_pending));
} else if (info.isFailed) {
tvTxBlockheight.setText(getString(R.string.tx_failed));
} else {
tvTxBlockheight.setText("" + info.blockheight);
}
String sign = (info.direction == TransactionInfo.Direction.Direction_In ? "+" : "-");
tvTxAmount.setText(sign + Wallet.getDisplayAmount(info.amount));
tvTxFee.setText(Wallet.getDisplayAmount(info.fee));
StringBuffer sb = new StringBuffer();
if (info.transfers != null) {

View File

@ -45,6 +45,8 @@ public class TransactionInfoAdapter extends RecyclerView.Adapter<TransactionInfo
static final int TX_RED = Color.rgb(255, 79, 65);
static final int TX_GREEN = Color.rgb(54, 176, 91);
static final int TX_PENDING = Color.rgb(72, 53, 176);
static final int TX_FAILED = Color.rgb(208, 0, 255);
public interface OnInteractionListener {
void onInteraction(View view, TransactionInfo item);
@ -89,6 +91,13 @@ public class TransactionInfoAdapter extends RecyclerView.Adapter<TransactionInfo
Collections.sort(data, new Comparator<TransactionInfo>() {
@Override
public int compare(TransactionInfo o1, TransactionInfo o2) {
if ((o1.isPending) && (o2.isPending)) {
long b1 = o1.timestamp;
long b2 = o2.timestamp;
return (b1 > b2) ? -1 : (b1 < b2) ? 1 : 0;
}
if (o1.isPending) return -1;
if (o2.isPending) return 1;
long b1 = o1.blockheight;
long b2 = o2.blockheight;
return (b1 > b2) ? -1 : (b1 < b2) ? 1 : 0;
@ -141,7 +150,16 @@ public class TransactionInfoAdapter extends RecyclerView.Adapter<TransactionInfo
this.tvAmount.setText(amountParts[0]);
this.tvAmountDecimal.setText(amountParts[1]);
if (infoItem.direction == TransactionInfo.Direction.Direction_In) {
if (infoItem.isPending) {
setTxColour(TX_PENDING);
if (infoItem.direction == TransactionInfo.Direction.Direction_Out) {
this.tvAmount.setText('-' + amountParts[0]);
}
} else if (infoItem.isFailed) {
this.tvAmount.setText('(' + amountParts[0]);
this.tvAmountDecimal.setText(amountParts[1] + ')');
setTxColour(TX_FAILED);
} else if (infoItem.direction == TransactionInfo.Direction.Direction_In) {
setTxColour(TX_GREEN);
} else {
setTxColour(TX_RED);

View File

@ -21,6 +21,7 @@ import android.os.Parcelable;
import android.util.Log;
import java.util.List;
import java.util.Random;
// this is not the TransactionInfo from the API as that is owned by the TransactionHistory
// this is a POJO for the TransactionInfoAdapter
@ -91,6 +92,7 @@ public class TransactionInfo implements Parcelable {
this.confirmations = confirmations;
this.transfers = transfers;
}
Random rnd = new Random();
public String toString() {
return direction + "@" + blockheight + " " + amount;

View File

@ -345,6 +345,7 @@ public class WalletService extends Service {
Log.d(TAG, "Wallet store failed: " + myWallet.getErrorString());
}
if (observer != null) observer.onWalletStored(rc);
listener.updated = true;
}
} else if (cmd.equals(REQUEST_CMD_SETNOTE)) {
Wallet myWallet = getWallet();

View File

@ -7,8 +7,8 @@
<color name="main_background">#f0eeef</color>
<color name="menu_background_color">#1c1c1c</color>
<color name="tx_green">#36b05b</color>
<color name="tx_red">#ff4f41</color>
<color name="tx_pending">#FF4081</color>
</resources>

View File

@ -135,6 +135,9 @@
<string name="tx_notes_set">Notes saved</string>
<string name="tx_notes_set_failed">Notes saved failed</string>
<string name="tx_pending">PENDING</string>
<string name="tx_failed">FAILED</string>
<string name="big_amount">999999.999999999999</string>
<string-array name="mixin">