Skip to content

Commit

Permalink
Execute send coins dryrun after updating the view.
Browse files Browse the repository at this point in the history
  • Loading branch information
schildbach committed Nov 16, 2014
1 parent 6bcde9c commit aaa9b35
Showing 1 changed file with 35 additions and 27 deletions.
62 changes: 35 additions & 27 deletions wallet/src/de/schildbach/wallet/ui/send/SendCoinsFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,8 @@ private void handleClear()
@Override
public void changed()
{
executeDryrun();
updateView();
handler.post(dryrunRunnable);
}

@Override
Expand Down Expand Up @@ -680,8 +680,8 @@ public void onResume()
loaderManager.initLoader(ID_RATE_LOADER, null, rateLoaderCallbacks);
loaderManager.initLoader(ID_RECEIVING_ADDRESS_LOADER, null, receivingAddressLoaderCallbacks);

executeDryrun();
updateView();
handler.post(dryrunRunnable);
}

@Override
Expand Down Expand Up @@ -1117,47 +1117,55 @@ private void handlePriority()
{
priority = !priority;

executeDryrun();
updateView();
handler.post(dryrunRunnable);
}

private void handleEmpty()
{
final Coin available = wallet.getBalance(BalanceType.AVAILABLE);

amountCalculatorLink.setBtcAmount(available);

executeDryrun();
updateView();
handler.post(dryrunRunnable);
}

private void executeDryrun()
private Runnable dryrunRunnable = new Runnable()
{
if (state != State.INPUT)
return;
@Override
public void run()
{
if (state == State.INPUT)
executeDryrun();

dryrunTransaction = null;
dryrunException = null;
updateView();
}

final Coin amount = amountCalculatorLink.getAmount();
if (amount != null)
private void executeDryrun()
{
try
{
final Address dummy = wallet.currentReceiveAddress(); // won't be used, tx is never committed
final SendRequest sendRequest = paymentIntent.mergeWithEditedValues(amount, dummy).toSendRequest();
sendRequest.signInputs = false;
sendRequest.emptyWallet = paymentIntent.mayEditAmount() && amount.equals(wallet.getBalance(BalanceType.AVAILABLE));
sendRequest.feePerKb = priority ? SendRequest.DEFAULT_FEE_PER_KB.multiply(10) : SendRequest.DEFAULT_FEE_PER_KB;
wallet.completeTx(sendRequest);
dryrunTransaction = sendRequest.tx;
}
catch (final Exception x)
dryrunTransaction = null;
dryrunException = null;

final Coin amount = amountCalculatorLink.getAmount();
if (amount != null)
{
dryrunException = x;
try
{
final Address dummy = wallet.currentReceiveAddress(); // won't be used, tx is never committed
final SendRequest sendRequest = paymentIntent.mergeWithEditedValues(amount, dummy).toSendRequest();
sendRequest.signInputs = false;
sendRequest.emptyWallet = paymentIntent.mayEditAmount() && amount.equals(wallet.getBalance(BalanceType.AVAILABLE));
sendRequest.feePerKb = priority ? SendRequest.DEFAULT_FEE_PER_KB.multiply(10) : SendRequest.DEFAULT_FEE_PER_KB;
wallet.completeTx(sendRequest);
dryrunTransaction = sendRequest.tx;
}
catch (final Exception x)
{
dryrunException = x;
}
}
}
}
};

private void setState(final State state)
{
Expand Down Expand Up @@ -1474,8 +1482,8 @@ else if (paymentIntent.isHttpPaymentUrl())
directPaymentEnableView.setChecked(!Constants.BUG_OPENSSL_HEARTBLEED);

requestFocusFirst();
executeDryrun();
updateView();
handler.post(dryrunRunnable);
}

if (paymentIntent.hasPaymentRequestUrl())
Expand Down Expand Up @@ -1519,8 +1527,8 @@ public void onPaymentIntent(final PaymentIntent paymentIntent)
{
// success
updateStateFrom(paymentIntent);
executeDryrun();
updateView();
handler.post(dryrunRunnable);
}
else
{
Expand Down

0 comments on commit aaa9b35

Please sign in to comment.