Commit 647a350d authored by Sarath's avatar Sarath
Browse files

Improved pool choose screen with viewmodel

parent 9ec6d0a5
......@@ -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
......
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.fragments
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import androidx.transition.Fade
import androidx.transition.TransitionManager
import com.google.android.material.snackbar.Snackbar
import com.samourai.wallet.api.backend.beans.UnspentOutput
import com.samourai.wallet.databinding.FragmentWhirlpoolReviewBinding
import com.samourai.wallet.util.FormatsUtil
import com.samourai.wallet.whirlpool.WhirlpoolTx0
import com.samourai.wallet.whirlpool.newPool.NewPoolViewModel
import com.samourai.whirlpool.client.tx0.Tx0Preview
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 com.samourai.whirlpool.client.whirlpool.beans.Pool
import kotlinx.coroutines.*
class ReviewPoolFragment : Fragment() {
......@@ -25,104 +21,37 @@ class ReviewPoolFragment : Fragment() {
private val coroutineContext = CoroutineScope(Dispatchers.IO)
private lateinit var binding: FragmentWhirlpoolReviewBinding
private val newPoolViewModel: NewPoolViewModel by activityViewModels()
private val account = 0
private var tx0: WhirlpoolTx0? = null;
private var tx0FeeTarget: Tx0FeeTarget? = null
private var mixFeeTarget: Tx0FeeTarget? = null
private var pool: Pool? = null
private var onLoading: (Boolean, Exception?) -> Unit = { _: Boolean, _: Exception? -> }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.entropyBar.setMaxBars(4)
binding.entropyBar.setRange(4)
binding.previewRetryButton.setOnClickListener {
makeTxoPreview()
}
newPoolViewModel.getPool.observe(this.viewLifecycleOwner, { pool ->
setFees(pool?.tx0Preview)
})
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View {
binding = FragmentWhirlpoolReviewBinding.inflate(inflater, container, false);
return binding.root
}
fun showProgress(show: Boolean) {
binding.progressBar.visibility = if (show) View.VISIBLE else View.GONE
}
fun setLoadingListener(listener: (Boolean, Exception?) -> Unit) {
this.onLoading = listener
}
fun setTx0(
tx0: WhirlpoolTx0,
tx0FeeTarget: Tx0FeeTarget?,
mixFeeTarget: Tx0FeeTarget?,
pool: Pool?
) {
this.pool = pool
this.tx0 = tx0
this.tx0FeeTarget = tx0FeeTarget
this.mixFeeTarget = mixFeeTarget
makeTxoPreview()
binding.minerFees.text = ""
binding.feePerUtxo.text = ""
binding.poolFees.text = ""
binding.uncycledAmount.text = ""
binding.amountToCycle.text = ""
binding.poolTotalFees.text = ""
binding.totalPoolAmount.text = ""
binding.poolAmount.text = getBTCDisplayAmount(tx0.pool)
binding.totalUtxoCreated.text = "${tx0.premixRequested}";
}
private fun makeTxoPreview() {
if (tx0 == null) {
return;
}
showLoadingProgress(true)
onLoading.invoke(true, null)
val whirlpoolWallet = AndroidWhirlpoolWalletService.getInstance().whirlpoolWalletOrNull
val spendFroms: MutableCollection<UnspentOutput> =
WhirlpoolUtils.getInstance().toUnspentOutputs(this.tx0!!.outpoints)
coroutineContext.launch(Dispatchers.IO) {
val tx0Config = whirlpoolWallet.getTx0Config(tx0FeeTarget, mixFeeTarget)
tx0Config.changeWallet = WhirlpoolAccount.DEPOSIT
try {
val tx0Previews = whirlpoolWallet.tx0Previews(tx0Config, spendFroms)
val tx0Preview = tx0Previews.getTx0Preview(pool?.poolId)
withContext(Dispatchers.Main) {
showLoadingProgress(false)
setFees(tx0Preview);
onLoading.invoke(false, null);
}
} catch (e: Exception) {
e.printStackTrace()
withContext(Dispatchers.Main) {
Snackbar.make(binding.root, "Error ${e.message}", Snackbar.LENGTH_LONG).show()
onLoading.invoke(false, e)
showLoadingProgress(false)
binding.previewRetryButton.visibility = View.VISIBLE
}
}
}
}
private fun showLoadingProgress(loading: Boolean) {
if (loading) {
binding.previewRetryButton.visibility = View.GONE
binding.loadingFeeDetails.show()
} else {
binding.loadingFeeDetails.hide()
}
}
private fun setFees(tx0Preview: Tx0Preview?) {
tx0Preview?.let {
binding.poolAmount.text = getBTCDisplayAmount(it.pool.denomination)
binding.totalUtxoCreated.text = "${it.nbPremix}";
TransitionManager.beginDelayedTransition(binding.root, Fade())
val embeddedTotalFees = tx0Preview.mixMinerFee;
binding.minerFees.text = getBTCDisplayAmount(it.tx0MinerFee);
......@@ -132,11 +61,16 @@ class ReviewPoolFragment : Fragment() {
if (it.feeDiscountPercent != 0) {
val scodeMessage = "SCODE Applied, ${it.feeDiscountPercent}% Discount"
binding.discountText.text = scodeMessage
}
try {
tx0 = WhirlpoolTx0(tx0Preview.pool.denomination, tx0Preview.tx0MinerFee, 0, newPoolViewModel.getUtxos.value)
} catch (ex: java.lang.Exception) {