From 3a68802ae710d4dc173e7f8f060a1cbf8cd69f02 Mon Sep 17 00:00:00 2001 From: m2049r <30435443+m2049r@users.noreply.github.com> Date: Sun, 20 Aug 2017 17:53:10 +0200 Subject: [PATCH] deal with pending transactions --- .../java/com/m2049r/xmrwallet/TxFragment.java | 22 +++++++++++++++---- .../layout/TransactionInfoAdapter.java | 20 ++++++++++++++++- .../xmrwallet/model/TransactionInfo.java | 2 ++ .../xmrwallet/service/WalletService.java | 1 + app/src/main/res/values/colors.xml | 2 +- app/src/main/res/values/strings.xml | 3 +++ 6 files changed, 44 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/m2049r/xmrwallet/TxFragment.java b/app/src/main/java/com/m2049r/xmrwallet/TxFragment.java index 8cc30af9..5faeeb4b 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/TxFragment.java +++ b/app/src/main/java/com/m2049r/xmrwallet/TxFragment.java @@ -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) { diff --git a/app/src/main/java/com/m2049r/xmrwallet/layout/TransactionInfoAdapter.java b/app/src/main/java/com/m2049r/xmrwallet/layout/TransactionInfoAdapter.java index 948805d4..56436250 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/layout/TransactionInfoAdapter.java +++ b/app/src/main/java/com/m2049r/xmrwallet/layout/TransactionInfoAdapter.java @@ -45,6 +45,8 @@ public class TransactionInfoAdapter extends RecyclerView.Adapter() { @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#f0eeef #1c1c1c - #36b05b #ff4f41 + #FF4081 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b2091288..7259a53d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -135,6 +135,9 @@ Notes saved Notes saved failed + PENDING + FAILED + 999999.999999999999