Updated on 2026-08-14
This commit is contained in:
parent
9d36a97fd9
commit
4d36c61c78
9 changed files with 78 additions and 43 deletions
|
|
@ -21,7 +21,7 @@ public class PINStorage {
|
|||
private static String mSavedPIN, mUserPIN, mLastUsedPIN, mEncryptedPIN, mPIN2;
|
||||
private static SharedPreferences sharedPreferences = null;
|
||||
|
||||
public static void Init(Context context) {
|
||||
public static void init(Context context) {
|
||||
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
mSavedPIN = sharedPreferences.getString("SavedPIN", null);
|
||||
mUserPIN = null;
|
||||
|
|
|
|||
|
|
@ -1,17 +1,18 @@
|
|||
package com.tangem.di
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.nfc.Tag
|
||||
import android.os.Bundle
|
||||
import com.tangem.domain.wallet.TangemCard
|
||||
import com.tangem.presentation.activity.EmptyWalletActivity
|
||||
import com.tangem.presentation.activity.LoadedWalletActivity
|
||||
|
||||
import com.tangem.presentation.activity.MainActivity
|
||||
import com.tangem.presentation.activity.VerifyCardActivity
|
||||
import com.tangem.presentation.fragment.LoadedWallet
|
||||
|
||||
class Navigator {
|
||||
|
||||
fun showMain(context: Context) {
|
||||
fun showMain(context: Activity) {
|
||||
context.startActivity(MainActivity.callingIntent(context))
|
||||
}
|
||||
|
||||
|
|
@ -23,13 +24,15 @@ class Navigator {
|
|||
context.startActivity(EmptyWalletActivity.callingIntent(context))
|
||||
}
|
||||
|
||||
fun showVerifyCard(context: Context) {
|
||||
fun showVerifyCard(context: Activity, card: TangemCard) {
|
||||
context.startActivityForResult(VerifyCardActivity.callingIntent(context, card), LoadedWallet.REQUEST_CODE_VERIFY_CARD)
|
||||
}
|
||||
|
||||
fun showPreparePayment(context: Activity) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
fun showCreateNewWallet(context: Context) {
|
||||
fun showCreateNewWallet(context: Activity) {
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
package com.tangem.di;
|
||||
|
||||
import com.tangem.presentation.activity.EmptyWalletActivity;
|
||||
import com.tangem.presentation.activity.LoadedWalletActivity;
|
||||
import com.tangem.presentation.activity.LogoActivity;
|
||||
import com.tangem.presentation.activity.MainActivity;
|
||||
import com.tangem.presentation.activity.VerifyCardActivity;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
|
|
@ -18,6 +20,10 @@ public interface NavigatorComponent {
|
|||
|
||||
void inject(MainActivity activity);
|
||||
|
||||
void inject(LoadedWalletActivity activity);
|
||||
|
||||
void inject(VerifyCardActivity activity);
|
||||
|
||||
void inject(EmptyWalletActivity activity);
|
||||
|
||||
}
|
||||
|
|
@ -13,14 +13,14 @@ import java.io.InputStreamReader;
|
|||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class FW {
|
||||
private static JsonArray jaFirmwares=null;
|
||||
private static JsonArray jaFirmwares = null;
|
||||
|
||||
public static boolean needInit() {
|
||||
return jaFirmwares == null;
|
||||
}
|
||||
|
||||
public static void Init(Context context) {
|
||||
try(InputStream is=context.getAssets().open("fw_hashes.json")) {
|
||||
public static void init(Context context) {
|
||||
try (InputStream is = context.getAssets().open("fw_hashes.json")) {
|
||||
try (InputStreamReader reader = new InputStreamReader(is, StandardCharsets.UTF_8)) {
|
||||
JsonParser parser = new JsonParser();
|
||||
jaFirmwares = parser.parse(reader).getAsJsonArray();
|
||||
|
|
@ -30,8 +30,7 @@ public class FW {
|
|||
}
|
||||
}
|
||||
|
||||
public static class VerifyCodeRecord
|
||||
{
|
||||
public static class VerifyCodeRecord {
|
||||
public String hashAlg;
|
||||
public int blockIndex;
|
||||
public int blockCount;
|
||||
|
|
@ -57,9 +56,7 @@ public class FW {
|
|||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -59,20 +59,20 @@ public class Issuer {
|
|||
return id;
|
||||
}
|
||||
|
||||
private static List<Issuer> instances=new ArrayList<>();
|
||||
private static List<Issuer> instances = new ArrayList<>();
|
||||
|
||||
public static boolean needInit() {
|
||||
return instances.size() == 0;
|
||||
}
|
||||
|
||||
public static void Init(Context context) {
|
||||
public static void init(Context context) {
|
||||
try {
|
||||
Issuer unknown = new Issuer();
|
||||
unknown.id = "UNKNOWN";
|
||||
unknown.officialName = "UNKNOWN";
|
||||
|
||||
try(InputStream is=context.getAssets().open("issuers.json")) {
|
||||
try ( InputStreamReader reader = new InputStreamReader(is, StandardCharsets.UTF_8)) {
|
||||
try (InputStream is = context.getAssets().open("issuers.json")) {
|
||||
try (InputStreamReader reader = new InputStreamReader(is, StandardCharsets.UTF_8)) {
|
||||
Type listType = new TypeToken<List<Issuer>>() {
|
||||
}.getType();
|
||||
instances = new Gson().fromJson(reader, listType);
|
||||
|
|
|
|||
|
|
@ -6,11 +6,17 @@ import android.nfc.NfcAdapter
|
|||
import android.nfc.Tag
|
||||
import android.os.Bundle
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import com.tangem.App
|
||||
import com.tangem.di.Navigator
|
||||
import com.tangem.presentation.fragment.LoadedWallet
|
||||
import com.tangem.wallet.R
|
||||
import javax.inject.Inject
|
||||
|
||||
class LoadedWalletActivity : AppCompatActivity() {
|
||||
|
||||
@Inject
|
||||
lateinit var navigator: Navigator
|
||||
|
||||
companion object {
|
||||
fun callingIntent(context: Context, lastTag: Tag, cardInfo: Bundle): Intent {
|
||||
val intent = Intent(context, LoadedWalletActivity::class.java)
|
||||
|
|
@ -24,6 +30,8 @@ class LoadedWalletActivity : AppCompatActivity() {
|
|||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_loaded_wallet)
|
||||
|
||||
App.getNavigatorComponent().inject(this)
|
||||
|
||||
MainActivity.commonInit(applicationContext)
|
||||
|
||||
if (intent.extras!!.containsKey(NfcAdapter.EXTRA_TAG)) {
|
||||
|
|
|
|||
|
|
@ -63,13 +63,13 @@ class MainActivity : AppCompatActivity(), NfcAdapter.ReaderCallback, CardProtoco
|
|||
|
||||
fun commonInit(context: Context) {
|
||||
if (PINStorage.needInit())
|
||||
PINStorage.Init(context)
|
||||
PINStorage.init(context)
|
||||
|
||||
if (Issuer.needInit())
|
||||
Issuer.Init(context)
|
||||
Issuer.init(context)
|
||||
|
||||
if (FW.needInit())
|
||||
FW.Init(context)
|
||||
FW.init(context)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,15 +1,36 @@
|
|||
package com.tangem.presentation.activity
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import com.tangem.App
|
||||
import com.tangem.di.Navigator
|
||||
import com.tangem.domain.wallet.TangemCard
|
||||
import com.tangem.presentation.fragment.VerifyCard
|
||||
import com.tangem.wallet.R
|
||||
import javax.inject.Inject
|
||||
|
||||
class VerifyCardActivity : AppCompatActivity() {
|
||||
|
||||
@Inject
|
||||
lateinit var navigator: Navigator
|
||||
|
||||
companion object {
|
||||
fun callingIntent(context: Context, card: TangemCard): Intent {
|
||||
val intent = Intent(context, VerifyCardActivity::class.java)
|
||||
intent.putExtra(TangemCard.EXTRA_UID, card.uid)
|
||||
intent.putExtra(TangemCard.EXTRA_CARD, card.asBundle)
|
||||
return intent
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_verify_card)
|
||||
|
||||
App.getNavigatorComponent().inject(this)
|
||||
|
||||
MainActivity.commonInit(applicationContext)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import com.tangem.data.network.ServerApiInfura
|
|||
import com.tangem.data.network.model.CardVerifyAndGetInfo
|
||||
import com.tangem.data.network.model.InfuraResponse
|
||||
import com.tangem.data.nfc.VerifyCardTask
|
||||
import com.tangem.di.Navigator
|
||||
import com.tangem.domain.cardReader.CardProtocol
|
||||
import com.tangem.domain.cardReader.NfcManager
|
||||
import com.tangem.domain.wallet.*
|
||||
|
|
@ -49,12 +50,13 @@ import org.json.JSONException
|
|||
import java.io.InputStream
|
||||
import java.math.BigInteger
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
|
||||
class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notifications, SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
companion object {
|
||||
val TAG: String = LoadedWallet::class.java.simpleName
|
||||
private const val REQUEST_CODE_SEND_PAYMENT = 1
|
||||
private const val REQUEST_CODE_VERIFY_CARD = 4
|
||||
const val REQUEST_CODE_VERIFY_CARD = 4
|
||||
private const val REQUEST_CODE_PURGE = 2
|
||||
private const val REQUEST_CODE_REQUEST_PIN2_FOR_PURGE = 3
|
||||
private const val REQUEST_CODE_ENTER_NEW_PIN = 5
|
||||
|
|
@ -191,13 +193,12 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
btnDetails.setOnClickListener {
|
||||
if (cardProtocol != null)
|
||||
openVerifyCard(cardProtocol!!)
|
||||
// (activity as LoadedWalletActivity).navigator.showVerifyCard(activity, ctx.card)
|
||||
|
||||
else
|
||||
showSingleToast(R.string.need_attach_card_again)
|
||||
}
|
||||
btnScanAgain.setOnClickListener {
|
||||
val intent = Intent(activity, MainActivity::class.java)
|
||||
startActivity(intent)
|
||||
}
|
||||
btnScanAgain.setOnClickListener { (activity as LoadedWalletActivity).navigator.showMain(activity) }
|
||||
btnExtract.setOnClickListener {
|
||||
val engine = CoinEngineFactory.create(ctx)
|
||||
if (UtilHelper.isOnline(activity)) {
|
||||
|
|
@ -625,9 +626,9 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
}
|
||||
REQUEST_CODE_SEND_PAYMENT, REQUEST_CODE_RECEIVE_PAYMENT -> {
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
ctx.coinData!!.clearInfo()
|
||||
srl!!.postDelayed({ this.refresh() }, 5000)
|
||||
srl!!.isRefreshing = true
|
||||
ctx.coinData?.clearInfo()
|
||||
srl?.postDelayed({ this.refresh() }, 5000)
|
||||
srl?.isRefreshing = true
|
||||
updateViews()
|
||||
}
|
||||
|
||||
|
|
@ -807,19 +808,19 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
|
||||
requestVerifyAndGetInfo()
|
||||
|
||||
// Bitcoin
|
||||
if (ctx.blockchain == Blockchain.Bitcoin || ctx.blockchain == Blockchain.BitcoinTestNet) {
|
||||
ctx.coinData.setIsBalanceEqual(true)
|
||||
// Bitcoin
|
||||
if (ctx.blockchain == Blockchain.Bitcoin || ctx.blockchain == Blockchain.BitcoinTestNet) {
|
||||
ctx.coinData.setIsBalanceEqual(true)
|
||||
|
||||
requestElectrum(ElectrumRequest.checkBalance(ctx.card!!.wallet))
|
||||
requestElectrum(ElectrumRequest.listUnspent(ctx.card!!.wallet))
|
||||
requestRateInfo("bitcoin")
|
||||
}
|
||||
|
||||
// BitcoinCash
|
||||
else if (ctx.blockchain == Blockchain.BitcoinCash) {
|
||||
ctx.coinData.setIsBalanceEqual(true)
|
||||
val engine = CoinEngineFactory.create(ctx)
|
||||
// BitcoinCash
|
||||
else if (ctx.blockchain == Blockchain.BitcoinCash) {
|
||||
ctx.coinData.setIsBalanceEqual(true)
|
||||
val engine = CoinEngineFactory.create(ctx)
|
||||
|
||||
requestElectrum(ElectrumRequest.checkBalance((engine as BtcCashEngine).convertToLegacyAddress(ctx.card!!.wallet)))
|
||||
requestElectrum(ElectrumRequest.listUnspent((engine as BtcCashEngine).convertToLegacyAddress(ctx.card!!.wallet)))
|
||||
|
|
@ -843,11 +844,11 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
}
|
||||
|
||||
private fun requestElectrum(electrumRequest: ElectrumRequest) {
|
||||
if (UtilHelper.isOnline(activity!!)) {
|
||||
if (UtilHelper.isOnline(activity)) {
|
||||
requestCounter++
|
||||
serverApiElectrum.electrumRequestData(ctx.card, electrumRequest)
|
||||
} else {
|
||||
Toast.makeText(activity!!, getString(R.string.no_connection), Toast.LENGTH_SHORT).show()
|
||||
Toast.makeText(activity, getString(R.string.no_connection), Toast.LENGTH_SHORT).show()
|
||||
srl?.isRefreshing = false
|
||||
}
|
||||
}
|
||||
|
|
@ -902,11 +903,10 @@ class LoadedWallet : Fragment(), NfcAdapter.ReaderCallback, CardProtocol.Notific
|
|||
// Log.v(TAG, "UID: $sUID")
|
||||
}
|
||||
|
||||
if (lastReadSuccess) {
|
||||
if (lastReadSuccess)
|
||||
isoDep.timeout = 1000
|
||||
} else {
|
||||
else
|
||||
isoDep.timeout = 65000
|
||||
}
|
||||
|
||||
verifyCardTask = VerifyCardTask(activity, ctx.card, nfcManager, isoDep, this)
|
||||
verifyCardTask!!.start()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue