Handle tx history better, and work on the send screen a bit

NOTE: This commit still logs seed phrases for development purposes
This commit is contained in:
pokkst 2022-09-07 19:18:47 -05:00
parent ae232d1a92
commit 569e1e5f5b
No known key found for this signature in database
GPG Key ID: 90C2ED85E67A50FF
12 changed files with 150 additions and 27 deletions

View File

@ -86,7 +86,7 @@ public class TransactionInfoAdapter extends RecyclerView.Adapter<TransactionInfo
TextView confirmationsTextView = ((TextView)itemView.findViewById(R.id.tvConfirmations));
CircularProgressIndicator confirmationsProgressBar = ((CircularProgressIndicator)itemView.findViewById(R.id.pbConfirmations));
confirmationsProgressBar.setMax(TransactionInfo.CONFIRMATION);
this.amountTextView = ((TextView)itemView.findViewById(R.id.tx_amount));
((TextView)itemView.findViewById(R.id.tx_failed)).setVisibility(View.GONE);
if(txInfo.isFailed) {
@ -176,6 +176,7 @@ public class TransactionInfoAdapter extends RecyclerView.Adapter<TransactionInfo
public void submitList(List<TransactionInfo> dataSet) {
this.localDataSet = dataSet;
notifyDataSetChanged();
}
// Create new views (invoked by the layout manager)

View File

@ -41,6 +41,7 @@ public class ReceiveBottomSheetDialog extends BottomSheetDialogFragment {
AddressService.getInstance().address.observe(getViewLifecycleOwner(), addr -> {
if (!addr.isEmpty()) {
System.out.println(addr);
addressTextView.setText(addr);
addressImageView.setImageBitmap(generate(addr, 256, 256));
}

View File

@ -1,9 +1,11 @@
package com.m2049r.xmrwallet.fragment.dialog;
import android.content.ClipboardManager;
import android.os.Bundle;
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
import com.m2049r.xmrwallet.R;
import com.m2049r.xmrwallet.model.Wallet;
import com.m2049r.xmrwallet.service.BalanceService;
import com.m2049r.xmrwallet.service.TxService;
import android.view.LayoutInflater;
@ -11,12 +13,19 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.Observer;
public class SendBottomSheetDialog extends BottomSheetDialogFragment {
private MutableLiveData<Boolean> _sendingMax = new MutableLiveData<>(false);
public LiveData<Boolean> sendingMax = _sendingMax;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
@ -26,26 +35,56 @@ public class SendBottomSheetDialog extends BottomSheetDialogFragment {
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
ImageButton pasteAddressImageButton = view.findViewById(R.id.paste_address_imagebutton);
Button sendMaxButton = view.findViewById(R.id.send_max_button);
EditText addressEditText = view.findViewById(R.id.address_edittext);
EditText amountEditText = view.findViewById(R.id.amount_edittext);
Button sendButton = view.findViewById(R.id.send_button);
TextView sendAllTextView = view.findViewById(R.id.sending_all_textview);
TxService.getInstance().clearSendEvent.observe(getViewLifecycleOwner(), o -> {
dismiss();
});
pasteAddressImageButton.setOnClickListener(view1 -> {
});
sendMaxButton.setOnClickListener(view1 -> {
boolean currentValue = sendingMax.getValue() != null ? sendingMax.getValue() : false;
_sendingMax.postValue(!currentValue);
});
sendButton.setOnClickListener(view1 -> {
String address = addressEditText.getText().toString().trim();
String amount = amountEditText.getText().toString().trim();
boolean validAddress = Wallet.isAddressValid(address);
if (validAddress && !amount.isEmpty()) {
long amountRaw = Wallet.getAmountFromString(amount);
long balance = BalanceService.getInstance().getUnlockedBalanceRaw();
if(amountRaw >= balance || amountRaw <= 0) {
Toast.makeText(getActivity(), getString(R.string.send_amount_invalid), Toast.LENGTH_SHORT).show();
}
sendButton.setEnabled(false);
TxService.getInstance().sendTx(address, amount);
boolean sendAll = sendingMax.getValue() != null ? sendingMax.getValue() : false;
TxService.getInstance().sendTx(address, amount, sendAll);
} else if (!validAddress) {
Toast.makeText(getActivity(), getString(R.string.send_address_invalid), Toast.LENGTH_SHORT).show();
} else if (amount.isEmpty()) {
Toast.makeText(getActivity(), getString(R.string.send_amount_empty), Toast.LENGTH_SHORT).show();
}
});
sendingMax.observe(getViewLifecycleOwner(), sendingMax -> {
if(sendingMax) {
amountEditText.setVisibility(View.INVISIBLE);
sendAllTextView.setVisibility(View.VISIBLE);
sendMaxButton.setText(getText(R.string.undo));
} else {
amountEditText.setVisibility(View.VISIBLE);
sendAllTextView.setVisibility(View.GONE);
sendMaxButton.setText(getText(R.string.send_max));
}
});
}
}

View File

@ -34,6 +34,8 @@ import com.m2049r.xmrwallet.service.BalanceService;
import com.m2049r.xmrwallet.service.HistoryService;
import com.m2049r.xmrwallet.service.TxService;
import java.util.Collections;
public class HomeFragment extends Fragment implements TransactionInfoAdapter.TxInfoAdapterListener {
private HomeViewModel mViewModel;
@ -74,10 +76,20 @@ public class HomeFragment extends Fragment implements TransactionInfoAdapter.TxI
private void bindObservers(View view) {
RecyclerView txHistoryRecyclerView = view.findViewById(R.id.transaction_history_recyclerview);
TextView balanceTextView = view.findViewById(R.id.balance_textview);
TextView unlockedBalanceTextView = view.findViewById(R.id.balance_unlocked_textview);
TextView lockedBalanceTextView = view.findViewById(R.id.balance_locked_textview);
BalanceService.getInstance().balance.observe(getViewLifecycleOwner(), balance -> {
balanceTextView.setText(getString(R.string.wallet_balance_text, Wallet.getDisplayAmount(balance)));
unlockedBalanceTextView.setText(getString(R.string.wallet_balance_text, Wallet.getDisplayAmount(balance)));
});
BalanceService.getInstance().lockedBalance.observe(getViewLifecycleOwner(), lockedBalance -> {
if(lockedBalance == 0) {
lockedBalanceTextView.setVisibility(View.INVISIBLE);
} else {
lockedBalanceTextView.setText(getString(R.string.wallet_locked_balance_text, Wallet.getDisplayAmount(lockedBalance)));
lockedBalanceTextView.setVisibility(View.VISIBLE);
}
});
TransactionInfoAdapter adapter = new TransactionInfoAdapter(this);
@ -87,6 +99,7 @@ public class HomeFragment extends Fragment implements TransactionInfoAdapter.TxI
if(history.isEmpty()) {
txHistoryRecyclerView.setVisibility(View.GONE);
} else {
Collections.sort(history);
adapter.submitList(history);
txHistoryRecyclerView.setVisibility(View.VISIBLE);
}

View File

@ -15,6 +15,8 @@ public class BalanceService extends ServiceBase {
private final MutableLiveData<Long> _balance = new MutableLiveData<>(0L);
public LiveData<Long> balance = _balance;
private final MutableLiveData<Long> _lockedBalance = new MutableLiveData<>(0L);
public LiveData<Long> lockedBalance = _lockedBalance;
public BalanceService(MainActivity mainActivity, MoneroHandlerThread thread) {
super(mainActivity, thread);
@ -22,6 +24,19 @@ public class BalanceService extends ServiceBase {
}
public void refreshBalance() {
_balance.postValue(WalletManager.getInstance().getWallet().getBalance());
_balance.postValue(getUnlockedBalanceRaw());
_lockedBalance.postValue(getLockedBalanceRaw());
}
public long getUnlockedBalanceRaw() {
return WalletManager.getInstance().getWallet().getUnlockedBalance();
}
public long getTotalBalanceRaw() {
return WalletManager.getInstance().getWallet().getBalance();
}
public long getLockedBalanceRaw() {
return getTotalBalanceRaw() - getUnlockedBalanceRaw();
}
}

View File

@ -7,6 +7,7 @@ import com.m2049r.xmrwallet.MainActivity;
import com.m2049r.xmrwallet.model.TransactionInfo;
import com.m2049r.xmrwallet.model.WalletManager;
import java.util.Collections;
import java.util.List;
public class HistoryService extends ServiceBase {
@ -25,7 +26,7 @@ public class HistoryService extends ServiceBase {
}
public void refreshHistory() {
_history.postValue(WalletManager.getInstance().getWallet().getHistory().getAll());
_history.postValue(getHistory());
}
public List<TransactionInfo> getHistory() {

View File

@ -97,9 +97,9 @@ public class MoneroHandlerThread extends Thread implements WalletListener {
listener.onRefresh();
}
public boolean sendTx(String address, String amountStr) {
long amount = Wallet.getAmountFromString(amountStr);
PendingTransaction pendingTx = wallet.createTransaction(new TxData(address, SWEEP_ALL, 0, PendingTransaction.Priority.Priority_Default));
public boolean sendTx(String address, String amountStr, boolean sendAll) {
long amount = sendAll ? SWEEP_ALL : Wallet.getAmountFromString(amountStr);
PendingTransaction pendingTx = wallet.createTransaction(new TxData(address, amount, 0, PendingTransaction.Priority.Priority_Default));
return pendingTx.commit("", true);
}

View File

@ -18,8 +18,8 @@ public class TxService extends ServiceBase {
instance = this;
}
public void sendTx(String address, String amount) {
boolean success = this.getThread().sendTx(address, amount);
public void sendTx(String address, String amount, boolean sendAll) {
boolean success = this.getThread().sendTx(address, amount, sendAll);
if (success) {
_clearSendEvent.call();
}

View File

@ -4,6 +4,6 @@
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="@color/btn_color_selector"
android:fillColor="@color/oled_textColorPrimary"
android:pathData="M19,2h-4.18C14.4,0.84 13.3,0 12,0c-1.3,0 -2.4,0.84 -2.82,2L5,2c-1.1,0 -2,0.9 -2,2v16c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2L21,4c0,-1.1 -0.9,-2 -2,-2zM12,2c0.55,0 1,0.45 1,1s-0.45,1 -1,1 -1,-0.45 -1,-1 0.45,-1 1,-1zM19,20L5,20L5,4h2v3h10L17,4h2v16z" />
</vector>

View File

@ -6,35 +6,37 @@
android:layout_height="match_parent"
tools:context=".fragment.home.HomeFragment">
<ImageView
android:id="@+id/settings_imageview"
android:layout_width="wrap_content"
<TextView
android:id="@+id/balance_unlocked_textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/ic_settings"
android:layout_marginStart="24dp"
android:layout_marginEnd="24dp"
android:layout_marginTop="24dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
android:textAlignment="center"
tools:text="UNLOCKED BALANCE"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<TextView
android:id="@+id/balance_textview"
android:id="@+id/balance_locked_textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginEnd="24dp"
android:textAlignment="center"
tools:text="BALANCE"
tools:text="LOCKED BALANCE"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@id/settings_imageview"
app:layout_constraintBottom_toBottomOf="@id/settings_imageview"/>
app:layout_constraintTop_toBottomOf="@id/balance_unlocked_textview" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/transaction_history_recyclerview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="@id/balance_textview"
app:layout_constraintTop_toBottomOf="@id/balance_locked_textview"
app:layout_constraintBottom_toTopOf="@id/receive_button"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
@ -63,4 +65,14 @@
app:layout_constraintStart_toEndOf="@id/receive_button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
<ImageView
android:id="@+id/settings_imageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_settings"
android:layout_marginEnd="24dp"
app:layout_constraintTop_toTopOf="@id/balance_unlocked_textview"
app:layout_constraintBottom_toBottomOf="@id/balance_unlocked_textview"
app:layout_constraintEnd_toEndOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -19,25 +19,62 @@
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginEnd="24dp"
android:layout_marginBottom="32dp"
android:hint="Address"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@id/amount_edittext"/>
<ImageButton
android:id="@+id/paste_address_imagebutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:padding="8dp"
android:src="@drawable/ic_content_paste_24dp"
app:layout_constraintTop_toTopOf="@id/address_edittext"
app:layout_constraintBottom_toBottomOf="@id/address_edittext"
app:layout_constraintEnd_toEndOf="@id/address_edittext"/>
<EditText
android:id="@+id/amount_edittext"
android:layout_width="match_parent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginEnd="24dp"
android:layout_marginEnd="12dp"
android:hint="Amount"
android:inputType="numberDecimal"
app:layout_constraintBottom_toTopOf="@id/send_button"/>
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/send_max_button"
app:layout_constraintBottom_toTopOf="@id/send_button"
tools:visibility="visible"/>
<TextView
android:id="@+id/sending_all_textview"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginEnd="12dp"
android:text="SENDING ALL"
android:textStyle="bold"
android:visibility="gone"
app:layout_constraintTop_toTopOf="@id/amount_edittext"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@id/send_max_button"
app:layout_constraintBottom_toBottomOf="@id/amount_edittext"/>
<Button
android:id="@+id/send_max_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="24dp"
android:text="@string/send_max"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@id/amount_edittext"
app:layout_constraintBottom_toBottomOf="@id/amount_edittext"
app:layout_constraintStart_toEndOf="@id/amount_edittext"/>
<Button
android:id="@+id/send_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginEnd="24dp"
android:layout_marginTop="32dp"
android:text="Send"
app:layout_constraintTop_toBottomOf="@id/amount_edittext"
app:layout_constraintStart_toStartOf="parent"/>

View File

@ -536,5 +536,9 @@
<string name="hello_first_fragment">Hello first fragment</string>
<string name="hello_second_fragment">Hello second fragment. Arg: %1$s</string>
<string name="wallet_balance_text">%1$s XMR</string>
<string name="wallet_locked_balance_text">+ %1$s confirming</string>
<string name="send_amount_empty">Please enter an amount</string>
<string name="send_amount_invalid">Please enter a valid amount</string>
<string name="send_max">Send Max</string>
<string name="undo">Undo</string>
</resources>