Search in sources :

Example 26 with Address

use of org.bitcoinj.core.Address in project bitcoin-wallet by bitcoin-wallet.

the class WalletTransactionsFragment method onTransactionMenuClick.

@Override
public void onTransactionMenuClick(final View view, final Transaction tx) {
    final boolean txSent = tx.getValue(wallet).signum() < 0;
    final Address txAddress = txSent ? WalletUtils.getToAddressOfSent(tx, wallet) : WalletUtils.getWalletAddressOfReceived(tx, wallet);
    final byte[] txSerialized = tx.unsafeBitcoinSerialize();
    final boolean txRotation = tx.getPurpose() == Purpose.KEY_ROTATION;
    final PopupMenu popupMenu = new PopupMenu(activity, view);
    popupMenu.inflate(R.menu.wallet_transactions_context);
    final MenuItem editAddressMenuItem = popupMenu.getMenu().findItem(R.id.wallet_transactions_context_edit_address);
    if (!txRotation && txAddress != null) {
        editAddressMenuItem.setVisible(true);
        final boolean isAdd = AddressBookProvider.resolveLabel(activity, txAddress.toBase58()) == null;
        final boolean isOwn = wallet.isPubKeyHashMine(txAddress.getHash160());
        if (isOwn)
            editAddressMenuItem.setTitle(isAdd ? R.string.edit_address_book_entry_dialog_title_add_receive : R.string.edit_address_book_entry_dialog_title_edit_receive);
        else
            editAddressMenuItem.setTitle(isAdd ? R.string.edit_address_book_entry_dialog_title_add : R.string.edit_address_book_entry_dialog_title_edit);
    } else {
        editAddressMenuItem.setVisible(false);
    }
    popupMenu.getMenu().findItem(R.id.wallet_transactions_context_show_qr).setVisible(!txRotation && txSerialized.length < SHOW_QR_THRESHOLD_BYTES);
    popupMenu.getMenu().findItem(R.id.wallet_transactions_context_raise_fee).setVisible(RaiseFeeDialogFragment.feeCanLikelyBeRaised(wallet, tx));
    popupMenu.getMenu().findItem(R.id.wallet_transactions_context_browse).setVisible(Constants.ENABLE_BROWSE);
    popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(final MenuItem item) {
            switch(item.getItemId()) {
                case R.id.wallet_transactions_context_edit_address:
                    handleEditAddress(tx);
                    return true;
                case R.id.wallet_transactions_context_show_qr:
                    handleShowQr();
                    return true;
                case R.id.wallet_transactions_context_raise_fee:
                    RaiseFeeDialogFragment.show(getFragmentManager(), tx);
                    return true;
                case R.id.wallet_transactions_context_report_issue:
                    handleReportIssue(tx);
                    return true;
                case R.id.wallet_transactions_context_browse:
                    if (!txRotation) {
                        final String txHash = tx.getHashAsString();
                        final Uri blockExplorerUri = config.getBlockExplorer();
                        log.info("Viewing transaction {} on {}", txHash, blockExplorerUri);
                        startActivity(new Intent(Intent.ACTION_VIEW, Uri.withAppendedPath(blockExplorerUri, "tx/" + txHash)));
                    } else {
                        startActivity(new Intent(Intent.ACTION_VIEW, KEY_ROTATION_URI));
                    }
                    return true;
            }
            return false;
        }

        private void handleEditAddress(final Transaction tx) {
            EditAddressBookEntryFragment.edit(getFragmentManager(), txAddress);
        }

        private void handleShowQr() {
            final Bitmap qrCodeBitmap = Qr.bitmap(Qr.encodeCompressBinary(txSerialized));
            BitmapFragment.show(getFragmentManager(), qrCodeBitmap);
        }

        private void handleReportIssue(final Transaction tx) {
            final StringBuilder contextualData = new StringBuilder();
            try {
                contextualData.append(tx.getValue(wallet).toFriendlyString()).append(" total value");
            } catch (final ScriptException x) {
                contextualData.append(x.getMessage());
            }
            contextualData.append('\n');
            if (tx.hasConfidence())
                contextualData.append("  confidence: ").append(tx.getConfidence()).append('\n');
            contextualData.append(tx.toString());
            ReportIssueDialogFragment.show(getFragmentManager(), R.string.report_issue_dialog_title_transaction, R.string.report_issue_dialog_message_issue, Constants.REPORT_SUBJECT_ISSUE, contextualData.toString());
        }
    });
    popupMenu.show();
}
Also used : Address(org.bitcoinj.core.Address) SpannableStringBuilder(android.text.SpannableStringBuilder) OnMenuItemClickListener(android.widget.PopupMenu.OnMenuItemClickListener) MenuItem(android.view.MenuItem) Intent(android.content.Intent) Uri(android.net.Uri) ScriptException(org.bitcoinj.core.ScriptException) Bitmap(android.graphics.Bitmap) Transaction(org.bitcoinj.core.Transaction) PopupMenu(android.widget.PopupMenu)

Aggregations

Address (org.bitcoinj.core.Address)26 WalletService (io.bitsquare.btc.WalletService)8 Coin (org.bitcoinj.core.Coin)8 Transaction (org.bitcoinj.core.Transaction)8 AddressEntry (io.bitsquare.btc.AddressEntry)7 TextView (android.widget.TextView)5 View (android.view.View)3 Offer (io.bitsquare.trade.offer.Offer)3 DialogInterface (android.content.DialogInterface)2 Intent (android.content.Intent)2 Uri (android.net.Uri)2 Bundle (android.os.Bundle)2 Inject (com.google.inject.Inject)2 Arbitrator (io.bitsquare.arbitration.Arbitrator)2 PreparedDepositTxAndOffererInputs (io.bitsquare.btc.data.PreparedDepositTxAndOffererInputs)2 BalanceListener (io.bitsquare.btc.listeners.BalanceListener)2 UserThread (io.bitsquare.common.UserThread)2 NodeAddress (io.bitsquare.p2p.NodeAddress)2 Trade (io.bitsquare.trade.Trade)2 InetSocketAddress (java.net.InetSocketAddress)2