Search in sources :

Example 31 with JSONObject

use of run.wallet.common.json.JSONObject in project run-wallet-android by runplay.

the class Store method loadWallet.

private static void loadWallet(Context context) {
    if (store.currentSeed != null) {
        SharedPreferences sp = context.getSharedPreferences(store.currentSeed.id, Context.MODE_PRIVATE);
        String jobString = SpManager.getEncryptedPreference(sp, PREF_WALLET, "[]");
        store.currentWallet = null;
        try {
            JSONObject job = new JSONObject(jobString);
            if (job != null) {
                store.currentWallet = new Wallet(job);
            }
        } catch (Exception e) {
        }
    }
}
Also used : JSONObject(run.wallet.common.json.JSONObject) SharedPreferences(android.content.SharedPreferences)

Example 32 with JSONObject

use of run.wallet.common.json.JSONObject in project run-wallet-android by runplay.

the class Store method updateTickers.

public static void updateTickers(Context context, JSONObject job) {
    if (job != null && job.optInt("result") == 200 && job.has("data")) {
        store.tickers.clear();
        JSONArray jar = job.optJSONArray("data");
        if (jar != null && jar.length() > 0) {
            SharedPreferences sp = context.getSharedPreferences(SP_STORE, Context.MODE_PRIVATE);
            sp.edit().putString(PREF_EXCHANGERATES, jar.toString()).commit();
            for (int i = 0; i < jar.length(); i++) {
                JSONObject ob = null;
                try {
                    ob = jar.optJSONObject(i);
                } catch (Exception e) {
                    Log.e("EXCH", "e2: " + e.getMessage());
                }
                if (ob != null) {
                    Ticker ticker = new Ticker(ob);
                    if (ticker.getCp() != null) {
                        store.tickers.put(ticker.getCp(), ticker);
                    }
                }
            }
        }
    }
}
Also used : JSONObject(run.wallet.common.json.JSONObject) SharedPreferences(android.content.SharedPreferences) JSONArray(run.wallet.common.json.JSONArray)

Example 33 with JSONObject

use of run.wallet.common.json.JSONObject in project run-wallet-android by runplay.

the class Store method addTransfers.

public static List<Transfer> addTransfers(Context context, Seeds.Seed seed, List<Transfer> transfers) {
    List<Transfer> ntransfers = new ArrayList<>();
    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);
            ntransfers.add(add);
        }
    } catch (Exception e) {
    }
    Collections.reverse(transfers);
    for (Transfer tran : transfers) {
        ntransfers.add(0, tran);
    }
    JSONArray trans = new JSONArray();
    for (Transfer t : ntransfers) {
        trans.put(t.toJson());
    }
    SpManager.setEncryptedPreference(sp, PREF_TRANSFERS, trans.toString());
    if (store.currentSeed.id.equals(seed.id)) {
        loadTransfers(context);
    }
    return transfers;
}
Also used : JSONObject(run.wallet.common.json.JSONObject) SharedPreferences(android.content.SharedPreferences) ArrayList(java.util.ArrayList) JSONArray(run.wallet.common.json.JSONArray)

Example 34 with JSONObject

use of run.wallet.common.json.JSONObject in project run-wallet-android by runplay.

the class Store method loadTickerValues.

private static void loadTickerValues(Context context) {
    SharedPreferences sp = context.getSharedPreferences(SP_STORE, Context.MODE_PRIVATE);
    JSONArray jar = null;
    try {
        jar = new JSONArray(sp.getString(PREF_EXCHANGERATES, "[]"));
    } catch (Exception e) {
    }
    if (jar != null) {
        store.tickers.clear();
        for (int i = 0; i < jar.length(); i++) {
            JSONObject ob = null;
            try {
                ob = jar.optJSONObject(i);
            } catch (Exception e) {
            }
            if (ob != null) {
                Ticker ticker = new Ticker(ob);
                if (ticker.getCp() != null) {
                    store.tickers.put(ticker.getCp(), ticker);
                }
            }
        }
    }
}
Also used : JSONObject(run.wallet.common.json.JSONObject) SharedPreferences(android.content.SharedPreferences) JSONArray(run.wallet.common.json.JSONArray)

Example 35 with JSONObject

use of run.wallet.common.json.JSONObject in project run-wallet-android by runplay.

the class Wallet method toJson.

public JSONObject toJson() {
    JSONObject job = new JSONObject();
    job.put("seedid", seedId);
    job.put("balance", balance);
    job.put("lastupdate", getLastUpdate());
    job.put("pendingin", balancePendingIn);
    job.put("pendingout", balancePendingOut);
    return job;
}
Also used : JSONObject(run.wallet.common.json.JSONObject)

Aggregations

JSONObject (run.wallet.common.json.JSONObject)37 SharedPreferences (android.content.SharedPreferences)24 JSONArray (run.wallet.common.json.JSONArray)21 ArrayList (java.util.ArrayList)6 BufferedReader (java.io.BufferedReader)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 URL (java.net.URL)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 Fragment (android.app.Fragment)1 FragmentManager (android.app.FragmentManager)1 FragmentTransaction (android.app.FragmentTransaction)1 Bundle (android.os.Bundle)1 Nullable (android.support.annotation.Nullable)1 File (java.io.File)1 HttpURLConnection (java.net.HttpURLConnection)1 TextFile (run.wallet.common.TextFile)1 JSONException (run.wallet.common.json.JSONException)1 WebGetExchangeRatesHistoryRequest (run.wallet.iota.api.requests.WebGetExchangeRatesHistoryRequest)1