get transaction id for first_publish and new_channel rewards
This commit is contained in:
parent
acbe33c66d
commit
613634adcf
2 changed files with 46 additions and 3 deletions
|
@ -4,9 +4,12 @@ import android.content.Context;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -14,6 +17,8 @@ import io.lbry.browser.R;
|
||||||
import io.lbry.browser.exceptions.ApiCallException;
|
import io.lbry.browser.exceptions.ApiCallException;
|
||||||
import io.lbry.browser.exceptions.LbryioRequestException;
|
import io.lbry.browser.exceptions.LbryioRequestException;
|
||||||
import io.lbry.browser.exceptions.LbryioResponseException;
|
import io.lbry.browser.exceptions.LbryioResponseException;
|
||||||
|
import io.lbry.browser.model.Claim;
|
||||||
|
import io.lbry.browser.model.lbryinc.Reward;
|
||||||
import io.lbry.browser.utils.Helper;
|
import io.lbry.browser.utils.Helper;
|
||||||
import io.lbry.browser.utils.Lbry;
|
import io.lbry.browser.utils.Lbry;
|
||||||
import io.lbry.browser.utils.Lbryio;
|
import io.lbry.browser.utils.Lbryio;
|
||||||
|
@ -43,6 +48,15 @@ public class ClaimRewardTask extends AsyncTask<Void, Void, String> {
|
||||||
public String doInBackground(Void... params) {
|
public String doInBackground(Void... params) {
|
||||||
String message = null;
|
String message = null;
|
||||||
try {
|
try {
|
||||||
|
String txid = null;
|
||||||
|
if (Reward.TYPE_FIRST_CHANNEL.equalsIgnoreCase(type)) {
|
||||||
|
// fetch a channel
|
||||||
|
txid = fetchSingleClaimTxid(Claim.TYPE_CHANNEL);
|
||||||
|
} else if (Reward.TYPE_FIRST_PUBLISH.equalsIgnoreCase(type)) {
|
||||||
|
// fetch a publish
|
||||||
|
txid = fetchSingleClaimTxid(Claim.TYPE_STREAM);
|
||||||
|
}
|
||||||
|
|
||||||
// Get a new wallet address for the reward
|
// Get a new wallet address for the reward
|
||||||
String address = (String) Lbry.genericApiCall(Lbry.METHOD_ADDRESS_UNUSED);
|
String address = (String) Lbry.genericApiCall(Lbry.METHOD_ADDRESS_UNUSED);
|
||||||
Map<String, String> options = new HashMap<>();
|
Map<String, String> options = new HashMap<>();
|
||||||
|
@ -50,8 +64,11 @@ public class ClaimRewardTask extends AsyncTask<Void, Void, String> {
|
||||||
options.put("wallet_address", address);
|
options.put("wallet_address", address);
|
||||||
if (!Helper.isNullOrEmpty(rewardCode)) {
|
if (!Helper.isNullOrEmpty(rewardCode)) {
|
||||||
options.put("code", rewardCode);
|
options.put("code", rewardCode);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
if (!Helper.isNullOrEmpty(txid)) {
|
||||||
|
options.put("transaction_id", txid);
|
||||||
|
}
|
||||||
|
|
||||||
JSONObject reward = (JSONObject) Lbryio.parseResponse(
|
JSONObject reward = (JSONObject) Lbryio.parseResponse(
|
||||||
Lbryio.call("reward", "claim", options, Helper.METHOD_POST, null));
|
Lbryio.call("reward", "claim", options, Helper.METHOD_POST, null));
|
||||||
amountClaimed = Helper.getJSONDouble("reward_amount", 0, reward);
|
amountClaimed = Helper.getJSONDouble("reward_amount", 0, reward);
|
||||||
|
@ -61,7 +78,7 @@ public class ClaimRewardTask extends AsyncTask<Void, Void, String> {
|
||||||
amountClaimed == 1 ? 1 : 2,
|
amountClaimed == 1 ? 1 : 2,
|
||||||
new DecimalFormat(Helper.LBC_CURRENCY_FORMAT_PATTERN).format(amountClaimed)) : "";
|
new DecimalFormat(Helper.LBC_CURRENCY_FORMAT_PATTERN).format(amountClaimed)) : "";
|
||||||
message = Helper.getJSONString("reward_notification", defaultMessage, reward);
|
message = Helper.getJSONString("reward_notification", defaultMessage, reward);
|
||||||
} catch (ApiCallException | LbryioRequestException | LbryioResponseException ex) {
|
} catch (ApiCallException | JSONException | LbryioRequestException | LbryioResponseException ex) {
|
||||||
error = ex;
|
error = ex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,6 +96,23 @@ public class ClaimRewardTask extends AsyncTask<Void, Void, String> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String fetchSingleClaimTxid(String claimType) throws ApiCallException, JSONException {
|
||||||
|
Map<String, Object> options = new HashMap<>();
|
||||||
|
options.put("claim_type", claimType);
|
||||||
|
options.put("page", 1);
|
||||||
|
options.put("page_size", 1);
|
||||||
|
options.put("resolve", true);
|
||||||
|
|
||||||
|
JSONObject result = (JSONObject) Lbry.genericApiCall(Lbry.METHOD_CLAIM_LIST, options);
|
||||||
|
JSONArray items = result.getJSONArray("items");
|
||||||
|
if (items.length() > 0) {
|
||||||
|
Claim claim = Claim.fromJSONObject(items.getJSONObject(0));
|
||||||
|
return claim.getTxid();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public interface ClaimRewardHandler {
|
public interface ClaimRewardHandler {
|
||||||
void onSuccess(double amountClaimed, String message);
|
void onSuccess(double amountClaimed, String message);
|
||||||
void onError(Exception error);
|
void onError(Exception error);
|
||||||
|
|
|
@ -12,6 +12,7 @@ import android.graphics.Color;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
import android.text.format.DateUtils;
|
import android.text.format.DateUtils;
|
||||||
import android.view.ContextMenu;
|
import android.view.ContextMenu;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
@ -1190,7 +1191,15 @@ public class FileViewFragment extends BaseFragment implements
|
||||||
Claim.GenericMetadata metadata = claim.getValue();
|
Claim.GenericMetadata metadata = claim.getValue();
|
||||||
if (!Helper.isNullOrEmpty(claim.getThumbnailUrl())) {
|
if (!Helper.isNullOrEmpty(claim.getThumbnailUrl())) {
|
||||||
ImageView thumbnailView = root.findViewById(R.id.file_view_thumbnail);
|
ImageView thumbnailView = root.findViewById(R.id.file_view_thumbnail);
|
||||||
Glide.with(getContext().getApplicationContext()).load(claim.getThumbnailUrl()).centerCrop().into(thumbnailView);
|
new Handler().postDelayed(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (claim != null && context != null && thumbnailView != null) {
|
||||||
|
Glide.with(context.getApplicationContext()).load(claim.getThumbnailUrl()).centerCrop().into(thumbnailView);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 200);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// display first x letters of claim name, with random background
|
// display first x letters of claim name, with random background
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue