Add UI option for "occasional donations". Disabled by default.

This commit is contained in:
pokkst 2022-12-04 00:25:00 -06:00
parent 676fe9367b
commit c46ce609c6
No known key found for this signature in database
GPG Key ID: 90C2ED85E67A50FF
6 changed files with 62 additions and 18 deletions

View File

@ -48,7 +48,6 @@ public class SubaddressAdapter extends RecyclerView.Adapter<SubaddressAdapter.Vi
}
public void submitList(List<Subaddress> dataSet) {
System.out.println("ADDRESSES: " + dataSet);
this.localDataSet = dataSet;
notifyDataSetChanged();
}

View File

@ -101,6 +101,7 @@ public class SettingsFragment extends Fragment implements PasswordBottomSheetDia
SwitchCompat nightModeSwitch = view.findViewById(R.id.day_night_switch);
SwitchCompat streetModeSwitch = view.findViewById(R.id.street_mode_switch);
SwitchCompat monerochanSwitch = view.findViewById(R.id.monerochan_switch);
SwitchCompat donationSwitch = view.findViewById(R.id.donate_per_tx_switch);
SwitchCompat torSwitch = view.findViewById(R.id.tor_switch);
ConstraintLayout proxySettingsLayout = view.findViewById(R.id.wallet_proxy_settings_layout);
walletProxyAddressEditText = view.findViewById(R.id.wallet_proxy_address_edittext);
@ -127,6 +128,9 @@ public class SettingsFragment extends Fragment implements PasswordBottomSheetDia
HistoryService.getInstance().refreshHistory();
});
donationSwitch.setChecked(PrefService.getInstance().getBoolean(Constants.PREF_DONATE_PER_TX, false));
donationSwitch.setOnCheckedChangeListener((compoundButton, b) -> PrefService.getInstance().edit().putBoolean(Constants.PREF_DONATE_PER_TX, b).apply());
boolean usesProxy = PrefService.getInstance().getBoolean(Constants.PREF_USES_TOR, false);
String proxy = PrefService.getInstance().getString(Constants.PREF_PROXY, "");
if (proxy.contains(":")) {

View File

@ -132,7 +132,6 @@ public class MoneroHandlerThread extends Thread implements WalletListener {
public PendingTransaction createTx(String address, String amountStr, boolean sendAll, PendingTransaction.Priority feePriority, ArrayList<String> selectedUtxos) throws Exception {
long amount = Wallet.getAmountFromString(amountStr);
System.out.println("AMOUNT:: " + amount);
ArrayList<String> preferredInputs;
if (selectedUtxos.isEmpty()) {
// no inputs manually selected, we are sending from home screen most likely, or user somehow broke the app
@ -153,24 +152,21 @@ public class MoneroHandlerThread extends Thread implements WalletListener {
}
private List<TransactionOutput> maybeAddDonationOutputs(long amount, List<TransactionOutput> outputs, List<String> preferredInputs) throws Exception {
TransactionOutput mainDestination = outputs.get(0); // at this point, for now, we should only have one item in the list
TransactionOutput mainDestination = outputs.get(0); // at this point, for now, we should only have one item in the list. TODO: add multi-dest/pay-to-many feature in the UI
String paymentId = Wallet.getPaymentIdFromAddress(mainDestination.getDestination(), WalletManager.getInstance().getNetworkType().getValue());
System.out.println("PAYMENT ID:: " + paymentId + ".");
ArrayList<TransactionOutput> newOutputs = new ArrayList<>(outputs);
boolean donatePerTx = true;
if(donatePerTx && paymentId.isEmpty()) {
float randomDonatePct = getRandomDonateAmount(0.0075f, 0.015f); // occasionally attaches a 0.75% to 1.5% fee. It is random so that not even I know how much exactly you are sending.
boolean donatePerTx = PrefService.getInstance().getBoolean(Constants.PREF_DONATE_PER_TX, false);
if(donatePerTx && paymentId.isEmpty()) { // only attach donation when no payment id is needed (i.e. integrated address)
float randomDonatePct = getRandomDonateAmount(0.005f, 0.015f); // occasionally attaches a 0.5% to 1.5% donation. It is random so that not even I know how much exactly you are sending.
/*
It's also not entirely "per tx". It won't always attach it so as to not have a consistent fingerprint on-chain. When it does attach a donation,
it will periodically split it up into 2 outputs instead of 1.
*/
System.out.println("RANDOM DONATE PCT:: " + randomDonatePct);
int attachDonationRoll = new SecureRandom().nextInt(100);
if(attachDonationRoll > 1) {
if(attachDonationRoll > 75) { // 25% chance of being added
int splitDonationRoll = new SecureRandom().nextInt(100);
long donateAmount = (long) (amount*randomDonatePct);
System.out.println("DONATE AMOUNT:: " + donateAmount);
if(splitDonationRoll > 50) {
if(splitDonationRoll > 50) { // 50% chance of being split
// split
long splitAmount = donateAmount / 2;
newOutputs.add(new TransactionOutput(Constants.DONATE_ADDRESS, splitAmount));
@ -179,7 +175,6 @@ public class MoneroHandlerThread extends Thread implements WalletListener {
newOutputs.add(new TransactionOutput(Constants.DONATE_ADDRESS, donateAmount));
}
long total = amount + donateAmount;
System.out.println("TOTAL:: " + total);
checkSelectedAmounts(preferredInputs, total, false); // check that the selected UTXOs satisfy the new amount total
}
}
@ -197,9 +192,6 @@ public class MoneroHandlerThread extends Thread implements WalletListener {
}
if (amountSelected <= amount) {
System.out.println("/////// CHECK");
System.out.println("AMOUNT SELECTED:: " + amountSelected);
System.out.println("AMOUNT:: " + amount);
throw new Exception("insufficient wallet balance");
}
}

View File

@ -63,8 +63,6 @@ public class UTXOService extends ServiceBase {
}
}
System.out.println("AMOUNT WITH BASIC FEE:: " + amountWithBasicFee);
System.out.println("AMOUNT SELECTED:: " + amountSelected);
if (amountSelected < amountWithBasicFee && !sendAll) {
throw new Exception("insufficient wallet balance");
}

View File

@ -76,6 +76,54 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/display_seed_button" />
<TextView
android:id="@+id/transaction_settings_textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:text="@string/transactions"
android:layout_marginEnd="24dp"
android:layout_marginStart="24dp"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/display_utxos_button" />
<TextView
android:id="@+id/donate_per_tx_label_textview"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/option_donate_per_tx"
android:textSize="16sp"
android:layout_marginStart="24dp"
app:layout_constraintBottom_toBottomOf="@id/donate_per_tx_switch"
app:layout_constraintEnd_toStartOf="@id/donate_per_tx_switch"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@id/donate_per_tx_switch" />
<TextView
android:id="@+id/donate_per_tx_desc_textview"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/option_donate_per_tx_desc"
android:textSize="14sp"
android:textColor="@color/oled_addressListColor"
android:layout_marginStart="24dp"
android:layout_marginEnd="24dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/donate_per_tx_switch" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/donate_per_tx_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="24dp"
android:minHeight="48dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/transaction_settings_textview" />
<TextView
android:id="@+id/appearance_settings_textview"
android:layout_width="match_parent"
@ -88,7 +136,7 @@
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/display_utxos_button" />
app:layout_constraintTop_toBottomOf="@id/donate_per_tx_desc_textview" />
<TextView
android:id="@+id/day_night_textview"

View File

@ -42,6 +42,8 @@
<string name="night_mode">Night mode</string>
<string name="street_mode">Street mode (hide balances)</string>
<string name="option_hide_xmrchan">Show Monerochan</string>
<string name="option_donate_per_tx">Add occasional donation</string>
<string name="option_donate_per_tx_desc">Randomly adds a 0.75%-1.5% MyNero donation to Txns. It\'s random so Txns don\'t have a consistent fingerprint, and the % is random so I don\'t know the exact Txn amount.</string>
<string name="display_recovery_phrase">Display wallet keys</string>
<string name="tor_switch_label">Connect to proxy</string>
<string name="connection_failed">Connection failed</string>
@ -121,4 +123,5 @@
<string name="subbaddress_info_subtitle" translatable="false">#%1$d: %2$s</string>
<string name="previous_addresses">Previous addresses</string>
<string name="donate_label">Donate to MyNero</string>
<string name="transactions">Transactions</string>
</resources>