diff --git a/app/src/main/java/com/alphawallet/app/repository/EthereumNetworkBase.java b/app/src/main/java/com/alphawallet/app/repository/EthereumNetworkBase.java index ae123080a1..841a8a7a4a 100644 --- a/app/src/main/java/com/alphawallet/app/repository/EthereumNetworkBase.java +++ b/app/src/main/java/com/alphawallet/app/repository/EthereumNetworkBase.java @@ -36,7 +36,6 @@ import static com.alphawallet.ethereum.EthereumNetworkBase.GOERLI_ID; import static com.alphawallet.ethereum.EthereumNetworkBase.HECO_ID; import static com.alphawallet.ethereum.EthereumNetworkBase.HECO_RPC_URL; -import static com.alphawallet.ethereum.EthereumNetworkBase.HOLESKY_FALLBACK_URL; import static com.alphawallet.ethereum.EthereumNetworkBase.HOLESKY_ID; import static com.alphawallet.ethereum.EthereumNetworkBase.HOLESKY_RPC_URL; import static com.alphawallet.ethereum.EthereumNetworkBase.IOTEX_MAINNET_ID; @@ -752,7 +751,7 @@ else if (isTestnet && !testnetList.contains(info.chainId)) private void checkCustomNetworkSetting() { - if (list.size() > 0 && !list.get(0).isCustom) + if (!list.isEmpty() && !list.get(0).isCustom) { //need to update the list List copyList = new ArrayList<>(list); list.clear(); @@ -902,7 +901,7 @@ private void addNetworks(List result, boolean withValue) public static String getChainOverrideAddress(long chainId) { - return addressOverride.containsKey(chainId) ? addressOverride.get(chainId) : ""; + return addressOverride.getOrDefault(chainId, ""); } @Override @@ -969,7 +968,7 @@ public List getSelectedFilters() if (check != null) selectedIds.add(networkId); } - if (selectedIds.size() == 0) + if (selectedIds.isEmpty()) { selectedIds.add(getDefaultNetwork()); } @@ -1337,14 +1336,7 @@ public static String getChainSymbol(long chainId) public static boolean isEventBlockLimitEnforced(long chainId) { - if (chainId == POLYGON_ID || chainId == POLYGON_TEST_ID || chainId == POLYGON_AMOY_ID) - { - return true; - } - else - { - return false; - } + return chainId == POLYGON_ID || chainId == POLYGON_TEST_ID || chainId == POLYGON_AMOY_ID; } public static BigInteger getMaxEventFetch(long chainId) diff --git a/app/src/main/java/com/alphawallet/app/ui/WalletDiagnosticActivity.java b/app/src/main/java/com/alphawallet/app/ui/WalletDiagnosticActivity.java index a4f6d72b6a..255bb7dc96 100644 --- a/app/src/main/java/com/alphawallet/app/ui/WalletDiagnosticActivity.java +++ b/app/src/main/java/com/alphawallet/app/ui/WalletDiagnosticActivity.java @@ -30,8 +30,11 @@ import com.alphawallet.app.util.Utils; import com.alphawallet.app.viewmodel.BackupKeyViewModel; import com.alphawallet.app.widget.AWalletAlertDialog; +import com.alphawallet.app.widget.CopyTextView; import com.alphawallet.app.widget.FunctionButtonBar; import com.alphawallet.app.widget.SignTransactionDialog; + +import org.web3j.crypto.WalletUtils; import org.web3j.utils.Numeric; import com.fasterxml.jackson.databind.ObjectMapper; @@ -40,6 +43,7 @@ import org.web3j.crypto.WalletFile; import java.io.File; +import java.math.BigInteger; import java.util.ArrayList; import java.util.Collections; import java.util.regex.Matcher; @@ -354,11 +358,21 @@ private void testKeyStore() } } + private void exposeStatus() + { + LinearLayout llStatus = findViewById(R.id.layout_status); + llStatus.setVisibility(View.VISIBLE); + CopyTextView pkView = findViewById(R.id.copy_pk); + pkView.setVisibility(View.GONE); + } + private boolean testKeyType(String keyData) { //could either be a seed phrase or a keystore Pattern pattern = Pattern.compile(ImportSeedFragment.validator, Pattern.MULTILINE); - TextView status = findViewById(R.id.status_txt); + TextView status = findViewById(R.id.text_status); + CopyTextView pubKeyText = findViewById(R.id.copy_public); + exposeStatus(); //first check for seed phrase final Matcher matcher = pattern.matcher(keyData); @@ -371,9 +385,14 @@ private boolean testKeyType(String keyData) //is valid seed phrase HDWallet newWallet = new HDWallet(keyData, ""); PrivateKey pk = newWallet.getKeyForCoin(CoinType.ETHEREUM); - - status.setText(getString(R.string.seed_phrase_public_key, Numeric.toHexString(pk.getPublicKeySecp256k1(false).data()))); + status.setText(R.string.seed_phrase_public_key); status.setTextColor(getColor(R.color.green)); + pubKeyText.setText(Numeric.toHexString(pk.getPublicKeySecp256k1(false).data())); + + CopyTextView pkView = findViewById(R.id.copy_pk); + pkView.setVisibility(View.VISIBLE); + String pkStr = (new BigInteger(1, pk.data())).toString(16); + pkView.setFixedText(pkStr); isSeedPhrase = true; return true; } @@ -393,7 +412,15 @@ private boolean testKeyType(String keyData) } else { - status.setText(getString(R.string.keystore_public_key, credentials.getEcKeyPair().getPublicKey().toString(16))); + status.setText(R.string.keystore_public_key); + status.setTextColor(getColor(R.color.green)); + pubKeyText.setText(credentials.getEcKeyPair().getPublicKey().toString(16)); + + //show PK + CopyTextView pkView = findViewById(R.id.copy_pk); + pkView.setVisibility(View.VISIBLE); + String pk = credentials.getEcKeyPair().getPrivateKey().toString(16); + pkView.setFixedText(pk); isKeyStore = true; return true; } @@ -470,7 +497,7 @@ private String dumpKeystoreFromSeedPhrase(String seedPhrase, String keystorePass private void showError(String error) { - TextView statusTxt = findViewById(R.id.status_txt); + TextView statusTxt = findViewById(R.id.text_status); statusTxt.setText(error); statusTxt.setTextColor(getColor(R.color.danger)); if (dialog != null && dialog.isShowing()) dialog.dismiss(); diff --git a/app/src/main/java/com/alphawallet/app/util/Utils.java b/app/src/main/java/com/alphawallet/app/util/Utils.java index 4e15879449..f0fec93532 100644 --- a/app/src/main/java/com/alphawallet/app/util/Utils.java +++ b/app/src/main/java/com/alphawallet/app/util/Utils.java @@ -42,6 +42,7 @@ import com.alphawallet.token.entity.Signable; import com.google.gson.Gson; import com.google.zxing.client.android.Intents; +import com.google.zxing.common.StringUtils; import com.journeyapps.barcodescanner.ScanOptions; import org.jetbrains.annotations.NotNull; @@ -619,13 +620,41 @@ public static String formatAddress(String address, int frontCharCount) } } - public static String splitAddress(String address) + public static String splitAddress(String address, int lines) { address = Keys.toChecksumAddress(address); - int split = address.length()/2; - String front = address.substring(0, split); - String back = address.substring(split); - return front + " " + back; + return splitHex(address, lines); + } + + public static String splitHex(String hex, int lines) + { + int split = hex.length()/lines; + StringBuilder sb = new StringBuilder(); + int index = 0; + int addend = 0; + for (int i = 0; i < (lines-1); i++) + { + addend = 0; + if (index > 0) + { + sb.append(" "); + } + else + { + if (lines%2 != 0) + { + addend = 1; + } + } + sb.append(hex.substring(0, split + addend)); + index += split; + hex = hex.substring(split + addend); + } + sb.append(" "); + sb.append(hex); + //String front = hex.substring(0, split); + //String back = hex.substring(split); + return sb.toString(); } public static String formatTxHash(String txHash) @@ -1522,4 +1551,9 @@ public static String parseResponseValue(@Nullable String metaDataURI, BigInteger return metaDataURI; } } + + public static boolean isDivisibleString(String originalText) + { + return !TextUtils.isEmpty(originalText) && originalText.length() <= 64; + } } diff --git a/app/src/main/java/com/alphawallet/app/widget/ActionSheetSignDialog.java b/app/src/main/java/com/alphawallet/app/widget/ActionSheetSignDialog.java index d66bf3795b..59c611e15e 100644 --- a/app/src/main/java/com/alphawallet/app/widget/ActionSheetSignDialog.java +++ b/app/src/main/java/com/alphawallet/app/widget/ActionSheetSignDialog.java @@ -26,6 +26,7 @@ import com.alphawallet.token.entity.SignMessageType; import com.alphawallet.token.entity.Signable; import com.bumptech.glide.Glide; +import com.bumptech.glide.request.RequestOptions; import java.util.ArrayList; import java.util.Collections; diff --git a/app/src/main/java/com/alphawallet/app/widget/CopyTextView.java b/app/src/main/java/com/alphawallet/app/widget/CopyTextView.java index 0069bb00d2..8f7ee8bfea 100644 --- a/app/src/main/java/com/alphawallet/app/widget/CopyTextView.java +++ b/app/src/main/java/com/alphawallet/app/widget/CopyTextView.java @@ -67,11 +67,12 @@ private void getAttrs(Context context, AttributeSet attrs) private void bindViews() { - if (lines == 2) + if (lines > 1) { button = findViewById(R.id.button_address); findViewById(R.id.button).setVisibility(View.GONE); button.setVisibility(View.VISIBLE); + button.setLines(lines); } else { @@ -95,7 +96,11 @@ public void setFixedText(CharSequence text) if (Utils.isAddressValid(originalText)) { - button.setText(Utils.splitAddress(originalText)); + button.setText(Utils.splitAddress(originalText, lines)); + } + else if (Utils.isDivisibleString(originalText)) + { + button.setText(Utils.splitHex(originalText, lines)); } else if (Utils.isTxHashValid(originalText)) { diff --git a/app/src/main/res/layout/activity_wallet_diagnostic.xml b/app/src/main/res/layout/activity_wallet_diagnostic.xml index 3eebf5cb22..0230cac180 100644 --- a/app/src/main/res/layout/activity_wallet_diagnostic.xml +++ b/app/src/main/res/layout/activity_wallet_diagnostic.xml @@ -2,15 +2,17 @@ @@ -92,32 +94,92 @@ - + + + + + + android:orientation="vertical" + android:visibility="gone" + tools:visibility="visible"> - + - - + + + + + + + android:layout_height="wrap_content" + android:layout_marginStart="@dimen/standard_16" + android:orientation="horizontal" + tools:ignore="UseCompoundDrawables"> + + + + - + - + + + - Key Diagnostic Key found Unable to find Key - Seed Phrase detected public key: %1$s - Decoded Keystore public key: %1$s + Seed Phrase detected public key + Decoded Keystore public key Locked Key type in Database Key Entry in Secure Enclave diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index d60bd598b6..7a89ba1805 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -926,8 +926,8 @@ Key Diagnostic Key found Unable to find Key - Seed Phrase detected public key: %1$s - Decoded Keystore public key: %1$s + Seed Phrase detected public key + Decoded Keystore public key Locked Key type in Database Key Entry in Secure Enclave diff --git a/app/src/main/res/values-id/strings.xml b/app/src/main/res/values-id/strings.xml index 4c3f8bbb4b..c5dd9e7c50 100644 --- a/app/src/main/res/values-id/strings.xml +++ b/app/src/main/res/values-id/strings.xml @@ -918,8 +918,8 @@ Key Diagnostic Key found Unable to find Key - Seed Phrase detected public key: %1$s - Decoded Keystore public key: %1$s + Seed Phrase detected public key + Decoded Keystore public key Locked Key type in Database Key Entry in Secure Enclave diff --git a/app/src/main/res/values-my/strings.xml b/app/src/main/res/values-my/strings.xml index e0225eee1b..138815aa2e 100644 --- a/app/src/main/res/values-my/strings.xml +++ b/app/src/main/res/values-my/strings.xml @@ -948,8 +948,8 @@ Key Diagnostic Key found Unable to find Key - Seed Phrase detected public key: %1$s - Decoded Keystore public key: %1$s + Seed Phrase detected public key + Decoded Keystore public key Locked Key type in Database Key Entry in Secure Enclave diff --git a/app/src/main/res/values-vi/strings.xml b/app/src/main/res/values-vi/strings.xml index 495d7f302d..66cef1f537 100644 --- a/app/src/main/res/values-vi/strings.xml +++ b/app/src/main/res/values-vi/strings.xml @@ -928,8 +928,8 @@ Key Diagnostic Key found Unable to find Key - Seed Phrase detected public key: %1$s - Decoded Keystore public key: %1$s + Seed Phrase detected public key + Decoded Keystore public key Locked Key type in Database Key Entry in Secure Enclave diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 669ac28514..261d8e2244 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -913,8 +913,8 @@ Key Diagnostic Key found Unable to find Key - Seed Phrase detected public key: %1$s - Decoded Keystore public key: %1$s + Seed Phrase detected public key + Decoded Keystore public key Locked Key type in Database Key Entry in Secure Enclave diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b0d1219085..34530750c1 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -991,8 +991,8 @@ Key Diagnostic Key found Unable to find Key - Seed Phrase detected public key: %1$s - Decoded Keystore public key: %1$s + Seed Phrase detected public key + Decoded Keystore public key Locked Key type in Database Key Entry in Secure Enclave