Commit bd3cb7b4 authored by Wallet Guy's avatar Wallet Guy
Browse files

Merge branch 'staging' of https://code.samourai.io/wallet/samourai-wallet-android into styles-wg

parents 62939342 4cd81f6f
......@@ -224,7 +224,7 @@ class WhirlpoolHome : SamouraiActivity() {
)
val mediumFee = FeeUtil.getInstance().normalFee.defaultPerKB.toLong() / 1000L
val tx0 = WhirlpoolTx0(
WhirlpoolMeta.getInstance(this@WhirlpoolHome).minimumPoolDenomination,
WhirlpoolMeta.getMinimumPoolDenomination(),
mediumFee,
1,
coins
......
......@@ -43,7 +43,7 @@ public class WhirlpoolMeta {
return WhirlpoolAccount.BADBANK.getAccountIndex();
}
public long getMinimumPoolDenomination() {
public static long getMinimumPoolDenomination() {
return 100000L;
}
......
package com.samourai.wallet.whirlpool.adapters;
import android.content.Context;
import androidx.annotation.NonNull;
import androidx.constraintlayout.widget.Group;
import androidx.recyclerview.widget.AsyncListDiffer;
import androidx.recyclerview.widget.DiffUtil;
import androidx.recyclerview.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.TextView;
import com.google.android.material.checkbox.MaterialCheckBox;
import com.samourai.wallet.R;
import com.samourai.wallet.api.Tx;
import com.samourai.wallet.whirlpool.models.PoolViewModel;
import com.samourai.whirlpool.client.tx0.Tx0Preview;
import java.util.ArrayList;
......@@ -20,12 +29,11 @@ import static com.samourai.wallet.util.FormatsUtil.getPoolBTCDecimalFormat;
public class PoolsAdapter extends RecyclerView.Adapter<PoolsAdapter.ViewHolder> {
private Context mContext;
private ArrayList<PoolViewModel> pools;
private OnItemsSelected onItemsSelected;
private static final String TAG = "CoinsAdapter";
private final AsyncListDiffer<PoolViewModel> mDiffer = new AsyncListDiffer<>(this, DIFF_CALLBACK);
public PoolsAdapter(Context context, ArrayList<PoolViewModel> pools) {
this.pools = pools;
mContext = context;
}
......@@ -38,45 +46,46 @@ public class PoolsAdapter extends RecyclerView.Adapter<PoolsAdapter.ViewHolder>
@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
final PoolViewModel poolViewModel = pools.get(position);
holder.poolAmount.setText(getPoolBTCDecimalFormat(poolViewModel.getDenomination()).concat(" BTC Pool"));
holder.poolFees.setText(mContext.getString(R.string.pool_fee).concat(" ").concat(getBTCDecimalFormat(poolViewModel.getFeeValue())).concat(" BTC"));
holder.totalFees.setText(mContext.getString(R.string.total_fees).concat(" ").concat(getBTCDecimalFormat(poolViewModel.getTotalFee())).concat(" BTC").concat(" (").concat(String.valueOf(poolViewModel.getTotalEstimatedBytes())).concat( " bytes)"));
holder.minerFee.setText(mContext.getString(R.string.miner_fee).concat(" ").concat(getBTCDecimalFormat(poolViewModel.getMinerFee() * poolViewModel.getTotalEstimatedBytes())).concat(" BTC"));
final PoolViewModel poolViewModel = mDiffer.getCurrentList().get(position);
if(poolViewModel.getTx0Preview() != null){
Tx0Preview preview = poolViewModel.getTx0Preview();
long embeddedTotalFees = preview.getMixMinerFee();
long totalFees = embeddedTotalFees + preview.getFeeValue() + preview.getTx0MinerFee();
holder.poolAmount.setText(getPoolBTCDecimalFormat(preview.getPool().getDenomination()).concat(" BTC Pool"));
holder.poolFees.setText(mContext.getString(R.string.pool_fee).concat(" ").concat(getBTCDecimalFormat(preview.getFeeValue())).concat(" BTC"));
holder.totalFees.setText(mContext.getString(R.string.total_fees).concat(" ").concat(getBTCDecimalFormat(totalFees)).concat(" BTC"));
holder.minerFee.setText(mContext.getString(R.string.miner_fee).concat(" ").concat(getBTCDecimalFormat(preview.getTx0MinerFee()).concat(" BTC")));
}else{
holder.poolAmount.setText(getPoolBTCDecimalFormat(poolViewModel.getDenomination()).concat(" BTC Pool"));
holder.poolFees.setText(mContext.getString(R.string.pool_fee).concat(" ").concat(getBTCDecimalFormat(poolViewModel.getFeeValue())).concat(" BTC"));
holder.totalFees.setText(mContext.getString(R.string.total_fees).concat(" ").concat(getBTCDecimalFormat(poolViewModel.getTotalFee())).concat(" BTC").concat(" (").concat(String.valueOf(poolViewModel.getTotalEstimatedBytes())).concat( " bytes)"));
holder.minerFee.setText(mContext.getString(R.string.miner_fee).concat(" ").concat(getBTCDecimalFormat(poolViewModel.getMinerFee() * poolViewModel.getTotalEstimatedBytes())).concat(" BTC"));
}
if (poolViewModel.isSelected()) {
holder.feesGroup.setVisibility(View.VISIBLE);
}
holder.checkBox.setEnabled(poolViewModel.getTx0Preview() != null);
holder.checkBox.setOnCheckedChangeListener(null);
holder.checkBox.setChecked(poolViewModel.isSelected());
if (poolViewModel.isSelected()) {
holder.feesGroup.setVisibility(View.VISIBLE);
}
if (!poolViewModel.isDisabled())
holder.checkBox.setOnCheckedChangeListener((compoundButton, b) -> {
onItemsSelected.onItemsSelected(position);
});
holder.checkBox.setOnCheckedChangeListener((compoundButton, b) -> {
onItemsSelected.onItemsSelected(position);
});
if (poolViewModel.isDisabled()) {
holder.layout.setAlpha(0.4f);
holder.layout.setClickable(false);
} else {
if (poolViewModel.getTx0Preview() != null) {
holder.layout.setOnClickListener(view -> onItemsSelected.onItemsSelected(position));
holder.layout.setAlpha(1f);
holder.layout.setClickable(true);
}else{
holder.layout.setAlpha(0.4f);
holder.layout.setClickable(false);
}
holder.checkBox.setEnabled(!poolViewModel.isDisabled());
}
private void selectItem(ViewHolder holder, int position) {
PoolViewModel poolViewModel = pools.get(position);
pools.get(position).setSelected(!poolViewModel.isSelected());
holder.checkBox.setChecked(poolViewModel.isSelected());
}
@Override
public int getItemCount() {
if (pools.isEmpty()) {
return 0;
}
return pools.size();
return mDiffer.getCurrentList().size();
}
public void setOnItemsSelectListener(OnItemsSelected onItemsSelected) {
......@@ -84,14 +93,13 @@ public class PoolsAdapter extends RecyclerView.Adapter<PoolsAdapter.ViewHolder>
}
public void update(ArrayList<PoolViewModel> poolViewModels) {
this.pools = poolViewModels;
this.notifyDataSetChanged();
mDiffer.submitList(poolViewModels);
}
class ViewHolder extends RecyclerView.ViewHolder {
private TextView poolAmount, poolFees, minerFee, totalFees;
private CheckBox checkBox;
private MaterialCheckBox checkBox;
private View layout;
private Group feesGroup;
......@@ -103,7 +111,7 @@ public class PoolsAdapter extends RecyclerView.Adapter<PoolsAdapter.ViewHolder>
totalFees = itemView.findViewById(R.id.pool_item_total_fee);
checkBox = itemView.findViewById(R.id.pool_item_checkbox);
feesGroup = itemView.findViewById(R.id.item_pool_fees_group);
layout = itemView;
layout = itemView.findViewById(R.id.item_coin_layout);
}
}
......@@ -113,5 +121,18 @@ public class PoolsAdapter extends RecyclerView.Adapter<PoolsAdapter.ViewHolder>
}
public static final DiffUtil.ItemCallback<PoolViewModel> DIFF_CALLBACK
= new DiffUtil.ItemCallback<PoolViewModel>() {
@Override
public boolean areItemsTheSame(@NonNull PoolViewModel oldItem, @NonNull PoolViewModel newItem) {
return oldItem.getPoolId().equals(newItem.getPoolId());
}
@Override
public boolean areContentsTheSame(@NonNull PoolViewModel oldItem, @NonNull PoolViewModel newItem) {
return false;
}
};
}
......@@ -5,6 +5,7 @@ import android.util.Log;
import com.samourai.wallet.util.LogUtil;
import com.samourai.wallet.utxos.models.UTXOCoin;
import com.samourai.wallet.whirlpool.WhirlpoolTx0;
import com.samourai.whirlpool.client.tx0.Tx0Preview;
import com.samourai.whirlpool.client.whirlpool.beans.Pool;
import java.util.List;
......@@ -17,8 +18,11 @@ public class PoolViewModel extends com.samourai.whirlpool.client.whirlpool.beans
private long totalMinerFee = 0L;
private long totalEstimatedBytes = 0L;
private WhirlpoolTx0 tx0;
private Pool pool;
private Tx0Preview tx0Preview = null;
public PoolViewModel(Pool pool) {
this.pool = pool;
this.setDenomination(pool.getDenomination());
this.setFeeValue(pool.getFeeValue());
this.setPoolId(pool.getPoolId());
......@@ -44,6 +48,14 @@ public class PoolViewModel extends com.samourai.whirlpool.client.whirlpool.beans
return isSelected;
}
public void setTx0Preview(Tx0Preview tx0Preview) {
this.tx0Preview = tx0Preview;
}
public Tx0Preview getTx0Preview() {
return tx0Preview;
}
public void setSelected(boolean selected) {
isSelected = selected;
}
......@@ -60,6 +72,10 @@ public class PoolViewModel extends com.samourai.whirlpool.client.whirlpool.beans
return totalEstimatedBytes;
}
public Pool getPool() {
return pool;
}
public Long getMinerFee() {
return minerFee;
}
......
......@@ -6,12 +6,10 @@ import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.RelativeSizeSpan;
import android.text.style.StyleSpan;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
......@@ -19,7 +17,6 @@ import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
......@@ -34,18 +31,15 @@ import com.samourai.wallet.SamouraiActivity;
import com.samourai.wallet.api.backend.beans.UnspentOutput;
import com.samourai.wallet.send.BlockedUTXO;
import com.samourai.wallet.send.FeeUtil;
import com.samourai.wallet.send.SendFactory;
import com.samourai.wallet.service.JobRefreshService;
import com.samourai.wallet.util.FormatsUtil;
import com.samourai.wallet.util.LogUtil;
import com.samourai.wallet.util.PrefsUtil;
import com.samourai.wallet.utxos.PreSelectUtil;
import com.samourai.wallet.utxos.UTXOUtil;
import com.samourai.wallet.utxos.models.UTXOCoin;
import com.samourai.wallet.whirlpool.WhirlpoolMeta;
import com.samourai.wallet.whirlpool.WhirlpoolTx0;
import com.samourai.wallet.whirlpool.models.PoolCyclePriority;
import com.samourai.wallet.whirlpool.models.PoolViewModel;
import com.samourai.wallet.whirlpool.newPool.fragments.ChooseUTXOsFragment;
import com.samourai.wallet.whirlpool.newPool.fragments.ReviewPoolFragment;
import com.samourai.wallet.whirlpool.newPool.fragments.SelectPoolFragment;
......@@ -60,19 +54,14 @@ import com.samourai.whirlpool.client.wallet.beans.Tx0FeeTarget;
import com.samourai.whirlpool.client.wallet.beans.WhirlpoolAccount;
import org.bitcoinj.core.TransactionOutput;
import org.bouncycastle.util.encoders.Hex;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.TimeUnit;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.lifecycle.ViewModelProvider;
import io.reactivex.Completable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
......@@ -97,19 +86,16 @@ public class NewPoolActivity extends SamouraiActivity {
private int account = 0;
private MaterialButton confirmButton;
private CompositeDisposable disposables = new CompositeDisposable();
private NewPoolViewModel newPoolViewModel;
private List<UTXOCoin> selectedCoins = new ArrayList<>();
private ArrayList<Long> fees = new ArrayList<Long>();
private PoolViewModel selectedPoolViewModel = null;
private PoolCyclePriority selectedPoolPriority = PoolCyclePriority.NORMAL;
private Tx0FeeTarget tx0FeeTarget = Tx0FeeTarget.BLOCKS_2;
private LinearLayout tx0Progress;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_new_whirlpool_cycle);
Toolbar toolbar = findViewById(R.id.toolbar_new_whirlpool);
newPoolViewModel = new ViewModelProvider(this).get(NewPoolViewModel.class);
setSupportActionBar(toolbar);
if (getSupportActionBar() != null) {
......@@ -119,11 +105,6 @@ public class NewPoolActivity extends SamouraiActivity {
cycleTotalAmount = findViewById(R.id.cycle_total_amount);
cycleTotalAmount.setText(FormatsUtil.formatBTC(0L));
fees.add(FeeUtil.getInstance().getLowFee().getDefaultPerKB().longValue() / 1000L);
fees.add(FeeUtil.getInstance().getNormalFee().getDefaultPerKB().longValue() / 1000L);
fees.add(FeeUtil.getInstance().getHighFee().getDefaultPerKB().longValue() / 1000L);
String preselectId = null;
if (getIntent().getExtras() != null && getIntent().getExtras().containsKey("preselected")) {
preselectId = getIntent().getExtras().getString("preselected");
......@@ -135,7 +116,6 @@ public class NewPoolActivity extends SamouraiActivity {
chooseUTXOsFragment = ChooseUTXOsFragment.newInstance(preselectId);
selectPoolFragment = new SelectPoolFragment();
reviewPoolFragment = new ReviewPoolFragment();
selectPoolFragment.setFees(this.fees);
tx0Progress = findViewById(R.id.new_pool_tx0_progress);
newPoolViewPager = findViewById(R.id.new_pool_viewpager);
......@@ -155,13 +135,24 @@ public class NewPoolActivity extends SamouraiActivity {
if (account != WhirlpoolMeta.getInstance(getApplicationContext()).getWhirlpoolPostmix())
chooseUTXOsFragment.setOnUTXOSelectionListener(this::onUTXOSelected);
selectPoolFragment.setOnPoolSelectionComplete((poolViewModel, priority) -> {
selectedPoolViewModel = poolViewModel;
selectedPoolPriority = priority;
if (tx0 != null && poolViewModel != null) {
tx0.setPool(poolViewModel.getDenomination());
newPoolViewModel.getGetPoolLoadError().observe(this,exception -> {
if(exception!=null){
if(exception.getMessage()!=null){
Snackbar.make(findViewById(R.id.new_pool_snackbar_layout),exception.getMessage(),Snackbar.LENGTH_LONG).show();
}
}
});
newPoolViewModel.getGetPool().observe(this,(pool) -> {
if (tx0 != null && pool != null) {
tx0.setPool(pool.getDenomination());
}
enableConfirmButton(pool != null);
});
newPoolViewModel.getGetPool().observe(this,poolViewModel -> {
if(poolViewModel != null && newPoolViewPager.getCurrentItem() == 1){
enableConfirmButton(true);
}
enableConfirmButton(selectedPoolViewModel != null);
});
reviewPoolFragment.setLoadingListener((aBoolean, e) -> {
......@@ -176,22 +167,14 @@ public class NewPoolActivity extends SamouraiActivity {
case 0: {
newPoolViewPager.setCurrentItem(1);
initUTXOReviewButton(selectedCoins);
enableConfirmButton(selectedPoolViewModel != null);
newPoolViewModel.loadPools();
enableConfirmButton(newPoolViewModel.getGetPool().getValue() != null);
break;
}
case 1: {
try {
// tx0.make();
} catch (Exception ex) {
Toast.makeText(this, ex.getMessage(), Toast.LENGTH_LONG).show();
return;
}
calculateTx0(selectedPoolViewModel.getDenomination(), selectedPoolViewModel.getMinerFee());
newPoolViewPager.setCurrentItem(2);
confirmButton.setText(getString(R.string.begin_cycle));
confirmButton.setBackgroundTintList(ContextCompat.getColorStateList(getApplicationContext(), R.color.green_ui_2));
reviewPoolFragment.setTx0(tx0, tx0FeeTarget, tx0FeeTarget, selectedPoolViewModel);
break;
}
case 2: {
......@@ -254,6 +237,8 @@ public class NewPoolActivity extends SamouraiActivity {
// default set to lowest pool
calculateTx0(WhirlpoolMeta.getInstance(NewPoolActivity.this).getMinimumPoolDenomination(), mediumFee);
}
newPoolViewModel.setUtxos(selectedCoins);
}
private void calculateTx0(long denomination, long fee) {
......@@ -328,24 +313,23 @@ public class NewPoolActivity extends SamouraiActivity {
}
Collection<UnspentOutput> spendFroms = WhirlpoolUtils.getInstance().toUnspentOutputsCoins(coins);
if (selectedPoolPriority == PoolCyclePriority.HIGH) {
tx0FeeTarget = Tx0FeeTarget.BLOCKS_2;
} else if (selectedPoolPriority == PoolCyclePriority.NORMAL) {
tx0FeeTarget = Tx0FeeTarget.BLOCKS_6;
Tx0FeeTarget mixFeeTarget = Tx0FeeTarget.BLOCKS_2;
} else if (selectedPoolPriority == PoolCyclePriority.LOW) {
tx0FeeTarget = Tx0FeeTarget.BLOCKS_24;
if (newPoolViewModel.getGetTx0PoolPriority().getValue() == PoolCyclePriority.HIGH) {
mixFeeTarget = Tx0FeeTarget.BLOCKS_2;
} else if (newPoolViewModel.getGetTx0PoolPriority().getValue() == PoolCyclePriority.NORMAL) {
mixFeeTarget = Tx0FeeTarget.BLOCKS_6;
} else if (newPoolViewModel.getGetTx0PoolPriority().getValue() == PoolCyclePriority.LOW) {
mixFeeTarget = Tx0FeeTarget.BLOCKS_24;
}
Tx0FeeTarget mixFeeTarget = tx0FeeTarget;
Tx0Config tx0Config = whirlpoolWallet.getTx0Config(tx0FeeTarget, mixFeeTarget);
Tx0Config tx0Config = whirlpoolWallet.getTx0Config(mixFeeTarget, mixFeeTarget);
if (account == WhirlpoolMeta.getInstance(getApplicationContext()).getWhirlpoolPostmix()) {
tx0Config.setChangeWallet(WhirlpoolAccount.POSTMIX);
} else {
tx0Config.setChangeWallet(WhirlpoolAccount.DEPOSIT);
}
try {
com.samourai.whirlpool.client.whirlpool.beans.Pool pool = whirlpoolWallet.getPoolSupplier().findPoolById(selectedPoolViewModel.getPoolId());
com.samourai.whirlpool.client.whirlpool.beans.Pool pool = whirlpoolWallet.getPoolSupplier().findPoolById(newPoolViewModel.getGetPool().getValue().getPoolId());
Tx0 tx0 = whirlpoolWallet.tx0(spendFroms, tx0Config, pool);
final String txHash = tx0.getTx().getHashAsString();
......@@ -405,7 +389,7 @@ public class NewPoolActivity extends SamouraiActivity {
case 1: {
initUTXOReviewButton(selectedCoins);
enableStep2(true);
enableConfirmButton(selectedPoolViewModel != null);
enableConfirmButton(newPoolViewModel.getGetPool().getValue() != null);
break;
}
case 2: {
......
package com.samourai.wallet.whirlpool.newPool
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.samourai.wallet.api.backend.MinerFeeTarget
import com.samourai.wallet.api.backend.beans.UnspentOutput
import com.samourai.wallet.utxos.models.UTXOCoin
import com.samourai.wallet.whirlpool.WhirlpoolMeta
import com.samourai.wallet.whirlpool.WhirlpoolTx0
import com.samourai.wallet.whirlpool.models.PoolCyclePriority
import com.samourai.wallet.whirlpool.models.PoolViewModel
import com.samourai.whirlpool.client.wallet.AndroidWhirlpoolWalletService
import com.samourai.whirlpool.client.wallet.WhirlpoolUtils
import com.samourai.whirlpool.client.wallet.beans.Tx0FeeTarget
import com.samourai.whirlpool.client.wallet.beans.WhirlpoolAccount
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
class NewPoolViewModel : ViewModel() {
private val poolsLiveData: MutableLiveData<ArrayList<PoolViewModel>> = MutableLiveData(arrayListOf())
private val utxos: MutableLiveData<List<UTXOCoin>> = MutableLiveData(arrayListOf())
private val loadingPools: MutableLiveData<Boolean> = MutableLiveData(false)
private val tx0PoolPriority: MutableLiveData<PoolCyclePriority> = MutableLiveData(PoolCyclePriority.NORMAL)
private var pool: MutableLiveData<PoolViewModel?> = MutableLiveData(null);
private val poolLoadError: MutableLiveData<Exception?> = MutableLiveData(null)
val getTx0PoolPriority: LiveData<PoolCyclePriority> get() = tx0PoolPriority
val getPool: LiveData<PoolViewModel?> get() = pool
val getPools: LiveData<ArrayList<PoolViewModel>> get() = poolsLiveData
val getUtxos: LiveData<List<UTXOCoin>> get() = utxos
val getLoadingPools: LiveData<Boolean> get() = loadingPools
val getPoolLoadError: LiveData<Exception?> get() = poolLoadError
fun setPoolPriority(poolCyclePriority: PoolCyclePriority) {
this.tx0PoolPriority.postValue(poolCyclePriority)
}
fun setUtxos(utxos: List<UTXOCoin>) {
this.utxos.postValue(utxos)
}
fun loadPools() {
val whirlpoolWallet = AndroidWhirlpoolWalletService.getInstance().whirlpoolWalletOrNull
?: return
loadingPools.postValue(true)
poolsLiveData.postValue(arrayListOf())
viewModelScope.launch(Dispatchers.IO) {
val pools = whirlpoolWallet.poolSupplier.pools
val feeSupplier = whirlpoolWallet.minerFeeSupplier;
try {
var mixFeeTarget = Tx0FeeTarget.BLOCKS_2
when (tx0PoolPriority.value) {
PoolCyclePriority.HIGH -> {
mixFeeTarget = Tx0FeeTarget.BLOCKS_2
}
PoolCyclePriority.NORMAL -> {
mixFeeTarget = Tx0FeeTarget.BLOCKS_6
}
PoolCyclePriority.LOW -> {
mixFeeTarget = Tx0FeeTarget.BLOCKS_24
}
}
var fee = feeSupplier.getFee(MinerFeeTarget.BLOCKS_2)
if (tx0PoolPriority.value != null) {
when (tx0PoolPriority.value) {
PoolCyclePriority.HIGH -> fee = feeSupplier.getFee(MinerFeeTarget.BLOCKS_2)
PoolCyclePriority.NORMAL -> fee = feeSupplier.getFee(MinerFeeTarget.BLOCKS_6)
PoolCyclePriority.LOW -> {
fee = feeSupplier.getFee(MinerFeeTarget.BLOCKS_24)
}
}
}
val tx0Config = whirlpoolWallet.getTx0Config(mixFeeTarget, mixFeeTarget)
tx0Config.changeWallet = WhirlpoolAccount.DEPOSIT
val tx0 = WhirlpoolTx0(WhirlpoolMeta.getMinimumPoolDenomination(), fee.toLong(), 0, utxos.value)
val spendFroms: MutableCollection<UnspentOutput> =
WhirlpoolUtils.getInstance().toUnspentOutputs(tx0.outpoints)
val poolModels = ArrayList<PoolViewModel>();
val tx0Previews = whirlpoolWallet.tx0Previews(tx0Config, spendFroms)
for (whirlpoolPool in pools) {
val poolViewModel = PoolViewModel(whirlpoolPool)
if (getPool.value != null) {
poolViewModel.isSelected = getPool.value!!.poolId == poolViewModel.poolId
}
val txoPreview = tx0Previews.getTx0Preview(poolViewModel.pool.poolId)
poolViewModel.setMinerFee(fee.toLong(),utxos.value)
if (txoPreview != null) {
poolViewModel.tx0Preview = txoPreview
}
poolModels.add(poolViewModel)
//
}
if(pool.value!=null){
pool.postValue(poolModels.find { it.pool.poolId == pool.value!!.poolId })
}
poolsLiveData.postValue(poolModels)
loadingPools.postValue(false)
} catch (ex: Exception) {
ex.printStackTrace()
loadingPools.postValue(false)
poolLoadError.postValue(ex)
throw CancellationException(ex.message)
}
}
}
fun setSelectedPool(position: Int) {
if (this.poolsLiveData.value != null) {
var pools: List<PoolViewModel> = this.poolsLiveData.value!!
pools = pools.mapIndexed { index, poolViewModel ->
if( index == position){
poolViewModel.isSelected = !poolViewModel.isSelected
}else{
poolViewModel.isSelected = false
}
poolViewModel
}
this.poolsLiveData.postValue(ArrayList(pools))
this.pool.postValue(pools.find { it.isSelected })
}
}