mirror of
https://codeberg.org/anoncontributorxmr/mysu.git
synced 2024-11-22 07:22:26 +00:00
Add ability to select UTXOs to spend
This commit is contained in:
parent
fef87ef576
commit
2ebc828d3e
17 changed files with 447 additions and 13 deletions
|
@ -1083,12 +1083,13 @@ Java_net_mynero_wallet_model_Wallet_getCoinsJ(JNIEnv *env, jobject instance) {
|
|||
|
||||
jobject newCoinsInfo(JNIEnv *env, Monero::CoinsInfo *info) {
|
||||
jmethodID c = env->GetMethodID(class_CoinsInfo, "<init>",
|
||||
"(JZLjava/lang/String;)V");
|
||||
"(JZLjava/lang/String;J)V");
|
||||
jstring _key_image = env->NewStringUTF(info->keyImage().c_str());
|
||||
jobject result = env->NewObject(class_CoinsInfo, c,
|
||||
static_cast<jlong> (info->globalOutputIndex()),
|
||||
info->spent(),
|
||||
_key_image);
|
||||
_key_image,
|
||||
static_cast<jlong> (info->amount()));
|
||||
env->DeleteLocalRef(_key_image);
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ import net.mynero.wallet.service.HistoryService;
|
|||
import net.mynero.wallet.service.MoneroHandlerThread;
|
||||
import net.mynero.wallet.service.PrefService;
|
||||
import net.mynero.wallet.service.TxService;
|
||||
import net.mynero.wallet.service.UTXOService;
|
||||
import net.mynero.wallet.util.Constants;
|
||||
import net.mynero.wallet.util.UriData;
|
||||
|
||||
|
@ -36,6 +37,7 @@ public class MainActivity extends AppCompatActivity implements MoneroHandlerThre
|
|||
private AddressService addressService = null;
|
||||
private HistoryService historyService = null;
|
||||
private BlockchainService blockchainService = null;
|
||||
private UTXOService utxoService = null;
|
||||
|
||||
private boolean proceedToSend = false;
|
||||
private UriData uriData = null;
|
||||
|
@ -96,6 +98,7 @@ public class MainActivity extends AppCompatActivity implements MoneroHandlerThre
|
|||
this.addressService = new AddressService(thread);
|
||||
this.historyService = new HistoryService(thread);
|
||||
this.blockchainService = new BlockchainService(thread);
|
||||
this.utxoService = new UTXOService(thread);
|
||||
thread.start();
|
||||
}
|
||||
|
||||
|
@ -105,6 +108,7 @@ public class MainActivity extends AppCompatActivity implements MoneroHandlerThre
|
|||
this.balanceService.refreshBalance();
|
||||
this.blockchainService.refreshBlockchain();
|
||||
this.addressService.refreshAddresses();
|
||||
this.utxoService.refreshUtxos();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,111 @@
|
|||
/*
|
||||
* Copyright (c) 2017 m2049r
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.mynero.wallet.adapter;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import net.mynero.wallet.R;
|
||||
import net.mynero.wallet.model.CoinsInfo;
|
||||
import net.mynero.wallet.model.Wallet;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CoinsInfoAdapter extends RecyclerView.Adapter<CoinsInfoAdapter.ViewHolder> {
|
||||
|
||||
private List<CoinsInfo> localDataSet;
|
||||
private List<String> selectedUtxos;
|
||||
private CoinsInfoAdapterListener listener = null;
|
||||
|
||||
/**
|
||||
* Initialize the dataset of the Adapter.
|
||||
*/
|
||||
public CoinsInfoAdapter(CoinsInfoAdapterListener listener) {
|
||||
this.listener = listener;
|
||||
this.localDataSet = new ArrayList<>();
|
||||
this.selectedUtxos = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void submitList(List<CoinsInfo> dataSet, List<String> selectedUtxos) {
|
||||
this.localDataSet = dataSet;
|
||||
this.selectedUtxos = selectedUtxos;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void updateSelectedUtxos(List<String> selectedUtxos) {
|
||||
this.selectedUtxos = selectedUtxos;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
// Create new views (invoked by the layout manager)
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
|
||||
// Create a new view, which defines the UI of the list item
|
||||
View view = LayoutInflater.from(viewGroup.getContext())
|
||||
.inflate(R.layout.utxo_selection_item, viewGroup, false);
|
||||
|
||||
return new ViewHolder(listener, view);
|
||||
}
|
||||
|
||||
// Replace the contents of a view (invoked by the layout manager)
|
||||
@Override
|
||||
public void onBindViewHolder(ViewHolder viewHolder, final int position) {
|
||||
CoinsInfo tx = localDataSet.get(position);
|
||||
viewHolder.bind(tx, selectedUtxos);
|
||||
}
|
||||
|
||||
// Return the size of your dataset (invoked by the layout manager)
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return localDataSet.size();
|
||||
}
|
||||
|
||||
public interface CoinsInfoAdapterListener {
|
||||
void onUtxoSelected(CoinsInfo coinsInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a reference to the type of views that you are using
|
||||
* (custom ViewHolder).
|
||||
*/
|
||||
public static class ViewHolder extends RecyclerView.ViewHolder {
|
||||
private CoinsInfoAdapterListener listener = null;
|
||||
|
||||
public ViewHolder(CoinsInfoAdapterListener listener, View view) {
|
||||
super(view);
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
public void bind(CoinsInfo coinsInfo, List<String> selectedUtxos) {
|
||||
boolean selected = selectedUtxos.contains(coinsInfo.getKeyImage());
|
||||
TextView keyImageTextView = itemView.findViewById(R.id.utxo_key_image_textview);
|
||||
TextView amountTextView = itemView.findViewById(R.id.utxo_amount_textview);
|
||||
amountTextView.setText(Wallet.getDisplayAmount(coinsInfo.getAmount()));
|
||||
keyImageTextView.setText(coinsInfo.getKeyImage());
|
||||
itemView.setOnLongClickListener(view -> {
|
||||
listener.onUtxoSelected(coinsInfo);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -27,16 +27,20 @@ import com.google.zxing.client.android.Intents;
|
|||
import com.journeyapps.barcodescanner.ScanContract;
|
||||
import com.journeyapps.barcodescanner.ScanOptions;
|
||||
import net.mynero.wallet.R;
|
||||
import net.mynero.wallet.model.CoinsInfo;
|
||||
import net.mynero.wallet.model.PendingTransaction;
|
||||
import net.mynero.wallet.model.Wallet;
|
||||
import net.mynero.wallet.service.BalanceService;
|
||||
import net.mynero.wallet.service.TxService;
|
||||
import net.mynero.wallet.service.UTXOService;
|
||||
import net.mynero.wallet.util.Helper;
|
||||
import net.mynero.wallet.util.UriData;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SendBottomSheetDialog extends BottomSheetDialogFragment {
|
||||
public ArrayList<String> selectedUtxos = new ArrayList<>();
|
||||
private final MutableLiveData<Boolean> _sendingMax = new MutableLiveData<>(false);
|
||||
public LiveData<Boolean> sendingMax = _sendingMax; private final ActivityResultLauncher<String> cameraPermissionsLauncher = registerForActivityResult(new ActivityResultContracts.RequestPermission(),
|
||||
granted -> {
|
||||
|
@ -61,6 +65,7 @@ public class SendBottomSheetDialog extends BottomSheetDialogFragment {
|
|||
private TextView addressTextView;
|
||||
private TextView amountTextView;
|
||||
private TextView feeRadioGroupLabelTextView;
|
||||
private TextView selectedUtxosValueTextView;
|
||||
private Button createButton;
|
||||
private Button sendButton;
|
||||
private Button sendMaxButton;
|
||||
|
@ -92,6 +97,7 @@ public class SendBottomSheetDialog extends BottomSheetDialogFragment {
|
|||
amountTextView = view.findViewById(R.id.amount_pending_textview);
|
||||
feeRadioGroup = view.findViewById(R.id.tx_fee_radiogroup);
|
||||
feeRadioGroupLabelTextView = view.findViewById(R.id.tx_fee_radiogroup_label_textview);
|
||||
selectedUtxosValueTextView = view.findViewById(R.id.selected_utxos_value_textview);
|
||||
|
||||
if (uriData != null) {
|
||||
addressEditText.setText(uriData.getAddress());
|
||||
|
@ -100,6 +106,22 @@ public class SendBottomSheetDialog extends BottomSheetDialogFragment {
|
|||
}
|
||||
}
|
||||
|
||||
if(!selectedUtxos.isEmpty()) {
|
||||
long selectedValue = 0;
|
||||
|
||||
for(CoinsInfo coinsInfo : UTXOService.getInstance().getUtxos()) {
|
||||
if(selectedUtxos.contains(coinsInfo.getKeyImage())) {
|
||||
selectedValue += coinsInfo.getAmount();
|
||||
}
|
||||
}
|
||||
|
||||
String valueString = Wallet.getDisplayAmount(selectedValue);
|
||||
selectedUtxosValueTextView.setVisibility(View.VISIBLE);
|
||||
selectedUtxosValueTextView.setText(getResources().getString(R.string.selected_utxos_value, valueString));
|
||||
} else {
|
||||
selectedUtxosValueTextView.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
bindObservers();
|
||||
bindListeners();
|
||||
}
|
||||
|
@ -232,7 +254,7 @@ public class SendBottomSheetDialog extends BottomSheetDialogFragment {
|
|||
|
||||
private void createTx(String address, String amount, boolean sendAll, PendingTransaction.Priority feePriority) {
|
||||
AsyncTask.execute(() -> {
|
||||
PendingTransaction pendingTx = TxService.getInstance().createTx(address, amount, sendAll, feePriority);
|
||||
PendingTransaction pendingTx = TxService.getInstance().createTx(address, amount, sendAll, feePriority, selectedUtxos);
|
||||
if (pendingTx != null && pendingTx.getStatus() == PendingTransaction.Status.Status_Ok) {
|
||||
_pendingTransaction.postValue(pendingTx);
|
||||
} else {
|
||||
|
|
|
@ -18,7 +18,11 @@ import androidx.annotation.Nullable;
|
|||
import androidx.appcompat.widget.SwitchCompat;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.navigation.NavDirections;
|
||||
import androidx.navigation.fragment.NavHostFragment;
|
||||
|
||||
import net.mynero.wallet.R;
|
||||
import net.mynero.wallet.data.DefaultNodes;
|
||||
|
@ -73,6 +77,8 @@ public class SettingsFragment extends Fragment implements PasswordBottomSheetDia
|
|||
super.onViewCreated(view, savedInstanceState);
|
||||
mViewModel = new ViewModelProvider(this).get(SettingsViewModel.class);
|
||||
Button displaySeedButton = view.findViewById(R.id.display_seed_button);
|
||||
Button displayUtxosButton = view.findViewById(R.id.display_utxos_button);
|
||||
|
||||
selectNodeButton = view.findViewById(R.id.select_node_button);
|
||||
SwitchCompat nightModeSwitch = view.findViewById(R.id.day_night_switch);
|
||||
SwitchCompat torSwitch = view.findViewById(R.id.tor_switch);
|
||||
|
@ -138,6 +144,10 @@ public class SettingsFragment extends Fragment implements PasswordBottomSheetDia
|
|||
}
|
||||
});
|
||||
|
||||
displayUtxosButton.setOnClickListener(view1 -> {
|
||||
navigate(R.id.nav_to_utxos);
|
||||
});
|
||||
|
||||
TextView statusTextView = view.findViewById(R.id.status_textview);
|
||||
BlockchainService.getInstance().connectionStatus.observe(getViewLifecycleOwner(), connectionStatus -> {
|
||||
if(connectionStatus == Wallet.ConnectionStatus.ConnectionStatus_Connected) {
|
||||
|
@ -218,4 +228,16 @@ public class SettingsFragment extends Fragment implements PasswordBottomSheetDia
|
|||
dialog.listener = this;
|
||||
dialog.show(getActivity().getSupportFragmentManager(), "node_selection_dialog");
|
||||
}
|
||||
|
||||
private void navigate(int destination) {
|
||||
FragmentActivity activity = getActivity();
|
||||
if (activity != null) {
|
||||
FragmentManager fm = activity.getSupportFragmentManager();
|
||||
NavHostFragment navHostFragment =
|
||||
(NavHostFragment) fm.findFragmentById(R.id.nav_host_fragment);
|
||||
if (navHostFragment != null) {
|
||||
navHostFragment.getNavController().navigate(destination);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
package net.mynero.wallet.fragment.utxos;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import net.mynero.wallet.R;
|
||||
import net.mynero.wallet.adapter.CoinsInfoAdapter;
|
||||
import net.mynero.wallet.fragment.dialog.SendBottomSheetDialog;
|
||||
import net.mynero.wallet.model.CoinsInfo;
|
||||
import net.mynero.wallet.service.UTXOService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class UtxosFragment extends Fragment implements CoinsInfoAdapter.CoinsInfoAdapterListener {
|
||||
|
||||
private UtxosViewModel mViewModel;
|
||||
private ArrayList<String> selectedUtxos = new ArrayList<>();
|
||||
private CoinsInfoAdapter adapter = new CoinsInfoAdapter(this);
|
||||
private Button sendUtxosButton;
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.fragment_utxos, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
mViewModel = new ViewModelProvider(this).get(UtxosViewModel.class);
|
||||
bindListeners(view);
|
||||
bindObservers(view);
|
||||
}
|
||||
|
||||
private void bindListeners(View view) {
|
||||
sendUtxosButton = view.findViewById(R.id.send_utxos_button);
|
||||
sendUtxosButton.setVisibility(View.GONE);
|
||||
sendUtxosButton.setOnClickListener(view1 -> {
|
||||
SendBottomSheetDialog sendDialog = new SendBottomSheetDialog();
|
||||
sendDialog.selectedUtxos = selectedUtxos;
|
||||
sendDialog.show(getActivity().getSupportFragmentManager(), null);
|
||||
});
|
||||
}
|
||||
|
||||
private void bindObservers(View view) {
|
||||
RecyclerView utxosRecyclerView = view.findViewById(R.id.transaction_history_recyclerview);
|
||||
UTXOService utxoService = UTXOService.getInstance();
|
||||
utxosRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
|
||||
utxosRecyclerView.setAdapter(adapter);
|
||||
if (utxoService != null) {
|
||||
utxoService.utxos.observe(getViewLifecycleOwner(), utxos -> {
|
||||
ArrayList<CoinsInfo> filteredUtxos = new ArrayList<>();
|
||||
for(CoinsInfo coinsInfo : utxos) {
|
||||
if(!coinsInfo.isSpent()) {
|
||||
filteredUtxos.add(coinsInfo);
|
||||
}
|
||||
}
|
||||
if (filteredUtxos.isEmpty()) {
|
||||
utxosRecyclerView.setVisibility(View.GONE);
|
||||
} else {
|
||||
adapter.submitList(filteredUtxos, selectedUtxos);
|
||||
utxosRecyclerView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUtxoSelected(CoinsInfo coinsInfo) {
|
||||
boolean selected = selectedUtxos.contains(coinsInfo.getKeyImage());
|
||||
if(selected) {
|
||||
System.out.println("Deselecting: " + coinsInfo.getKeyImage());
|
||||
selectedUtxos.remove(coinsInfo.getKeyImage());
|
||||
} else {
|
||||
System.out.println("Selecting: " + coinsInfo.getKeyImage());
|
||||
selectedUtxos.add(coinsInfo.getKeyImage());
|
||||
}
|
||||
|
||||
if(selectedUtxos.isEmpty()) {
|
||||
sendUtxosButton.setVisibility(View.GONE);
|
||||
} else {
|
||||
sendUtxosButton.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
adapter.updateSelectedUtxos(selectedUtxos);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package net.mynero.wallet.fragment.utxos;
|
||||
|
||||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
public class UtxosViewModel extends ViewModel {
|
||||
|
||||
}
|
|
@ -32,11 +32,13 @@ public class CoinsInfo implements Parcelable {
|
|||
long globalOutputIndex;
|
||||
boolean spent;
|
||||
String keyImage;
|
||||
long amount;
|
||||
|
||||
public CoinsInfo(long globalOutputIndex, boolean spent, String keyImage) {
|
||||
public CoinsInfo(long globalOutputIndex, boolean spent, String keyImage, long amount) {
|
||||
this.globalOutputIndex = globalOutputIndex;
|
||||
this.spent = spent;
|
||||
this.keyImage = keyImage;
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
protected CoinsInfo(Parcel in) {
|
||||
|
@ -67,6 +69,10 @@ public class CoinsInfo implements Parcelable {
|
|||
return keyImage;
|
||||
}
|
||||
|
||||
public long getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
|
|
|
@ -122,10 +122,14 @@ public class MoneroHandlerThread extends Thread implements WalletListener {
|
|||
listener.onRefresh();
|
||||
}
|
||||
|
||||
public PendingTransaction createTx(String address, String amountStr, boolean sendAll, PendingTransaction.Priority feePriority) {
|
||||
public PendingTransaction createTx(String address, String amountStr, boolean sendAll, PendingTransaction.Priority feePriority, ArrayList<String> selectedUtxos) {
|
||||
long amount = sendAll ? SWEEP_ALL : Wallet.getAmountFromString(amountStr);
|
||||
ArrayList<String> preferredInputs = new ArrayList<>();
|
||||
preferredInputs.add("");
|
||||
ArrayList<String> preferredInputs;
|
||||
if(selectedUtxos.isEmpty()) {
|
||||
preferredInputs = UTXOService.getInstance().selectUtxos(amount, sendAll);
|
||||
} else {
|
||||
preferredInputs = selectedUtxos;
|
||||
}
|
||||
return wallet.createTransaction(new TxData(address, amount, 0, feePriority, preferredInputs));
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,8 @@ package net.mynero.wallet.service;
|
|||
|
||||
import net.mynero.wallet.model.PendingTransaction;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class TxService extends ServiceBase {
|
||||
public static TxService instance = null;
|
||||
|
||||
|
@ -14,8 +16,8 @@ public class TxService extends ServiceBase {
|
|||
return instance;
|
||||
}
|
||||
|
||||
public PendingTransaction createTx(String address, String amount, boolean sendAll, PendingTransaction.Priority feePriority) {
|
||||
return this.getThread().createTx(address, amount, sendAll, feePriority);
|
||||
public PendingTransaction createTx(String address, String amount, boolean sendAll, PendingTransaction.Priority feePriority, ArrayList<String> selectedUtxos) {
|
||||
return this.getThread().createTx(address, amount, sendAll, feePriority, selectedUtxos);
|
||||
}
|
||||
|
||||
public boolean sendTx(PendingTransaction pendingTransaction) {
|
||||
|
|
60
app/src/main/java/net/mynero/wallet/service/UTXOService.java
Normal file
60
app/src/main/java/net/mynero/wallet/service/UTXOService.java
Normal file
|
@ -0,0 +1,60 @@
|
|||
package net.mynero.wallet.service;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import net.mynero.wallet.model.CoinsInfo;
|
||||
import net.mynero.wallet.model.TransactionInfo;
|
||||
import net.mynero.wallet.model.Wallet;
|
||||
import net.mynero.wallet.model.WalletManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class UTXOService extends ServiceBase {
|
||||
public static UTXOService instance = null;
|
||||
private final MutableLiveData<List<CoinsInfo>> _utxos = new MutableLiveData<>();
|
||||
public LiveData<List<CoinsInfo>> utxos = _utxos;
|
||||
public UTXOService(MoneroHandlerThread thread) {
|
||||
super(thread);
|
||||
instance = this;
|
||||
}
|
||||
|
||||
public static UTXOService getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void refreshUtxos() {
|
||||
_utxos.postValue(getUtxos());
|
||||
}
|
||||
|
||||
public List<CoinsInfo> getUtxos() {
|
||||
return WalletManager.getInstance().getWallet().getCoins().getAll();
|
||||
}
|
||||
|
||||
public ArrayList<String> selectUtxos(long amount, boolean sendAll) {
|
||||
ArrayList<String> selectedUtxos = new ArrayList<>();
|
||||
List<CoinsInfo> utxos = getUtxos();
|
||||
if(sendAll) {
|
||||
for(CoinsInfo coinsInfo : utxos) {
|
||||
selectedUtxos.add(coinsInfo.getKeyImage());
|
||||
}
|
||||
} else {
|
||||
long amountSelected = 0;
|
||||
Collections.shuffle(utxos);
|
||||
for (CoinsInfo coinsInfo : utxos) {
|
||||
if (amount == Wallet.SWEEP_ALL) {
|
||||
selectedUtxos.add(coinsInfo.getKeyImage());
|
||||
} else {
|
||||
if (amountSelected <= amount) {
|
||||
selectedUtxos.add(coinsInfo.getKeyImage());
|
||||
amountSelected += coinsInfo.getAmount();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return selectedUtxos;
|
||||
}
|
||||
}
|
|
@ -56,6 +56,18 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/wallet_settings_textview" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/display_utxos_button"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:background="@drawable/button_bg"
|
||||
android:text="@string/view_utxos"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.0"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/display_seed_button" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/appearance_settings_textview"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -66,7 +78,7 @@
|
|||
android:textStyle="bold"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/display_seed_button" />
|
||||
app:layout_constraintTop_toBottomOf="@id/display_utxos_button" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/day_night_textview"
|
||||
|
|
34
app/src/main/res/layout/fragment_utxos.xml
Normal file
34
app/src/main/res/layout/fragment_utxos.xml
Normal file
|
@ -0,0 +1,34 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context="net.mynero.wallet.fragment.home.HomeFragment">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/transaction_history_recyclerview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:clipToPadding="false"
|
||||
android:paddingStart="24dp"
|
||||
android:paddingEnd="24dp"
|
||||
android:paddingBottom="128dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_bias="0.0" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/send_utxos_button"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="24dp"
|
||||
android:layout_marginBottom="24dp"
|
||||
android:background="@drawable/button_bg"
|
||||
android:text="@string/send"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -25,7 +25,17 @@
|
|||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/selected_utxos_value_textview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:text="@string/selected_utxos_value"
|
||||
android:textSize="16sp"
|
||||
app:layout_constraintBottom_toTopOf="@id/address_edittext"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/send_monero_textview" />
|
||||
<EditText
|
||||
android:id="@+id/address_edittext"
|
||||
android:layout_width="0dp"
|
||||
|
@ -38,7 +48,7 @@
|
|||
app:layout_constraintBottom_toTopOf="@id/amount_edittext"
|
||||
app:layout_constraintEnd_toStartOf="@id/paste_address_imagebutton"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/send_monero_textview"
|
||||
app:layout_constraintTop_toBottomOf="@id/selected_utxos_value_textview"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<ImageButton
|
||||
|
|
31
app/src/main/res/layout/utxo_selection_item.xml
Normal file
31
app/src/main/res/layout/utxo_selection_item.xml
Normal file
|
@ -0,0 +1,31 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="8dp"
|
||||
android:layout_marginBottom="8dp">
|
||||
<TextView
|
||||
android:id="@+id/utxo_key_image_textview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Key Image"
|
||||
android:textStyle="bold"
|
||||
android:textSize="16sp"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintBottom_toTopOf="@id/utxo_amount_textview"
|
||||
app:layout_constraintTop_toTopOf="parent"/>
|
||||
<TextView
|
||||
android:id="@+id/utxo_amount_textview"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Amount"
|
||||
android:ellipsize="middle"
|
||||
app:layout_constraintTop_toBottomOf="@id/utxo_key_image_textview"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
android:singleLine="true" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -30,7 +30,17 @@
|
|||
android:id="@+id/settings_fragment"
|
||||
android:name="net.mynero.wallet.fragment.settings.SettingsFragment"
|
||||
android:label="fragment_send_amount"
|
||||
tools:layout="@layout/fragment_settings" />
|
||||
tools:layout="@layout/fragment_settings">
|
||||
<action
|
||||
android:id="@+id/nav_to_utxos"
|
||||
app:destination="@id/utxos_fragment">
|
||||
</action>
|
||||
</fragment>
|
||||
<fragment
|
||||
android:id="@+id/utxos_fragment"
|
||||
android:name="net.mynero.wallet.fragment.utxos.UtxosFragment"
|
||||
android:label="fragment_utxos"
|
||||
tools:layout="@layout/fragment_utxos" />
|
||||
<fragment
|
||||
android:id="@+id/onboarding_fragment"
|
||||
android:name="net.mynero.wallet.fragment.onboarding.OnboardingFragment"
|
||||
|
|
|
@ -101,4 +101,6 @@
|
|||
<string name="low">Low</string>
|
||||
<string name="medium">Medium</string>
|
||||
<string name="high">High</string>
|
||||
<string name="view_utxos">View UTXOs</string>
|
||||
<string name="selected_utxos_value">Selected value: %1$s XMR</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue