use of run.wallet.common.json.JSONObject in project run-wallet-android by runplay.
the class Seeds method save.
protected void save(Context context) {
// SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences sp = context.getSharedPreferences(SP_WALLETS, Context.MODE_PRIVATE);
JSONArray jar = new JSONArray();
try {
for (Seed seed : seeds) {
JSONObject job = new JSONObject();
job.put(J_NAME, seed.name);
job.put(J_VALUE, new String(seed.value));
job.put(J_DEFAULT, seed.isdefault);
job.put(J_ID, seed.id);
job.put(J_APPGEN, seed.isappgenerated);
jar.put(job);
}
} catch (Exception e) {
}
if (jar.length() > 0) {
SpManager.setEncryptedPreference(sp, PREF_SEEDS, jar.toString());
}
}
use of run.wallet.common.json.JSONObject in project run-wallet-android by runplay.
the class Store method getWallet.
@Nullable
public static Wallet getWallet(Context context, Seeds.Seed seed) {
if (Validator.isValidCaller()) {
SharedPreferences sp = context.getSharedPreferences(seed.id, Context.MODE_PRIVATE);
String jobString = SpManager.getEncryptedPreference(sp, PREF_WALLET, "[]");
try {
JSONObject job = new JSONObject(jobString);
if (job != null) {
return new Wallet(job);
}
} catch (Exception e) {
}
}
return null;
}
use of run.wallet.common.json.JSONObject in project run-wallet-android by runplay.
the class Store method getTransfers.
public static List<Transfer> getTransfers(Context context, Seeds.Seed seed) {
List<Transfer> transfers = new ArrayList<>();
if (Validator.isValidCaller()) {
SharedPreferences sp = context.getSharedPreferences(seed.id, Context.MODE_PRIVATE);
String jarrayString = SpManager.getEncryptedPreference(sp, PREF_TRANSFERS, "[]");
try {
JSONArray jar = new JSONArray(jarrayString);
for (int i = 0; i < jar.length(); i++) {
JSONObject job = jar.getJSONObject(i);
Transfer add = new Transfer(job);
transfers.add(add);
}
} catch (Exception e) {
}
}
return transfers;
}
use of run.wallet.common.json.JSONObject in project run-wallet-android by runplay.
the class Store method updateTickerHist.
public static void updateTickerHist(Context context, JSONObject job) {
if (job != null && job.optInt("result") == 200 && job.has("data")) {
JSONArray jar = job.optJSONArray("data");
if (jar != null) {
String cp = job.optString("cp");
List<Tick> history = new ArrayList<>();
for (int i = 0; i < jar.length(); i++) {
Tick ticker = new Tick(jar.optJSONObject(i));
// Log.e("TCIK",ticker.getLast()+"--"+jar.optJSONObject(i).toString());
history.add(ticker);
}
TickerHist thist = new TickerHist();
thist.setTicker(cp);
thist.setStep(job.optInt("step"));
thist.setTicks(history);
thist.setLastUpdate(System.currentTimeMillis());
// Log.e("STORE-THIST",cp);
store.tickerHist.put(cp + thist.getStep(), thist);
// JSONObject save=new JSONObject();
SharedPreferences sp = context.getSharedPreferences(SP_STORE, Context.MODE_PRIVATE);
String strJson = sp.getString(PREF_TICKHIST, "{}");
if (strJson != null) {
JSONObject tickerHistories = new JSONObject(strJson);
tickerHistories.put(cp + thist.getStep(), job);
tickerHistories.put("last", System.currentTimeMillis());
// Log.e("STL",tickerHistories.toString());
sp.edit().putString(PREF_TICKHIST, tickerHistories.toString()).commit();
}
}
}
}
use of run.wallet.common.json.JSONObject in project run-wallet-android by runplay.
the class Store method loadAddresses.
private static void loadAddresses(Context context) {
if (store.currentSeed != null) {
SharedPreferences sp = context.getSharedPreferences(store.currentSeed.id, Context.MODE_PRIVATE);
String jarrayString = SpManager.getEncryptedPreference(sp, PREF_ADDRESSES, "[]");
// Log.e("LOAD-ADDRESS",jarrayString);
store.addresses.clear();
try {
JSONArray jar = new JSONArray(jarrayString);
for (int i = 0; i < jar.length(); i++) {
JSONObject job = jar.optJSONObject(i);
Address add = new Address(job);
store.addresses.add(add);
}
for (Address add : store.addresses) {
if (add.isUsed() && add.getValue() > 0) {
store.currentSeed.warnUsed = true;
}
}
} catch (Exception e) {
}
}
}
Aggregations