use of de.schildbach.wallet.data.PaymentIntent in project bitcoin-wallet by bitcoin-wallet.
the class SendCoinsFragment method requestPaymentRequest.
private void requestPaymentRequest() {
final String paymentRequestHost;
if (!Bluetooth.isBluetoothUrl(paymentIntent.paymentRequestUrl))
paymentRequestHost = Uri.parse(paymentIntent.paymentRequestUrl).getHost();
else
paymentRequestHost = Bluetooth.decompressMac(Bluetooth.getBluetoothMac(paymentIntent.paymentRequestUrl));
ProgressDialogFragment.showProgress(fragmentManager, getString(R.string.send_coins_fragment_request_payment_request_progress, paymentRequestHost));
setState(State.REQUEST_PAYMENT_REQUEST);
final RequestPaymentRequestTask.ResultCallback callback = new RequestPaymentRequestTask.ResultCallback() {
@Override
public void onPaymentIntent(final PaymentIntent paymentIntent) {
ProgressDialogFragment.dismissProgress(fragmentManager);
if (SendCoinsFragment.this.paymentIntent.isExtendedBy(paymentIntent)) {
// success
setState(State.INPUT);
updateStateFrom(paymentIntent);
updateView();
handler.post(dryrunRunnable);
} else {
final List<String> reasons = new LinkedList<>();
if (!SendCoinsFragment.this.paymentIntent.equalsAddress(paymentIntent))
reasons.add("address");
if (!SendCoinsFragment.this.paymentIntent.equalsAmount(paymentIntent))
reasons.add("amount");
if (reasons.isEmpty())
reasons.add("unknown");
final DialogBuilder dialog = DialogBuilder.warn(activity, R.string.send_coins_fragment_request_payment_request_failed_title);
dialog.setMessage(getString(R.string.send_coins_fragment_request_payment_request_failed_message, paymentRequestHost, Joiner.on(", ").join(reasons)));
dialog.singleDismissButton(new DialogInterface.OnClickListener() {
@Override
public void onClick(final DialogInterface dialog, final int which) {
handleCancel();
}
});
dialog.show();
log.info("BIP72 trust check failed: {}", reasons);
}
}
@Override
public void onFail(final int messageResId, final Object... messageArgs) {
ProgressDialogFragment.dismissProgress(fragmentManager);
final DialogBuilder dialog = DialogBuilder.warn(activity, R.string.send_coins_fragment_request_payment_request_failed_title);
dialog.setMessage(getString(messageResId, messageArgs));
dialog.setPositiveButton(R.string.button_retry, new DialogInterface.OnClickListener() {
@Override
public void onClick(final DialogInterface dialog, final int which) {
requestPaymentRequest();
}
});
dialog.setNegativeButton(R.string.button_dismiss, new DialogInterface.OnClickListener() {
@Override
public void onClick(final DialogInterface dialog, final int which) {
if (!paymentIntent.hasOutputs())
handleCancel();
else
setState(State.INPUT);
}
});
dialog.show();
}
};
if (!Bluetooth.isBluetoothUrl(paymentIntent.paymentRequestUrl))
new RequestPaymentRequestTask.HttpRequestTask(backgroundHandler, callback, application.httpUserAgent()).requestPaymentRequest(paymentIntent.paymentRequestUrl);
else
new RequestPaymentRequestTask.BluetoothRequestTask(backgroundHandler, callback, bluetoothAdapter).requestPaymentRequest(paymentIntent.paymentRequestUrl);
}
use of de.schildbach.wallet.data.PaymentIntent in project bitcoin-wallet by bitcoin-wallet.
the class SendCoinsFragment method updateStateFrom.
private void updateStateFrom(final PaymentIntent paymentIntent) {
log.info("got {}", paymentIntent);
this.paymentIntent = paymentIntent;
validatedAddress = null;
directPaymentAck = null;
// delay these actions until fragment is resumed
handler.post(new Runnable() {
@Override
public void run() {
if (paymentIntent.hasPaymentRequestUrl() && paymentIntent.isBluetoothPaymentRequestUrl()) {
if (bluetoothAdapter.isEnabled())
requestPaymentRequest();
else
// ask for permission to enable bluetooth
startActivityForResult(new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE), REQUEST_CODE_ENABLE_BLUETOOTH_FOR_PAYMENT_REQUEST);
} else if (paymentIntent.hasPaymentRequestUrl() && paymentIntent.isHttpPaymentRequestUrl()) {
requestPaymentRequest();
} else {
setState(State.INPUT);
receivingAddressView.setText(null);
amountCalculatorLink.setBtcAmount(paymentIntent.getAmount());
if (paymentIntent.isBluetoothPaymentUrl())
directPaymentEnableView.setChecked(bluetoothAdapter != null && bluetoothAdapter.isEnabled());
else if (paymentIntent.isHttpPaymentUrl())
directPaymentEnableView.setChecked(true);
requestFocusFirst();
updateView();
handler.post(dryrunRunnable);
}
}
});
}
use of de.schildbach.wallet.data.PaymentIntent in project bitcoin-wallet by bitcoin-wallet.
the class SweepWalletFragment method onActivityResult.
@Override
public void onActivityResult(final int requestCode, final int resultCode, final Intent intent) {
if (requestCode == REQUEST_CODE_SCAN) {
if (resultCode == Activity.RESULT_OK) {
final String input = intent.getStringExtra(ScanActivity.INTENT_EXTRA_RESULT);
new StringInputParser(input) {
@Override
protected void handlePrivateKey(final VersionedChecksummedBytes key) {
privateKeyToSweep = key;
setState(State.DECODE_KEY);
maybeDecodeKey();
}
@Override
protected void handlePaymentIntent(final PaymentIntent paymentIntent) {
cannotClassify(input);
}
@Override
protected void handleDirectTransaction(final Transaction transaction) throws VerificationException {
cannotClassify(input);
}
@Override
protected void error(final int messageResId, final Object... messageArgs) {
dialog(activity, null, R.string.button_scan, messageResId, messageArgs);
}
}.parse();
}
}
}
use of de.schildbach.wallet.data.PaymentIntent in project bitcoin-wallet by bitcoin-wallet.
the class SendingAddressesFragment method onActivityResult.
@Override
public void onActivityResult(final int requestCode, final int resultCode, final Intent intent) {
if (requestCode == REQUEST_CODE_SCAN && resultCode == Activity.RESULT_OK) {
final String input = intent.getStringExtra(ScanActivity.INTENT_EXTRA_RESULT);
new StringInputParser(input) {
@Override
protected void handlePaymentIntent(final PaymentIntent paymentIntent) {
// workaround for "IllegalStateException: Can not perform this action after
// onSaveInstanceState"
handler.postDelayed(new Runnable() {
@Override
public void run() {
if (paymentIntent.hasAddress()) {
final Address address = paymentIntent.getAddress();
if (!wallet.isPubKeyHashMine(address.getHash160()))
EditAddressBookEntryFragment.edit(getFragmentManager(), address);
else
dialog(activity, null, R.string.address_book_options_scan_title, R.string.address_book_options_scan_own_address);
} else {
dialog(activity, null, R.string.address_book_options_scan_title, R.string.address_book_options_scan_invalid);
}
}
}, 500);
}
@Override
protected void handleDirectTransaction(final Transaction transaction) throws VerificationException {
cannotClassify(input);
}
@Override
protected void error(final int messageResId, final Object... messageArgs) {
dialog(activity, null, R.string.address_book_options_scan_title, messageResId, messageArgs);
}
}.parse();
}
}
use of de.schildbach.wallet.data.PaymentIntent in project bitcoin-wallet by bitcoin-wallet.
the class WalletActivity method handleIntent.
private void handleIntent(final Intent intent) {
final String action = intent.getAction();
if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) {
final String inputType = intent.getType();
final NdefMessage ndefMessage = (NdefMessage) intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES)[0];
final byte[] input = Nfc.extractMimePayload(Constants.MIMETYPE_TRANSACTION, ndefMessage);
new BinaryInputParser(inputType, input) {
@Override
protected void handlePaymentIntent(final PaymentIntent paymentIntent) {
cannotClassify(inputType);
}
@Override
protected void error(final int messageResId, final Object... messageArgs) {
dialog(WalletActivity.this, null, 0, messageResId, messageArgs);
}
}.parse();
}
}
Aggregations