use of run.wallet.iota.model.Address in project run-wallet-android by runplay.
the class WalletAddressCardAdapter method load.
public static synchronized void load(Context context, boolean force) {
// Log.e("TRANS-ADAPT","Called for refresh of addresses");
if (force || seed == null || !seed.id.equals(Store.getCurrentSeed().id) || addresses.isEmpty()) {
// Log.e("ADD-ADAPT","*******************loading addresses for list");
seed = Store.getCurrentSeed();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean showused = prefs.getBoolean(Constants.PREFERENCES_SHOW_USED, true);
addresses.clear();
for (Address add : Store.getDisplayAddresses(Store.getAddresses())) {
if (add.isAttached()) {
// Log.e("ADDU",add.getAddress()+" -- "+showused +"="+ add.isUsed());
if (showused)
addresses.add(add);
else if (!showused && !add.isUsed())
addresses.add(add);
else if (!showused && add.isUsed() && (add.getValue() > 0 || add.getPendingValue() != 0))
addresses.add(add);
}
}
// Collections.reverse(addresses);
// this.notifyDataSetChanged();
}
}
use of run.wallet.iota.model.Address in project run-wallet-android by runplay.
the class WalletAddressCardAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
int adapterPosition = holder.getAdapterPosition();
Address address = getItem(adapterPosition - 1);
if (address != null) {
holder.address = address.getAddress();
try {
holder.addressChecksum = Checksum.addChecksum(holder.address);
} catch (Exception e) {
}
if (holder.addressChecksum != null) {
holder.isUsed = address.isUsed();
holder.isAttached = address.isAttached();
holder.isPig = address.isPig();
holder.pigInt = address.getPigInt();
holder.setIsRecyclable(false);
IotaToText.IotaDisplayData data = IotaToText.getIotaDisplayData(address.getValue());
holder.addressId.setText("a" + address.getIndexName());
holder.addressId.setBackgroundColor(B.getColor(context, AppTheme.getPrimary()));
holder.addressValue.setText(data.value);
holder.addressValueThird.setText(data.thirdDecimal);
holder.addressValueUnit.setText(data.unit);
holder.rawValue.setText(" ");
if (address.getValue() > 0) {
holder.addressValue.setTextColor(B.getColor(context, R.color.green));
holder.addressValueThird.setTextColor(B.getColor(context, R.color.green));
holder.addressValueUnit.setTextColor(B.getColor(context, AppTheme.getPrimary()));
} else {
holder.addressValue.setTextColor(B.getColor(context, R.color.grey));
holder.addressValueThird.setTextColor(B.getColor(context, R.color.grey));
holder.addressValueUnit.setTextColor(B.getColor(context, R.color.grey));
// holder.rawValue.setVisibility(View.GONE);
}
holder.securityValue.setText("s" + address.getSecurity());
holder.securityValue.setBackgroundColor(B.getColor(context, AppTheme.getPrimary()));
holder.rawValue.setTextColor(B.getColor(context, R.color.greyDark));
holder.rawValue.setCompoundDrawables(null, null, null, null);
if (address.getPendingValue() != 0) {
// holder.rawValue.setVisibility(View.VISIBLE);
holder.rawValue.setCompoundDrawables(B.getDrawable(context, R.drawable.navigation_refresh), null, null, null);
holder.rawValue.setText(IotaToText.convertRawIotaAmountToDisplayText(address.getPendingValue(), true));
if (address.getPendingValue() < 0) {
holder.rawValue.setTextColor(B.getColor(context, R.color.flatRed));
} else {
holder.rawValue.setTextColor(B.getColor(context, R.color.green));
}
}
if (address.isUsed()) {
holder.addressLabel.setText(address.getShortAddress() + "***");
} else {
holder.addressLabel.setText(holder.addressChecksum);
}
holder.addressImage.setImageResource(R.drawable.ic_address);
holder.addressLabel.setPaintFlags(0);
holder.addressValue.setPaintFlags(0);
holder.addressValue.setAlpha(1F);
holder.cardView.setCardBackgroundColor(B.getColor(context, R.color.white));
holder.cardView.setAlpha(1F);
if (address.isUsed()) {
holder.addressImage.setColorFilter(ContextCompat.getColor(context, R.color.flatRed));
holder.addressLabel.setPaintFlags(holder.addressLabel.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
holder.addressLabel.setTextColor(B.getColor(context, R.color.flatRed));
holder.addressValue.setAlpha(0.5F);
holder.cardView.setAlpha(0.6F);
holder.addressValue.setPaintFlags(holder.addressLabel.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
} else if (address.isPig()) {
holder.cardView.setCardBackgroundColor(B.getColor(context, R.color.whiteAlpha));
holder.addressImage.setImageResource(AppTheme.getPigRdrawable());
holder.addressLabel.setTextColor(B.getColor(context, AppTheme.getPrimaryDark()));
} else if (!address.isAttached()) {
holder.addressImage.setColorFilter(ContextCompat.getColor(context, R.color.flatGreen));
holder.addressLabel.setTextColor(B.getColor(context, R.color.grey));
} else if (!address.isUsed()) {
holder.addressImage.setColorFilter(ContextCompat.getColor(context, R.color.greyDark));
holder.addressLabel.setTextColor(B.getColor(context, R.color.textDark));
}
}
}
}
use of run.wallet.iota.model.Address in project run-wallet-android by runplay.
the class WalletAddressesItemDialog 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();
if (address != null) {
switch(which) {
case 0:
ClipData clipAddress = ClipData.newPlainText(getActivity().getString(R.string.address), addressChecksum);
clipboard.setPrimaryClip(clipAddress);
break;
case 1:
if (!isAddressUsed) {
QRCode qrCode = new QRCode();
qrCode.setAddress(addressChecksum);
bundle.putParcelable(Constants.QRCODE, qrCode);
fragment = new GenerateQRCodeFragment();
fragment.setArguments(bundle);
getActivity().getFragmentManager().beginTransaction().setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN).replace(R.id.container, fragment, null).addToBackStack(null).commit();
} else {
Snackbar.make(getActivity().findViewById(R.id.drawer_layout), getString(R.string.messages_address_used), Snackbar.LENGTH_LONG).show();
}
break;
case 2:
if (isPig == 1) {
Snackbar.make(getActivity().findViewById(R.id.drawer_layout), getString(R.string.help_aw_piglock_no_unlock), Snackbar.LENGTH_LONG).show();
} else {
if (isPig > 1) {
// Log.e("SET-PIG","set to false");
Store.setCurrentAddressPig(getActivity(), address, false);
} else {
// Log.e("SET-PIG","set to true");
Store.setCurrentAddressPig(getActivity(), address, true);
}
AppService.refreshEvent();
}
break;
case 3:
Address useaddress = Store.isAlreadyAddress(address, Store.getAddresses());
if (useaddress != null) {
Store.setCacheAddress(useaddress);
UiManager.openFragmentBackStack(getActivity(), AddressSecurityFragment.class);
}
break;
}
}
}
use of run.wallet.iota.model.Address in project run-wallet-android by runplay.
the class AuditAddressesRequestHandler method handle.
@Override
public ApiResponse handle(ApiRequest inrequest) {
AuditAddressesRequest request = (AuditAddressesRequest) inrequest;
// check less than 2, 1..iteself, and no others
if (AppService.countSeedRunningTasks(request.getSeed()) < 2) {
List<Address> addresses = Store.getAddresses(context, request.getSeed());
List<Address> getaddresses = new ArrayList<>();
if (!addresses.isEmpty()) {
for (Address address : addresses) {
if (!address.isAttached()) {
getaddresses.add(address);
}
}
}
if (!getaddresses.isEmpty()) {
GetNodeInfoResponse info = apiProxy.getNodeInfo();
if (info != null && info.getLatestMilestoneIndex() == info.getLatestSolidSubtangleMilestoneIndex()) {
// List<String> addstr = new ArrayList<>();
int count = 0;
for (Address add : getaddresses) {
FindTransactionResponse tr1 = null;
try {
tr1 = apiProxy.findTransactionsByAddresses(add.getAddress());
} catch (Exception e) {
}
if (tr1 != null) {
if (tr1.getHashes().length == 0) {
AppService.attachNewAddress(context, request.getSeed(), add.getAddress());
} else {
add.setAttached(true);
Store.updateAddress(context, request.getSeed(), add);
AppService.refreshEvent();
}
// addstr.add(add.getAddress());
}
if (++count > 1 || tr1 == null)
;
break;
}
}
} else {
int countemptyattached = 0;
for (Address address : addresses) {
if (address.isAttached() && address.getValue() == 0 && !address.isUsed() && !address.isPig()) {
countemptyattached++;
}
}
Store.loadDefaults(context);
int countmin = Store.getAutoAttach();
if (countemptyattached < countmin) {
// Log.e("AUDIT","Gen new address");
try {
GetNewAddressRequest gnr = new GetNewAddressRequest(request.getSeed());
gnr.setIndex(addresses.size());
final GetNewAddressResponse gna = apiProxy.getNewAddress(String.valueOf(Store.getSeedRaw(context, request.getSeed())), gnr.getSecurity(), addresses.size(), gnr.isChecksum(), 1, gnr.isReturnAll());
run.wallet.iota.api.responses.GetNewAddressResponse gnar = new run.wallet.iota.api.responses.GetNewAddressResponse(request.getSeed(), gna);
Store.addAddress(context, gnr, gnar);
AppService.auditAddressesWithDelay(context, request.getSeed());
} catch (Exception e) {
}
} else {
// Log.e("AUDIT","no address need creating");
}
}
} else {
// Log.e("AUDIT","Called but skipped.. hopefully good");
}
return new ApiResponse();
}
use of run.wallet.iota.model.Address in project run-wallet-android by runplay.
the class SendTransferRequestHandler method handle.
@Override
public ApiResponse handle(ApiRequest request) {
int notificationId = Utils.createNewID();
ApiResponse response;
try {
List<Transfer> transfers = ((SendTransferRequest) request).prepareTransfers();
List<Input> inputs = null;
String remainder = null;
if (((SendTransferRequest) request).getFromAddresses() != null) {
inputs = new ArrayList<>();
for (Address address : ((SendTransferRequest) request).getFromAddresses()) {
Input inp = new Input(address.getAddress(), address.getValue(), address.getIndex(), address.getSecurity());
inputs.add(inp);
}
remainder = ((SendTransferRequest) request).getRemainder().getAddress();
}
try {
response = new SendTransferResponse(context, ((SendTransferRequest) request).getSeed(), apiProxy.sendTransfer(String.valueOf(Store.getSeedRaw(context, ((SendTransferRequest) request).getSeed())), ((SendTransferRequest) request).getSecurity(), ((SendTransferRequest) request).getDepth(), ((SendTransferRequest) request).getMinWeightMagnitude(), transfers, // inputs
inputs, // remainder address
remainder, true, false));
} catch (Exception e) {
// currently this just waits 10 seconds and re-tries
try {
wait(10000);
} catch (Exception ew) {
}
response = new SendTransferResponse(context, ((SendTransferRequest) request).getSeed(), apiProxy.sendTransfer(String.valueOf(Store.getSeedRaw(context, ((SendTransferRequest) request).getSeed())), ((SendTransferRequest) request).getSecurity(), ((SendTransferRequest) request).getDepth(), ((SendTransferRequest) request).getMinWeightMagnitude(), transfers, // inputs
inputs, // remainder address
remainder, true, false));
}
AppService.setFastMode();
} catch (ArgumentException | IllegalAccessError e) {
// Log.e("SNT","ex: "+e.getMessage());
NetworkError error = new NetworkError();
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
if (mNotificationManager != null) {
mNotificationManager.cancel(notificationId);
}
if (e instanceof IllegalStateException) {
// if (e.getMessage().contains("Sending to a used address.") || e.getMessage().contains("Private key reuse detect!")) {
final Activity activity = (Activity) context;
Bundle bundle = new Bundle();
bundle.putString("error", e.getMessage());
KeyReuseDetectedDialog dialog = new KeyReuseDetectedDialog();
dialog.setArguments(bundle);
dialog.show(activity.getFragmentManager(), null);
error.setErrorType(NetworkErrorType.KEY_REUSE_ERROR);
// }
}
if (e instanceof ArgumentException) {
if (e.getMessage().contains("Sending to a used address.") || e.getMessage().contains("Private key reuse detect!")) {
final Activity activity = (Activity) context;
Bundle bundle = new Bundle();
bundle.putString("error", e.getMessage());
KeyReuseDetectedDialog dialog = new KeyReuseDetectedDialog();
dialog.setArguments(bundle);
dialog.show(activity.getFragmentManager(), null);
error.setErrorType(NetworkErrorType.KEY_REUSE_ERROR);
}
}
if (e instanceof IllegalAccessError) {
error.setErrorType(NetworkErrorType.ACCESS_ERROR);
if (((SendTransferRequest) request).getTag().equals(Constants.NEW_ADDRESS_TAG))
NotificationHelper.responseNotification(context, R.drawable.ic_error, context.getString(R.string.notification_address_attach_to_tangle_blocked_title), notificationId);
else
NotificationHelper.responseNotification(context, R.drawable.ic_error, context.getString(R.string.notification_transfer_attach_to_tangle_blocked_title), notificationId);
} else {
if (error.getErrorType() != NetworkErrorType.KEY_REUSE_ERROR) {
error.setErrorType(NetworkErrorType.NETWORK_ERROR);
}
if (((SendTransferRequest) request).getValue() == 0 && ((SendTransferRequest) request).getTag().equals(Constants.NEW_ADDRESS_TAG)) {
NotificationHelper.responseNotification(context, R.drawable.ic_address, context.getString(R.string.notification_attaching_new_address_response_failed_title), notificationId);
} else {
NotificationHelper.responseNotification(context, R.drawable.ic_fab_send, context.getString(R.string.notification_send_transfer_response_failed_title), notificationId);
}
}
response = error;
}
if (response instanceof SendTransferResponse && ((SendTransferRequest) request).getValue() == 0 && ((SendTransferRequest) request).getTag().equals(Constants.NEW_ADDRESS_TAG)) {
} else if (response instanceof SendTransferResponse) {
if (Arrays.asList(((SendTransferResponse) response).getSuccessfully()).contains(true)) {
if (AppService.isAppStarted()) {
NotificationHelper.vibrate(context);
} else {
NotificationHelper.responseNotification(context, R.drawable.ic_fab_send, context.getString(R.string.notification_send_transfer_response_succeeded_title), notificationId);
}
} else {
NotificationHelper.responseNotification(context, R.drawable.ic_fab_send, context.getString(R.string.notification_send_transfer_response_failed_title), notificationId);
}
}
return response;
}
Aggregations