Updated on 2026-08-14

This commit is contained in:
Tangem 2018-07-17 17:21:56 +03:00
commit aad7f48601
5 changed files with 44 additions and 55 deletions

25
.idea/misc.xml generated
View file

@ -1,30 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="NullableNotNullManager">
<option name="myDefaultNullable" value="android.support.annotation.Nullable" />
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
<option name="myNullables">
<value>
<list size="5">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
<item index="2" class="java.lang.String" itemvalue="javax.annotation.CheckForNull" />
<item index="3" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
<item index="4" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
</list>
</value>
</option>
<option name="myNotNulls">
<value>
<list size="4">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
</list>
</value>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>

View file

@ -1,5 +1,7 @@
package com.tangem.domain.wallet;
import com.tangem.wallet.R;
public class BalanceValidator {
private String firstLine;
private String secondLine;
@ -17,36 +19,39 @@ public class BalanceValidator {
return score + "% safe. " + secondLine;
}
}
public int GetColor() {
if (score>89) { return R.color.msg_okay;}
else if (score>74) { return android.R.color.holo_orange_light;}
else if (score>0) { return android.R.color.holo_orange_dark;}
else { return android.R.color.holo_red_light;}
}
public void Check(TangemCard card)
{
String defaultFirstLine = "Unknown balance";
String successFirstLine = "Verified balance";
firstLine = successFirstLine;
firstLine = "Verification failed";
secondLine = "";
// rule 1
if(!CheckOfflineBalance(card) && !CheckOnlineBalance(card)) {
score = 0;
secondLine = "Balance cannot be verified.";
firstLine = defaultFirstLine;
firstLine = "Unknown balance";
secondLine = "Balance cannot be verified. Swipe down to refresh.";
return;
}
// rule 2.a
if(!VerificationWalletKey(card)) {
score = 0;
secondLine = "Wallet verification failed.";
firstLine = defaultFirstLine;
firstLine = "Verification failed";
secondLine = "Wallet verification failed. Tap again.";
return;
}
// rule 2.c
if(!CheckAttestationServiceResult(card)) {
if(!CheckAttestationServiceResult(card) && CheckAttestationServiceAvailable(card)) {
score = 0;
secondLine = "Do not accept. Tangem Attestation service says card is not genuine. ";
firstLine = successFirstLine;
firstLine = "Not genuine banknote";
secondLine = "Tangem Attestation service says the banknote is not genuine.";
return;
}
@ -56,17 +61,20 @@ public class BalanceValidator {
if(card.isBalanceRecieved() && card.isBalanceEqual()) {
score = 100;
firstLine = "Verified balance";
secondLine += " Confirmed balance and banknote identity. ";
secondLine += "Confirmed balance and banknote identity. ";
if(card.getBalance() == 0) {
firstLine = "Zero balance";
}
}
if(card.getFailedBalanceRequestCounter()!=0) {
score = 100 - 5 * card.getFailedBalanceRequestCounter();
firstLine = "Verified balance";
secondLine += "Not all nodes have returned balance. Swipe down to refresh. ";
score -= 5 * card.getFailedBalanceRequestCounter();
secondLine += "Not all nodes have returned balance. Swipe down or tap again. ";
if(score <= 0)
return;
}
//
//
// if(card.isBalanceRecieved() && !card.isBalanceEqual()) {
// score = 0;
// firstLine = "Disputed balance";
@ -78,9 +86,9 @@ public class BalanceValidator {
// rule 7
if(CheckOfflineBalance(card) && !CheckOnlineBalance(card))
{
score -= 10;
String firstLine = "Verified offline balance";
secondLine += "Restore internet connection to be more confidient. ";
score = 90;
firstLine = "Verified offline balance";
secondLine += "Restore internet connection to be more confident. ";
if(score <= 0)
return;
}
@ -90,7 +98,6 @@ public class BalanceValidator {
{
score -= 15;
secondLine += "Card identity was not verified. Cannot reach attestation service. ";
firstLine = successFirstLine;
if(score <= 0)
return;
}
@ -99,7 +106,7 @@ public class BalanceValidator {
if(IsLostSecondRead(card))
{
score -= 30;
secondLine += "Wallet and banknote keys were not verified (tap again). ";
secondLine += "Wallet and banknote keys were not verified. Tap again. ";
if(score <= 0)
return;
}
@ -108,8 +115,8 @@ public class BalanceValidator {
if(!CheckSignHashes(card))
{
score -= 50;
secondLine = "Unguaranteed balance";
firstLine += "Potential unsent transaction at the moment. Try to tap and check this banknote later. ";
firstLine = "Unguaranteed balance";
secondLine += "Potential unsent transaction at the moment. Try to tap and check this banknote later. ";
if(score <= 0)
return;
}

View file

@ -100,7 +100,7 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre
private Timer timerHideErrorAndMessage = null;
private String newPIN = "", newPIN2 = "";
private CardProtocol mCardProtocol;
private int scanTimes = 0;
// private int scanTimes = 0;
OnlineVerifyTask onlineVerifyTask;
public LoadedWallet() {
@ -254,7 +254,7 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre
if (mCardProtocol != null)
openVerifyCard(mCardProtocol);
else {
scanTimes++;
// scanTimes++;
Toast.makeText(getContext(), R.string.need_attach_card_again, Toast.LENGTH_LONG).show();
}
});
@ -508,8 +508,13 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre
CoinEngine engine = CoinEngineFactory.Create(mCard.getBlockchain());
if ( (mCard.isOnlineVerified()==null || !mCard.isOnlineVerified()) && onlineVerifyTask ==null) {
onlineVerifyTask = new OnlineVerifyTask();
// updateTasks.add(onlineVerifyTask);
onlineVerifyTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, VerificationServerProtocol.Verify.prepare(mCard));
}
if (mCard.getBlockchain() == Blockchain.Bitcoin || mCard.getBlockchain() == Blockchain.BitcoinTestNet) {
mCard.resetFailedBalanceRequestCounter();
SharedData data = new SharedData(SharedData.COUNT_REQUEST);
mCard.resetFailedBalanceRequestCounter();
mCard.setIsBalanceEqual(true);
@ -634,11 +639,12 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre
mCardProtocol = cardProtocol;
// Log.i(TAG, "scanTimes " + scanTimes);
if (scanTimes > 0)
openVerifyCard(mCardProtocol);
// if (scanTimes > 0)
// openVerifyCard(mCardProtocol);
scanTimes++;
// scanTimes++;
onRefresh();
//addCard(cardProtocol.getCard());
});
@ -744,6 +750,7 @@ public class LoadedWallet extends Fragment implements SwipeRefreshLayout.OnRefre
validator.Check(mCard);
tvBalanceLine1.setText(validator.GetFirstLine());
tvBalanceLine2.setText(validator.GetSecondLine());
tvBalanceLine1.setTextColor(ContextCompat.getColor(Objects.requireNonNull(getContext()),validator.GetColor()));
}
if (engine.HasBalanceInfo(mCard) || mCard.getOfflineBalance() == null) {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 104 KiB

After

Width:  |  Height:  |  Size: 96 KiB

Before After
Before After

View file

@ -142,7 +142,7 @@
android:layout_marginTop="5dp"
android:fontFamily="@font/montserrat_light"
android:textAlignment="center"
android:textColor="@color/msg_okay"
android:textColor="@android:color/holo_orange_dark"
android:textSize="18sp" />
<TextView