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();
}
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));
}
}
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();
}
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);
}
}
Aggregations