use of run.wallet.iota.api.requests.GetAccountDataRequest in project run-wallet-android by runplay.
the class GetAccountDataRequestHandler method handle.
@Override
public ApiResponse handle(ApiRequest inrequest) {
GetAccountDataRequest request = (GetAccountDataRequest) inrequest;
GetTransferResponse gtr = null;
StopWatch stopWatch = new StopWatch();
NodeInfoResponse nodeInfo = Store.getNodeInfo();
Wallet wallet = Store.getWallet(context, request.getSeed());
if (wallet != null && nodeInfo != null) {
List<Address> alreadyAddress = Store.getAddresses(context, request.getSeed());
List<Address> usingAddress = Store.getDisplayAddresses(alreadyAddress);
List<Address> checkAddress = new ArrayList<>();
if (request.getIfSingleAddressOrNull() != null) {
Address address = Store.isAlreadyAddress(request.getIfSingleAddressOrNull(), alreadyAddress);
if (address != null) {
checkAddress.add(address);
}
} else {
for (Address add : usingAddress) {
if (!add.isUsed() || (add.isUsed() && (add.getPendingValue() != 0 || add.getValue() != 0))) {
if (request.isForce() || nodeInfo.getLatestMilestoneIndex() != add.getLastMilestone()) {
checkAddress.add(add);
}
}
}
}
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 (addr.getValue() != gotBalance || addr.getPendingValue() != 0) {
addr.setValue(gotBalance);
checkAddressString.add(addr.getAddress());
}
}
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, request.getSeed());
Audit.bundlePopulateTransfers(gtr.getTransfers(), transfers, alreadyAddress);
if (request.getIfSingleAddressOrNull() != null) {
Audit.setTransfersToAddresses(request.getSeed(), transfers, alreadyAddress, wallet, alreadyTransfer);
} else {
Audit.setTransfersToAddresses(request.getSeed(), transfers, alreadyAddress, wallet, alreadyTransfer);
}
Audit.processNudgeAttempts(context, request.getSeed(), transfers);
Store.updateAccountData(context, request.getSeed(), wallet, transfers, alreadyAddress);
}
if (request.getIfSingleAddressOrNull() == null) {
WalletAddressesFragment.setShouldRefresh(true);
WalletTransfersFragment.setShouldRefresh(true);
List<String> checkOthersString = new ArrayList<>();
for (Address address : checkAddress) {
if (!checkAddressString.contains(address.getAddress()))
checkOthersString.add(address.getAddress());
}
if (!checkOthersString.isEmpty()) {
Bundle[] bundles = apiProxy.bundlesFromAddresses(checkOthersString.toArray(new String[checkOthersString.size()]), true);
gtr = GetTransferResponse.create(bundles, stopWatch.getElapsedTimeMili());
}
if (gtr != null && gtr.getTransfers().length > 0) {
transfers = new ArrayList<>();
List<Transfer> alreadyTransfer = Store.getTransfers(context, request.getSeed());
Audit.bundlePopulateTransfers(gtr.getTransfers(), transfers, alreadyAddress);
if (request.getIfSingleAddressOrNull() != null) {
Audit.setTransfersToAddresses(request.getSeed(), transfers, alreadyAddress, wallet, alreadyTransfer);
} else {
Audit.setTransfersToAddresses(request.getSeed(), transfers, alreadyAddress, wallet, alreadyTransfer);
}
Audit.processNudgeAttempts(context, request.getSeed(), transfers);
Store.updateAccountData(context, request.getSeed(), wallet, transfers, alreadyAddress);
}
}
} catch (Exception e) {
Log.e("ERR066", "ERROR: " + e.getMessage());
}
}
AppService.setFastMode();
return new GetAccountDataResponse();
}
return new ApiResponse();
}
use of run.wallet.iota.api.requests.GetAccountDataRequest in project run-wallet-android by runplay.
the class AppService method getAccountData.
public static void getAccountData(Context context, Seeds.Seed seed, boolean force) {
if (Validator.isValidCaller() && Store.getCurrentSeed() != null) {
if (SERVICE != null && countSeedRunningTasks(seed) == 0 && !isGetAccountDataRunning(seed)) {
if (force || SERVICE.lastAccountCall < System.currentTimeMillis() - 10000) {
SERVICE.lastAccountCall = System.currentTimeMillis();
TaskManager rt = new TaskManager(SERVICE);
GetAccountDataRequest gna = new GetAccountDataRequest(seed);
gna.setForce(force);
runTask(rt, gna);
}
}
}
}
use of run.wallet.iota.api.requests.GetAccountDataRequest in project run-wallet-android by runplay.
the class AppService method getAccountDataSingleAddress.
public static void getAccountDataSingleAddress(Context context, Seeds.Seed seed, String address) {
if (Validator.isValidCaller() && Store.getCurrentSeed() != null) {
if (SERVICE != null && !isGetAccountDataRunning(Store.getCurrentSeed())) {
TaskManager rt = new TaskManager(SERVICE);
GetAccountDataRequest gna = new GetAccountDataRequest(seed);
gna.setSingleAddressRefresh(address);
runTask(rt, gna);
}
}
}
use of run.wallet.iota.api.requests.GetAccountDataRequest in project run-wallet-android by runplay.
the class UiManager method displayInfoBar.
public static void displayInfoBar(Activity context, LinearLayout forView) {
makeElements(context);
forView.setBackgroundColor(B.getColor(context, AppTheme.getPrimaryDark()));
try {
List<ApiRequest> attaching = AppService.getRunningTasks();
List<LinearLayout> processing = new ArrayList<>();
if (!attaching.isEmpty()) {
Seeds.Seed currentSeed = Store.getCurrentSeed();
for (ApiRequest req : attaching) {
if (req instanceof SendTransferRequest) {
SendTransferRequest str = (SendTransferRequest) req;
if (str.getSeed().id.equals(currentSeed.id)) {
if (str.getValue() == 0) {
processing.add(createProcessRunningPod(context, R.drawable.tran_white, context.getString(R.string.info_new_attach), 0));
} else {
processing.add(createProcessRunningPod(context, R.drawable.send_white, context.getString(R.string.info_transfer), str.getValue()));
}
}
} else if (req instanceof GetAccountDataRequest) {
GetAccountDataRequest request = (GetAccountDataRequest) req;
if (request.getSeed().id.equals(currentSeed.id)) {
processing.add(createProcessRunningPod(context, R.drawable.refresh_white, context.getString(R.string.info_refresh), 0));
}
} else if (req instanceof GetNewAddressRequest) {
GetNewAddressRequest request = (GetNewAddressRequest) req;
if (request.getSeed().id.equals(currentSeed.id)) {
processing.add(createProcessRunningPod(context, R.drawable.tran_white, context.getString(R.string.info_new_address), 0));
}
} else if (req instanceof GetFirstLoadRequest) {
GetFirstLoadRequest request = (GetFirstLoadRequest) req;
if (request.getSeed().id.equals(currentSeed.id)) {
processing.add(createProcessRunningPod(context, R.drawable.refresh_white, context.getString(R.string.info_first_load), 0));
}
} else if (req instanceof AuditAddressesRequest) {
AuditAddressesRequest request = (AuditAddressesRequest) req;
if (request.getSeed().id.equals(currentSeed.id)) {
processing.add(createProcessRunningPod(context, R.drawable.refresh_white, context.getString(R.string.info_audit), 0));
}
} else if (req instanceof ReplayBundleRequest) {
ReplayBundleRequest request = (ReplayBundleRequest) req;
if (request.getSeed().id.equals(currentSeed.id)) {
processing.add(createProcessRunningPod(context, R.drawable.send_white, context.getString(R.string.info_resend), 0));
}
} else if (req instanceof NudgeRequest) {
NudgeRequest request = (NudgeRequest) req;
if (request.getSeed().id.equals(currentSeed.id)) {
processing.add(createProcessRunningPod(context, R.drawable.send_white, context.getString(R.string.info_nudge), 0));
}
} else if (req instanceof AutoNudgeRequest) {
// if(request.getSeed().id.equals(currentSeed.id)) {
processing.add(createProcessRunningPod(context, R.drawable.send_white, context.getString(R.string.auto), 0));
// }
} else if (req instanceof RefreshUsedAddressesRequest) {
// if(request.getSeed().id.equals(currentSeed.id)) {
processing.add(createProcessRunningPod(context, R.drawable.send_white, context.getString(R.string.info_audit), 0));
// }
}
}
}
forView.removeAllViews();
if (!processing.isEmpty()) {
for (LinearLayout addview : processing) {
forView.addView(addview);
}
forView.canScrollHorizontally(View.LAYOUT_DIRECTION_LTR);
if (forView.getVisibility() != View.VISIBLE) {
forView.setVisibility(View.VISIBLE);
AnimationUtils.loadAnimation(context, R.anim.slide_in_from_bottom);
}
} else if (Store.getUsedAddressCheckResult() != null) {
Snackbar.make(forView, Store.getUsedAddressCheckResult(), Snackbar.LENGTH_LONG).show();
Store.setUsedAddressCheckResult(null);
} else if (Store.getCurrentSeed().warnUsed) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean showused = prefs.getBoolean(Constants.PREFERENCES_SHOW_USED, true);
TextView messy = new TextView(context);
if (showused) {
messy.setText(context.getString(R.string.usedAddressWarn));
} else {
messy.setText(context.getString(R.string.usedAddressSettings));
}
messy.setTextColor(Color.WHITE);
messy.setPadding(30, 30, 30, 30);
messy.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent settings = new Intent(context, SettingsActivity.class);
context.startActivityForResult(settings, 0);
}
});
forView.addView(messy);
forView.canScrollHorizontally(View.LAYOUT_DIRECTION_LTR);
if (forView.getVisibility() != View.VISIBLE) {
AnimationUtils.loadAnimation(context, R.anim.slide_in_from_bottom);
}
} else {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
if (prefs.getBoolean(Constants.PREFERENCES_SHOW_CANCELLED, true) && !prefs.getBoolean(Constants.PREFERENCES_SHOW_ATTACH, true) && Store.getTransfers().size() > 15) {
int count = prefs.getInt(Constants.PREF_MSG_MESSY, 0);
if (count < 2) {
TextView messy = new TextView(context);
messy.setText(context.getString(R.string.message_messy_view));
messy.setTextColor(Color.WHITE);
messy.setPadding(30, 30, 30, 30);
// messy.setText
messy.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent settings = new Intent(context, SettingsActivity.class);
context.startActivityForResult(settings, 0);
}
});
forView.addView(messy);
forView.canScrollHorizontally(View.LAYOUT_DIRECTION_LTR);
if (forView.getVisibility() != View.VISIBLE) {
AnimationUtils.loadAnimation(context, R.anim.slide_in_from_bottom);
}
prefs.edit().putInt(Constants.PREF_MSG_MESSY, ++count).commit();
}
} else {
AnimationUtils.loadAnimation(context, R.anim.slide_out_to_bottom);
}
}
} catch (Exception e) {
}
}
Aggregations