Fix mass tips unlocking (#1157)

This commit is contained in:
Javi Rueda 2021-03-06 00:32:12 +01:00 committed by GitHub
parent a8cdc4a771
commit d0a8b3b218
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2,24 +2,16 @@ package io.lbry.browser.tasks.wallet;
import android.os.AsyncTask; import android.os.AsyncTask;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import io.lbry.browser.exceptions.ApiCallException; import io.lbry.browser.exceptions.ApiCallException;
import io.lbry.browser.model.WalletBalance;
import io.lbry.browser.tasks.GenericTaskHandler; import io.lbry.browser.tasks.GenericTaskHandler;
import io.lbry.browser.utils.Helper;
import io.lbry.browser.utils.Lbry; import io.lbry.browser.utils.Lbry;
public class UnlockTipsTask extends AsyncTask<Void, Void, Boolean> { public class UnlockTipsTask extends AsyncTask<Void, Void, Boolean> {
private GenericTaskHandler handler; private final GenericTaskHandler handler;
private Exception error; private Exception error;
public UnlockTipsTask(GenericTaskHandler handler) { public UnlockTipsTask(GenericTaskHandler handler) {
@ -27,35 +19,16 @@ public class UnlockTipsTask extends AsyncTask<Void, Void, Boolean> {
} }
public Boolean doInBackground(Void... params) { public Boolean doInBackground(Void... params) {
List<String> txids = new ArrayList<>();
try { try {
Map<String, Object> options = new HashMap<>(); Map<String, Object> options = new HashMap<>();
options.put("type", "support"); options.put("type", "support");
options.put("is_not_my_input", true); options.put("is_not_my_input", true);
options.put("is_my_output", true);
JSONObject result = (JSONObject) Lbry.genericApiCall(Lbry.METHOD_TXO_LIST, options);
if (result.has("items") && !result.isNull("items")) {
JSONArray items = result.getJSONArray("items");
for (int i = 0; i < items.length(); i++) {
JSONObject item = items.getJSONObject(i);
String txid = Helper.getJSONString("txid", null, item);
if (!Helper.isNullOrEmpty(txid)) {
txids.add(txid);
}
}
}
if (txids.size() > 0) {
options = new HashMap<>();
options.put("txid", txids);
options.put("blocking", true); options.put("blocking", true);
Lbry.genericApiCall(Lbry.METHOD_TXO_SPEND, options); Lbry.genericApiCall(Lbry.METHOD_TXO_SPEND, options);
}
return true; return true;
} catch (ApiCallException | ClassCastException | JSONException ex) { } catch (ApiCallException | ClassCastException ex) {
error = ex; error = ex;
return false; return false;
} }