From 38c0ead45c937df0cd951a71a769cca99183969b Mon Sep 17 00:00:00 2001 From: m2049r Date: Mon, 19 Apr 2021 17:39:12 +0200 Subject: [PATCH] random fixes (#747) --- .../fragment/send/SendAddressWizardFragment.java | 4 +++- .../java/com/m2049r/xmrwallet/util/Helper.java | 7 ++++--- .../m2049r/xmrwallet/util/LegacyStorageHelper.java | 1 + .../java/com/m2049r/xmrwallet/util/Notice.java | 14 ++++++++------ .../com/m2049r/xmrwallet/util/RestoreHeight.java | 4 +++- 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/com/m2049r/xmrwallet/fragment/send/SendAddressWizardFragment.java b/app/src/main/java/com/m2049r/xmrwallet/fragment/send/SendAddressWizardFragment.java index 190e956f..38feb6a9 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/fragment/send/SendAddressWizardFragment.java +++ b/app/src/main/java/com/m2049r/xmrwallet/fragment/send/SendAddressWizardFragment.java @@ -183,6 +183,7 @@ public class SendAddressWizardFragment extends SendWizardFragment { selectedCrypto = Crypto.XMR; sendListener.setMode(SendFragment.Mode.XMR); } + if (!Helper.ALLOW_SHIFT) return; if ((selectedCrypto == null) && isEthAddress(address)) { Timber.d("isEthAddress"); possibleCryptos.add(Crypto.ETH); @@ -465,7 +466,8 @@ public class SendAddressWizardFragment extends SendWizardFragment { possibleCryptos.add(barcodeData.asset); selectedCrypto = barcodeData.asset; } - updateCryptoButtons(false); + if (Helper.ALLOW_SHIFT) + updateCryptoButtons(false); if (checkAddress()) { if (barcodeData.security == BarcodeData.Security.OA_NO_DNSSEC) etAddress.setError(getString(R.string.send_address_no_dnssec)); diff --git a/app/src/main/java/com/m2049r/xmrwallet/util/Helper.java b/app/src/main/java/com/m2049r/xmrwallet/util/Helper.java index e0935737..d53c84d6 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/util/Helper.java +++ b/app/src/main/java/com/m2049r/xmrwallet/util/Helper.java @@ -80,6 +80,7 @@ public class Helper { static public final String NOCRAZYPASS_FLAGFILE = ".nocrazypass"; static public final String BASE_CRYPTO = Crypto.XMR.getSymbol(); + static public final int XMR_DECIMALS = 12; static public final boolean SHOW_EXCHANGERATES = true; static public final boolean ALLOW_SHIFT = true; @@ -159,11 +160,11 @@ public class Helper { } static public BigDecimal getDecimalAmount(long amount) { - return new BigDecimal(amount).scaleByPowerOfTen(-12); + return new BigDecimal(amount).scaleByPowerOfTen(-XMR_DECIMALS); } static public String getDisplayAmount(long amount) { - return getDisplayAmount(amount, 12); + return getDisplayAmount(amount, XMR_DECIMALS); } static public String getDisplayAmount(long amount, int maxDecimals) { @@ -195,7 +196,7 @@ public class Helper { static public String getDisplayAmount(double amount) { // a Java bug does not strip zeros properly if the value is 0 BigDecimal d = new BigDecimal(amount) - .setScale(12, BigDecimal.ROUND_HALF_UP) + .setScale(XMR_DECIMALS, BigDecimal.ROUND_HALF_UP) .stripTrailingZeros(); if (d.scale() < 1) d = d.setScale(1, BigDecimal.ROUND_UNNECESSARY); diff --git a/app/src/main/java/com/m2049r/xmrwallet/util/LegacyStorageHelper.java b/app/src/main/java/com/m2049r/xmrwallet/util/LegacyStorageHelper.java index 9ccdf5cf..68a1f6b6 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/util/LegacyStorageHelper.java +++ b/app/src/main/java/com/m2049r/xmrwallet/util/LegacyStorageHelper.java @@ -53,6 +53,7 @@ public class LegacyStorageHelper { public void migrate() { String addressPrefix = WalletManager.getInstance().addressPrefix(); File[] wallets = srcDir.listFiles((dir, filename) -> filename.endsWith(".keys")); + if (wallets == null) return; for (File wallet : wallets) { final String walletName = wallet.getName().substring(0, wallet.getName().length() - ".keys".length()); if (addressPrefix.indexOf(getAddress(walletName).charAt(0)) < 0) { diff --git a/app/src/main/java/com/m2049r/xmrwallet/util/Notice.java b/app/src/main/java/com/m2049r/xmrwallet/util/Notice.java index 8e5c4dfd..673e37a2 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/util/Notice.java +++ b/app/src/main/java/com/m2049r/xmrwallet/util/Notice.java @@ -30,6 +30,7 @@ import androidx.fragment.app.FragmentManager; import com.m2049r.xmrwallet.R; import com.m2049r.xmrwallet.dialog.HelpFragment; +import com.m2049r.xmrwallet.ledger.Ledger; import java.util.ArrayList; import java.util.List; @@ -52,12 +53,13 @@ public class Notice { R.string.help_xmrto, 1) ); - notices.add( - new Notice(NOTICE_SHOW_LEDGER, - R.string.info_ledger_enabled, - R.string.help_create_ledger, - 1) - ); + if (Ledger.ENABLED) + notices.add( + new Notice(NOTICE_SHOW_LEDGER, + R.string.info_ledger_enabled, + R.string.help_create_ledger, + 1) + ); } } diff --git a/app/src/main/java/com/m2049r/xmrwallet/util/RestoreHeight.java b/app/src/main/java/com/m2049r/xmrwallet/util/RestoreHeight.java index f0177d39..1619bf26 100644 --- a/app/src/main/java/com/m2049r/xmrwallet/util/RestoreHeight.java +++ b/app/src/main/java/com/m2049r/xmrwallet/util/RestoreHeight.java @@ -26,6 +26,8 @@ import java.util.TimeZone; import java.util.concurrent.TimeUnit; public class RestoreHeight { + static final int DIFFICULTY_TARGET = 120; // seconds + static private RestoreHeight Singleton = null; static public RestoreHeight getInstance() { @@ -190,7 +192,7 @@ public class RestoreHeight { } else { long days = TimeUnit.DAYS.convert(query.getTimeInMillis() - prevTime, TimeUnit.MILLISECONDS); - height = Math.round(prevBc + 1.0 * days * (24 * 60 / 2)); + height = Math.round(prevBc + 1.0 * days * (24f * 60 * 60 / DIFFICULTY_TARGET)); } return height; }