Search in sources :

Example 1 with Tx

use of com.samourai.wallet.api.Tx in project samourai-wallet-android by Samourai-Wallet.

the class BalanceActivity method onCreate.

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_balance);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    if (SamouraiWallet.getInstance().isTestNet()) {
        setTitle(getText(R.string.app_name) + ":" + "TestNet");
    }
    LayoutInflater inflator = BalanceActivity.this.getLayoutInflater();
    tvBalanceBar = (LinearLayout) inflator.inflate(R.layout.balance_layout, null);
    tvBalanceBar.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (isBTC) {
                isBTC = false;
            } else {
                isBTC = true;
            }
            displayBalance();
            txAdapter.notifyDataSetChanged();
            return false;
        }
    });
    tvBalanceAmount = (TextView) tvBalanceBar.findViewById(R.id.BalanceAmount);
    tvBalanceUnits = (TextView) tvBalanceBar.findViewById(R.id.BalanceUnits);
    ibQuickSend = (FloatingActionsMenu) findViewById(R.id.wallet_menu);
    actionSend = (FloatingActionButton) findViewById(R.id.send);
    actionSend.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            Intent intent = new Intent(BalanceActivity.this, SendActivity.class);
            intent.putExtra("via_menu", true);
            startActivity(intent);
        }
    });
    actionReceive = (FloatingActionButton) findViewById(R.id.receive);
    actionReceive.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            try {
                HD_Wallet hdw = HD_WalletFactory.getInstance(BalanceActivity.this).get();
                if (hdw != null) {
                    Intent intent = new Intent(BalanceActivity.this, ReceiveActivity.class);
                    startActivity(intent);
                }
            } catch (IOException | MnemonicException.MnemonicLengthException e) {
                ;
            }
        }
    });
    actionBIP47 = (FloatingActionButton) findViewById(R.id.bip47);
    actionBIP47.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            Intent intent = new Intent(BalanceActivity.this, com.samourai.wallet.bip47.BIP47Activity.class);
            startActivity(intent);
        }
    });
    txs = new ArrayList<Tx>();
    txStates = new HashMap<String, Boolean>();
    txList = (ListView) findViewById(R.id.txList);
    txAdapter = new TransactionAdapter();
    txList.setAdapter(txAdapter);
    txList.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, final View view, int position, long id) {
            if (position == 0) {
                return;
            }
            long viewId = view.getId();
            View v = (View) view.getParent();
            final Tx tx = txs.get(position - 1);
            ImageView ivTxStatus = (ImageView) v.findViewById(R.id.TransactionStatus);
            TextView tvConfirmationCount = (TextView) v.findViewById(R.id.ConfirmationCount);
            if (viewId == R.id.ConfirmationCount || viewId == R.id.TransactionStatus) {
                if (txStates.containsKey(tx.getHash()) && txStates.get(tx.getHash()) == true) {
                    txStates.put(tx.getHash(), false);
                    displayTxStatus(false, tx.getConfirmations(), tvConfirmationCount, ivTxStatus);
                } else {
                    txStates.put(tx.getHash(), true);
                    displayTxStatus(true, tx.getConfirmations(), tvConfirmationCount, ivTxStatus);
                }
            } else {
                String message = getString(R.string.options_unconfirmed_tx);
                // RBF
                if (tx.getConfirmations() < 1 && tx.getAmount() < 0.0 && RBFUtil.getInstance().contains(tx.getHash())) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(BalanceActivity.this);
                    builder.setTitle(R.string.app_name);
                    builder.setMessage(message);
                    builder.setCancelable(true);
                    builder.setPositiveButton(R.string.options_bump_fee, new DialogInterface.OnClickListener() {

                        public void onClick(final DialogInterface dialog, int whichButton) {
                            if (rbfTask == null || rbfTask.getStatus().equals(AsyncTask.Status.FINISHED)) {
                                rbfTask = new RBFTask();
                                rbfTask.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, tx.getHash());
                            }
                        }
                    });
                    builder.setNegativeButton(R.string.options_block_explorer, new DialogInterface.OnClickListener() {

                        public void onClick(final DialogInterface dialog, int whichButton) {
                            doExplorerView(tx.getHash());
                        }
                    });
                    AlertDialog alert = builder.create();
                    alert.show();
                } else // CPFP receive
                if (tx.getConfirmations() < 1 && tx.getAmount() >= 0.0) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(BalanceActivity.this);
                    builder.setTitle(R.string.app_name);
                    builder.setMessage(message);
                    builder.setCancelable(true);
                    builder.setPositiveButton(R.string.options_bump_fee, new DialogInterface.OnClickListener() {

                        public void onClick(final DialogInterface dialog, int whichButton) {
                            if (cpfpTask == null || cpfpTask.getStatus().equals(AsyncTask.Status.FINISHED)) {
                                cpfpTask = new CPFPTask();
                                cpfpTask.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, tx.getHash());
                            }
                        }
                    });
                    builder.setNegativeButton(R.string.options_block_explorer, new DialogInterface.OnClickListener() {

                        public void onClick(final DialogInterface dialog, int whichButton) {
                            doExplorerView(tx.getHash());
                        }
                    });
                    AlertDialog alert = builder.create();
                    alert.show();
                } else // CPFP spend
                if (tx.getConfirmations() < 1 && tx.getAmount() < 0.0) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(BalanceActivity.this);
                    builder.setTitle(R.string.app_name);
                    builder.setMessage(message);
                    builder.setCancelable(true);
                    builder.setPositiveButton(R.string.options_bump_fee, new DialogInterface.OnClickListener() {

                        public void onClick(final DialogInterface dialog, int whichButton) {
                            if (cpfpTask == null || cpfpTask.getStatus().equals(AsyncTask.Status.FINISHED)) {
                                cpfpTask = new CPFPTask();
                                cpfpTask.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, tx.getHash());
                            }
                        }
                    });
                    builder.setNegativeButton(R.string.options_block_explorer, new DialogInterface.OnClickListener() {

                        public void onClick(final DialogInterface dialog, int whichButton) {
                            doExplorerView(tx.getHash());
                        }
                    });
                    AlertDialog alert = builder.create();
                    alert.show();
                } else {
                    doExplorerView(tx.getHash());
                    return;
                }
            }
        }
    });
    swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swiperefresh);
    swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            new Handler().post(new Runnable() {

                @Override
                public void run() {
                    refreshTx(false, true, true, false);
                }
            });
        }
    });
    swipeRefreshLayout.setColorSchemeResources(android.R.color.holo_blue_bright, android.R.color.holo_green_light, android.R.color.holo_orange_light, android.R.color.holo_red_light);
    IntentFilter filter = new IntentFilter(ACTION_INTENT);
    LocalBroadcastManager.getInstance(BalanceActivity.this).registerReceiver(receiver, filter);
    // TorUtil.getInstance(BalanceActivity.this).setStatusFromBroadcast(false);
    registerReceiver(torStatusReceiver, new IntentFilter(OrbotHelper.ACTION_STATUS));
    boolean notifTx = false;
    boolean fetch = false;
    Bundle extras = getIntent().getExtras();
    if (extras != null && extras.containsKey("notifTx")) {
        notifTx = extras.getBoolean("notifTx");
    }
    if (extras != null && extras.containsKey("uri")) {
        fetch = extras.getBoolean("fetch");
    }
    refreshTx(notifTx, fetch, false, true);
    if (PrefsUtil.getInstance(BalanceActivity.this).getValue(PrefsUtil.PAYNYM_CLAIMED, false) == false && PrefsUtil.getInstance(BalanceActivity.this).getValue(PrefsUtil.PAYNYM_REFUSED, false) == false) {
        doClaimPayNym();
    }
    if (!AppUtil.getInstance(BalanceActivity.this).isClipboardSeen()) {
        doClipboardCheck();
    }
}
Also used : AlertDialog(android.app.AlertDialog) HD_Wallet(com.samourai.wallet.hd.HD_Wallet) DialogInterface(android.content.DialogInterface) ScriptBuilder(org.bitcoinj.script.ScriptBuilder) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) MnemonicException(org.bitcoinj.crypto.MnemonicException) TextView(android.widget.TextView) ImageView(android.widget.ImageView) IntentFilter(android.content.IntentFilter) Tx(com.samourai.wallet.api.Tx) PushTx(com.samourai.wallet.send.PushTx) Bundle(android.os.Bundle) Handler(android.os.Handler) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) MyTransactionOutPoint(com.samourai.wallet.send.MyTransactionOutPoint) MotionEvent(android.view.MotionEvent) LayoutInflater(android.view.LayoutInflater) OnClickListener(android.view.View.OnClickListener) AdapterView(android.widget.AdapterView)

Example 2 with Tx

use of com.samourai.wallet.api.Tx in project samourai-wallet-android by Samourai-Wallet.

the class PaynymTxListAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    Tx tx = txList.get(position);
    SimpleDateFormat sdf = new SimpleDateFormat("MMM d, yyyy", Locale.US);
    sdf.setTimeZone(TimeZone.getDefault());
    holder.date.setText(sdf.format(tx.getTS() * 1000L));
    holder.amount.setText(sdf.format(tx.getTS() * 1000L));
    long _amount = 0L;
    if (tx.getAmount() < 0.0) {
        _amount = Math.abs((long) tx.getAmount());
    } else {
        _amount = (long) tx.getAmount();
    }
    if (tx.getAmount() < 0.0) {
        holder.icon.setImageResource(R.drawable.out_going_tx_whtie_arrow);
        holder.amount.setText(context.getString(R.string.you_sent).concat(" ").concat(this.getBTCDisplayAmount(_amount)).concat(" BTC"));
    } else {
        holder.icon.setImageResource(R.drawable.incoming_tx_green);
        holder.amount.setText(context.getString(R.string.you_received).concat(" ").concat(this.getBTCDisplayAmount(_amount)).concat(" BTC"));
    }
    holder.amount.getRootView().setOnClickListener(view -> {
        Intent txIntent = new Intent(context, TxDetailsActivity.class);
        txIntent.putExtra("TX", tx.toJSON().toString());
        context.startActivity(txIntent);
    });
}
Also used : Tx(com.samourai.wallet.api.Tx) Intent(android.content.Intent) SimpleDateFormat(java.text.SimpleDateFormat)

Example 3 with Tx

use of com.samourai.wallet.api.Tx in project samourai-wallet-android by Samourai-Wallet.

the class BalanceViewModel method loadOfflineData.

void loadOfflineData() {
    try {
        JSONObject response = PayloadUtil.getInstance(getApplication()).deserializeMultiAddr();
        if (response != null) {
            Disposable disposable = parseXPUB(new JSONObject(response.toString())).subscribeOn(Schedulers.computation()).observeOn(AndroidSchedulers.mainThread()).subscribe(boo -> {
                List<Tx> txes = new ArrayList<Tx>();
                for (String key : xpub_txs.keySet()) {
                    List<Tx> txs = xpub_txs.get(key);
                    txes.addAll(txs);
                }
                Collections.sort(txes, new APIFactory.TxMostRecentDateComparator());
                txs.postValue(txes);
                toggleSat.setValue(false);
                balance.postValue(xpub_balance - BlockedUTXO.getInstance().getTotalValueBlocked0());
            }, error -> {
                txs.postValue(new ArrayList<>());
                toggleSat.setValue(false);
                balance.postValue(0L);
            });
            compositeDisposables.add(disposable);
        }
    // Log.i(TAG, "BalanceViewModel: ".concat(response));
    } catch (IOException | JSONException e) {
        e.printStackTrace();
        txs.setValue(new ArrayList<>());
        toggleSat.setValue(false);
        balance.setValue(0L);
    }
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) APIFactory(com.samourai.wallet.api.APIFactory) JSONObject(org.json.JSONObject) Tx(com.samourai.wallet.api.Tx) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) IOException(java.io.IOException)

Example 4 with Tx

use of com.samourai.wallet.api.Tx in project samourai-wallet-android by Samourai-Wallet.

the class BalanceActivity method initViewModel.

private void initViewModel() {
    TxAdapter adapter = new TxAdapter(getApplicationContext(), new ArrayList<>(), account);
    adapter.setHasStableIds(true);
    adapter.setClickListener((position, tx) -> txDetails(tx));
    TxRecyclerView.setAdapter(adapter);
    balanceViewModel.getBalance().observe(this, balance -> {
        if (balance < 0) {
            return;
        }
        if (balanceViewModel.getSatState().getValue() != null) {
            setBalance(balance, balanceViewModel.getSatState().getValue());
        } else {
            setBalance(balance, false);
        }
    });
    adapter.setTxes(balanceViewModel.getTxs().getValue());
    setBalance(balanceViewModel.getBalance().getValue(), false);
    balanceViewModel.getSatState().observe(this, state -> {
        if (state == null) {
            state = false;
        }
        setBalance(balanceViewModel.getBalance().getValue(), state);
        adapter.toggleDisplayUnit(state);
    });
    balanceViewModel.getTxs().observe(this, new Observer<List<Tx>>() {

        @Override
        public void onChanged(@Nullable List<Tx> list) {
            adapter.setTxes(list);
        }
    });
    mCollapsingToolbar.setOnClickListener(view -> balanceViewModel.toggleSat());
}
Also used : Tx(com.samourai.wallet.api.Tx) ArrayList(java.util.ArrayList) List(java.util.List) TxAdapter(com.samourai.wallet.home.adapters.TxAdapter)

Example 5 with Tx

use of com.samourai.wallet.api.Tx in project samourai-wallet-android by Samourai-Wallet.

the class TxDetailsActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_tx);
    setSupportActionBar(findViewById(R.id.toolbar));
    if (getIntent().hasExtra("TX")) {
        try {
            JSONObject TxJsonObject = new JSONObject(getIntent().getStringExtra("TX"));
            tx = new Tx(TxJsonObject);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    payNymUsername = findViewById(R.id.tx_paynym_username);
    btcUnit = findViewById(R.id.tx_unit);
    amount = findViewById(R.id.tx_amount);
    payNymAvatar = findViewById(R.id.img_paynym_avatar);
    txId = findViewById(R.id.transaction_id);
    txStatus = findViewById(R.id.tx_status);
    txDate = findViewById(R.id.tx_date);
    bottomButton = findViewById(R.id.btn_bottom_button);
    Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true);
    progressBar = findViewById(R.id.progressBar);
    minerFee = findViewById(R.id.tx_miner_fee_paid);
    minerFeeRate = findViewById(R.id.tx_miner_fee_rate);
    amount.setOnClickListener(view -> toggleUnits());
    btcUnit.setOnClickListener(view -> toggleUnits());
    setTx();
    bottomButton.setOnClickListener(view -> {
        if (this.isBoostingAvailable()) {
            this.doBoosting();
        } else {
            refundOrPayAgain();
        }
    });
    txId.setOnClickListener(view -> {
        new android.app.AlertDialog.Builder(this).setTitle(R.string.app_name).setMessage(R.string.txid_to_clipboard).setCancelable(false).setPositiveButton(R.string.yes, (dialog, whichButton) -> {
            android.content.ClipboardManager clipboard = (android.content.ClipboardManager) TxDetailsActivity.this.getSystemService(android.content.Context.CLIPBOARD_SERVICE);
            android.content.ClipData clip;
            clip = android.content.ClipData.newPlainText("tx id", ((TextView) view).getText());
            if (clipboard != null) {
                clipboard.setPrimaryClip(clip);
            }
            Toast.makeText(TxDetailsActivity.this, R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show();
        }).setNegativeButton(R.string.no, (dialog, whichButton) -> {
        }).show();
    });
}
Also used : Bundle(android.os.Bundle) ProgressBar(android.widget.ProgressBar) Coin(org.bitcoinj.core.Coin) DecimalFormatSymbols(java.text.DecimalFormatSymbols) Uri(android.net.Uri) Intent(android.content.Intent) RBFTask(com.samourai.wallet.send.boost.RBFTask) TransitionManager(android.transition.TransitionManager) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) MenuItem(android.view.MenuItem) Picasso(com.squareup.picasso.Picasso) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) SamouraiWallet(com.samourai.wallet.SamouraiWallet) Toast(android.widget.Toast) Menu(android.view.Menu) View(android.view.View) SendActivity(com.samourai.wallet.send.SendActivity) Observable(io.reactivex.Observable) Schedulers(io.reactivex.schedulers.Schedulers) CPFPTask(com.samourai.wallet.send.boost.CPFPTask) Tx(com.samourai.wallet.api.Tx) DateUtil(com.samourai.wallet.util.DateUtil) AsyncTask(android.os.AsyncTask) ContextCompat(android.support.v4.content.ContextCompat) CircleImageView(com.samourai.wallet.widgets.CircleImageView) DecimalFormat(java.text.DecimalFormat) R(com.samourai.wallet.R) AppCompatActivity(android.support.v7.app.AppCompatActivity) ViewGroup(android.view.ViewGroup) Objects(java.util.Objects) RBFUtil(com.samourai.wallet.send.RBFUtil) Disposable(io.reactivex.disposables.Disposable) AlertDialog(android.support.v7.app.AlertDialog) TextView(android.widget.TextView) Observer(io.reactivex.Observer) AutoTransition(android.transition.AutoTransition) BIP47Meta(com.samourai.wallet.bip47.BIP47Meta) APIFactory(com.samourai.wallet.api.APIFactory) JSONObject(org.json.JSONObject) Tx(com.samourai.wallet.api.Tx) JSONException(org.json.JSONException) TextView(android.widget.TextView)

Aggregations

Tx (com.samourai.wallet.api.Tx)10 ArrayList (java.util.ArrayList)6 JSONObject (org.json.JSONObject)5 Disposable (io.reactivex.disposables.Disposable)4 Intent (android.content.Intent)3 View (android.view.View)3 TextView (android.widget.TextView)3 Bundle (android.os.Bundle)2 ContextCompat (android.support.v4.content.ContextCompat)2 TransitionManager (android.transition.TransitionManager)2 LayoutInflater (android.view.LayoutInflater)2 ViewGroup (android.view.ViewGroup)2 ImageView (android.widget.ImageView)2 R (com.samourai.wallet.R)2 APIFactory (com.samourai.wallet.api.APIFactory)2 BIP47Meta (com.samourai.wallet.bip47.BIP47Meta)2 PushTx (com.samourai.wallet.send.PushTx)2 CompositeDisposable (io.reactivex.disposables.CompositeDisposable)2 IOException (java.io.IOException)2 SimpleDateFormat (java.text.SimpleDateFormat)2