Updated on 2026-08-14
This commit is contained in:
parent
8a0b654663
commit
7ab858de77
20 changed files with 129 additions and 133 deletions
|
|
@ -1,15 +1,17 @@
|
|||
package com.tangem.domain.wallet;
|
||||
package com.tangem.data.network.request;
|
||||
|
||||
/**
|
||||
* Created by Ilia on 19.12.2017.
|
||||
*/
|
||||
|
||||
import com.tangem.domain.wallet.Blockchain;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
|
||||
public class Infura_Request {
|
||||
public class InfuraRequest {
|
||||
public static final String METHOD_ETH_GetBalance = "eth_getBalance";
|
||||
public static final String METHOD_ETH_GetOutTransactionCount = "eth_getTransactionCount";
|
||||
public static final String METHOD_ETH_GetGasPrice = "eth_gasPrice";
|
||||
|
|
@ -33,10 +35,10 @@ public class Infura_Request {
|
|||
return blockchain;
|
||||
}
|
||||
|
||||
private Infura_Request() {
|
||||
private InfuraRequest() {
|
||||
}
|
||||
|
||||
public Infura_Request(JSONObject jsRequest) {
|
||||
public InfuraRequest(JSONObject jsRequest) {
|
||||
try {
|
||||
jsRequestData = new JSONObject(jsRequest.toString());
|
||||
} catch (JSONException e) {
|
||||
|
|
@ -82,8 +84,8 @@ public class Infura_Request {
|
|||
return jsRequestData.getString("method").equals(methodName);
|
||||
}
|
||||
|
||||
public static Infura_Request GetBalance(String wallet) {
|
||||
Infura_Request request = new Infura_Request();
|
||||
public static InfuraRequest GetBalance(String wallet) {
|
||||
InfuraRequest request = new InfuraRequest();
|
||||
try {
|
||||
request.WalletAddress=wallet;
|
||||
request.jsRequestData = new JSONObject("{ \"method\":\"" + METHOD_ETH_GetBalance + "\", \"params\":[\"" + wallet + "\", \"latest\"] }");
|
||||
|
|
@ -94,9 +96,9 @@ public class Infura_Request {
|
|||
return request;
|
||||
}
|
||||
|
||||
public static Infura_Request GetTokenBalance(String wallet, String contract, int dec)
|
||||
public static InfuraRequest GetTokenBalance(String wallet, String contract, int dec)
|
||||
{
|
||||
Infura_Request request = new Infura_Request();
|
||||
InfuraRequest request = new InfuraRequest();
|
||||
try {
|
||||
request.WalletAddress=wallet;
|
||||
request.Dec = dec;
|
||||
|
|
@ -110,8 +112,8 @@ public class Infura_Request {
|
|||
return request;
|
||||
}
|
||||
|
||||
public static Infura_Request SendTransaction(String wallet, String tx) {
|
||||
Infura_Request request = new Infura_Request();
|
||||
public static InfuraRequest SendTransaction(String wallet, String tx) {
|
||||
InfuraRequest request = new InfuraRequest();
|
||||
try {
|
||||
request.WalletAddress=wallet;
|
||||
request.jsRequestData = new JSONObject("{ \"method\":\"" + METHOD_ETH_SendRawTransaction + "\", \"params\":[\"" + tx + "\"] }");
|
||||
|
|
@ -124,8 +126,8 @@ public class Infura_Request {
|
|||
|
||||
|
||||
|
||||
public static Infura_Request GetOutTransactionCount(String wallet) {
|
||||
Infura_Request request = new Infura_Request();
|
||||
public static InfuraRequest GetOutTransactionCount(String wallet) {
|
||||
InfuraRequest request = new InfuraRequest();
|
||||
try {
|
||||
request.WalletAddress=wallet;
|
||||
request.jsRequestData = new JSONObject("{ \"method\":\"" + METHOD_ETH_GetOutTransactionCount + "\", \"params\":[\"" + wallet + "\", \"latest\"] }");
|
||||
|
|
@ -136,8 +138,8 @@ public class Infura_Request {
|
|||
return request;
|
||||
}
|
||||
|
||||
public static Infura_Request GetPendingTransactionCount(String wallet) {
|
||||
Infura_Request request = new Infura_Request();
|
||||
public static InfuraRequest GetPendingTransactionCount(String wallet) {
|
||||
InfuraRequest request = new InfuraRequest();
|
||||
try {
|
||||
request.WalletAddress=wallet;
|
||||
request.jsRequestData = new JSONObject("{ \"method\":\"" + METHOD_ETH_GetOutTransactionCount + "\", \"params\":[\"" + wallet + "\", \"pending\"] }");
|
||||
|
|
@ -148,8 +150,8 @@ public class Infura_Request {
|
|||
return request;
|
||||
}
|
||||
|
||||
public static Infura_Request GetGasPrise(String wallet) {
|
||||
Infura_Request request = new Infura_Request();
|
||||
public static InfuraRequest GetGasPrise(String wallet) {
|
||||
InfuraRequest request = new InfuraRequest();
|
||||
try {
|
||||
request.WalletAddress=wallet;
|
||||
request.jsRequestData = new JSONObject("{ \"method\":\"" + METHOD_ETH_GetGasPrice + "\", \"params\":[] }");
|
||||
|
|
@ -161,8 +163,8 @@ public class Infura_Request {
|
|||
}
|
||||
|
||||
|
||||
public static Infura_Request SendTransactionCount(String wallet, String TX) {
|
||||
Infura_Request request = new Infura_Request();
|
||||
public static InfuraRequest SendTransactionCount(String wallet, String TX) {
|
||||
InfuraRequest request = new InfuraRequest();
|
||||
try {
|
||||
request.WalletAddress=wallet;
|
||||
request.jsRequestData = new JSONObject("{ \"method\":\"" + METHOD_ETH_SendRawTransaction + "\", \"params\":[\"" + TX + "\"] }");
|
||||
|
|
@ -7,7 +7,7 @@ package com.tangem.data.network.task;
|
|||
import android.os.AsyncTask;
|
||||
|
||||
import com.tangem.domain.wallet.Blockchain;
|
||||
import com.tangem.domain.wallet.Infura_Request;
|
||||
import com.tangem.data.network.request.InfuraRequest;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
|
|
@ -25,7 +25,7 @@ import javax.net.ssl.HttpsURLConnection;
|
|||
* Created by Ilia on 04.12.2017.
|
||||
*/
|
||||
|
||||
public class InfuraTask extends AsyncTask<Infura_Request, Void, List<Infura_Request>> {
|
||||
public class InfuraTask extends AsyncTask<InfuraRequest, Void, List<InfuraRequest>> {
|
||||
private Exception exception;
|
||||
private Blockchain blockchain;
|
||||
public InfuraTask(Blockchain blockchainNet)
|
||||
|
|
@ -33,13 +33,13 @@ public class InfuraTask extends AsyncTask<Infura_Request, Void, List<Infura_Requ
|
|||
blockchain = blockchainNet;
|
||||
}
|
||||
boolean useOurNode = false;
|
||||
protected List<Infura_Request> doInBackground(Infura_Request... requests) {
|
||||
List<Infura_Request> result = new ArrayList<>();
|
||||
protected List<InfuraRequest> doInBackground(InfuraRequest... requests) {
|
||||
List<InfuraRequest> result = new ArrayList<>();
|
||||
for (int i = 0; i < requests.length; i++) {
|
||||
result.add(requests[i]);
|
||||
}
|
||||
|
||||
for (Infura_Request request: result)
|
||||
for (InfuraRequest request: result)
|
||||
{
|
||||
HttpURLConnection httpcon = null;
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ package com.tangem.domain.wallet;
|
|||
|
||||
import android.util.Log;
|
||||
|
||||
import com.tangem.util.FormatUtil;
|
||||
import com.tangem.util.Util;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import android.net.Uri;
|
|||
|
||||
import com.tangem.domain.cardReader.CardProtocol;
|
||||
import com.tangem.domain.cardReader.TLV;
|
||||
import com.tangem.util.FormatUtil;
|
||||
import com.tangem.util.Util;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
|
@ -18,7 +19,7 @@ import java.util.Arrays;
|
|||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import static com.tangem.domain.wallet.FormatUtil.GetDecimalFormat;
|
||||
import static com.tangem.util.FormatUtil.GetDecimalFormat;
|
||||
|
||||
/**
|
||||
* Created by Ilia on 15.02.2018.
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import android.net.Uri;
|
|||
|
||||
import com.tangem.domain.cardReader.CardProtocol;
|
||||
import com.tangem.domain.cardReader.TLV;
|
||||
import com.tangem.util.FormatUtil;
|
||||
import com.tangem.util.Util;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
|
@ -19,7 +20,7 @@ import java.util.Date;
|
|||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import static com.tangem.domain.wallet.FormatUtil.GetDecimalFormat;
|
||||
import static com.tangem.util.FormatUtil.GetDecimalFormat;
|
||||
|
||||
/**
|
||||
* Created by Ilia on 15.02.2018.
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ public class CryptoUtil {
|
|||
return CURVE.getCurve().decodePoint(compEnc);
|
||||
}
|
||||
|
||||
public static byte[] recoverPubBytesFromSignature(int recId, ECDSASignature_ETH sig, byte[] messageHash) {
|
||||
public static byte[] recoverPubBytesFromSignature(int recId, ECDSASignatureETH sig, byte[] messageHash) {
|
||||
// 1.0 For j from 0 to h (h == recId here and the loop is outside this function)
|
||||
// 1.1 Let x = r + jn
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import java.math.BigInteger;
|
|||
* Created by Ilia on 07.01.2018.
|
||||
*/
|
||||
|
||||
public class ECDSASignature_ETH {
|
||||
public class ECDSASignatureETH {
|
||||
/**
|
||||
* The two components of the signature.
|
||||
*/
|
||||
|
|
@ -19,7 +19,7 @@ public class ECDSASignature_ETH {
|
|||
* @param r -
|
||||
* @param s -
|
||||
*/
|
||||
public ECDSASignature_ETH(BigInteger r, BigInteger s) {
|
||||
public ECDSASignatureETH(BigInteger r, BigInteger s) {
|
||||
this.r = r;
|
||||
this.s = s;
|
||||
}
|
||||
|
|
@ -30,8 +30,8 @@ public class ECDSASignature_ETH {
|
|||
* @param s
|
||||
* @return -
|
||||
*/
|
||||
private static ECDSASignature_ETH fromComponents(byte[] r, byte[] s) {
|
||||
return new ECDSASignature_ETH(new BigInteger(1, r), new BigInteger(1, s));
|
||||
private static ECDSASignatureETH fromComponents(byte[] r, byte[] s) {
|
||||
return new ECDSASignatureETH(new BigInteger(1, r), new BigInteger(1, s));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -41,8 +41,8 @@ public class ECDSASignature_ETH {
|
|||
* @param v -
|
||||
* @return -
|
||||
*/
|
||||
public static ECDSASignature_ETH fromComponents(byte[] r, byte[] s, byte v) {
|
||||
ECDSASignature_ETH signature = fromComponents(r, s);
|
||||
public static ECDSASignatureETH fromComponents(byte[] r, byte[] s, byte v) {
|
||||
ECDSASignatureETH signature = fromComponents(r, s);
|
||||
signature.v = v;
|
||||
return signature;
|
||||
}
|
||||
|
|
@ -17,7 +17,7 @@ import java.text.DecimalFormat;
|
|||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
|
||||
import static com.tangem.domain.wallet.FormatUtil.GetDecimalFormat;
|
||||
import static com.tangem.util.FormatUtil.GetDecimalFormat;
|
||||
|
||||
/**
|
||||
* Created by Ilia on 15.02.2018.
|
||||
|
|
@ -337,7 +337,7 @@ public class EthEngine extends CoinEngine {
|
|||
BigInteger nonce = nonceValue;
|
||||
BigInteger gasPrice = fee.divide(BigInteger.valueOf(21000));
|
||||
BigInteger gasLimit = BigInteger.valueOf(21000);
|
||||
Integer chainId = mCard.getBlockchain() == Blockchain.Ethereum ? ETH_Transaction.ChainEnum.Mainnet.getValue() : ETH_Transaction.ChainEnum.Rinkeby.getValue();
|
||||
Integer chainId = mCard.getBlockchain() == Blockchain.Ethereum ? EthTransaction.ChainEnum.Mainnet.getValue() : EthTransaction.ChainEnum.Rinkeby.getValue();
|
||||
|
||||
Long multiplicator = 1000000000L;
|
||||
amount = amount.multiply(BigInteger.valueOf(multiplicator));
|
||||
|
|
@ -349,7 +349,7 @@ public class EthEngine extends CoinEngine {
|
|||
to = to.substring(2);
|
||||
}
|
||||
|
||||
ETH_Transaction tx = ETH_Transaction.create(to, amount, nonce, gasPrice, gasLimit, chainId);
|
||||
EthTransaction tx = EthTransaction.create(to, amount, nonce, gasPrice, gasLimit, chainId);
|
||||
|
||||
byte[][] hashesForSign = new byte[1][];
|
||||
byte[] for_hash = tx.getRawHash();
|
||||
|
|
@ -377,7 +377,7 @@ public class EthEngine extends CoinEngine {
|
|||
Log.e("ETH-CHECK", "Sign Failed.");
|
||||
}
|
||||
|
||||
tx.signature = new ECDSASignature_ETH(r, s);
|
||||
tx.signature = new ECDSASignatureETH(r, s);
|
||||
int v = tx.BruteRecoveryID2(tx.signature, for_hash, pbKey);
|
||||
if (v != 27 && v != 28) {
|
||||
Log.e("ETH", "invalid v");
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ package com.tangem.domain.wallet;
|
|||
|
||||
import android.util.Log;
|
||||
|
||||
import com.tangem.util.ByteUtil;
|
||||
|
||||
import org.bitcoinj.core.ECKey;
|
||||
import org.bitcoinj.core.Sha256Hash;
|
||||
import org.spongycastle.util.BigIntegers;
|
||||
|
|
@ -11,13 +13,13 @@ import org.spongycastle.util.encoders.Hex;
|
|||
import java.math.BigInteger;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static com.tangem.domain.wallet.ByteUtil.EMPTY_BYTE_ARRAY;
|
||||
import static com.tangem.util.ByteUtil.EMPTY_BYTE_ARRAY;
|
||||
|
||||
/**
|
||||
* Created by Ilia on 07.01.2018.
|
||||
*/
|
||||
|
||||
public class ETH_Transaction {
|
||||
public class EthTransaction {
|
||||
byte[] nonce;
|
||||
byte[] gasPrice;
|
||||
byte[] gasLimit;
|
||||
|
|
@ -26,15 +28,15 @@ public class ETH_Transaction {
|
|||
byte[] data;
|
||||
Integer chainId;
|
||||
byte[] rlpRaw;
|
||||
public ECDSASignature_ETH signature;
|
||||
public ECDSASignatureETH signature;
|
||||
byte[] rlpEncoded;
|
||||
|
||||
private static final int CHAIN_ID_INC = 35;
|
||||
private static final int LOWER_REAL_V = 27;
|
||||
|
||||
public static ETH_Transaction create(String to, BigInteger amount, BigInteger nonce, BigInteger gasPrice,
|
||||
public static EthTransaction create(String to, BigInteger amount, BigInteger nonce, BigInteger gasPrice,
|
||||
BigInteger gasLimit, Integer chainId){
|
||||
return new ETH_Transaction(BigIntegers.asUnsignedByteArray(nonce),
|
||||
return new EthTransaction(BigIntegers.asUnsignedByteArray(nonce),
|
||||
BigIntegers.asUnsignedByteArray(gasPrice),
|
||||
BigIntegers.asUnsignedByteArray(gasLimit),
|
||||
Hex.decode(to),
|
||||
|
|
@ -44,9 +46,9 @@ public class ETH_Transaction {
|
|||
}
|
||||
|
||||
|
||||
public static ETH_Transaction create(String to, BigInteger amount, BigInteger nonce, BigInteger gasPrice,
|
||||
public static EthTransaction create(String to, BigInteger amount, BigInteger nonce, BigInteger gasPrice,
|
||||
BigInteger gasLimit, Integer chainId, byte[] data){
|
||||
return new ETH_Transaction(BigIntegers.asUnsignedByteArray(nonce),
|
||||
return new EthTransaction(BigIntegers.asUnsignedByteArray(nonce),
|
||||
BigIntegers.asUnsignedByteArray(gasPrice),
|
||||
BigIntegers.asUnsignedByteArray(gasLimit),
|
||||
Hex.decode(to),
|
||||
|
|
@ -55,7 +57,7 @@ public class ETH_Transaction {
|
|||
chainId);
|
||||
}
|
||||
|
||||
public ETH_Transaction(byte[] nonce, byte[] gasPrice, byte[] gasLimit, byte[] receiveAddress, byte[] value, byte[] data,
|
||||
public EthTransaction(byte[] nonce, byte[] gasPrice, byte[] gasLimit, byte[] receiveAddress, byte[] value, byte[] data,
|
||||
Integer chainId) {
|
||||
this.nonce = nonce;
|
||||
this.gasPrice = gasPrice;
|
||||
|
|
@ -112,7 +114,7 @@ public class ETH_Transaction {
|
|||
return kec.digest(plainMsg);
|
||||
}
|
||||
|
||||
public int BruteRecoveryID2(ECDSASignature_ETH sig, byte[] messageHash, byte[] thisKey)
|
||||
public int BruteRecoveryID2(ECDSASignatureETH sig, byte[] messageHash, byte[] thisKey)
|
||||
{
|
||||
Log.e("ETH_KZ", BTCUtils.toHex(thisKey));
|
||||
int recId = -1;
|
||||
|
|
@ -6,8 +6,8 @@ package com.tangem.domain.wallet;
|
|||
|
||||
import java.util.Arrays;
|
||||
|
||||
import static com.tangem.domain.wallet.ByteUtil.isNullOrZeroArray;
|
||||
import static com.tangem.domain.wallet.ByteUtil.isSingleZero;
|
||||
import static com.tangem.util.ByteUtil.isNullOrZeroArray;
|
||||
import static com.tangem.util.ByteUtil.isSingleZero;
|
||||
|
||||
public class RLP {
|
||||
public static final byte[] EMPTY_ELEMENT_RLP = encodeElement(new byte[0]);
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import android.os.Bundle;
|
|||
|
||||
import com.google.common.base.Strings;
|
||||
import com.tangem.domain.cardReader.SettingsMask;
|
||||
import com.tangem.util.FormatUtil;
|
||||
import com.tangem.util.Util;
|
||||
|
||||
import java.math.BigInteger;
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ import java.text.DecimalFormat;
|
|||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
|
||||
import static com.tangem.domain.wallet.FormatUtil.GetDecimalFormat;
|
||||
import static com.tangem.util.FormatUtil.GetDecimalFormat;
|
||||
|
||||
/**
|
||||
* Created by Ilia on 20.03.2018.
|
||||
|
|
@ -331,7 +331,7 @@ public class TokenEngine extends CoinEngine {
|
|||
BigInteger nonce = nonceValue;
|
||||
BigInteger gasPrice = fee.divide(BigInteger.valueOf(21000));
|
||||
BigInteger gasLimit = BigInteger.valueOf(60000);
|
||||
Integer chainId = ETH_Transaction.ChainEnum.Mainnet.getValue();
|
||||
Integer chainId = EthTransaction.ChainEnum.Mainnet.getValue();
|
||||
BigInteger amountZero = BigInteger.ZERO;
|
||||
|
||||
Long multiplicator = 1000000000L;
|
||||
|
|
@ -363,7 +363,7 @@ public class TokenEngine extends CoinEngine {
|
|||
|
||||
|
||||
byte[] data = BTCUtils.fromHex(cmd);
|
||||
ETH_Transaction tx = ETH_Transaction.create(contractAddress, amountZero, nonce, gasPrice, gasLimit, chainId, data);
|
||||
EthTransaction tx = EthTransaction.create(contractAddress, amountZero, nonce, gasPrice, gasLimit, chainId, data);
|
||||
|
||||
byte[][] hashesForSign = new byte[1][];
|
||||
byte[] for_hash = tx.getRawHash();
|
||||
|
|
@ -390,7 +390,7 @@ public class TokenEngine extends CoinEngine {
|
|||
Log.e("ETH-CHECK", "Sign Failed.");
|
||||
}
|
||||
|
||||
tx.signature = new ECDSASignature_ETH(r, s);
|
||||
tx.signature = new ECDSASignatureETH(r, s);
|
||||
int v = tx.BruteRecoveryID2(tx.signature, for_hash, pbKey);
|
||||
if (v != 27 && v != 28) {
|
||||
Log.e("ETH", "invalid v");
|
||||
|
|
|
|||
|
|
@ -34,8 +34,8 @@ import com.tangem.domain.wallet.DerEncodingUtil;
|
|||
import com.tangem.data.network.task.ElectrumTask;
|
||||
import com.tangem.data.network.request.FeeRequest;
|
||||
import com.tangem.data.network.task.FeeTask;
|
||||
import com.tangem.domain.wallet.FormatUtil;
|
||||
import com.tangem.domain.wallet.Infura_Request;
|
||||
import com.tangem.util.FormatUtil;
|
||||
import com.tangem.data.network.request.InfuraRequest;
|
||||
import com.tangem.data.network.task.InfuraTask;
|
||||
import com.tangem.wallet.R;
|
||||
import com.tangem.domain.wallet.SharedData;
|
||||
|
|
@ -249,7 +249,7 @@ public class ConfirmPaymentActivity extends AppCompatActivity implements NfcAdap
|
|||
|
||||
if (mCard.getBlockchain() == Blockchain.Ethereum || mCard.getBlockchain() == Blockchain.EthereumTestNet || mCard.getBlockchain() == Blockchain.Token) {
|
||||
ETHRequestTask task = new ETHRequestTask(mCard.getBlockchain());
|
||||
Infura_Request req = Infura_Request.GetGasPrise(mCard.getWallet());
|
||||
InfuraRequest req = InfuraRequest.GetGasPrise(mCard.getWallet());
|
||||
req.setID(67);
|
||||
req.setBlockchain(mCard.getBlockchain());
|
||||
rgFee.setEnabled(false);
|
||||
|
|
@ -532,14 +532,14 @@ public class ConfirmPaymentActivity extends AppCompatActivity implements NfcAdap
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(List<Infura_Request> requests) {
|
||||
protected void onPostExecute(List<InfuraRequest> requests) {
|
||||
super.onPostExecute(requests);
|
||||
for (Infura_Request request : requests) {
|
||||
for (InfuraRequest request : requests) {
|
||||
try {
|
||||
Long price = 0L;
|
||||
if (request.error == null) {
|
||||
|
||||
if (request.isMethod(Infura_Request.METHOD_ETH_GetGasPrice)) {
|
||||
if (request.isMethod(InfuraRequest.METHOD_ETH_GetGasPrice)) {
|
||||
try {
|
||||
String gasPrice = request.getResultString();
|
||||
gasPrice = gasPrice.substring(2);
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ public class MainActivity extends AppCompatActivity implements PopupMenu.OnMenuI
|
|||
// }
|
||||
|
||||
OnCardsClean onCardsClean;
|
||||
// OnCreateNFCDialog onCreateNFCDialog;
|
||||
// OnCreateNFCDialog onCreateNFCDialog;
|
||||
NfcAdapter.ReaderCallback onNFCReaderCallback;
|
||||
FloatingActionButton fab;
|
||||
|
||||
|
|
@ -126,8 +126,7 @@ public class MainActivity extends AppCompatActivity implements PopupMenu.OnMenuI
|
|||
commonInit(getApplicationContext());
|
||||
|
||||
TextView tvNFCHint = findViewById(R.id.tvNFCHint);
|
||||
if(tvNFCHint != null)
|
||||
{
|
||||
if (tvNFCHint != null) {
|
||||
// tvNFCHint.setText("Scan a banknote with your\n" + PhoneUtility.GetPhoneName() + "\nas shown above");
|
||||
tvNFCHint.setText("Scan a banknote with your\n smartphone as shown above");
|
||||
}
|
||||
|
|
@ -139,16 +138,16 @@ public class MainActivity extends AppCompatActivity implements PopupMenu.OnMenuI
|
|||
final RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) hand.getLayoutParams();
|
||||
final RelativeLayout.LayoutParams lp2 = (RelativeLayout.LayoutParams) nfc.getLayoutParams();
|
||||
final float dp = getResources().getDisplayMetrics().density;
|
||||
final float lm = dp*(69 + antenna.X * 75);
|
||||
lp.topMargin = (int) (dp*(-100 + antenna.Y * 250));
|
||||
lp2.topMargin = (int) (dp*(-125 + antenna.Y * 250));
|
||||
final float lm = dp * (69 + antenna.X * 75);
|
||||
lp.topMargin = (int) (dp * (-100 + antenna.Y * 250));
|
||||
lp2.topMargin = (int) (dp * (-125 + antenna.Y * 250));
|
||||
nfc.setLayoutParams(lp2);
|
||||
|
||||
Animation a = new Animation() {
|
||||
|
||||
@Override
|
||||
protected void applyTransformation(float interpolatedTime, Transformation t) {
|
||||
lp.leftMargin = (int)(lm * interpolatedTime);
|
||||
lp.leftMargin = (int) (lm * interpolatedTime);
|
||||
hand.setLayoutParams(lp);
|
||||
}
|
||||
};
|
||||
|
|
@ -165,15 +164,14 @@ public class MainActivity extends AppCompatActivity implements PopupMenu.OnMenuI
|
|||
}
|
||||
});
|
||||
|
||||
MainFragment mainFragment =(MainFragment)getSupportFragmentManager().findFragmentById(R.id.fragmentMain);
|
||||
if( mainFragment.getCardListAdapter().getItemCount()>0 )
|
||||
{
|
||||
MainFragment mainFragment = (MainFragment) getSupportFragmentManager().findFragmentById(R.id.fragmentMain);
|
||||
if (mainFragment.getCardListAdapter().getItemCount() > 0) {
|
||||
showCleanButton();
|
||||
}else {
|
||||
} else {
|
||||
hideCleanButton();
|
||||
}
|
||||
|
||||
final RippleBackground rippleBackground=(RippleBackground)findViewById(R.id.imNFC);
|
||||
final RippleBackground rippleBackground = findViewById(R.id.imNFC);
|
||||
rippleBackground.startRippleAnimation();
|
||||
|
||||
|
||||
|
|
@ -186,12 +184,11 @@ public class MainActivity extends AppCompatActivity implements PopupMenu.OnMenuI
|
|||
}
|
||||
}
|
||||
|
||||
public static void commonInit(Context context)
|
||||
{
|
||||
if( PINStorage.needInit() ) {
|
||||
public static void commonInit(Context context) {
|
||||
if (PINStorage.needInit()) {
|
||||
PINStorage.Init(context);
|
||||
}
|
||||
if( LastSignStorage.needInit() ) {
|
||||
if (LastSignStorage.needInit()) {
|
||||
LastSignStorage.Init(context);
|
||||
}
|
||||
}
|
||||
|
|
@ -211,7 +208,6 @@ public class MainActivity extends AppCompatActivity implements PopupMenu.OnMenuI
|
|||
onNFCReaderCallback.onTagDiscovered(tag);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -230,8 +226,8 @@ public class MainActivity extends AppCompatActivity implements PopupMenu.OnMenuI
|
|||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
getMenuInflater().inflate(R.menu.menu_main, menu);
|
||||
if( BuildConfig.DEBUG ) {
|
||||
for(int i=0; i<menu.size(); i++ ) menu.getItem(i).setVisible(true);
|
||||
if (BuildConfig.DEBUG) {
|
||||
for (int i = 0; i < menu.size(); i++) menu.getItem(i).setVisible(true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
@ -333,8 +329,9 @@ public class MainActivity extends AppCompatActivity implements PopupMenu.OnMenuI
|
|||
PopupMenu popup = new PopupMenu(this, v);
|
||||
MenuInflater inflater = popup.getMenuInflater();
|
||||
inflater.inflate(R.menu.menu_main, popup.getMenu());
|
||||
if( BuildConfig.DEBUG ) {
|
||||
for(int i=0; i<popup.getMenu().size(); i++ ) popup.getMenu().getItem(i).setVisible(true);
|
||||
if (BuildConfig.DEBUG) {
|
||||
for (int i = 0; i < popup.getMenu().size(); i++)
|
||||
popup.getMenu().getItem(i).setVisible(true);
|
||||
}
|
||||
popup.setOnMenuItemClickListener(this);
|
||||
popup.show();
|
||||
|
|
@ -386,7 +383,6 @@ public class MainActivity extends AppCompatActivity implements PopupMenu.OnMenuI
|
|||
case R.id.about:
|
||||
showLogoActivity();
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
|
|
@ -394,7 +390,7 @@ public class MainActivity extends AppCompatActivity implements PopupMenu.OnMenuI
|
|||
|
||||
private void showLogoActivity() {
|
||||
Intent intent = new Intent(getBaseContext(), LogoActivity.class);
|
||||
intent.putExtra("skipAutoHide",true);
|
||||
intent.putExtra("skipAutoHide", true);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
|
|
@ -410,4 +406,3 @@ public class MainActivity extends AppCompatActivity implements PopupMenu.OnMenuI
|
|||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ import com.tangem.domain.cardReader.NfcManager;
|
|||
import com.tangem.domain.wallet.Blockchain;
|
||||
import com.tangem.domain.wallet.CoinEngine;
|
||||
import com.tangem.domain.wallet.CoinEngineFactory;
|
||||
import com.tangem.domain.wallet.FormatUtil;
|
||||
import com.tangem.util.FormatUtil;
|
||||
import com.tangem.domain.wallet.TangemCard;
|
||||
import com.tangem.wallet.R;
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import com.tangem.domain.wallet.CoinEngine;
|
|||
import com.tangem.domain.wallet.CoinEngineFactory;
|
||||
import com.tangem.data.network.request.ElectrumRequest;
|
||||
import com.tangem.data.network.task.ElectrumTask;
|
||||
import com.tangem.domain.wallet.Infura_Request;
|
||||
import com.tangem.data.network.request.InfuraRequest;
|
||||
import com.tangem.data.network.task.InfuraTask;
|
||||
import com.tangem.domain.wallet.LastSignStorage;
|
||||
import com.tangem.domain.wallet.TangemCard;
|
||||
|
|
@ -49,7 +49,7 @@ public class SendTransactionActivity extends AppCompatActivity {
|
|||
CoinEngine engine = CoinEngineFactory.Create(mCard.getBlockchain());
|
||||
if (mCard.getBlockchain() == Blockchain.Ethereum || mCard.getBlockchain() == Blockchain.EthereumTestNet || mCard.getBlockchain() == Blockchain.Token) {
|
||||
ETHRequestTask task = new ETHRequestTask(mCard.getBlockchain());
|
||||
Infura_Request req = Infura_Request.SendTransaction(mCard.getWallet(), tx);
|
||||
InfuraRequest req = InfuraRequest.SendTransaction(mCard.getWallet(), tx);
|
||||
req.setID(67);
|
||||
req.setBlockchain(mCard.getBlockchain());
|
||||
task.execute(req);
|
||||
|
|
@ -98,12 +98,12 @@ public class SendTransactionActivity extends AppCompatActivity {
|
|||
super(blockchain);
|
||||
}
|
||||
@Override
|
||||
protected void onPostExecute(List<Infura_Request> requests) {
|
||||
protected void onPostExecute(List<InfuraRequest> requests) {
|
||||
super.onPostExecute(requests);
|
||||
for (Infura_Request request : requests) {
|
||||
for (InfuraRequest request : requests) {
|
||||
try {
|
||||
if (request.error == null) {
|
||||
if (request.isMethod(Infura_Request.METHOD_ETH_SendRawTransaction)) {
|
||||
if (request.isMethod(InfuraRequest.METHOD_ETH_SendRawTransaction)) {
|
||||
try {
|
||||
String hashTX = "";
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ import com.tangem.domain.wallet.CoinEngineFactory;
|
|||
import com.tangem.data.network.task.ElectrumTask;
|
||||
import com.tangem.data.network.request.ExchangeRequest;
|
||||
import com.tangem.data.network.task.ExchangeTask;
|
||||
import com.tangem.domain.wallet.Infura_Request;
|
||||
import com.tangem.data.network.request.InfuraRequest;
|
||||
import com.tangem.data.network.task.InfuraTask;
|
||||
import com.tangem.domain.wallet.LastSignStorage;
|
||||
import com.tangem.presentation.dialog.NoExtendedLengthSupportDialog;
|
||||
|
|
@ -174,11 +174,11 @@ public class LoadedWalletFragment extends Fragment implements SwipeRefreshLayout
|
|||
}
|
||||
else if (mCard.getBlockchain() == Blockchain.Ethereum || mCard.getBlockchain() == Blockchain.EthereumTestNet) {
|
||||
ETHRequestTask updateETH = new ETHRequestTask(mCard.getBlockchain());
|
||||
Infura_Request reqETH = Infura_Request.GetBalance(mCard.getWallet());
|
||||
InfuraRequest reqETH = InfuraRequest.GetBalance(mCard.getWallet());
|
||||
reqETH.setID(67);
|
||||
reqETH.setBlockchain(mCard.getBlockchain());
|
||||
|
||||
Infura_Request reqNonce = Infura_Request.GetOutTransactionCount(mCard.getWallet());
|
||||
InfuraRequest reqNonce = InfuraRequest.GetOutTransactionCount(mCard.getWallet());
|
||||
reqNonce.setID(67);
|
||||
reqNonce.setBlockchain(mCard.getBlockchain());
|
||||
|
||||
|
|
@ -191,15 +191,15 @@ public class LoadedWalletFragment extends Fragment implements SwipeRefreshLayout
|
|||
|
||||
} else if (mCard.getBlockchain() == Blockchain.Token) {
|
||||
ETHRequestTask updateETH = new ETHRequestTask(mCard.getBlockchain());
|
||||
Infura_Request reqETH = Infura_Request.GetTokenBalance(mCard.getWallet(), engine.GetContractAddress(mCard), engine.GetTokenDecimals(mCard));
|
||||
InfuraRequest reqETH = InfuraRequest.GetTokenBalance(mCard.getWallet(), engine.GetContractAddress(mCard), engine.GetTokenDecimals(mCard));
|
||||
reqETH.setID(67);
|
||||
reqETH.setBlockchain(mCard.getBlockchain());
|
||||
|
||||
Infura_Request reqBalance = Infura_Request.GetBalance(mCard.getWallet());
|
||||
InfuraRequest reqBalance = InfuraRequest.GetBalance(mCard.getWallet());
|
||||
reqBalance.setID(67);
|
||||
reqBalance.setBlockchain(mCard.getBlockchain());
|
||||
|
||||
Infura_Request reqNonce = Infura_Request.GetOutTransactionCount(mCard.getWallet());
|
||||
InfuraRequest reqNonce = InfuraRequest.GetOutTransactionCount(mCard.getWallet());
|
||||
reqNonce.setID(67);
|
||||
reqNonce.setBlockchain(mCard.getBlockchain());
|
||||
updateETH.execute(reqETH, reqNonce, reqBalance);
|
||||
|
|
@ -775,7 +775,7 @@ public class LoadedWalletFragment extends Fragment implements SwipeRefreshLayout
|
|||
CoinEngine engine = CoinEngineFactory.Create(mCard.getBlockchain());
|
||||
if (mCard.getBlockchain() == Blockchain.Ethereum || mCard.getBlockchain() == Blockchain.EthereumTestNet || mCard.getBlockchain() == Blockchain.Token) {
|
||||
ETHRequestTask task = new ETHRequestTask(mCard.getBlockchain());
|
||||
Infura_Request req = Infura_Request.SendTransaction(mCard.getWallet(), tx);
|
||||
InfuraRequest req = InfuraRequest.SendTransaction(mCard.getWallet(), tx);
|
||||
req.setID(67);
|
||||
req.setBlockchain(mCard.getBlockchain());
|
||||
task.execute(req);
|
||||
|
|
@ -1060,13 +1060,13 @@ public class LoadedWalletFragment extends Fragment implements SwipeRefreshLayout
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(List<Infura_Request> requests) {
|
||||
protected void onPostExecute(List<InfuraRequest> requests) {
|
||||
super.onPostExecute(requests);
|
||||
for (Infura_Request request : requests) {
|
||||
for (InfuraRequest request : requests) {
|
||||
try {
|
||||
if (request.error == null) {
|
||||
|
||||
if (request.isMethod(Infura_Request.METHOD_ETH_GetBalance)) {
|
||||
if (request.isMethod(InfuraRequest.METHOD_ETH_GetBalance)) {
|
||||
try {
|
||||
String balanceCap = request.getResultString();
|
||||
balanceCap = balanceCap.substring(2);
|
||||
|
|
@ -1084,7 +1084,7 @@ public class LoadedWalletFragment extends Fragment implements SwipeRefreshLayout
|
|||
e.printStackTrace();
|
||||
ErrorOnUpdate(e.toString());
|
||||
}
|
||||
} else if (request.isMethod(Infura_Request.METHOD_ETH_Call)) {
|
||||
} else if (request.isMethod(InfuraRequest.METHOD_ETH_Call)) {
|
||||
try {
|
||||
String balanceCap = request.getResultString();
|
||||
balanceCap = balanceCap.substring(2);
|
||||
|
|
@ -1107,7 +1107,7 @@ public class LoadedWalletFragment extends Fragment implements SwipeRefreshLayout
|
|||
e.printStackTrace();
|
||||
ErrorOnUpdate(e.toString());
|
||||
}
|
||||
} else if (request.isMethod(Infura_Request.METHOD_ETH_GetOutTransactionCount)) {
|
||||
} else if (request.isMethod(InfuraRequest.METHOD_ETH_GetOutTransactionCount)) {
|
||||
try {
|
||||
String nonce = request.getResultString();
|
||||
nonce = nonce.substring(2);
|
||||
|
|
@ -1117,7 +1117,7 @@ public class LoadedWalletFragment extends Fragment implements SwipeRefreshLayout
|
|||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else if (request.isMethod(Infura_Request.METHOD_ETH_SendRawTransaction)) {
|
||||
} else if (request.isMethod(InfuraRequest.METHOD_ETH_SendRawTransaction)) {
|
||||
try {
|
||||
String hashTX = "";
|
||||
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ import com.tangem.domain.wallet.CoinEngineFactory;
|
|||
import com.tangem.data.network.task.ElectrumTask;
|
||||
import com.tangem.data.network.request.ExchangeRequest;
|
||||
import com.tangem.data.network.task.ExchangeTask;
|
||||
import com.tangem.domain.wallet.Infura_Request;
|
||||
import com.tangem.data.network.request.InfuraRequest;
|
||||
import com.tangem.data.network.task.InfuraTask;
|
||||
import com.tangem.presentation.dialog.NoExtendedLengthSupportDialog;
|
||||
import com.tangem.domain.wallet.PINStorage;
|
||||
|
|
@ -241,10 +241,10 @@ public class MainFragment extends Fragment implements NfcAdapter.ReaderCallback,
|
|||
CoinEngine engine = CoinEngineFactory.Create(card.getBlockchain());
|
||||
if (card.getBlockchain() == Blockchain.Ethereum || card.getBlockchain() == Blockchain.EthereumTestNet) {
|
||||
ETHRequestTask task = new ETHRequestTask(card.getBlockchain());
|
||||
Infura_Request req = Infura_Request.GetBalance(card.getWallet());
|
||||
InfuraRequest req = InfuraRequest.GetBalance(card.getWallet());
|
||||
req.setID(67);
|
||||
req.setBlockchain(card.getBlockchain());
|
||||
Infura_Request reqNonce = Infura_Request.GetOutTransactionCount(card.getWallet());
|
||||
InfuraRequest reqNonce = InfuraRequest.GetOutTransactionCount(card.getWallet());
|
||||
reqNonce.setID(67);
|
||||
reqNonce.setBlockchain(card.getBlockchain());
|
||||
|
||||
|
|
@ -297,12 +297,12 @@ public class MainFragment extends Fragment implements NfcAdapter.ReaderCallback,
|
|||
|
||||
}else if (card.getBlockchain() == Blockchain.Token) {
|
||||
ETHRequestTask updateETH = new ETHRequestTask(card.getBlockchain());
|
||||
Infura_Request reqETH = Infura_Request.GetTokenBalance(card.getWallet(), engine.GetContractAddress(card), engine.GetTokenDecimals(card));
|
||||
InfuraRequest reqETH = InfuraRequest.GetTokenBalance(card.getWallet(), engine.GetContractAddress(card), engine.GetTokenDecimals(card));
|
||||
reqETH.setID(67);
|
||||
reqETH.setBlockchain(card.getBlockchain());
|
||||
|
||||
|
||||
Infura_Request reqBalance = Infura_Request.GetBalance(card.getWallet());
|
||||
InfuraRequest reqBalance = InfuraRequest.GetBalance(card.getWallet());
|
||||
reqBalance.setID(67);
|
||||
reqBalance.setBlockchain(card.getBlockchain());
|
||||
|
||||
|
|
@ -311,7 +311,7 @@ public class MainFragment extends Fragment implements NfcAdapter.ReaderCallback,
|
|||
ExchangeRequest rate = ExchangeRequest.GetRate(card.getWallet(), "basic-attention-token", "ethereum");
|
||||
taskRate.execute(rate);
|
||||
|
||||
Infura_Request reqNonce = Infura_Request.GetOutTransactionCount(card.getWallet());
|
||||
InfuraRequest reqNonce = InfuraRequest.GetOutTransactionCount(card.getWallet());
|
||||
reqNonce.setID(67);
|
||||
reqNonce.setBlockchain(card.getBlockchain());
|
||||
|
||||
|
|
@ -334,10 +334,10 @@ public class MainFragment extends Fragment implements NfcAdapter.ReaderCallback,
|
|||
|
||||
if (card.getBlockchain() == Blockchain.Ethereum || card.getBlockchain() == Blockchain.EthereumTestNet) {
|
||||
ETHRequestTask task = new ETHRequestTask(card.getBlockchain());
|
||||
Infura_Request req = Infura_Request.GetBalance(card.getWallet());
|
||||
InfuraRequest req = InfuraRequest.GetBalance(card.getWallet());
|
||||
req.setID(67);
|
||||
req.setBlockchain(card.getBlockchain());
|
||||
Infura_Request reqNonce = Infura_Request.GetOutTransactionCount(card.getWallet());
|
||||
InfuraRequest reqNonce = InfuraRequest.GetOutTransactionCount(card.getWallet());
|
||||
reqNonce.setID(67);
|
||||
reqNonce.setBlockchain(card.getBlockchain());
|
||||
|
||||
|
|
@ -396,12 +396,12 @@ public class MainFragment extends Fragment implements NfcAdapter.ReaderCallback,
|
|||
}
|
||||
else if (card.getBlockchain() == Blockchain.Token) {
|
||||
ETHRequestTask updateETH = new ETHRequestTask(card.getBlockchain());
|
||||
Infura_Request reqETH = Infura_Request.GetTokenBalance(card.getWallet(), engine.GetContractAddress(card), engine.GetTokenDecimals(card));
|
||||
InfuraRequest reqETH = InfuraRequest.GetTokenBalance(card.getWallet(), engine.GetContractAddress(card), engine.GetTokenDecimals(card));
|
||||
reqETH.setID(67);
|
||||
reqETH.setBlockchain(card.getBlockchain());
|
||||
|
||||
|
||||
Infura_Request reqBalance = Infura_Request.GetBalance(card.getWallet());
|
||||
InfuraRequest reqBalance = InfuraRequest.GetBalance(card.getWallet());
|
||||
reqBalance.setID(67);
|
||||
reqBalance.setBlockchain(card.getBlockchain());
|
||||
|
||||
|
|
@ -410,7 +410,7 @@ public class MainFragment extends Fragment implements NfcAdapter.ReaderCallback,
|
|||
ExchangeRequest rate = ExchangeRequest.GetRate(card.getWallet(), "basic-attention-token", "ethereum");
|
||||
taskRate.execute(rate);
|
||||
|
||||
Infura_Request reqNonce = Infura_Request.GetOutTransactionCount(card.getWallet());
|
||||
InfuraRequest reqNonce = InfuraRequest.GetOutTransactionCount(card.getWallet());
|
||||
reqNonce.setID(67);
|
||||
reqNonce.setBlockchain(card.getBlockchain());
|
||||
|
||||
|
|
@ -936,13 +936,13 @@ public class MainFragment extends Fragment implements NfcAdapter.ReaderCallback,
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(List<Infura_Request> requests) {
|
||||
protected void onPostExecute(List<InfuraRequest> requests) {
|
||||
super.onPostExecute(requests);
|
||||
for (Infura_Request request : requests) {
|
||||
for (InfuraRequest request : requests) {
|
||||
try {
|
||||
if (request.error == null) {
|
||||
|
||||
if (request.isMethod(Infura_Request.METHOD_ETH_GetBalance)) {
|
||||
if (request.isMethod(InfuraRequest.METHOD_ETH_GetBalance)) {
|
||||
try {
|
||||
String mWalletAddress = request.getParams().getString(0);
|
||||
|
||||
|
|
@ -958,7 +958,7 @@ public class MainFragment extends Fragment implements NfcAdapter.ReaderCallback,
|
|||
e.printStackTrace();
|
||||
FinishWithError(request.WalletAddress, e.toString());
|
||||
}
|
||||
} else if (request.isMethod(Infura_Request.METHOD_ETH_Call)) {
|
||||
} else if (request.isMethod(InfuraRequest.METHOD_ETH_Call)) {
|
||||
try {
|
||||
String mWalletAddress = request.WalletAddress;
|
||||
|
||||
|
|
@ -983,7 +983,7 @@ public class MainFragment extends Fragment implements NfcAdapter.ReaderCallback,
|
|||
e.printStackTrace();
|
||||
FinishWithError(request.WalletAddress, e.toString());
|
||||
}
|
||||
} else if (request.isMethod(Infura_Request.METHOD_ETH_GetOutTransactionCount)) {
|
||||
} else if (request.isMethod(InfuraRequest.METHOD_ETH_GetOutTransactionCount)) {
|
||||
try {
|
||||
String mWalletAddress = request.getParams().getString(0);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package com.tangem.domain.wallet;
|
||||
package com.tangem.util;
|
||||
|
||||
public class ByteUtil {
|
||||
|
||||
|
|
@ -1,11 +1,9 @@
|
|||
package com.tangem.domain.wallet;
|
||||
package com.tangem.util;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.DecimalFormatSymbols;
|
||||
import java.util.Locale;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Created by Ilia on 15.02.2018.
|
||||
|
|
@ -16,15 +14,13 @@ public class FormatUtil {
|
|||
return new BigDecimal(valueStr).multiply(BigDecimal.valueOf(1_0000_0000)).setScale(0, BigDecimal.ROUND_HALF_DOWN).longValueExact();
|
||||
}
|
||||
|
||||
public static String DoubleToString(double amount)
|
||||
{
|
||||
public static String DoubleToString(double amount) {
|
||||
DecimalFormat myFormatter = GetDecimalFormat();
|
||||
String output = myFormatter.format(amount);
|
||||
return output;
|
||||
}
|
||||
|
||||
public static DecimalFormat GetDecimalFormat()
|
||||
{
|
||||
public static DecimalFormat GetDecimalFormat() {
|
||||
DecimalFormatSymbols symbols = new DecimalFormatSymbols();
|
||||
symbols.setDecimalSeparator('.');
|
||||
|
||||
|
|
@ -36,16 +32,13 @@ public class FormatUtil {
|
|||
return myFormatter;
|
||||
}
|
||||
|
||||
|
||||
public static long ConvertStringToLong(String caption) throws Exception {
|
||||
|
||||
|
||||
BigDecimal d = new BigDecimal(caption);
|
||||
d = d.multiply(new BigDecimal(100000));
|
||||
d = d.setScale(5);
|
||||
BigInteger b = d.toBigInteger();
|
||||
long l = b.longValue();
|
||||
return l;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue