use of org.bitcoinj.core.InsufficientMoneyException in project bitcoin-wallet by bitcoin-wallet.
the class SendCoinsFragment method updateView.
private void updateView() {
if (!isResumed())
return;
if (paymentIntent != null) {
final MonetaryFormat btcFormat = config.getFormat();
getView().setVisibility(View.VISIBLE);
if (paymentIntent.hasPayee()) {
payeeNameView.setVisibility(View.VISIBLE);
payeeNameView.setText(paymentIntent.payeeName);
payeeVerifiedByView.setVisibility(View.VISIBLE);
final String verifiedBy = paymentIntent.payeeVerifiedBy != null ? paymentIntent.payeeVerifiedBy : getString(R.string.send_coins_fragment_payee_verified_by_unknown);
payeeVerifiedByView.setText(Constants.CHAR_CHECKMARK + String.format(getString(R.string.send_coins_fragment_payee_verified_by), verifiedBy));
} else {
payeeNameView.setVisibility(View.GONE);
payeeVerifiedByView.setVisibility(View.GONE);
}
if (paymentIntent.hasOutputs()) {
payeeGroup.setVisibility(View.VISIBLE);
receivingAddressView.setVisibility(View.GONE);
receivingStaticView.setVisibility(!paymentIntent.hasPayee() || paymentIntent.payeeVerifiedBy == null ? View.VISIBLE : View.GONE);
receivingStaticLabelView.setText(paymentIntent.memo);
if (paymentIntent.hasAddress())
receivingStaticAddressView.setText(WalletUtils.formatAddress(paymentIntent.getAddress(), Constants.ADDRESS_FORMAT_GROUP_SIZE, Constants.ADDRESS_FORMAT_LINE_SIZE));
else
receivingStaticAddressView.setText(R.string.send_coins_fragment_receiving_address_complex);
} else if (validatedAddress != null) {
payeeGroup.setVisibility(View.VISIBLE);
receivingAddressView.setVisibility(View.GONE);
receivingStaticView.setVisibility(View.VISIBLE);
receivingStaticAddressView.setText(WalletUtils.formatAddress(validatedAddress.address, Constants.ADDRESS_FORMAT_GROUP_SIZE, Constants.ADDRESS_FORMAT_LINE_SIZE));
final String addressBookLabel = AddressBookProvider.resolveLabel(activity, validatedAddress.address.toBase58());
final String staticLabel;
if (addressBookLabel != null)
staticLabel = addressBookLabel;
else if (validatedAddress.label != null)
staticLabel = validatedAddress.label;
else
staticLabel = getString(R.string.address_unlabeled);
receivingStaticLabelView.setText(staticLabel);
receivingStaticLabelView.setTextColor(getResources().getColor(validatedAddress.label != null ? R.color.fg_significant : R.color.fg_insignificant));
} else if (paymentIntent.standard == null) {
payeeGroup.setVisibility(View.VISIBLE);
receivingStaticView.setVisibility(View.GONE);
receivingAddressView.setVisibility(View.VISIBLE);
} else {
payeeGroup.setVisibility(View.GONE);
}
receivingAddressView.setEnabled(state == State.INPUT);
amountGroup.setVisibility(paymentIntent.hasAmount() || (state != null && state.compareTo(State.INPUT) >= 0) ? View.VISIBLE : View.GONE);
amountCalculatorLink.setEnabled(state == State.INPUT && paymentIntent.mayEditAmount());
final boolean directPaymentVisible;
if (paymentIntent.hasPaymentUrl()) {
if (paymentIntent.isBluetoothPaymentUrl())
directPaymentVisible = bluetoothAdapter != null;
else
directPaymentVisible = true;
} else {
directPaymentVisible = false;
}
directPaymentEnableView.setVisibility(directPaymentVisible ? View.VISIBLE : View.GONE);
directPaymentEnableView.setEnabled(state == State.INPUT);
hintView.setVisibility(View.GONE);
if (state == State.INPUT) {
if (blockchainState != null && blockchainState.replaying) {
hintView.setTextColor(getResources().getColor(R.color.fg_error));
hintView.setVisibility(View.VISIBLE);
hintView.setText(R.string.send_coins_fragment_hint_replaying);
} else if (paymentIntent.mayEditAddress() && validatedAddress == null && !receivingAddressView.getText().toString().trim().isEmpty()) {
hintView.setTextColor(getResources().getColor(R.color.fg_error));
hintView.setVisibility(View.VISIBLE);
hintView.setText(R.string.send_coins_fragment_receiving_address_error);
} else if (dryrunException != null) {
hintView.setTextColor(getResources().getColor(R.color.fg_error));
hintView.setVisibility(View.VISIBLE);
if (dryrunException instanceof DustySendRequested)
hintView.setText(getString(R.string.send_coins_fragment_hint_dusty_send));
else if (dryrunException instanceof InsufficientMoneyException)
hintView.setText(getString(R.string.send_coins_fragment_hint_insufficient_money, btcFormat.format(((InsufficientMoneyException) dryrunException).missing)));
else if (dryrunException instanceof CouldNotAdjustDownwards)
hintView.setText(getString(R.string.send_coins_fragment_hint_empty_wallet_failed));
else
hintView.setText(dryrunException.toString());
} else if (dryrunTransaction != null && dryrunTransaction.getFee() != null) {
hintView.setVisibility(View.VISIBLE);
final int hintResId;
final int colorResId;
if (feeCategory == FeeCategory.ECONOMIC) {
hintResId = R.string.send_coins_fragment_hint_fee_economic;
colorResId = R.color.fg_less_significant;
} else if (feeCategory == FeeCategory.PRIORITY) {
hintResId = R.string.send_coins_fragment_hint_fee_priority;
colorResId = R.color.fg_less_significant;
} else {
hintResId = R.string.send_coins_fragment_hint_fee;
colorResId = R.color.fg_insignificant;
}
hintView.setTextColor(getResources().getColor(colorResId));
hintView.setText(getString(hintResId, btcFormat.format(dryrunTransaction.getFee())));
} else if (paymentIntent.mayEditAddress() && validatedAddress != null && wallet.isPubKeyHashMine(validatedAddress.address.getHash160())) {
hintView.setTextColor(getResources().getColor(R.color.fg_insignificant));
hintView.setVisibility(View.VISIBLE);
hintView.setText(R.string.send_coins_fragment_receiving_address_own);
}
}
if (sentTransaction != null) {
sentTransactionView.setVisibility(View.VISIBLE);
sentTransactionAdapter.setFormat(btcFormat);
sentTransactionAdapter.replace(sentTransaction);
sentTransactionAdapter.bindViewHolder(sentTransactionViewHolder, 0);
} else {
sentTransactionView.setVisibility(View.GONE);
}
if (directPaymentAck != null) {
directPaymentMessageView.setVisibility(View.VISIBLE);
directPaymentMessageView.setText(directPaymentAck ? R.string.send_coins_fragment_direct_payment_ack : R.string.send_coins_fragment_direct_payment_nack);
} else {
directPaymentMessageView.setVisibility(View.GONE);
}
viewCancel.setEnabled(state != State.REQUEST_PAYMENT_REQUEST && state != State.DECRYPTING && state != State.SIGNING);
viewGo.setEnabled(everythingPlausible() && dryrunTransaction != null && fees != null && (blockchainState == null || !blockchainState.replaying));
if (state == null || state == State.REQUEST_PAYMENT_REQUEST) {
viewCancel.setText(R.string.button_cancel);
viewGo.setText(null);
} else if (state == State.INPUT) {
viewCancel.setText(R.string.button_cancel);
viewGo.setText(R.string.send_coins_fragment_button_send);
} else if (state == State.DECRYPTING) {
viewCancel.setText(R.string.button_cancel);
viewGo.setText(R.string.send_coins_fragment_state_decrypting);
} else if (state == State.SIGNING) {
viewCancel.setText(R.string.button_cancel);
viewGo.setText(R.string.send_coins_preparation_msg);
} else if (state == State.SENDING) {
viewCancel.setText(R.string.send_coins_fragment_button_back);
viewGo.setText(R.string.send_coins_sending_msg);
} else if (state == State.SENT) {
viewCancel.setText(R.string.send_coins_fragment_button_back);
viewGo.setText(R.string.send_coins_sent_msg);
} else if (state == State.FAILED) {
viewCancel.setText(R.string.send_coins_fragment_button_back);
viewGo.setText(R.string.send_coins_failed_msg);
}
final boolean privateKeyPasswordViewVisible = (state == State.INPUT || state == State.DECRYPTING) && wallet.isEncrypted();
privateKeyPasswordViewGroup.setVisibility(privateKeyPasswordViewVisible ? View.VISIBLE : View.GONE);
privateKeyPasswordView.setEnabled(state == State.INPUT);
// focus linking
final int activeAmountViewId = amountCalculatorLink.activeTextView().getId();
receivingAddressView.setNextFocusDownId(activeAmountViewId);
receivingAddressView.setNextFocusForwardId(activeAmountViewId);
amountCalculatorLink.setNextFocusId(privateKeyPasswordViewVisible ? R.id.send_coins_private_key_password : R.id.send_coins_go);
privateKeyPasswordView.setNextFocusUpId(activeAmountViewId);
privateKeyPasswordView.setNextFocusDownId(R.id.send_coins_go);
privateKeyPasswordView.setNextFocusForwardId(R.id.send_coins_go);
viewGo.setNextFocusUpId(privateKeyPasswordViewVisible ? R.id.send_coins_private_key_password : activeAmountViewId);
} else {
getView().setVisibility(View.GONE);
}
}
use of org.bitcoinj.core.InsufficientMoneyException in project bitcoin-wallet by bitcoin-wallet.
the class SendCoinsOfflineTask method sendCoinsOffline.
public final void sendCoinsOffline(final SendRequest sendRequest) {
backgroundHandler.post(new Runnable() {
@Override
public void run() {
org.bitcoinj.core.Context.propagate(Constants.CONTEXT);
try {
log.info("sending: {}", sendRequest);
// can take long
final Transaction transaction = wallet.sendCoinsOffline(sendRequest);
log.info("send successful, transaction committed: {}", transaction.getHashAsString());
callbackHandler.post(new Runnable() {
@Override
public void run() {
onSuccess(transaction);
}
});
} catch (final InsufficientMoneyException x) {
final Coin missing = x.missing;
if (missing != null)
log.info("send failed, {} missing", missing.toFriendlyString());
else
log.info("send failed, insufficient coins");
callbackHandler.post(new Runnable() {
@Override
public void run() {
onInsufficientMoney(x.missing);
}
});
} catch (final ECKey.KeyIsEncryptedException x) {
log.info("send failed, key is encrypted: {}", x.getMessage());
callbackHandler.post(new Runnable() {
@Override
public void run() {
onFailure(x);
}
});
} catch (final KeyCrypterException x) {
log.info("send failed, key crypter exception: {}", x.getMessage());
final boolean isEncrypted = wallet.isEncrypted();
callbackHandler.post(new Runnable() {
@Override
public void run() {
if (isEncrypted)
onInvalidEncryptionKey();
else
onFailure(x);
}
});
} catch (final CouldNotAdjustDownwards x) {
log.info("send failed, could not adjust downwards: {}", x.getMessage());
callbackHandler.post(new Runnable() {
@Override
public void run() {
onEmptyWalletFailed();
}
});
} catch (final CompletionException x) {
log.info("send failed, cannot complete: {}", x.getMessage());
callbackHandler.post(new Runnable() {
@Override
public void run() {
onFailure(x);
}
});
}
}
});
}
Aggregations