Search in sources :

Example 11 with Transfer

use of run.wallet.iota.model.Transfer in project run-wallet-android by runplay.

the class WalletTransfersItemDialog method onClick.

@Override
public void onClick(DialogInterface dialogInterface, int which) {
    ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
    Fragment fragment;
    final Bundle bundle = new Bundle();
    switch(which) {
        case 0:
            String useAddress = transfer.getAddress();
            try {
                useAddress = Checksum.addChecksum(transfer.getAddress());
            } catch (Exception e) {
            }
            ClipData clipAddress = ClipData.newPlainText(getActivity().getString(R.string.address), useAddress);
            clipboard.setPrimaryClip(clipAddress);
            break;
        case 1:
            ClipData clipHash = ClipData.newPlainText(getActivity().getString(R.string.hash), hash);
            clipboard.setPrimaryClip(clipHash);
            break;
        case 2:
            // Log.e("DIALOG","GO");
            if (transfer.isMarkDoubleAddress()) {
                Transfer gottransfer = Store.isAlreadyTransfer(hash, Store.getTransfers());
                if (gottransfer != null) {
                    Store.setCacheTransfer(gottransfer);
                    UiManager.openFragmentBackStack(getActivity(), PendingCancelledFragment.class);
                }
            } else if (!transfer.isCompleted()) {
                Transfer transfer = Store.getCurrentTransferFromHash(hash);
                if (transfer != null) {
                    AppService.nudgeTransaction(getActivity(), Store.getCurrentSeed(), transfer);
                }
            } else {
                Snackbar.make(getActivity().findViewById(R.id.drawer_layout), getString(R.string.messages_transaction_already_confirmed), Snackbar.LENGTH_LONG).show();
            }
            break;
        case 3:
            if (!transfer.isCompleted()) {
                Transfer transfer = Store.getCurrentTransferFromHash(hash);
                if (transfer != null) {
                    AppService.replayBundleTransaction(getActivity(), Store.getCurrentSeed(), hash, transfer.getAddress());
                }
            } else {
                Snackbar.make(getActivity().findViewById(R.id.drawer_layout), getString(R.string.messages_transaction_already_confirmed), Snackbar.LENGTH_LONG).show();
            }
    }
}
Also used : ClipboardManager(android.content.ClipboardManager) Bundle(android.os.Bundle) Transfer(run.wallet.iota.model.Transfer) PendingCancelledFragment(run.wallet.iota.ui.fragment.PendingCancelledFragment) DialogFragment(android.app.DialogFragment) Fragment(android.app.Fragment) ClipData(android.content.ClipData)

Example 12 with Transfer

use of run.wallet.iota.model.Transfer in project run-wallet-android by runplay.

the class PendingCancelledFragment method onResume.

@Override
public void onResume() {
    super.onResume();
    if (Store.getCacheTransfer() == null) {
        getActivity().onBackPressed();
    } else {
        View v = view.findViewById(R.id.transfer_card);
        TransferViewManager.populateViewHolder(getActivity(), new TransferViewManager.ViewHolder(getActivity(), v), Store.getCacheTransfer(), false, -1, false);
        List<TransferTransaction> transactions = new ArrayList<>();
        transactions.addAll(Store.getCacheTransfer().getTransactions());
        transactions.addAll(Store.getCacheTransfer().getOtherTransactions());
        TransferViewManager.populateTransferTransactionOuts(getActivity(), breakdown, transactions, Store.getCacheTransfer());
        cancelledHash.setText(Store.getCacheTransfer().getHash());
        cancelledHash.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                ActivityMan.openAndroidBrowserUrl(getActivity(), sitesHash[0] + Store.getCacheTransfer().getHash());
            }
        });
        copyClip.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Transfer transfer = Store.getCacheTransfer();
                if (transfer != null) {
                    ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
                    StringBuilder sb = new StringBuilder();
                    sb.append("IOTA Transfer\n\n");
                    sb.append("time: " + Cal.getCal(transfer.getTimestamp()).getDatabaseDate());
                    sb.append("\nhash: " + transfer.getHash());
                    sb.append("\n\nTotal: " + transfer.getValue());
                    sb.append("\nStatus: " + (transfer.isCompleted() ? "Completed" : "Pending"));
                    sb.append("\nmilestone: " + transfer.getMilestone());
                    sb.append("\n\nAddress actions\n");
                    for (TransferTransaction tran : transfer.getTransactions()) {
                        sb.append(tran.getValue());
                        sb.append("    ");
                        sb.append(tran.getAddress());
                    }
                    for (TransferTransaction tran : transfer.getOtherTransactions()) {
                        sb.append(tran.getValue());
                        sb.append("    ");
                        sb.append(tran.getAddress());
                    }
                    sb.append("\n\nUsing run IOTA wallet, Android app http://iota.runplay.com");
                    ClipData clip = ClipData.newPlainText(getActivity().getString(R.string.seed), sb.toString());
                    clipboard.setPrimaryClip(clip);
                    Snackbar.make(getView(), getString(R.string.text_cancelled_copied), Snackbar.LENGTH_SHORT).show();
                }
            }
        });
        cancelledSites.setText(" " + sitesName[0]);
    }
}
Also used : ClipboardManager(android.content.ClipboardManager) ArrayList(java.util.ArrayList) Transfer(run.wallet.iota.model.Transfer) TransferViewManager(run.wallet.iota.ui.TransferViewManager) TransferTransaction(run.wallet.iota.model.TransferTransaction) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) CardView(android.support.v7.widget.CardView) TextView(android.widget.TextView) ClipData(android.content.ClipData)

Example 13 with Transfer

use of run.wallet.iota.model.Transfer in project run-wallet-android by runplay.

the class WalletTransfersCardAdapter method load.

public static synchronized void load(Context context, boolean force) {
    if (force || seed == null || (Store.getCurrentSeed() != null && !seed.id.equals(Store.getCurrentSeed().id)) || transfers.isEmpty()) {
        if (context != null) {
            transfers.clear();
            transfers.addAll(Store.getTransfers());
            if (filterAddress != null) {
                List<Transfer> filtered = new ArrayList<>();
                for (Transfer t : transfers) {
                    if (t.getAddress().equals(filterAddress))
                        filtered.add(t);
                    else {
                        boolean add = false;
                        for (TransferTransaction tt : t.getTransactions()) {
                            if (tt.getAddress().equals(filterAddress))
                                add = true;
                        }
                        if (add)
                            filtered.add(t);
                    }
                }
                transfers = filtered;
            }
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
            if (!prefs.getBoolean(Constants.PREFERENCES_SHOW_CANCELLED, true)) {
                List<Transfer> lesscancelled = new ArrayList<>();
                for (Transfer transfer : transfers) {
                    if (!transfer.isMarkDoubleSpend())
                        lesscancelled.add(transfer);
                }
                transfers = lesscancelled;
            }
            if (!prefs.getBoolean(Constants.PREFERENCES_SHOW_ATTACH, true)) {
                List<Transfer> lessattach = new ArrayList<>();
                for (Transfer transfer : transfers) {
                    if (transfer.getValue() != 0 || (transfer.getValue() == 0 && !transfer.getTransactions().isEmpty()))
                        lessattach.add(transfer);
                }
                transfers = lessattach;
            }
            int nudges = Sf.toInt(prefs.getString(Constants.PREF_TRANSFER_NUDGE_ATTEMPTS, "" + Constants.PREF_TRANSFER_NUDGE_ATTEMPTS_VALUE));
            isAutoNudge = nudges == 0 ? false : true;
        }
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) Transfer(run.wallet.iota.model.Transfer) ArrayList(java.util.ArrayList) TransferTransaction(run.wallet.iota.model.TransferTransaction) Paint(android.graphics.Paint)

Example 14 with Transfer

use of run.wallet.iota.model.Transfer in project run-wallet-android by runplay.

the class WalletTransfersCardAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final TransferViewManager.ViewHolder holder, int position) {
    int adapterPosition = holder.getAdapterPosition();
    Transfer transfer = getItem(adapterPosition - 1);
    if (transfer != null) {
        boolean isFiltered = filterAddress == null ? false : true;
        TransferViewManager.populateViewHolder(context, holder, transfer, isAutoNudge, adapterPosition, isFiltered);
        synchronized (holder) {
            holder.notifyAll();
        }
    } else {
    // Log.e("ADAPTER","has null value");
    }
}
Also used : Transfer(run.wallet.iota.model.Transfer) Paint(android.graphics.Paint)

Example 15 with Transfer

use of run.wallet.iota.model.Transfer in project run-wallet-android by runplay.

the class Audit method processTransfersToAddresses.

private static ProcessResult processTransfersToAddresses(Seeds.Seed seed, List<Transfer> transfers, List<Address> allAddresses) {
    Collections.sort(transfers);
    Collections.reverse(transfers);
    HashMap<String, Transfer> completed = new HashMap<String, Transfer>();
    HashMap<String, Transfer> completedAddresses = new HashMap<String, Transfer>();
    for (Transfer transfer : transfers) {
        if (!transfer.getTransactions().isEmpty()) {
            String key = transfer.getValue() + transfer.getAddress();
            Transfer comp = completed.get(key);
            if (comp == null) {
                completed.put(key, transfer);
            } else {
                if (comp.isCompleted()) {
                    transfer.setMarkDoubleSpend(true);
                } else {
                    comp.setMarkDoubleSpend(true);
                    completed.put(key, transfer);
                }
            }
            if (transfer.isCompleted()) {
                transfer.setMarkDoubleAddress(false);
                transfer.setMarkDoubleSpend(false);
                if (transfer.getTimestampConfirmed() == 0)
                    transfer.setTimestampConfirmed(System.currentTimeMillis());
                for (TransferTransaction trans : transfer.getTransactions()) {
                    if (trans.getValue() < 0) {
                        // Log.e("AUDIT","comp address: "+trans.getValue()+" - "+trans.getAddress());
                        completedAddresses.put(trans.getAddress(), transfer);
                    }
                }
            }
        }
    }
    for (Transfer transfer : transfers) {
        if (!transfer.isCompleted() && !transfer.isMarkDoubleSpend()) {
            // Log.e("AUDIT","check: "+transfer.getValue()+" - "+transfer.getHash());
            List<String> testAddress = new ArrayList<>();
            for (TransferTransaction trans : transfer.getTransactions()) {
                if (trans.getValue() < 0) {
                    // Log.e("AUDIT","-address: "+trans.getValue()+" - "+trans.getAddress());
                    testAddress.add(trans.getAddress());
                }
            }
            if (!testAddress.isEmpty()) {
                for (String testadd : testAddress) {
                    Transfer completedOnTransfer = completedAddresses.get(testadd);
                    if (completedOnTransfer != null && !completedOnTransfer.getHash().equals(transfer.getHash())) {
                        Address tmpadd = Store.isAlreadyAddress(testadd, allAddresses);
                        if (tmpadd != null && tmpadd.getValue() == 0) {
                            // Log.e("AUDIT", "completedOnTransfer: " + completedOnTransfer.getValue() + " - " + completedOnTransfer.getAddress());
                            transfer.setMarkDoubleAddress(true);
                        }
                    }
                }
            }
        }
    }
    long seedTotalPendingIn = 0;
    long seedTotalPendingOut = 0;
    List<TransferTransaction> already = new ArrayList<>();
    for (Transfer transfer : transfers) {
        if (transfer.isCompleted()) {
            for (TransferTransaction trans : transfer.getTransactions()) {
                Address address = Store.isAlreadyAddress(trans.getAddress(), allAddresses);
                if (address != null) {
                    // address.setValue(address.getValue() + trans.getValue());
                    if (trans.getValue() < 0) {
                        address.setUsed(true);
                    }
                }
            }
        } else if (!transfer.isCompleted()) {
            if (transfer.isInternal() || (!transfer.isMarkDoubleSpend() && !transfer.isMarkDoubleAddress())) {
                for (TransferTransaction trans : transfer.getTransactions()) {
                    Address address = Store.isAlreadyAddress(trans.getAddress(), allAddresses);
                    if (address != null) {
                        address.setPendingValue(address.getPendingValue() + trans.getValue());
                        if (trans.getValue() < 0) {
                            seedTotalPendingOut += trans.getValue();
                        } else {
                            seedTotalPendingIn += trans.getValue();
                        }
                        already.add(trans);
                    }
                }
            }
        }
    }
    long seedTotal = 0;
    for (Address address : allAddresses) {
        seedTotal += address.getValue();
        if (address.getPendingValue() != 0 && !address.isPigUser()) {
            address.setPigInt(1);
        }
    }
    // Log.e("SEED-TOTAL",seedTotal+" - pending out: "+seedTotalPendingOut);
    ProcessResult result = new ProcessResult();
    result.seedTotal = seedTotal;
    result.seedTotalPendingIn = seedTotalPendingIn;
    result.seedTotalPendingOut = seedTotalPendingOut;
    return result;
}
Also used : Address(run.wallet.iota.model.Address) HashMap(java.util.HashMap) Transfer(run.wallet.iota.model.Transfer) NudgeTransfer(run.wallet.iota.model.NudgeTransfer) ArrayList(java.util.ArrayList) TransferTransaction(run.wallet.iota.model.TransferTransaction)

Aggregations

Transfer (run.wallet.iota.model.Transfer)15 ArrayList (java.util.ArrayList)13 Address (run.wallet.iota.model.Address)9 Wallet (run.wallet.iota.model.Wallet)6 ApiResponse (run.wallet.iota.api.responses.ApiResponse)5 NudgeTransfer (run.wallet.iota.model.NudgeTransfer)5 TransferTransaction (run.wallet.iota.model.TransferTransaction)5 SharedPreferences (android.content.SharedPreferences)4 HashMap (java.util.HashMap)4 ArgumentException (jota.error.ArgumentException)4 Bundle (jota.model.Bundle)4 GetBalancesResponse (jota.dto.response.GetBalancesResponse)3 GetNewAddressResponse (jota.dto.response.GetNewAddressResponse)3 GetTransferResponse (jota.dto.response.GetTransferResponse)3 StopWatch (jota.utils.StopWatch)3 NudgeRequest (run.wallet.iota.api.requests.NudgeRequest)3 NudgeResponse (run.wallet.iota.api.responses.NudgeResponse)3 NetworkError (run.wallet.iota.api.responses.error.NetworkError)3 ClipData (android.content.ClipData)2 ClipboardManager (android.content.ClipboardManager)2