Search in sources :

Example 16 with JSONArray

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

the class Store method updateAddress.

public static void updateAddress(Context context, Seeds.Seed seed, Address address) {
    List<Address> addresses = getAddresses(context, seed);
    boolean updateAddress = false;
    if (addresses.isEmpty()) {
        addresses.add(address);
        updateAddress = true;
    } else {
        for (Address add : addresses) {
            if (add.getAddress().equals(address.getAddress())) {
                add.setValue(add.getValue() + address.getValue());
                add.setAttached(address.isAttached());
                add.setUsed(address.isUsed());
                add.setLastMilestone(address.getLastMilestone());
                add.setPigInt(address.getPigInt());
                updateAddress = true;
            }
        }
    }
    if (updateAddress) {
        // Log.e("Store","store - UPDATING Address");
        JSONArray jar = new JSONArray();
        for (Address add : addresses) {
            jar.put(add.toJson());
        }
        SharedPreferences sp = context.getSharedPreferences(seed.id, Context.MODE_PRIVATE);
        SpManager.setEncryptedPreference(sp, PREF_ADDRESSES, jar.toString());
    }
    if (store.currentSeed.id.equals(seed.id)) {
        reinit(context);
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) JSONArray(run.wallet.common.json.JSONArray)

Example 17 with JSONArray

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

the class Store method updateAccountDataOld.

@Deprecated
public static synchronized void updateAccountDataOld(Context context, Seeds.Seed seed, Wallet wallet, List<Transfer> transfers, List<Address> addresses) {
    if (seed != null) {
        SharedPreferences sp = context.getSharedPreferences(seed.id, Context.MODE_PRIVATE);
        List<Transfer> alreadyTransfers = getTransfers(context, seed);
        // Collections.reverse(transfers);
        for (Transfer t : transfers) {
            Transfer already = isAlreadyTransfer(t, alreadyTransfers);
            if (already == null) {
                alreadyTransfers.add(0, t);
            } else {
                already.setPersistence(t.getPersistence() != null ? t.getPersistence() : false);
                already.setMarkDoubleSpend(t.isMarkDoubleSpend());
                already.setTimestamp(t.getTimestamp());
            }
        }
        JSONArray trans = new JSONArray();
        for (Transfer t : alreadyTransfers) {
            trans.put(t.toJson());
        }
        SpManager.setEncryptedPreference(sp, PREF_TRANSFERS, trans.toString());
        List<Address> alreadyAddress = getAddresses(context, seed);
        for (Address add : addresses) {
            Address already = isAlreadyAddress(add, alreadyAddress);
            if (already == null) {
                alreadyAddress.add(add);
            } else {
                already.setAttached(add.isAttached());
                already.setValue(add.getValue());
                already.setPendingValue(add.getPendingValue());
                already.setUsed(add.isUsed());
            }
        }
        JSONArray jar = new JSONArray();
        for (Address add : alreadyAddress) {
            jar.put(add.toJson());
        }
        SpManager.setEncryptedPreference(sp, PREF_ADDRESSES, jar.toString());
        Store.addUpdateWallet(context, seed, wallet);
        if (store.currentSeed != null && seed.id.equals(store.currentSeed.id)) {
            reinit(context);
        }
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) JSONArray(run.wallet.common.json.JSONArray)

Example 18 with JSONArray

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

the class Store method setCurrentAddressPig.

public static void setCurrentAddressPig(Context context, String address, boolean isPig) {
    for (Address add : getAddresses()) {
        // Log.e("SET-PIG",add.getAddress().startsWith(address)+"--"+add.getAddress()+"-"+address+"----");
        if (add.getAddress().startsWith(address)) {
            add.setPigUser(isPig);
        }
        SharedPreferences sp = context.getSharedPreferences(getCurrentSeed().id, Context.MODE_PRIVATE);
        JSONArray jar = new JSONArray();
        for (Address addsave : getAddresses()) {
            jar.put(addsave.toJson());
        }
        SpManager.setEncryptedPreference(sp, PREF_ADDRESSES, jar.toString());
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) JSONArray(run.wallet.common.json.JSONArray)

Example 19 with JSONArray

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

the class Store method updateAccountData.

public static synchronized void updateAccountData(Context context, Seeds.Seed seed, Wallet wallet, List<Transfer> transfers, List<Address> addresses) {
    if (seed != null) {
        // Log.e("STORE","........updateAccountData()");
        SharedPreferences sp = context.getSharedPreferences(seed.id, Context.MODE_PRIVATE);
        if (!transfers.isEmpty()) {
            JSONArray trans = new JSONArray();
            for (Transfer t : transfers) {
                trans.put(t.toJson());
            }
            SpManager.setEncryptedPreference(sp, PREF_TRANSFERS, trans.toString());
            List<Address> alreadyAddress = getAddresses(context, seed);
            for (Address add : addresses) {
                Address already = isAlreadyAddress(add, alreadyAddress);
                if (already == null) {
                    // add.setIndex(alreadyAddress.size());
                    alreadyAddress.add(add);
                } else {
                    already.setAttached(add.isAttached());
                    already.setValue(add.getValue());
                    already.setPendingValue(add.getPendingValue());
                    already.setUsed(add.isUsed());
                    already.setPigInt(add.getPigInt());
                }
            }
            // Log.e("Store","store - UPDATING Address");
            JSONArray jar = new JSONArray();
            for (Address add : alreadyAddress) {
                jar.put(add.toJson());
            }
            // Log.e("ADDRESSES",jar.toString());
            SpManager.setEncryptedPreference(sp, PREF_ADDRESSES, jar.toString());
            Store.addUpdateWallet(context, seed, wallet);
            if (store.currentSeed != null && seed.id.equals(store.currentSeed.id)) {
                reinit(context);
                WalletAddressCardAdapter.load(context, true);
                WalletTransfersCardAdapter.load(context, true);
            }
        // updateStats(context, seed, wallet, addresses, transfers);
        }
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) JSONArray(run.wallet.common.json.JSONArray)

Example 20 with JSONArray

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

the class Store method getTickerHist.

public static TickerHist getTickerHist(Context context, String ticker, int step) {
    TickerHist hist = store.tickerHist.get(ticker + step);
    if (hist == null) {
        SharedPreferences sp = context.getSharedPreferences(SP_STORE, Context.MODE_PRIVATE);
        String strJson = sp.getString(PREF_TICKHIST, null);
        if (strJson != null) {
            JSONObject tickerHistories = new JSONObject(strJson);
            JSONObject gottickerhist = tickerHistories.optJSONObject(ticker + step);
            // Log.e("GTL",""+gottickerhist);
            if (gottickerhist != null) {
                String cp = gottickerhist.optString("cp");
                if (!cp.isEmpty()) {
                    long last = gottickerhist.optLong("last");
                    // Log.e("STORE-THIST", "get: " + cp);
                    List<Tick> history = new ArrayList<>();
                    JSONArray jar = gottickerhist.optJSONArray("data");
                    for (int i = 0; i < jar.length(); i++) {
                        Tick aticker = new Tick(jar.optJSONObject(i));
                        // Log.e("TCIK",ticker.getLast()+"--"+jar.optJSONObject(i).toString());
                        history.add(aticker);
                    }
                    TickerHist thist = new TickerHist();
                    thist.setTicker(cp);
                    thist.setStep(gottickerhist.optInt("step"));
                    thist.setTicks(history);
                    thist.setLastUpdate(last);
                    // Log.e("STORE-THIST",cp);
                    store.tickerHist.put(cp + step, thist);
                }
            }
        }
    }
    return store.tickerHist.get(ticker + step);
}
Also used : JSONObject(run.wallet.common.json.JSONObject) SharedPreferences(android.content.SharedPreferences) ArrayList(java.util.ArrayList) JSONArray(run.wallet.common.json.JSONArray)

Aggregations

JSONArray (run.wallet.common.json.JSONArray)36 SharedPreferences (android.content.SharedPreferences)33 JSONObject (run.wallet.common.json.JSONObject)21 ArrayList (java.util.ArrayList)6 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 HttpURLConnection (java.net.HttpURLConnection)1 URL (java.net.URL)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 WebGetExchangeRatesResponse (run.wallet.iota.api.responses.WebGetExchangeRatesResponse)1