Fix mass tips unlocking (#1157)
This commit is contained in:
parent
a8cdc4a771
commit
d0a8b3b218
1 changed files with 4 additions and 31 deletions
|
@ -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);
|
options.put("blocking", 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) {
|
Lbry.genericApiCall(Lbry.METHOD_TXO_SPEND, options);
|
||||||
options = new HashMap<>();
|
|
||||||
options.put("txid", txids);
|
|
||||||
options.put("blocking", true);
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue