Updated on 2026-08-14
This commit is contained in:
parent
3694c32695
commit
edbeb5f3bd
18 changed files with 145 additions and 393 deletions
|
|
@ -50,13 +50,13 @@ dependencies {
|
|||
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
|
||||
implementation 'com.android.support:cardview-v7:27.1.1'
|
||||
implementation 'com.android.support:support-v4:27.1.1'
|
||||
implementation 'com.android.volley:volley:1.1.0'
|
||||
implementation 'com.google.zxing:core:3.3.2'
|
||||
implementation 'com.google.code.gson:gson:2.8.5'
|
||||
implementation 'com.madgag.spongycastle:core:1.56.0.0'
|
||||
implementation 'com.madgag.spongycastle:prov:1.56.0.0'
|
||||
implementation 'com.scottyab:rootbeer-lib:0.0.6'
|
||||
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
|
||||
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
|
||||
implementation 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'
|
||||
implementation 'com.skyfishjy.ripplebackground:library:1.0.1'
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||
|
|
|
|||
|
|
@ -2,22 +2,9 @@ package com.tangem;
|
|||
|
||||
import android.app.Application;
|
||||
import android.support.v7.app.AppCompatDelegate;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.volley.Request;
|
||||
import com.android.volley.RequestQueue;
|
||||
import com.android.volley.VolleyLog;
|
||||
import com.android.volley.toolbox.Volley;
|
||||
|
||||
public class AppController extends Application {
|
||||
|
||||
public static final String TAG = "fragment." + AppController.class.getSimpleName();
|
||||
|
||||
/**
|
||||
* Global request queue for Volley
|
||||
*/
|
||||
private RequestQueue mRequestQueue;
|
||||
|
||||
/**
|
||||
* A singleton instance of the application class for easy access in other places
|
||||
*/
|
||||
|
|
@ -39,59 +26,10 @@ public class AppController extends Application {
|
|||
}
|
||||
|
||||
/**
|
||||
* @return SeoPult singleton instance
|
||||
* @return singleton instance
|
||||
*/
|
||||
public static synchronized AppController getInstance() {
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The Volley Request queue, the queue will be created if it is null
|
||||
*/
|
||||
public RequestQueue getRequestQueue() {
|
||||
// lazy initialize the request queue, the queue instance will be created when it is accessed for the first time
|
||||
if (mRequestQueue == null)
|
||||
mRequestQueue = Volley.newRequestQueue(getApplicationContext());
|
||||
|
||||
return mRequestQueue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the specified request to the global queue, if tag is specified
|
||||
* then it is used else Default TAG is used.
|
||||
*
|
||||
* @param req
|
||||
* @param tag
|
||||
*/
|
||||
public <T> void addToRequestQueue(Request<T> req, String tag) {
|
||||
// set the default tag if tag is empty
|
||||
req.setTag(TextUtils.isEmpty(tag) ? TAG : tag);
|
||||
VolleyLog.d("Adding request to queue: %s", req.getUrl());
|
||||
getRequestQueue().add(req);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the specified request to the global queue using the Default TAG.
|
||||
*
|
||||
* @param req
|
||||
*/
|
||||
public <T> void addToRequestQueue(Request<T> req) {
|
||||
// set the default tag if tag is empty
|
||||
req.setTag(TAG);
|
||||
|
||||
getRequestQueue().add(req);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels all pending requests by the specified TAG, it is important
|
||||
* to specify a TAG so that the pending/ongoing requests can be cancelled.
|
||||
*
|
||||
* @param tag
|
||||
*/
|
||||
public void cancelPendingRequests(Object tag) {
|
||||
if (mRequestQueue != null) {
|
||||
mRequestQueue.cancelAll(tag);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package com.tangem.data.network;
|
||||
|
||||
import com.tangem.data.network.model.RateInfoModel;
|
||||
import com.tangem.data.network.model.RateInfoResponse;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -9,5 +9,5 @@ import retrofit2.http.GET;
|
|||
|
||||
public interface CoinmarketApi {
|
||||
@GET(Server.ApiCoinmarket.Method.V1_TICKER_CONVERT)
|
||||
Observable<List<RateInfoModel>> getRateInfoList();
|
||||
}
|
||||
Observable<List<RateInfoResponse>> getRateInfoList();
|
||||
}
|
||||
|
|
@ -1,98 +0,0 @@
|
|||
package com.tangem.data.network;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.volley.AuthFailureError;
|
||||
import com.android.volley.NetworkResponse;
|
||||
import com.android.volley.ParseError;
|
||||
import com.android.volley.Request;
|
||||
import com.android.volley.Response;
|
||||
import com.android.volley.Response.ErrorListener;
|
||||
import com.android.volley.Response.Listener;
|
||||
import com.android.volley.toolbox.HttpHeaderParser;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Volley adapter for JSON requests with POST method that will be parsed into Java objects by Gson.
|
||||
*/
|
||||
public class GsonRequest<T> extends Request<T> {
|
||||
public static final String TAG = "api." + GsonRequest.class.getSimpleName();
|
||||
private Gson mGson = new Gson();
|
||||
private Class<T> clazz;
|
||||
private Map<String, String> headers;
|
||||
private Map<String, String> params;
|
||||
private Listener<T> listener;
|
||||
|
||||
/**
|
||||
* Make a GET request and return a parsed object from JSON.
|
||||
*
|
||||
* @param url URL of the request to make
|
||||
* @param clazz Relevant class object, for Gson's reflection
|
||||
*/
|
||||
public GsonRequest(int method,
|
||||
String url,
|
||||
Class<T> clazz,
|
||||
Listener<T> listener,
|
||||
ErrorListener errorListener) {
|
||||
super(method, url, errorListener);
|
||||
this.clazz = clazz;
|
||||
this.listener = listener;
|
||||
mGson = new Gson();
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a POST request and return a parsed object from JSON.
|
||||
*
|
||||
* @param url URL of the request to make
|
||||
* @param clazz Relevant class object, for Gson's reflection
|
||||
*/
|
||||
public GsonRequest(int method,
|
||||
String url,
|
||||
Class<T> clazz,
|
||||
Map<String, String> params,
|
||||
Listener<T> listener,
|
||||
ErrorListener errorListener) {
|
||||
|
||||
super(method, url, errorListener);
|
||||
this.clazz = clazz;
|
||||
this.params = params;
|
||||
this.listener = listener;
|
||||
this.headers = null;
|
||||
mGson = new Gson();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getHeaders() throws AuthFailureError {
|
||||
return headers != null ? headers : super.getHeaders();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, String> getParams() throws AuthFailureError {
|
||||
return params;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void deliverResponse(T response) {
|
||||
listener.onResponse(response);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Response<T> parseNetworkResponse(NetworkResponse response) {
|
||||
try {
|
||||
String json = new String(response.data, HttpHeaderParser.parseCharset(response.headers));
|
||||
Log.i(TAG, (json));
|
||||
return Response.success(mGson.fromJson(json, clazz), HttpHeaderParser.parseCacheHeaders(response));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
Log.e(TAG, "UnsupportedEncodingException");
|
||||
return Response.error(new ParseError(e));
|
||||
} catch (JsonSyntaxException e) {
|
||||
Log.e(TAG, "JsonSyntaxException");
|
||||
return Response.error(new ParseError(e));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -15,7 +15,7 @@ public class Server {
|
|||
* https://tangem-webapp.appspot.com/
|
||||
*/
|
||||
public static class ApiTangem {
|
||||
private static final String URL_TANGEM = ServerURL.API_TANGEM;
|
||||
public static final String URL_TANGEM = ServerURL.API_TANGEM;
|
||||
|
||||
public static class Method {
|
||||
public static final String INFO_VERIFY = URL_TANGEM + "info/version";
|
||||
|
|
@ -34,11 +34,7 @@ public class Server {
|
|||
|
||||
public static class Method {
|
||||
public static final String V1_TICKER_CONVERT = URL_COINMARKET + "v1/ticker/?convert=USD&lmit=10";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,15 +1,26 @@
|
|||
package com.tangem.data.network;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.util.Log;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
|
||||
import com.tangem.data.network.model.RateInfoModel;
|
||||
import com.tangem.data.network.model.CardVerify;
|
||||
import com.tangem.data.network.model.CardVerifyBody;
|
||||
import com.tangem.data.network.model.CardVerifyResponse;
|
||||
import com.tangem.data.network.model.RateInfoResponse;
|
||||
import com.tangem.data.network.request.ElectrumRequest;
|
||||
import com.tangem.domain.BitcoinNode;
|
||||
import com.tangem.domain.BitcoinNodeTestNet;
|
||||
import com.tangem.domain.wallet.Blockchain;
|
||||
import com.tangem.domain.wallet.TangemCard;
|
||||
import com.tangem.util.Util;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStream;
|
||||
|
|
@ -28,12 +39,62 @@ import io.reactivex.Observable;
|
|||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.observers.DefaultObserver;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
import retrofit2.Retrofit;
|
||||
import retrofit2.converter.gson.GsonConverterFactory;
|
||||
|
||||
public class ServerApiHelper {
|
||||
private static String TAG = ServerApiHelper.class.getSimpleName();
|
||||
|
||||
/**
|
||||
* HTTP
|
||||
* Card verify
|
||||
*/
|
||||
private CardVerifyListener cardVerifyListener;
|
||||
|
||||
public interface CardVerifyListener {
|
||||
void onCardVerify(CardVerifyResponse cardVerifyResponse);
|
||||
}
|
||||
|
||||
public void setCardVerify(CardVerifyListener listener) {
|
||||
cardVerifyListener = listener;
|
||||
}
|
||||
|
||||
public void cardVerify(TangemCard card) {
|
||||
Retrofit retrofit = new Retrofit.Builder()
|
||||
.baseUrl(Server.ApiTangem.URL_TANGEM)
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
.build();
|
||||
|
||||
TangemApi tangemApi = retrofit.create(TangemApi.class);
|
||||
|
||||
CardVerify[] requests = new CardVerify[1];
|
||||
requests[0] = new CardVerify(Util.bytesToHex(card.getCID()), Util.bytesToHex(card.getCardPublicKey()));
|
||||
|
||||
CardVerifyBody cardVerifyBody = new CardVerifyBody(requests);
|
||||
|
||||
Call<CardVerifyResponse> call = tangemApi.getCardVerify("application/json", cardVerifyBody);
|
||||
call.enqueue(new Callback<CardVerifyResponse>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<CardVerifyResponse> call, @NonNull Response<CardVerifyResponse> response) {
|
||||
if (response.code() == 200) {
|
||||
CardVerifyResponse cardVerifyResponse = response.body();
|
||||
cardVerifyListener.onCardVerify(cardVerifyResponse);
|
||||
Log.i(TAG, "cardVerify onResponse " + response.code());
|
||||
} else {
|
||||
Log.e(TAG, "cardVerify onResponse " + response.code());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<CardVerifyResponse> call, Throwable t) {
|
||||
Log.e(TAG, "cardVerify onFailure " + t.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTP
|
||||
* Used in Crypto-currency course
|
||||
|
|
@ -41,7 +102,7 @@ public class ServerApiHelper {
|
|||
private RateInfoDataListener rateInfoDataListener;
|
||||
|
||||
public interface RateInfoDataListener {
|
||||
void onRateInfoDataData(RateInfoModel rateInfoModel);
|
||||
void onRateInfoDataData(RateInfoResponse rateInfoResponse);
|
||||
}
|
||||
|
||||
public void setRateInfoData(RateInfoDataListener listener) {
|
||||
|
|
@ -63,7 +124,7 @@ public class ServerApiHelper {
|
|||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(rateInfoModelList -> {
|
||||
if (!rateInfoModelList.isEmpty()) {
|
||||
for (RateInfoModel rateInfoMode : rateInfoModelList) {
|
||||
for (RateInfoResponse rateInfoMode : rateInfoModelList) {
|
||||
if (rateInfoMode.getId().equals(cryptoId)) {
|
||||
rateInfoDataListener.onRateInfoDataData(rateInfoMode);
|
||||
Log.i("rateInfoData", rateInfoMode.getId());
|
||||
|
|
|
|||
|
|
@ -1,13 +1,6 @@
|
|||
|
||||
package com.tangem.data.network;
|
||||
|
||||
public class ServerURL {
|
||||
public static final String API_TANGEM = "https://verify.tangem.com/";
|
||||
public static final String API_COINMARKET = "https://api.coinmarketcap.com/";
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
14
app/src/main/java/com/tangem/data/network/TangemApi.java
Normal file
14
app/src/main/java/com/tangem/data/network/TangemApi.java
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
package com.tangem.data.network;
|
||||
|
||||
import com.tangem.data.network.model.CardVerifyBody;
|
||||
import com.tangem.data.network.model.CardVerifyResponse;
|
||||
|
||||
import retrofit2.Call;
|
||||
import retrofit2.http.Body;
|
||||
import retrofit2.http.Header;
|
||||
import retrofit2.http.POST;
|
||||
|
||||
public interface TangemApi {
|
||||
@POST(Server.ApiTangem.Method.VERIFY)
|
||||
Call<CardVerifyResponse> getCardVerify(@Header("Content-Type") String contentType, @Body CardVerifyBody body);
|
||||
}
|
||||
|
|
@ -1,108 +0,0 @@
|
|||
package com.tangem.data.network
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.support.v7.app.AlertDialog
|
||||
import com.android.volley.AuthFailureError
|
||||
import com.android.volley.DefaultRetryPolicy
|
||||
import com.android.volley.Request
|
||||
import com.android.volley.Response
|
||||
import com.android.volley.toolbox.StringRequest
|
||||
import com.google.gson.Gson
|
||||
import com.tangem.AppController
|
||||
import com.tangem.data.network.model.CardVerifyModel
|
||||
import com.tangem.domain.wallet.TangemCard
|
||||
import com.tangem.util.Util
|
||||
import com.tangem.wallet.R
|
||||
import java.util.*
|
||||
|
||||
class VolleyHelper (private val requestCardVerify: IRequestCardVerify){
|
||||
|
||||
interface IRequestCardVerify {
|
||||
|
||||
fun success(cardVerifyModel: CardVerifyModel)
|
||||
|
||||
fun error(error: String)
|
||||
}
|
||||
|
||||
fun requestCardVerify(card: TangemCard) {
|
||||
val params = HashMap<String, String>()
|
||||
params["CID"] = Util.bytesToHex(card.cid)
|
||||
params["publicKey"] = Util.bytesToHex(card.cardPublicKey)
|
||||
doRequestString(Server.ApiTangem.Method.VERIFY, params)
|
||||
}
|
||||
|
||||
fun requestCardVerifyShowResponse(context: Activity, card: TangemCard) {
|
||||
val params = HashMap<String, String>()
|
||||
params["CID"] = Util.bytesToHex(card.cid)
|
||||
params["publicKey"] = Util.bytesToHex(card.cardPublicKey)
|
||||
doRequestDebug(context, Server.ApiTangem.Method.VERIFY, params)
|
||||
}
|
||||
|
||||
fun doRequestDebug(context: Context, url: String, params: Map<String, String>) {
|
||||
val stringRequest = object : StringRequest(Request.Method.GET, url,
|
||||
{ response ->
|
||||
// Log.i(LoadedWallet.TAG, response.toString())
|
||||
val builder = AlertDialog.Builder(context)
|
||||
builder.setTitle(url)
|
||||
.setMessage(response.toString())
|
||||
.setPositiveButton(R.string.ok, null)
|
||||
.setNeutralButton(R.string.send) { _, _ ->
|
||||
val intent = Intent(Intent.ACTION_SEND)
|
||||
intent.type = "text/html"
|
||||
intent.putExtra(Intent.EXTRA_EMAIL, arrayOf("erogov@tangem.com"))
|
||||
intent.putExtra(Intent.EXTRA_SUBJECT, url)
|
||||
intent.putExtra(Intent.EXTRA_TEXT, response.toString())
|
||||
context.startActivity(Intent.createChooser(intent, "Send json"))
|
||||
}
|
||||
val alert = builder.create()
|
||||
alert.show()
|
||||
},
|
||||
{ error -> val networkResponse = error.networkResponse }) {
|
||||
|
||||
|
||||
@Throws(AuthFailureError::class)
|
||||
override fun getHeaders(): Map<String, String> {
|
||||
return Server.getHeader()
|
||||
}
|
||||
|
||||
@Throws(AuthFailureError::class)
|
||||
override fun getParams(): Map<String, String> {
|
||||
return params
|
||||
}
|
||||
}
|
||||
|
||||
stringRequest.retryPolicy = DefaultRetryPolicy(30000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)
|
||||
AppController.getInstance().addToRequestQueue(stringRequest)
|
||||
}
|
||||
|
||||
private fun doRequestString(url: String, params: Map<String, String>) {
|
||||
val stringRequest = object : StringRequest(Request.Method.GET, url,
|
||||
Response.Listener<String> { response ->
|
||||
val requestResponse = response.toString().substring(response.toString().lastIndexOf("Response:") + 10)
|
||||
|
||||
val responseVerify = Gson().fromJson(requestResponse, CardVerifyModel::class.java)
|
||||
|
||||
requestCardVerify.success(responseVerify)
|
||||
|
||||
// Log.i(LoadedWallet.TAG, responseVerify.results!![2].CID)
|
||||
},
|
||||
Response.ErrorListener { "That didn't work!" }) {
|
||||
|
||||
@Throws(AuthFailureError::class)
|
||||
override fun getHeaders(): Map<String, String> {
|
||||
return Server.getHeader()
|
||||
}
|
||||
|
||||
@Throws(AuthFailureError::class)
|
||||
override fun getParams(): Map<String, String> {
|
||||
return params
|
||||
}
|
||||
}
|
||||
|
||||
stringRequest.retryPolicy = DefaultRetryPolicy(30000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)
|
||||
AppController.getInstance().addToRequestQueue(stringRequest)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
package com.tangem.data.network.model;
|
||||
|
||||
public class CardVerify {
|
||||
private String CID;
|
||||
private String publicKey;
|
||||
|
||||
public CardVerify(String CID, String publicKey) {
|
||||
this.CID = CID;
|
||||
this.publicKey = publicKey;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
package com.tangem.data.network.model;
|
||||
|
||||
public class CardVerifyBody {
|
||||
private CardVerify[] requests;
|
||||
|
||||
public CardVerifyBody(CardVerify[] requests) {
|
||||
this.requests = requests;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -2,23 +2,17 @@ package com.tangem.data.network.model
|
|||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
data class CardVerifyModel(
|
||||
data class CardVerifyResponse(
|
||||
@SerializedName("results")
|
||||
var results: ArrayList<Verify>? = null,
|
||||
|
||||
@SerializedName("error")
|
||||
var error: String? = null
|
||||
var results: List<Verify>? = null
|
||||
) {
|
||||
|
||||
data class Verify(
|
||||
@SerializedName("error")
|
||||
var error: String = "",
|
||||
|
||||
@SerializedName("CID")
|
||||
var CID: String = "",
|
||||
|
||||
@SerializedName("passed")
|
||||
var passed: Boolean? = null
|
||||
var passed: Boolean = false
|
||||
)
|
||||
|
||||
}
|
||||
|
|
@ -5,7 +5,7 @@ import com.google.gson.annotations.SerializedName
|
|||
import kotlinx.android.parcel.Parcelize
|
||||
|
||||
@Parcelize
|
||||
data class RateInfoModel(
|
||||
data class RateInfoResponse(
|
||||
@SerializedName(ID)
|
||||
var id: String = "",
|
||||
|
||||
|
|
@ -54,7 +54,7 @@ data class RateInfoModel(
|
|||
) : Parcelable {
|
||||
|
||||
companion object {
|
||||
val TAG: String = RateInfoModel::class.java.simpleName
|
||||
val TAG: String = RateInfoResponse::class.java.simpleName
|
||||
|
||||
const val ID = "id"
|
||||
const val NAME = "name"
|
||||
|
|
@ -1,5 +1,7 @@
|
|||
package com.tangem.data.network.request;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.tangem.domain.wallet.TangemCard;
|
||||
|
|
@ -35,6 +37,7 @@ public class VerificationServerProtocol {
|
|||
|
||||
public void doPost(String hostURL) throws IOException {
|
||||
URL url = new URL(hostURL + "/" + command.getURL());
|
||||
Log.i("isOnlineVerified", hostURL + "/" + command.getURL());
|
||||
URLConnection con = url.openConnection();
|
||||
HttpURLConnection http = (HttpURLConnection) con;
|
||||
try {
|
||||
|
|
@ -171,7 +174,6 @@ public class VerificationServerProtocol {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public static Date strToDate(String date) throws ParseException {
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
|
||||
return new Date(formatter.parse(date).getTime());
|
||||
|
|
@ -186,4 +188,4 @@ public class VerificationServerProtocol {
|
|||
return new GsonBuilder().create();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -19,15 +19,11 @@ import android.view.LayoutInflater
|
|||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Toast
|
||||
import com.android.volley.BuildConfig
|
||||
import com.google.zxing.WriterException
|
||||
import com.tangem.data.network.VolleyHelper
|
||||
import com.tangem.data.network.model.CardVerifyModel
|
||||
import com.tangem.data.network.ServerApiHelper
|
||||
import com.tangem.data.network.request.ElectrumRequest
|
||||
import com.tangem.data.network.request.ExchangeRequest
|
||||
import com.tangem.data.network.request.InfuraRequest
|
||||
import com.tangem.data.network.request.VerificationServerProtocol
|
||||
import com.tangem.data.network.task.VerificationServerTask
|
||||
import com.tangem.data.network.task.loaded_wallet.ETHRequestTask
|
||||
import com.tangem.data.network.task.loaded_wallet.RateInfoTask
|
||||
import com.tangem.data.network.task.loaded_wallet.UpdateWalletInfoTask
|
||||
|
|
@ -45,21 +41,7 @@ import com.tangem.wallet.R
|
|||
import kotlinx.android.synthetic.main.fr_loaded_wallet.*
|
||||
import java.util.*
|
||||
|
||||
class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notifications, VolleyHelper.IRequestCardVerify, SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
|
||||
if (BuildConfig.DEBUG && this@LoadedWallet.isAdded) {
|
||||
debugNewRequestVerify = sharedPreferences!!.getBoolean(getString(R.string.key_debug_new_request_verify), false)
|
||||
debugNewRequestVerifyShowJson = sharedPreferences.getBoolean(getString(R.string.key_debug_new_request_verify_show_json), false)
|
||||
}
|
||||
}
|
||||
|
||||
override fun success(cardVerifyModel: CardVerifyModel) {
|
||||
// Toast.makeText(activity, cardVerifyModel.results!![1].CID, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
override fun error(error: String) {
|
||||
|
||||
}
|
||||
class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notifications, SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
|
||||
companion object {
|
||||
val TAG: String = LoadedWallet::class.java.simpleName
|
||||
|
|
@ -72,13 +54,13 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
private const val REQUEST_CODE_ENTER_NEW_PIN2 = 6
|
||||
private const val REQUEST_CODE_REQUEST_PIN2_FOR_SWAP_PIN = 7
|
||||
private const val REQUEST_CODE_SWAP_PIN = 8
|
||||
|
||||
// private const val URL_CARD_VERIFY = Server.API.Method.VERIFY
|
||||
}
|
||||
|
||||
private var singleToast: Toast? = null
|
||||
private var nfcManager: NfcManager? = null
|
||||
private var volleyHelper: VolleyHelper? = null
|
||||
|
||||
private var serverApiHelper: ServerApiHelper? = null
|
||||
|
||||
var card: TangemCard? = null
|
||||
private var lastTag: Tag? = null
|
||||
|
||||
|
|
@ -92,65 +74,19 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
private var newPIN2 = ""
|
||||
private var cardProtocol: CardProtocol? = null
|
||||
|
||||
private var onlineVerifyTask: OnlineVerifyTask? = null
|
||||
|
||||
private var sp: SharedPreferences? = null
|
||||
private var debugNewRequestVerify: Boolean = false
|
||||
private var debugNewRequestVerifyShowJson: Boolean = false
|
||||
|
||||
private inner class OnlineVerifyTask : VerificationServerTask() {
|
||||
|
||||
override fun onPostExecute(requests: List<VerificationServerProtocol.Request>) {
|
||||
super.onPostExecute(requests)
|
||||
onlineVerifyTask = null
|
||||
|
||||
for (request in requests) {
|
||||
if (request.error == null) {
|
||||
val answer = request.answer as VerificationServerProtocol.Verify.Answer
|
||||
if (answer.error == null) {
|
||||
card!!.isOnlineVerified = answer.results[0].passed
|
||||
// Log.i(TAG, "isOnlineVerified = " + answer.results[0].passed)
|
||||
} else {
|
||||
card!!.isOnlineVerified = null
|
||||
// Log.i(TAG, "isOnlineVerified = null")
|
||||
}
|
||||
} else {
|
||||
card!!.isOnlineVerified = null
|
||||
}
|
||||
}
|
||||
srlLoadedWallet!!.isRefreshing = false
|
||||
}
|
||||
}
|
||||
|
||||
private fun requestVerify() {
|
||||
if ((card!!.isOnlineVerified == null || !card!!.isOnlineVerified) && onlineVerifyTask == null) {
|
||||
if (debugNewRequestVerify) {
|
||||
volleyHelper!!.requestCardVerify(card!!)
|
||||
|
||||
if (debugNewRequestVerifyShowJson)
|
||||
this.activity?.let { volleyHelper!!.requestCardVerifyShowResponse(it, card!!) }
|
||||
|
||||
} else {
|
||||
onlineVerifyTask = OnlineVerifyTask()
|
||||
onlineVerifyTask!!.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, VerificationServerProtocol.Verify.prepare(card))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
sp = PreferenceManager.getDefaultSharedPreferences(activity)
|
||||
nfcManager = NfcManager(activity, this)
|
||||
|
||||
serverApiHelper = ServerApiHelper()
|
||||
|
||||
card = TangemCard(activity!!.intent.getStringExtra(TangemCard.EXTRA_CARD))
|
||||
card!!.loadFromBundle(activity!!.intent.extras.getBundle(TangemCard.EXTRA_CARD))
|
||||
|
||||
lastTag = activity!!.intent.getParcelableExtra(MainActivity.EXTRA_LAST_DISCOVERED_TAG)
|
||||
|
||||
volleyHelper = VolleyHelper(this)
|
||||
|
||||
debugNewRequestVerify = sp!!.getBoolean(getString(R.string.key_debug_new_request_verify), false)
|
||||
debugNewRequestVerifyShowJson = sp!!.getBoolean(getString(R.string.key_debug_new_request_verify_show_json), false)
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
|
|
@ -183,7 +119,7 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
srlLoadedWallet!!.postDelayed({ this.refresh() }, 1000)
|
||||
}
|
||||
|
||||
requestVerify()
|
||||
// requestCardVerify()
|
||||
|
||||
startVerify(lastTag)
|
||||
|
||||
|
|
@ -238,6 +174,18 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
startActivityForResult(intent, REQUEST_CODE_SEND_PAYMENT)
|
||||
}
|
||||
}
|
||||
|
||||
// request card verify listener
|
||||
serverApiHelper!!.setCardVerify {
|
||||
card!!.isOnlineVerified = it.results!![0].passed
|
||||
srlLoadedWallet!!.isRefreshing = false
|
||||
// Log.i(TAG, "setCardVerify " + it.results!![0].passed)
|
||||
}
|
||||
}
|
||||
|
||||
private fun requestCardVerify() {
|
||||
if ((card!!.isOnlineVerified == null || !card!!.isOnlineVerified))
|
||||
serverApiHelper!!.cardVerify(card)
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
|
|
@ -485,6 +433,10 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
WaitSecurityDelayDialog.onReadAfterRequest(activity!!)
|
||||
}
|
||||
|
||||
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
|
||||
|
||||
}
|
||||
|
||||
fun updateViews() {
|
||||
try {
|
||||
if (timerHideErrorAndMessage != null) {
|
||||
|
|
@ -567,7 +519,7 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
|
||||
val engine = CoinEngineFactory.create(card!!.blockchain)
|
||||
|
||||
requestVerify()
|
||||
requestCardVerify()
|
||||
|
||||
// Bitcoin
|
||||
if (card!!.blockchain == Blockchain.Bitcoin || card!!.blockchain == Blockchain.BitcoinTestNet) {
|
||||
|
|
|
|||
|
|
@ -11,12 +11,6 @@ class SettingsDebug : PreferenceFragment() {
|
|||
super.onCreate(savedInstanceState)
|
||||
addPreferencesFromResource(R.xml.fr_settings_debug)
|
||||
|
||||
val debug_new_request_verify = findPreference(getString(R.string.key_debug_new_request_verify)) as SwitchPreference
|
||||
val debug_new_request_verify_show_json = findPreference(getString(R.string.key_debug_new_request_verify_show_json)) as SwitchPreference
|
||||
|
||||
debug_new_request_verify.title = "Новый запрос verify card"
|
||||
debug_new_request_verify_show_json.title = "Показать ответ"
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
<resources>
|
||||
|
||||
<string name="key_debug_new_request_verify" translatable="false">debug_new_request_verify</string>
|
||||
<string name="key_debug_new_request_verify_show_json" translatable="false">debug_new_request_verify_show_json</string>
|
||||
|
||||
</resources>
|
||||
|
|
@ -1,14 +1,13 @@
|
|||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<PreferenceCategory
|
||||
android:title="">
|
||||
<PreferenceCategory android:title="">
|
||||
<SwitchPreference
|
||||
android:key="debug_new_request_verify"
|
||||
android:summary=""/>
|
||||
android:key="debug_switch_1"
|
||||
android:summary="" />
|
||||
|
||||
<SwitchPreference
|
||||
android:key="debug_new_request_verify_show_json"
|
||||
android:summary=""/>
|
||||
android:key="debug_switch_2"
|
||||
android:summary="" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue