Search in sources :

Example 11 with PaymentIntent

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);
}
Also used : DialogInterface(android.content.DialogInterface) PaymentIntent(de.schildbach.wallet.data.PaymentIntent) LinkedList(java.util.LinkedList) DialogBuilder(de.schildbach.wallet.ui.DialogBuilder)

Example 12 with PaymentIntent

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);
            }
        }
    });
}
Also used : PaymentIntent(de.schildbach.wallet.data.PaymentIntent) Intent(android.content.Intent)

Example 13 with PaymentIntent

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();
        }
    }
}
Also used : VersionedChecksummedBytes(org.bitcoinj.core.VersionedChecksummedBytes) Transaction(org.bitcoinj.core.Transaction) WalletTransaction(org.bitcoinj.wallet.WalletTransaction) StringInputParser(de.schildbach.wallet.ui.InputParser.StringInputParser) VerificationException(org.bitcoinj.core.VerificationException) PaymentIntent(de.schildbach.wallet.data.PaymentIntent) TransactionOutPoint(org.bitcoinj.core.TransactionOutPoint)

Example 14 with PaymentIntent

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();
    }
}
Also used : Address(org.bitcoinj.core.Address) Transaction(org.bitcoinj.core.Transaction) StringInputParser(de.schildbach.wallet.ui.InputParser.StringInputParser) VerificationException(org.bitcoinj.core.VerificationException) PaymentIntent(de.schildbach.wallet.data.PaymentIntent)

Example 15 with PaymentIntent

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();
    }
}
Also used : NdefMessage(android.nfc.NdefMessage) BinaryInputParser(de.schildbach.wallet.ui.InputParser.BinaryInputParser) PaymentIntent(de.schildbach.wallet.data.PaymentIntent)

Aggregations

PaymentIntent (de.schildbach.wallet.data.PaymentIntent)15 StringInputParser (de.schildbach.wallet.ui.InputParser.StringInputParser)6 Transaction (org.bitcoinj.core.Transaction)6 VerificationException (org.bitcoinj.core.VerificationException)6 VersionedChecksummedBytes (org.bitcoinj.core.VersionedChecksummedBytes)4 DialogInterface (android.content.DialogInterface)3 Intent (android.content.Intent)2 DialogBuilder (de.schildbach.wallet.ui.DialogBuilder)2 FileNotFoundException (java.io.FileNotFoundException)2 OnClickListener (android.content.DialogInterface.OnClickListener)1 NdefMessage (android.nfc.NdefMessage)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 UninitializedMessageException (com.google.protobuf.UninitializedMessageException)1 WalletApplication (de.schildbach.wallet.WalletApplication)1 BinaryInputParser (de.schildbach.wallet.ui.InputParser.BinaryInputParser)1 StreamInputParser (de.schildbach.wallet.ui.InputParser.StreamInputParser)1 InputStream (java.io.InputStream)1 KeyStore (java.security.KeyStore)1 KeyStoreException (java.security.KeyStoreException)1 ArrayList (java.util.ArrayList)1