Search in sources :

Example 6 with Wallet

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

the class RefreshUsedAddressesHandler method checkUsedAddressForSeed.

private GetAccountDataResponse checkUsedAddressForSeed(Seeds.Seed seed, boolean report) {
    Wallet wallet = Store.getWallet(context, seed);
    if (wallet != null) {
        List<Address> alreadyAddress = Store.getAddresses(context, seed);
        GetTransferResponse gtr = null;
        StopWatch stopWatch = new StopWatch();
        List<Address> checkAddress = new ArrayList<>();
        for (Address tmp : alreadyAddress) {
            if (tmp.isUsed() && tmp.getValue() == 0) {
                checkAddress.add(tmp);
            }
        }
        if (!checkAddress.isEmpty()) {
            try {
                List<String> checkAddressString = new ArrayList<>();
                List<String> checkAddressBal = new ArrayList<>();
                for (Address addr : checkAddress) {
                    checkAddressBal.add(addr.getAddress());
                }
                GetBalancesResponse gbal = apiProxy.getBalances(100, checkAddressBal);
                for (int i = 0; i < gbal.getBalances().length; i++) {
                    Address addr = checkAddress.get(i);
                    long gotBalance = Sf.toLong(gbal.getBalances()[i]);
                    if (gotBalance != 0 || addr.getPendingValue() != 0) {
                        addr.setValue(gotBalance);
                        checkAddressString.add(addr.getAddress());
                    }
                    if (report) {
                        if (gotBalance > 0) {
                            Store.setUsedAddressCheckResult(context.getString(R.string.usedAddressNoOk) + " " + IotaToText.convertRawIotaAmountToDisplayText(gotBalance, true));
                        } else {
                            Store.setUsedAddressCheckResult(context.getString(R.string.usedAddressOk));
                        }
                    }
                }
                if (!checkAddressString.isEmpty()) {
                    Bundle[] bundles = apiProxy.bundlesFromAddresses(checkAddressString.toArray(new String[checkAddressString.size()]), true);
                    gtr = GetTransferResponse.create(bundles, stopWatch.getElapsedTimeMili());
                }
                List<Transfer> transfers = new ArrayList<>();
                if (gtr != null && gtr.getTransfers().length > 0) {
                    List<Transfer> alreadyTransfer = Store.getTransfers(context, seed);
                    Audit.bundlePopulateTransfers(gtr.getTransfers(), transfers, alreadyAddress);
                    Audit.setTransfersToAddresses(seed, transfers, alreadyAddress, wallet, alreadyTransfer);
                    Audit.processNudgeAttempts(context, seed, transfers);
                    Store.updateAccountData(context, seed, wallet, transfers, alreadyAddress);
                }
            } catch (Exception e) {
                Log.e("ERR066", "ERROR: " + e.getMessage());
            }
        }
    }
    return new GetAccountDataResponse();
}
Also used : GetBalancesResponse(jota.dto.response.GetBalancesResponse) GetTransferResponse(jota.dto.response.GetTransferResponse) Address(run.wallet.iota.model.Address) Wallet(run.wallet.iota.model.Wallet) Bundle(jota.model.Bundle) ArrayList(java.util.ArrayList) StopWatch(jota.utils.StopWatch) GetAccountDataResponse(run.wallet.iota.api.responses.GetAccountDataResponse) Transfer(run.wallet.iota.model.Transfer)

Example 7 with Wallet

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

the class ChooseSeedAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
    int adapterPosition = holder.getAdapterPosition();
    Seeds.Seed address = getItem(adapterPosition - 1);
    holder.isDefault = address.isdefault;
    holder.setIsRecyclable(false);
    holder.seed = address;
    holder.addressLabel.setText(address.getShortValue());
    holder.seedName.setText(address.name);
    Wallet wallet = Store.getWallet(address);
    if (wallet != null) {
        holder.extraValue.setVisibility(View.VISIBLE);
        String balanceText = IotaToText.convertRawIotaAmountToDisplayText(wallet.getBalanceDisplay(), true);
        holder.seedValue.setText(balanceText);
        Currency defcur = Store.getDefaultCurrency(context);
        Ticker ticker = Store.getTicker("IOTA:" + defcur);
        if (ticker != null) {
            holder.extraValue.setText(ticker.getIotaValString(wallet.getBalanceDisplay()) + " " + defcur);
        } else {
            holder.extraValue.setVisibility(View.GONE);
        }
    } else {
        holder.extraValue.setVisibility(View.GONE);
    }
    if (address.id.equals(Store.getCurrentSeed().id)) {
        holder.addressImage.setImageDrawable(UiManager.getDrawable(context, R.drawable.check_green));
    // holder.addressLabel.setPaintFlags(holder.addressLabel.getPaintFlags() | Paint.);
    } else if (!address.isdefault) {
        holder.addressImage.setImageDrawable(UiManager.getDrawable(context, R.drawable.ic_address));
        holder.addressImage.setColorFilter(ContextCompat.getColor(context, R.color.flatGreen));
    }
}
Also used : Seeds(run.wallet.iota.model.Seeds) Wallet(run.wallet.iota.model.Wallet) Currency(run.wallet.common.Currency) Ticker(run.wallet.iota.model.Ticker)

Example 8 with Wallet

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

the class SnTrFragment method onViewCreated.

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    ((AppCompatActivity) getActivity()).setSupportActionBar(newTransferToolbar);
    setHasOptionsMenu(false);
    // paytoAddresses.clear();
    newTransferToolbar.setNavigationIcon(getResources().getDrawable(R.drawable.md_nav_back));
    newTransferToolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            getActivity().onBackPressed();
        }
    });
    initUnitsSpinner();
    addMessage.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (messageLayout.getVisibility() == View.GONE) {
                messageLayout.setVisibility(View.VISIBLE);
            } else {
                messageLayout.setVisibility(View.GONE);
            }
        }
    });
    addTag.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (tagLayout.getVisibility() == View.GONE) {
                tagLayout.setVisibility(View.VISIBLE);
            } else {
                tagLayout.setVisibility(View.GONE);
            }
        }
    });
    qrSelect.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            openQRCodeScanner();
        }
    });
    addPayment.setEnabled(false);
    addPayment.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            addAdress();
        }
    });
    next.setEnabled(false);
    next.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            goNext();
        }
    });
    Wallet wallet = Store.getCurrentWallet();
    balances = PayPacket.calculateAvailableBalances();
    availableBalance.setText(IotaToText.convertRawIotaAmountToDisplayText(balances.available, true));
    // if(wallet.getAvailableBalance()>0) {
    availableBalance.setTextColor(B.getColor(getActivity(), R.color.green));
    // }
    pendingBalance.setText(IotaToText.convertRawIotaAmountToDisplayText(balances.locked, true));
    pendingBalance.setAlpha(0.4F);
    pendingLabel.setAlpha(0.5F);
    if (wallet.getBalancePendingIn() > 0) {
        pendingBalance.setTextColor(B.getColor(getActivity(), R.color.green));
    }
    addressEditText.setOnLongClickListener(new View.OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            isLongClicked = true;
            return false;
        }
    });
    btnClear.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            addressEditText.setText("");
            amountEditText.setText("");
        }
    });
    addressEditText.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (isLongClicked) {
                isLongClicked = false;
                return false;
            }
            InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Activity.INPUT_METHOD_SERVICE);
            if (imm.isActive(addressEditText)) {
                return false;
            }
            int inType = addressEditText.getInputType();
            addressEditText.setInputType(InputType.TYPE_NULL);
            addressEditText.onTouchEvent(event);
            addressEditText.setInputType(inType);
            // consume touch event
            return true;
        }
    });
    addressEditText.addTextChangedListener(inputWatcher);
    amountEditText.addTextChangedListener(inputWatcher);
    btnBack.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            goBackBtn();
        }
    });
    keyboard.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            UiManager.setKeyboard(getActivity(), addressEditText, true);
            scroller.postDelayed(new Runnable() {

                @Override
                public void run() {
                    scrollView.post(new Runnable() {

                        @Override
                        public void run() {
                            scrollView.fullScroll(View.FOCUS_DOWN);
                            addressEditText.requestFocus();
                        }
                    });
                }
            }, 500);
        }
    });
    btnPaste.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData cd = clipboard.getPrimaryClip();
            if (cd != null && cd.getItemCount() > 0) {
                addressEditText.setText(cd.getItemAt(0).coerceToText(getActivity()));
            }
        }
    });
    Bundle bundle = getArguments();
    if (getArguments() != null) {
        QRCode qrCode = bundle.getParcelable(Constants.QRCODE);
        if (qrCode != null) {
            if (qrCode.getAddress() != null)
                addressEditText.setText(qrCode.getAddress());
            if (qrCode.getAmount() != null && !qrCode.getAmount().isEmpty()) {
                Long amount = Long.parseLong((qrCode.getAmount()));
                IotaUnits unit = IotaUnitConverter.findOptimalIotaUnitToDisplay(amount);
                String amountText = Math.round(IotaUnitConverter.convertAmountTo(amount, unit)) + "";
                amountEditText.setText(amountText);
                unitsSpinner.setSelection(toSpinnerItemIndex(unit));
            }
            if (qrCode.getMessage() != null)
                messageEditText.setText(qrCode.getMessage());
            if (qrCode.getTag() != null)
                tagEditText.setText(qrCode.getTag());
            checkContinue();
        }
    }
    checkContinue();
}
Also used : ClipboardManager(android.content.ClipboardManager) Wallet(run.wallet.iota.model.Wallet) Bundle(android.os.Bundle) AppCompatActivity(android.support.v7.app.AppCompatActivity) InputMethodManager(android.view.inputmethod.InputMethodManager) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ScrollView(android.widget.ScrollView) MotionEvent(android.view.MotionEvent) QRCode(run.wallet.iota.model.QRCode) IotaUnits(jota.utils.IotaUnits) ClipData(android.content.ClipData)

Example 9 with Wallet

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

the class WalletTabFragment method updateBalance.

private void updateBalance() {
    long walletBalanceIota = 0;
    long pendingIotaIn = 0;
    long pendingIotaOut = 0;
    Wallet wallet = Store.getCurrentWallet();
    if (wallet != null) {
        walletToolbar.setTitle(Store.getCurrentSeed().name);
        walletBalanceIota = wallet.getBalanceDisplay();
        pendingIotaIn = wallet.getBalancePendingIn();
        pendingIotaOut = wallet.getBalancePendingOut();
    }
    IotaToText.IotaDisplayData data = IotaToText.getIotaDisplayData(walletBalanceIota);
    String balanceText = data.value;
    tapBalance.setVisibility(View.GONE);
    if (tapCount < TAP_MAX) {
        if (wallet != null && (wallet.getBalancePendingIn() != 0 || wallet.getBalancePendingOut() != 0)) {
            tapBalance.setVisibility(View.VISIBLE);
        }
    }
    thirdDecimal.setText(data.thirdDecimal);
    balanceUnit.setText(data.unit);
    if (pendingIotaOut == 0) {
        pendingOut.setVisibility(View.GONE);
        pendingOut.setText(" ");
    } else {
        pendingOut.setText(IotaToText.convertRawIotaAmountToDisplayText(pendingIotaOut, true));
        pendingOut.setVisibility(View.VISIBLE);
    }
    if (pendingIotaIn == 0) {
        pendingIn.setVisibility(View.GONE);
        pendingIn.setText(" ");
    } else {
        pendingIn.setText(IotaToText.convertRawIotaAmountToDisplayText(pendingIotaIn, true));
        pendingIn.setVisibility(View.VISIBLE);
    }
    if (pendingIotaOut == 0 && pendingIotaIn == 0) {
        pending.setVisibility(View.GONE);
    } else {
        pending.setVisibility(View.VISIBLE);
    }
    if (!TextUtils.isEmpty(balanceText)) {
        balanceTextView.setText(balanceText);
    } else {
        balanceTextView.setText(R.string.account_balance_default);
    }
    updateAlternateBalance();
    updateFab();
    if (pendingIotaIn != 0 || pendingIotaOut != 0) {
        balanceType.setVisibility(View.VISIBLE);
        balanceType.setImageResource(R.drawable.bal_live);
        switch(Store.getBalanceDisplayType()) {
            case 1:
                balanceType.setImageResource(R.drawable.bal_avail);
                break;
            case 2:
                balanceType.setImageResource(R.drawable.bal_future);
                break;
        }
    } else {
        balanceType.setVisibility(View.GONE);
    }
}
Also used : Wallet(run.wallet.iota.model.Wallet) IotaToText(jota.utils.IotaToText)

Aggregations

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