Updated on 2026-08-14
This commit is contained in:
parent
56fc4cad76
commit
80b3aba688
5 changed files with 87 additions and 29 deletions
|
|
@ -21,6 +21,7 @@ public class Server {
|
|||
public static final String INFO_VERIFY = URL_TANGEM + "info/version";
|
||||
|
||||
public static final String CARD_VERIFY = URL_TANGEM + "card/verify";
|
||||
public static final String VERIFY = URL_TANGEM + "verify";
|
||||
public static final String CARD_VALIDATE = URL_TANGEM + "card/validate";
|
||||
public static final String CARD_ACTIVATE = URL_TANGEM + "card/activate";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
package com.tangem.data.network;
|
||||
|
||||
public class ServerURL {
|
||||
public static final String API_TANGEM = "https://tangem-webapp.appspot.com/";
|
||||
// public static final String API_TANGEM = "https://tangem-webapp.appspot.com/";
|
||||
public static final String API_TANGEM = "https://verify.tangem.com/";
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,29 +9,46 @@ 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.GsonBuilder
|
||||
import com.google.gson.JsonParser
|
||||
import com.google.gson.Gson
|
||||
import com.tangem.AppController
|
||||
import com.tangem.data.network.model.ResponseVerify
|
||||
import com.tangem.domain.wallet.TangemCard
|
||||
import com.tangem.presentation.fragment.LoadedWallet
|
||||
import com.tangem.util.Util
|
||||
import com.tangem.wallet.R
|
||||
import java.util.HashMap
|
||||
|
||||
class VolleyHelper {
|
||||
class VolleyHelper (private val requestCardVerify: IRequestCardVerify){
|
||||
|
||||
interface IRequestCardVerify {
|
||||
|
||||
fun success(responseVerify: ResponseVerify)
|
||||
|
||||
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.API.Method.VERIFY, params)
|
||||
}
|
||||
|
||||
fun doRequestDebug(context: Context, url: String, params: Map<String, String>) {
|
||||
val stringRequest = object : StringRequest(Request.Method.POST, url,
|
||||
val stringRequest = object : StringRequest(Request.Method.GET, url,
|
||||
{ response ->
|
||||
val data = GsonBuilder().setPrettyPrinting().create().toJson(JsonParser().parse(response))
|
||||
// Log.i(LoadedWallet.TAG, response.toString())
|
||||
val builder = AlertDialog.Builder(context)
|
||||
builder.setTitle(url)
|
||||
.setMessage(data)
|
||||
.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, data)
|
||||
context.startActivity(Intent.createChooser(intent, "Send gson"))
|
||||
intent.putExtra(Intent.EXTRA_TEXT, response.toString())
|
||||
context.startActivity(Intent.createChooser(intent, "Send json"))
|
||||
}
|
||||
val alert = builder.create()
|
||||
alert.show()
|
||||
|
|
@ -54,15 +71,19 @@ class VolleyHelper {
|
|||
AppController.getInstance().addToRequestQueue(stringRequest)
|
||||
}
|
||||
|
||||
fun doRequestString(context: Context, url: String, params: Map<String, String>) {
|
||||
val stringRequest = object : StringRequest(Request.Method.POST, url,
|
||||
private fun doRequestString(url: String, params: Map<String, String>) {
|
||||
val stringRequest = object : StringRequest(Request.Method.GET, url,
|
||||
Response.Listener<String> { response ->
|
||||
// val json = String(response)
|
||||
Log.i(LoadedWallet.TAG, response)
|
||||
val requestResponse = response.toString().substring(response.toString().lastIndexOf("Response:") + 10)
|
||||
|
||||
val responseVerify = Gson().fromJson(requestResponse, ResponseVerify::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()
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
package com.tangem.data.network.model
|
||||
|
||||
import com.google.gson.annotations.SerializedName
|
||||
|
||||
data class ResponseVerify(
|
||||
@SerializedName("results")
|
||||
var results: ArrayList<Verify>? = null,
|
||||
|
||||
@SerializedName("error")
|
||||
var error: String? = null
|
||||
) {
|
||||
|
||||
data class Verify(
|
||||
@SerializedName("error")
|
||||
var error: String = "",
|
||||
|
||||
@SerializedName("CID")
|
||||
var CID: String = "",
|
||||
|
||||
@SerializedName("passed")
|
||||
var passed: Boolean? = null
|
||||
)
|
||||
|
||||
}
|
||||
|
|
@ -16,6 +16,7 @@ import android.support.v4.app.Fragment
|
|||
import android.support.v4.content.ContextCompat
|
||||
import android.support.v4.widget.SwipeRefreshLayout
|
||||
import android.text.Html
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
|
|
@ -23,6 +24,7 @@ import android.widget.Toast
|
|||
import com.google.zxing.WriterException
|
||||
import com.tangem.data.network.Server
|
||||
import com.tangem.data.network.VolleyHelper
|
||||
import com.tangem.data.network.model.ResponseVerify
|
||||
import com.tangem.data.network.request.ElectrumRequest
|
||||
import com.tangem.data.network.request.ExchangeRequest
|
||||
import com.tangem.data.network.request.InfuraRequest
|
||||
|
|
@ -45,7 +47,15 @@ import com.tangem.wallet.R
|
|||
import kotlinx.android.synthetic.main.fr_loaded_wallet.*
|
||||
import java.util.*
|
||||
|
||||
class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notifications {
|
||||
class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notifications, VolleyHelper.IRequestCardVerify {
|
||||
|
||||
override fun success(responseVerify: ResponseVerify) {
|
||||
Toast.makeText(activity, responseVerify.results!![1].CID, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
override fun error(error: String) {
|
||||
|
||||
}
|
||||
|
||||
companion object {
|
||||
val TAG: String = LoadedWallet::class.java.simpleName
|
||||
|
|
@ -59,11 +69,12 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
private const val REQUEST_CODE_REQUEST_PIN2_FOR_SWAP_PIN = 7
|
||||
private const val REQUEST_CODE_SWAP_PIN = 8
|
||||
|
||||
private const val URL_CARD_VALIDATE = Server.API.Method.CARD_VALIDATE
|
||||
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
|
||||
var card: TangemCard? = null
|
||||
private var lastTag: Tag? = null
|
||||
|
||||
|
|
@ -90,8 +101,10 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
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
|
||||
|
|
@ -101,11 +114,13 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
}
|
||||
}
|
||||
|
||||
private fun requestCardValidate() {
|
||||
val params = HashMap<String, String>()
|
||||
params["CID"] = Util.bytesToHex(card!!.cid)
|
||||
params["publicKey"] = Util.bytesToHex(card!!.cardPublicKey)
|
||||
VolleyHelper().doRequestString(context!!, URL_CARD_VALIDATE, params)
|
||||
private fun requestVerify() {
|
||||
if ((card!!.isOnlineVerified == null || !card!!.isOnlineVerified) && onlineVerifyTask == null) {
|
||||
onlineVerifyTask = OnlineVerifyTask()
|
||||
onlineVerifyTask!!.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, VerificationServerProtocol.Verify.prepare(card))
|
||||
|
||||
// volleyHelper!!.requestCardVerify(card!!)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
|
|
@ -116,6 +131,8 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
card!!.loadFromBundle(activity!!.intent.extras.getBundle(TangemCard.EXTRA_CARD))
|
||||
|
||||
lastTag = activity!!.intent.getParcelableExtra(MainActivity.EXTRA_LAST_DISCOVERED_TAG)
|
||||
|
||||
volleyHelper = VolleyHelper(this)
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
|
|
@ -150,10 +167,7 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
srlLoadedWallet!!.postDelayed({ this.refresh() }, 1000)
|
||||
}
|
||||
|
||||
if ((card!!.isOnlineVerified == null || !card!!.isOnlineVerified) && onlineVerifyTask == null) {
|
||||
onlineVerifyTask = OnlineVerifyTask()
|
||||
onlineVerifyTask!!.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, VerificationServerProtocol.Verify.prepare(card))
|
||||
}
|
||||
requestVerify()
|
||||
|
||||
startVerify(lastTag)
|
||||
|
||||
|
|
@ -408,10 +422,7 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
|
||||
val engine = CoinEngineFactory.create(card!!.blockchain)
|
||||
|
||||
if ((card!!.isOnlineVerified == null || !card!!.isOnlineVerified) && onlineVerifyTask == null) {
|
||||
onlineVerifyTask = OnlineVerifyTask()
|
||||
onlineVerifyTask!!.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, VerificationServerProtocol.Verify.prepare(card))
|
||||
}
|
||||
requestVerify()
|
||||
|
||||
if (card!!.blockchain == Blockchain.Bitcoin || card!!.blockchain == Blockchain.BitcoinTestNet) {
|
||||
val data = SharedData(SharedData.COUNT_REQUEST)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue