Skip to content

Commit

Permalink
Pocket Change V2 (#914)
Browse files Browse the repository at this point in the history
* show PC on btc confirm
* random slots to refill
  • Loading branch information
m2049r authored Aug 28, 2023
1 parent bf1829f commit 17df7c3
Show file tree
Hide file tree
Showing 32 changed files with 88 additions and 47 deletions.
14 changes: 7 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 33
buildToolsVersion '33.0.2'
ndkVersion '17.2.4988734'
defaultConfig {
applicationId "com.m2049r.xmrwallet"
buildToolsVersion = '34.0.0'
compileSdk 33
minSdkVersion 21
targetSdkVersion 31
versionCode 3307
versionName "3.3.7 'Pocket Change'"
targetSdkVersion 33
versionCode 3308
versionName "3.3.8 'Pocket Change'"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
Expand Down Expand Up @@ -126,11 +126,11 @@ dependencies {
implementation 'androidx.core:core:1.10.1'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.3.0'
implementation 'androidx.recyclerview:recyclerview:1.3.1'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.preference:preference:1.2.0'
implementation 'androidx.preference:preference:1.2.1'

implementation 'com.google.android.material:material:1.9.0'

Expand Down
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-feature
android:name="android.hardware.camera"
android:required="false" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.USE_FINGERPRINT" />
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/com/m2049r/xmrwallet/WalletActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,6 @@ public void onWalletOpen(final Wallet.Device device) {

@Override
public void onWalletStarted(final Wallet.Status walletStatus) {
loadPocketChangeSettings();
runOnUiThread(() -> {
dismissProgressDialog();
if (walletStatus == null) {
Expand All @@ -648,6 +647,8 @@ else if (!walletStatus.isOk())
haveWallet = true;
invalidateOptionsMenu();

loadPocketChangeSettings();

if (requestStreetMode) onEnableStreetMode();

final WalletFragment walletFragment = getWalletFragment();
Expand Down
13 changes: 8 additions & 5 deletions app/src/main/java/com/m2049r/xmrwallet/data/TxData.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
import java.util.Set;

import lombok.Data;
Expand Down Expand Up @@ -136,8 +137,9 @@ public int describeContents() {
//////////////////////////

final static public int POCKETCHANGE_IDX = 1; // subaddress index of first pocketchange slot
final static public int POCKETCHANGE_SLOTS = 10; // number of pocketchange slots
final static public int POCKETCHANGE_IDX_MAX = POCKETCHANGE_IDX + POCKETCHANGE_SLOTS - 1;
final static public int POCKETCHANGE_SLOTS_MIN = 6; // min number of pocketchange slots
final static public int POCKETCHANGE_SLOTS_MAX = 14; // max number of pocketchange slots
final static public int POCKETCHANGE_IDX_MAX = POCKETCHANGE_IDX + POCKETCHANGE_SLOTS_MAX - 1;

@Data
static private class PocketChangeSlot {
Expand Down Expand Up @@ -171,8 +173,8 @@ public void createPocketChange(Wallet wallet) {
List<CoinsInfo> coins = wallet.getCoinsInfos(true);
Set<Integer> spendableSubaddressIdx = new HashSet<>();
PocketChangeSlot reserves = new PocketChangeSlot(); // everything not in a slot spendable
PocketChangeSlot[] slots = new PocketChangeSlot[POCKETCHANGE_SLOTS];
for (int i = 0; i < POCKETCHANGE_SLOTS; i++) {
PocketChangeSlot[] slots = new PocketChangeSlot[POCKETCHANGE_SLOTS_MAX];
for (int i = 0; i < POCKETCHANGE_SLOTS_MAX; i++) {
slots[i] = new PocketChangeSlot();
}
for (CoinsInfo coin : coins) {
Expand Down Expand Up @@ -205,7 +207,8 @@ public void createPocketChange(Wallet wallet) {
// find any slots to fill if possible:
List<Integer> slotsToFill = new ArrayList<>();
List<Long> slotToFillAmounts = new ArrayList<>();
for (int i = 0; i < POCKETCHANGE_SLOTS; i++) {
final int randomSlotCount = new Random().nextInt(POCKETCHANGE_SLOTS_MAX - POCKETCHANGE_SLOTS_MIN + 1) + POCKETCHANGE_SLOTS_MIN;
for (int i = 0; i < randomSlotCount; i++) {
if (slots[i].getAmount() < pocketChangeAmount) {
final long topupAmount = pocketChangeAmount - slots[i].getAmount();
if (topupAmount <= spendableAmount) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ public void setSendListener(SendConfirmWizardFragment.Listener listener) {
private View llConfirmSend;
private Button bSend;
private View pbProgressSend;
private TextView tvTxChange;
private View llPocketChange;


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Expand All @@ -92,6 +95,8 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,

tvTxFee = view.findViewById(R.id.tvTxFee);
tvTxTotal = view.findViewById(R.id.tvTxTotal);
tvTxChange = view.findViewById(R.id.tvTxChange);
llPocketChange = view.findViewById(R.id.llPocketChange);

llStageA = view.findViewById(R.id.llStageA);
evStageA = view.findViewById(R.id.evStageA);
Expand Down Expand Up @@ -217,6 +222,13 @@ public void transactionCreated(final String txTag, final PendingTransaction pend
tvTxFee.setText(Wallet.getDisplayAmount(pendingTransaction.getFee()));
tvTxTotal.setText(Wallet.getDisplayAmount(
pendingTransaction.getFee() + pendingTransaction.getAmount()));
final long change = pendingTransaction.getPocketChange();
if (change > 0) {
llPocketChange.setVisibility(View.VISIBLE);
tvTxChange.setText(Wallet.getDisplayAmount(change));
} else {
llPocketChange.setVisibility(View.GONE);
}
updateSendButton();
});
} else {
Expand Down
33 changes: 27 additions & 6 deletions app/src/main/res/layout/fragment_send_btc_confirm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,31 @@
android:orientation="vertical"
android:visibility="invisible">

<LinearLayout
android:id="@+id/llPocketChange"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:visibility="gone">

<TextView
style="@style/MoneroLabel.Gray"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/pocketchange_title"
android:textAlignment="textStart" />

<TextView
android:id="@+id/tvTxChange"
style="@style/MoneroText.Gray"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:textAlignment="textEnd"
tools:text="143.008000000000" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand All @@ -182,8 +207,7 @@
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/send_fee_btc_label"
android:textAlignment="textStart"
android:textSize="16sp" />
android:textAlignment="textStart" />

<TextView
android:id="@+id/tvTxFee"
Expand All @@ -192,7 +216,6 @@
android:layout_height="wrap_content"
android:layout_weight="2"
android:textAlignment="textEnd"
android:textSize="16sp"
tools:text="0.006817000000" />
</LinearLayout>

Expand All @@ -209,8 +232,7 @@
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/send_total_btc_label"
android:textAlignment="textStart"
android:textSize="16sp" />
android:textAlignment="textStart" />

<TextView
android:id="@+id/tvTxTotal"
Expand All @@ -219,7 +241,6 @@
android:layout_height="wrap_content"
android:layout_weight="2"
android:textAlignment="textEnd"
android:textSize="16sp"
tools:text="143.014817000000" />
</LinearLayout>
</LinearLayout>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-cat/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@

<string name="label_streetmode">Street Mode enabled\nOnly new transactions will be shown</string>

<string name="pocketchange_info">To reduce waiting time on repeated spending, Monerujo can create spare change at the expense of higher fees. It\'ll try to create and maintain 10 coins of the selected amount.</string>
<string name="pocketchange_info">To reduce waiting time on repeated spending, Monerujo can create spare change at the expense of higher fees. It\'ll try to create and maintain at least 6 coins of the selected amount.</string>
<string name="pocketchange_create_title">Create Change</string>

<string name="label_apply">APPLY</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@

<string name="label_streetmode">Street Mode enabled\nOnly new transactions will be shown</string>

<string name="pocketchange_info">To reduce waiting time on repeated spending, Monerujo can create spare change at the expense of higher fees. It\'ll try to create and maintain 10 coins of the selected amount.</string>
<string name="pocketchange_info">To reduce waiting time on repeated spending, Monerujo can create spare change at the expense of higher fees. It\'ll try to create and maintain at least 6 coins of the selected amount.</string>
<string name="pocketchange_create_title">Create Change</string>

<string name="label_apply">APPLY</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-el/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@

<string name="label_streetmode">Street Mode enabled\nOnly new transactions will be shown</string>

<string name="pocketchange_info">To reduce waiting time on repeated spending, Monerujo can create spare change at the expense of higher fees. It\'ll try to create and maintain 10 coins of the selected amount.</string>
<string name="pocketchange_info">To reduce waiting time on repeated spending, Monerujo can create spare change at the expense of higher fees. It\'ll try to create and maintain at least 6 coins of the selected amount.</string>
<string name="pocketchange_create_title">Create Change</string>

<string name="label_apply">APPLY</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-eo/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@

<string name="label_streetmode">Street Mode enabled\nOnly new transactions will be shown</string>

<string name="pocketchange_info">To reduce waiting time on repeated spending, Monerujo can create spare change at the expense of higher fees. It\'ll try to create and maintain 10 coins of the selected amount.</string>
<string name="pocketchange_info">To reduce waiting time on repeated spending, Monerujo can create spare change at the expense of higher fees. It\'ll try to create and maintain at least 6 coins of the selected amount.</string>
<string name="pocketchange_create_title">Create Change</string>

<string name="label_apply">APPLY</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@

<string name="label_streetmode">Modo calle activado\nSólo se ºmostrarán transacciones nuevas</string>

<string name="pocketchange_info">To reduce waiting time on repeated spending, Monerujo can create spare change at the expense of higher fees. It\'ll try to create and maintain 10 coins of the selected amount.</string>
<string name="pocketchange_info">To reduce waiting time on repeated spending, Monerujo can create spare change at the expense of higher fees. It\'ll try to create and maintain at least 6 coins of the selected amount.</string>
<string name="pocketchange_create_title">Create Change</string>

<string name="label_apply">APPLY</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-et/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@

<string name="label_streetmode">Street Mode enabled\nOnly new transactions will be shown</string>

<string name="pocketchange_info">To reduce waiting time on repeated spending, Monerujo can create spare change at the expense of higher fees. It\'ll try to create and maintain 10 coins of the selected amount.</string>
<string name="pocketchange_info">To reduce waiting time on repeated spending, Monerujo can create spare change at the expense of higher fees. It\'ll try to create and maintain at least 6 coins of the selected amount.</string>
<string name="pocketchange_create_title">Create Change</string>

<string name="label_apply">APPLY</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-fa/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@

<string name="label_streetmode">Street Mode enabled\nOnly new transactions will be shown</string>

<string name="pocketchange_info">To reduce waiting time on repeated spending, Monerujo can create spare change at the expense of higher fees. It\'ll try to create and maintain 10 coins of the selected amount.</string>
<string name="pocketchange_info">To reduce waiting time on repeated spending, Monerujo can create spare change at the expense of higher fees. It\'ll try to create and maintain at least 6 coins of the selected amount.</string>
<string name="pocketchange_create_title">Create Change</string>

<string name="label_apply">APPLY</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@

<string name="label_streetmode">Street Mode enabled\nOnly new transactions will be shown</string>

<string name="pocketchange_info">To reduce waiting time on repeated spending, Monerujo can create spare change at the expense of higher fees. It\'ll try to create and maintain 10 coins of the selected amount.</string>
<string name="pocketchange_info">To reduce waiting time on repeated spending, Monerujo can create spare change at the expense of higher fees. It\'ll try to create and maintain at least 6 coins of the selected amount.</string>
<string name="pocketchange_create_title">Create Change</string>

<string name="label_apply">APPLY</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-hu/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@

<string name="label_streetmode">Street Mode enabled\nOnly new transactions will be shown</string>

<string name="pocketchange_info">To reduce waiting time on repeated spending, Monerujo can create spare change at the expense of higher fees. It\'ll try to create and maintain 10 coins of the selected amount.</string>
<string name="pocketchange_info">To reduce waiting time on repeated spending, Monerujo can create spare change at the expense of higher fees. It\'ll try to create and maintain at least 6 coins of the selected amount.</string>
<string name="pocketchange_create_title">Create Change</string>

<string name="label_apply">APPLY</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@

<string name="label_streetmode">Street Mode enabled\nOnly new transactions will be shown</string>

<string name="pocketchange_info">To reduce waiting time on repeated spending, Monerujo can create spare change at the expense of higher fees. It\'ll try to create and maintain 10 coins of the selected amount.</string>
<string name="pocketchange_info">To reduce waiting time on repeated spending, Monerujo can create spare change at the expense of higher fees. It\'ll try to create and maintain at least 6 coins of the selected amount.</string>
<string name="pocketchange_create_title">Create Change</string>

<string name="label_apply">APPLY</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-ja/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@

<string name="label_streetmode">Street Mode enabled\nOnly new transactions will be shown</string>

<string name="pocketchange_info">To reduce waiting time on repeated spending, Monerujo can create spare change at the expense of higher fees. It\'ll try to create and maintain 10 coins of the selected amount.</string>
<string name="pocketchange_info">To reduce waiting time on repeated spending, Monerujo can create spare change at the expense of higher fees. It\'ll try to create and maintain at least 6 coins of the selected amount.</string>
<string name="pocketchange_create_title">Create Change</string>

<string name="label_apply">APPLY</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-nb/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@

<string name="label_streetmode">Street Mode enabled\nOnly new transactions will be shown</string>

<string name="pocketchange_info">To reduce waiting time on repeated spending, Monerujo can create spare change at the expense of higher fees. It\'ll try to create and maintain 10 coins of the selected amount.</string>
<string name="pocketchange_info">To reduce waiting time on repeated spending, Monerujo can create spare change at the expense of higher fees. It\'ll try to create and maintain at least 6 coins of the selected amount.</string>
<string name="pocketchange_create_title">Create Change</string>

<string name="label_apply">APPLY</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-nl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@

<string name="label_streetmode">Street Mode enabled\nOnly new transactions will be shown</string>

<string name="pocketchange_info">To reduce waiting time on repeated spending, Monerujo can create spare change at the expense of higher fees. It\'ll try to create and maintain 10 coins of the selected amount.</string>
<string name="pocketchange_info">To reduce waiting time on repeated spending, Monerujo can create spare change at the expense of higher fees. It\'ll try to create and maintain at least 6 coins of the selected amount.</string>
<string name="pocketchange_create_title">Create Change</string>

<string name="label_apply">APPLY</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-pt-rBR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ aqui.</string>

<string name="label_streetmode">Street Mode enabled\nOnly new transactions will be shown</string>

<string name="pocketchange_info">To reduce waiting time on repeated spending, Monerujo can create spare change at the expense of higher fees. It\'ll try to create and maintain 10 coins of the selected amount.</string>
<string name="pocketchange_info">To reduce waiting time on repeated spending, Monerujo can create spare change at the expense of higher fees. It\'ll try to create and maintain at least 6 coins of the selected amount.</string>
<string name="pocketchange_create_title">Create Change</string>

<string name="label_apply">APPLY</string>
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/values-pt/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -449,8 +449,8 @@

<string name="label_streetmode">Street Mode enabled\nOnly new transactions will be shown</string>

<string name="pocketchange_amount">10 × %1$3.1f XMR</string>
<string name="pocketchange_info">To reduce waiting time on repeated spending, Monerujo can create spare change at the expense of higher fees. It\'ll try to create and maintain 10 coins of the selected amount.</string>
<string name="pocketchange_info">To reduce waiting time on repeated spending, Monerujo can create spare change at the expense of higher fees. It\'ll try to create and maintain at least 6 coins of the selected amount.</string>
<string name="pocketchange_create_title">Create Change</string>

<string name="label_apply">APPLY</string>
</resources>
Loading

0 comments on commit 17df7c3

Please sign in to comment.