From d4e871ede555e178a18607326a4bda270dc7af5a Mon Sep 17 00:00:00 2001 From: pokkst Date: Sat, 11 Mar 2023 17:35:43 -0600 Subject: [PATCH] Testing safe-guard against integrated addresses inside of pay-to-many txs. It should fail anyway right now but this is a sanity check. --- .../wallet/fragment/send/SendFragment.java | 51 ++++++++++++------- .../wallet/fragment/send/SendViewModel.java | 7 +++ .../java/net/mynero/wallet/util/UriData.java | 5 ++ app/src/main/res/values/strings.xml | 2 + 4 files changed, 47 insertions(+), 18 deletions(-) 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 41e53be..ffbd4ca 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 @@ -137,7 +137,6 @@ public class SendFragment extends Fragment { } }); sendMaxButton.setOnClickListener(view1 -> { - addOutputImageView.setVisibility(View.INVISIBLE); boolean currentValue = mViewModel.sendingMax.getValue() != null ? mViewModel.sendingMax.getValue() : false; mViewModel.setSendingMax(!currentValue); }); @@ -192,17 +191,19 @@ public class SendFragment extends Fragment { mViewModel.sendingMax.observe(getViewLifecycleOwner(), sendingMax -> { if (mViewModel.pendingTransaction.getValue() == null) { if (sendingMax) { - addOutputImageView.setVisibility(View.GONE); prepareOutputsForMaxSend(); sendMaxButton.setText(getText(R.string.undo)); } else { - addOutputImageView.setVisibility(View.VISIBLE); unprepareMaxSend(); sendMaxButton.setText(getText(R.string.send_max)); } } }); + mViewModel.showAddOutputButton.observe(getViewLifecycleOwner(), show -> { + setAddOutputButtonVisibility(show ? View.VISIBLE : View.INVISIBLE); + }); + mViewModel.pendingTransaction.observe(getViewLifecycleOwner(), pendingTx -> { showConfirmationLayout(pendingTx != null); @@ -322,31 +323,41 @@ public class SendFragment extends Fragment { } private void pasteAddress(ConstraintLayout entryView, String clipboard, boolean pastingAmount) { + if(pastingAmount) { + try { + Double.parseDouble(clipboard); + setAmount(entryView, clipboard); + } catch (Exception e) { + Toast.makeText(getActivity(), getString(R.string.send_amount_invalid), Toast.LENGTH_SHORT).show(); + return; + } + } + UriData uriData = UriData.parse(clipboard); if (uriData != null) { + int currentOutputs = getDestCount(); + if(currentOutputs > 1 && uriData.hasPaymentId()) { + Toast.makeText(getActivity(), getString(R.string.paymentid_paytomany), Toast.LENGTH_SHORT).show(); + return; + } else if(currentOutputs == 1 && uriData.hasPaymentId()) { + mViewModel.setShowAddOutputButton(false); + } EditText addressField = entryView.findViewById(R.id.address_edittext); addressField.setText(uriData.getAddress()); if (uriData.hasAmount()) { - sendMaxButton.setEnabled(false); - EditText amountField = entryView.findViewById(R.id.amount_edittext); - amountField.setText(uriData.getAmount()); + setAmount(entryView, uriData.getAmount()); } } else { - if(pastingAmount) { - try { - Double.parseDouble(clipboard); - sendMaxButton.setEnabled(false); - EditText amountField = entryView.findViewById(R.id.amount_edittext); - amountField.setText(clipboard); - } catch (Exception e) { - Toast.makeText(getActivity(), getString(R.string.send_amount_invalid), Toast.LENGTH_SHORT).show(); - } - } else { - Toast.makeText(getActivity(), getString(R.string.send_address_invalid), Toast.LENGTH_SHORT).show(); - } + Toast.makeText(getActivity(), getString(R.string.send_address_invalid), Toast.LENGTH_SHORT).show(); } } + private void setAmount(ConstraintLayout entryView, String amount) { + sendMaxButton.setEnabled(false); + EditText amountField = entryView.findViewById(R.id.amount_edittext); + amountField.setText(amount); + } + private void createTx(List> dests, boolean sendAll, PendingTransaction.Priority feePriority) { ((MoneroApplication)getActivity().getApplication()).getExecutor().execute(() -> { try { @@ -393,4 +404,8 @@ public class SendFragment extends Fragment { } }); } + + private void setAddOutputButtonVisibility(int visibility) { + addOutputImageView.setVisibility(visibility); + } } \ No newline at end of file diff --git a/app/src/main/java/net/mynero/wallet/fragment/send/SendViewModel.java b/app/src/main/java/net/mynero/wallet/fragment/send/SendViewModel.java index cb807cc..7282c3c 100644 --- a/app/src/main/java/net/mynero/wallet/fragment/send/SendViewModel.java +++ b/app/src/main/java/net/mynero/wallet/fragment/send/SendViewModel.java @@ -9,11 +9,18 @@ import net.mynero.wallet.model.PendingTransaction; public class SendViewModel extends ViewModel { private final MutableLiveData _sendingMax = new MutableLiveData<>(false); public LiveData sendingMax = _sendingMax; + private final MutableLiveData _showAddOutputButton = new MutableLiveData<>(true); + public LiveData showAddOutputButton = _showAddOutputButton; private final MutableLiveData _pendingTransaction = new MutableLiveData<>(null); public LiveData pendingTransaction = _pendingTransaction; public void setSendingMax(boolean value) { _sendingMax.setValue(value); + setShowAddOutputButton(!value); + } + + public void setShowAddOutputButton(boolean value) { + _showAddOutputButton.setValue(value); } public void setPendingTransaction(PendingTransaction pendingTx) { diff --git a/app/src/main/java/net/mynero/wallet/util/UriData.java b/app/src/main/java/net/mynero/wallet/util/UriData.java index 9bf1f3d..9c08cc6 100644 --- a/app/src/main/java/net/mynero/wallet/util/UriData.java +++ b/app/src/main/java/net/mynero/wallet/util/UriData.java @@ -1,6 +1,7 @@ package net.mynero.wallet.util; import net.mynero.wallet.model.Wallet; +import net.mynero.wallet.model.WalletManager; import java.util.HashMap; @@ -46,6 +47,10 @@ public class UriData { return address; } + public boolean hasPaymentId() { + return !Wallet.getPaymentIdFromAddress(this.address, WalletManager.getInstance().getWallet().nettype()).isEmpty(); + } + public String getAmount() { String txAmount = params.get(Constants.URI_ARG_AMOUNT); if (txAmount == null) { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a811692..e96a051 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -125,4 +125,6 @@ [ auth ] To Maximum allowed outputs + Cannot send to integrated addresses in a pay-to-many transaction +