diff --git a/app/src/main/java/net/mynero/wallet/fragment/dialog/SendBottomSheetDialog.java b/app/src/main/java/net/mynero/wallet/fragment/dialog/SendBottomSheetDialog.java index 295265d..c46470a 100644 --- a/app/src/main/java/net/mynero/wallet/fragment/dialog/SendBottomSheetDialog.java +++ b/app/src/main/java/net/mynero/wallet/fragment/dialog/SendBottomSheetDialog.java @@ -17,6 +17,7 @@ import androidx.activity.result.ActivityResultLauncher; import androidx.activity.result.contract.ActivityResultContracts; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.fragment.app.FragmentActivity; import androidx.lifecycle.LiveData; import androidx.lifecycle.MutableLiveData; @@ -204,24 +205,27 @@ public class SendBottomSheetDialog extends BottomSheetDialogFragment { }); createButton.setOnClickListener(view1 -> { - boolean sendAll = sendingMax.getValue() != null ? sendingMax.getValue() : false; - String address = addressEditText.getText().toString().trim(); - String amount = amountEditText.getText().toString().trim(); - boolean validAddress = Wallet.isAddressValid(address); - if (validAddress && (!amount.isEmpty() || sendAll)) { - long amountRaw = Wallet.getAmountFromString(amount); - long balance = BalanceService.getInstance().getUnlockedBalanceRaw(); - if ((amountRaw >= balance || amountRaw <= 0) && !sendAll) { - Toast.makeText(getActivity(), getString(R.string.send_amount_invalid), Toast.LENGTH_SHORT).show(); - return; + FragmentActivity activity = getActivity(); + if(activity != null) { + boolean sendAll = sendingMax.getValue() != null ? sendingMax.getValue() : false; + String address = addressEditText.getText().toString().trim(); + String amount = amountEditText.getText().toString().trim(); + boolean validAddress = Wallet.isAddressValid(address); + if (validAddress && (!amount.isEmpty() || sendAll)) { + long amountRaw = Wallet.getAmountFromString(amount); + long balance = BalanceService.getInstance().getUnlockedBalanceRaw(); + if ((amountRaw >= balance || amountRaw <= 0) && !sendAll) { + Toast.makeText(activity, getString(R.string.send_amount_invalid), Toast.LENGTH_SHORT).show(); + return; + } + Toast.makeText(activity, getString(R.string.creating_tx), Toast.LENGTH_SHORT).show(); + createButton.setEnabled(false); + createTx(address, amount, sendAll, priority); + } else if (!validAddress) { + Toast.makeText(activity, getString(R.string.send_address_invalid), Toast.LENGTH_SHORT).show(); + } else { + Toast.makeText(activity, getString(R.string.send_amount_empty), Toast.LENGTH_SHORT).show(); } - Toast.makeText(getActivity(), getString(R.string.creating_tx), Toast.LENGTH_SHORT).show(); - createButton.setEnabled(false); - createTx(address, amount, sendAll, priority); - } else if (!validAddress) { - Toast.makeText(getActivity(), getString(R.string.send_address_invalid), Toast.LENGTH_SHORT).show(); - } else { - Toast.makeText(getActivity(), getString(R.string.send_amount_empty), Toast.LENGTH_SHORT).show(); } }); @@ -247,51 +251,50 @@ public class SendBottomSheetDialog extends BottomSheetDialogFragment { } private void sendTx(PendingTransaction pendingTx) { - ((MoneroApplication)getActivity().getApplication()).getExecutor().execute(() -> { - boolean success = TxService.getInstance().sendTx(pendingTx); - Activity activity = getActivity(); - if (activity != null) { + Activity activity = getActivity(); + if (activity != null) { + ((MoneroApplication) activity.getApplication()).getExecutor().execute(() -> { + boolean success = TxService.getInstance().sendTx(pendingTx); activity.runOnUiThread(() -> { if (success) { - Toast.makeText(getActivity(), getString(R.string.sent_tx), Toast.LENGTH_SHORT).show(); - if(listener != null) { + Toast.makeText(activity, getString(R.string.sent_tx), Toast.LENGTH_SHORT).show(); + if (listener != null) { listener.onSentTransaction(); } dismiss(); } else { sendButton.setEnabled(true); - Toast.makeText(getActivity(), getString(R.string.error_sending_tx), Toast.LENGTH_SHORT).show(); + Toast.makeText(activity, getString(R.string.error_sending_tx), Toast.LENGTH_SHORT).show(); } }); - } - }); + }); + } } private void createTx(String address, String amount, boolean sendAll, PendingTransaction.Priority feePriority) { - ((MoneroApplication)getActivity().getApplication()).getExecutor().execute(() -> { - try { - PendingTransaction pendingTx = TxService.getInstance().createTx(address, amount, sendAll, feePriority, selectedUtxos); - if (pendingTx != null && pendingTx.getStatus() == PendingTransaction.Status.Status_Ok) { - _pendingTransaction.postValue(pendingTx); - } else { - Activity activity = getActivity(); - if (activity != null) { + Activity activity = getActivity(); + if (activity != null) { + ((MoneroApplication)activity.getApplication()).getExecutor().execute(() -> { + try { + PendingTransaction pendingTx = TxService.getInstance().createTx(address, amount, sendAll, feePriority, selectedUtxos); + if (pendingTx != null && pendingTx.getStatus() == PendingTransaction.Status.Status_Ok) { + _pendingTransaction.postValue(pendingTx); + } else { activity.runOnUiThread(() -> { createButton.setEnabled(true); - Toast.makeText(getActivity(), getString(R.string.error_creating_tx), Toast.LENGTH_SHORT).show(); + if(pendingTx != null) { + Toast.makeText(activity, getString(R.string.error_creating_tx, pendingTx.getErrorString()), Toast.LENGTH_SHORT).show(); + } }); } - } - } catch (Exception e) { - Activity activity = getActivity(); - if (activity != null) { + } catch (Exception e) { activity.runOnUiThread(() -> { createButton.setEnabled(true); - Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_SHORT).show(); + Toast.makeText(activity, e.getMessage(), Toast.LENGTH_SHORT).show(); }); } - } - }); + }); + } } private void showConfirmationLayout(boolean show) { diff --git a/app/src/main/java/net/mynero/wallet/fragment/home/HomeFragment.java b/app/src/main/java/net/mynero/wallet/fragment/home/HomeFragment.java index e978438..71afd2a 100644 --- a/app/src/main/java/net/mynero/wallet/fragment/home/HomeFragment.java +++ b/app/src/main/java/net/mynero/wallet/fragment/home/HomeFragment.java @@ -92,7 +92,7 @@ public class HomeFragment extends Fragment implements TransactionInfoAdapter.TxI if (balanceService != null) { balanceService.balanceInfo.observe(getViewLifecycleOwner(), balanceInfo -> { if(balanceInfo != null) { - unlockedBalanceTextView.setText(getString(R.string.wallet_balance_text, balanceInfo.getUnlockedDisplay())); + unlockedBalanceTextView.setText(balanceInfo.getUnlockedDisplay()); if (balanceInfo.getLockedDisplay().equals(Constants.STREET_MODE_BALANCE) || balanceInfo.isLockedBalanceZero()) { lockedBalanceTextView.setVisibility(View.INVISIBLE); diff --git a/app/src/main/java/net/mynero/wallet/fragment/send/SendFragment.java b/app/src/main/java/net/mynero/wallet/fragment/send/SendFragment.java index 3563770..668837b 100644 --- a/app/src/main/java/net/mynero/wallet/fragment/send/SendFragment.java +++ b/app/src/main/java/net/mynero/wallet/fragment/send/SendFragment.java @@ -111,7 +111,7 @@ public class SendFragment extends Fragment { } private void init() { - addOutput(); + addOutput(true); } private void bindListeners() { @@ -131,7 +131,7 @@ public class SendFragment extends Fragment { sendMaxButton.setVisibility(View.GONE); int outputCount = getDestCount(); if(outputCount < 8) { - addOutput(); + addOutput(false); } else { Toast.makeText(getActivity(), getString(R.string.max_outputs_allowed), Toast.LENGTH_SHORT).show(); } @@ -214,11 +214,11 @@ public class SendFragment extends Fragment { }); } - private void addOutput() { + private void addOutput(boolean initial) { if (inflater != null) { int index = getDestCount(); ConstraintLayout entryView = (ConstraintLayout)inflater.inflate(R.layout.transaction_output_item, null); - + ImageButton removeOutputImageButton = entryView.findViewById(R.id.remove_output_imagebutton); entryView.findViewById(R.id.paste_address_imagebutton).setOnClickListener(view1 -> { Context ctx = getContext(); @@ -230,12 +230,19 @@ public class SendFragment extends Fragment { } }); entryView.findViewById(R.id.scan_address_imagebutton).setOnClickListener(view -> onScan(index)); - entryView.findViewById(R.id.remove_output_imagebutton).setOnClickListener(view -> { - int currentCount = getDestCount(); - if(currentCount > 1) { - destList.removeView(entryView); - } - }); + if(initial) { + removeOutputImageButton.setVisibility(View.INVISIBLE); + } else { + removeOutputImageButton.setOnClickListener(view -> { + int currentCount = getDestCount(); + if (currentCount > 1) { + if (currentCount == 2) { + sendMaxButton.setVisibility(View.VISIBLE); + } + destList.removeView(entryView); + } + }); + } destList.addView(entryView); } } @@ -254,14 +261,14 @@ public class SendFragment extends Fragment { private void unprepareMaxSend() { ConstraintLayout entryView = getDestView(0); - entryView.findViewById(R.id.sending_all_textview).setVisibility(View.GONE); + entryView.findViewById(R.id.sending_all_textview).setVisibility(View.INVISIBLE); entryView.findViewById(R.id.amount_edittext).setVisibility(View.VISIBLE); } private void prepareOutputsForMaxSend() { ConstraintLayout entryView = getDestView(0); entryView.findViewById(R.id.sending_all_textview).setVisibility(View.VISIBLE); - entryView.findViewById(R.id.amount_edittext).setVisibility(View.GONE); + entryView.findViewById(R.id.amount_edittext).setVisibility(View.INVISIBLE); } private void showConfirmationLayout(boolean show) { diff --git a/app/src/main/res/layout/fragment_home.xml b/app/src/main/res/layout/fragment_home.xml index cb160fc..fd99178 100644 --- a/app/src/main/res/layout/fragment_home.xml +++ b/app/src/main/res/layout/fragment_home.xml @@ -24,13 +24,12 @@ android:layout_height="wrap_content" android:layout_marginStart="24dp" android:layout_marginTop="24dp" - android:layout_marginEnd="24dp" - android:textSize="24sp" + android:textSize="32sp" android:textStyle="bold" app:layout_constraintEnd_toStartOf="@id/settings_imageview" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" - tools:text="100.000000000000 XMR" /> + tools:text="100.000000000000" /> - %1$s XMR + %1$s confirming Please enter an amount Please enter a valid amount Max Undo - Error sending tx - Error creating tx + Error sending transaction + Error creating: %1$s Create wallet Invalid mnemonic Passwords do not match