From ec72c5dddc98a23f1dadba13aafa3cb82127afc3 Mon Sep 17 00:00:00 2001 From: James Brown Date: Mon, 11 Sep 2023 18:28:03 +1000 Subject: [PATCH 1/3] Fix WalletConnect handling --- .../app/entity/GasPriceSpread.java | 22 +++++++- .../com/alphawallet/app/ui/HomeActivity.java | 50 +++++++++++++------ .../alphawallet/app/util/BalanceUtils.java | 2 +- .../WalletConnectV2SessionRequestHandler.java | 6 +++ .../alphawallet/app/widget/GasWidget2.java | 25 +++++++++- app/src/main/res/layout/item_gas_slider.xml | 42 ++++++++-------- 6 files changed, 106 insertions(+), 41 deletions(-) diff --git a/app/src/main/java/com/alphawallet/app/entity/GasPriceSpread.java b/app/src/main/java/com/alphawallet/app/entity/GasPriceSpread.java index 838fd54f17..ef9cd260b4 100644 --- a/app/src/main/java/com/alphawallet/app/entity/GasPriceSpread.java +++ b/app/src/main/java/com/alphawallet/app/entity/GasPriceSpread.java @@ -17,6 +17,8 @@ import java.util.HashMap; import java.util.Map; +import javax.annotation.Nullable; + /** * Created by JB on 20/01/2022. */ @@ -265,6 +267,18 @@ public void setCustom(BigInteger maxFeePerGas, BigInteger maxPriorityFeePerGas, fees.put(TXSpeed.CUSTOM, new GasSpeed(gsCustom.speed, fastSeconds, new EIP1559FeeOracleResult(maxFeePerGas, maxPriorityFeePerGas, baseFee))); } + public void setCustom(@Nullable GasSpeed gs) + { + if (gs != null) + { + GasSpeed rapid = fees.get(TXSpeed.RAPID); + BigInteger baseFee = rapid != null ? rapid.gasPrice.baseFee : gs.gasPrice.baseFee; + + GasSpeed custom = new GasSpeed(gs.speed, gs.seconds, new EIP1559FeeOracleResult(gs.gasPrice.maxFeePerGas, gs.gasPrice.priorityFee, baseFee)); + fees.put(TXSpeed.CUSTOM, custom); + } + } + public void setCustom(BigInteger gasPrice, long fastSeconds) { GasSpeed gsCustom = fees.get(TXSpeed.CUSTOM); @@ -344,7 +358,8 @@ public GasSpeed getGasSpeed() public boolean hasCustom() { - return fees.get(TXSpeed.CUSTOM).seconds != 0; + GasSpeed custom = fees.get(TXSpeed.CUSTOM); + return (custom != null && custom.seconds != 0); } public boolean hasLockedGas() { return hasLockedGas; } @@ -373,4 +388,9 @@ public int findItem(TXSpeed currentGasSpeedIndex) return 0; } + + public GasSpeed getCustom() + { + return fees.get(TXSpeed.CUSTOM); + } } diff --git a/app/src/main/java/com/alphawallet/app/ui/HomeActivity.java b/app/src/main/java/com/alphawallet/app/ui/HomeActivity.java index 6c3ac17b08..a7cd20325f 100644 --- a/app/src/main/java/com/alphawallet/app/ui/HomeActivity.java +++ b/app/src/main/java/com/alphawallet/app/ui/HomeActivity.java @@ -82,7 +82,6 @@ import com.alphawallet.app.viewmodel.HomeViewModel; import com.alphawallet.app.viewmodel.WalletConnectViewModel; import com.alphawallet.app.walletconnect.AWWalletConnectClient; -import com.alphawallet.app.walletconnect.util.WalletConnectHelper; import com.alphawallet.app.web3.entity.Web3Transaction; import com.alphawallet.app.widget.AWalletAlertDialog; import com.alphawallet.app.widget.AWalletConfirmationDialog; @@ -95,6 +94,7 @@ import com.github.florent37.tutoshowcase.TutoShowcase; import com.journeyapps.barcodescanner.ScanContract; import com.journeyapps.barcodescanner.ScanOptions; +import com.walletconnect.android.CoreClient; import net.yslibrary.android.keyboardvisibilityevent.KeyboardVisibilityEvent; @@ -137,6 +137,7 @@ public class HomeActivity extends BaseNavigationActivity implements View.OnClick private boolean isForeground; private volatile boolean tokenClicked = false; private String openLink; + private AWalletAlertDialog wcProgressDialog; private final ActivityResultLauncher requestPermissionLauncher = registerForActivityResult(new ActivityResultContracts.RequestPermission(), isGranted -> { if (isGranted) @@ -826,10 +827,7 @@ public void tokenScriptError(String message) aDialog.setMessage(message); aDialog.setIcon(AWalletAlertDialog.ERROR); aDialog.setButtonText(R.string.button_ok); - aDialog.setButtonListener(v -> - { - aDialog.dismiss(); - }); + aDialog.setButtonListener(v -> aDialog.dismiss()); dialog = aDialog; dialog.show(); }, 500); @@ -953,6 +951,10 @@ private void hideDialog() { dialog.dismiss(); } + if (wcProgressDialog != null && wcProgressDialog.isShowing()) + { + wcProgressDialog.dismiss(); + } } private boolean checkNotificationPermission(int permissionTag) @@ -1187,22 +1189,18 @@ else if (importData != null && importData.length() > 22 && importData.contains(A } else if (importData != null && importData.startsWith("wc:")) { - Intent intent; - - if (WalletConnectHelper.isWalletConnectV1(importData)) + //Determine if any action is required; if this is not a pairing request then ignore for now + if (importData.contains("relay-protocol")) { - intent = new Intent(this, WalletConnectActivity.class); - intent.putExtra("qrCode", WalletConnectActivity.WC_INTENT + importData); + Intent intent = new Intent(this, WalletConnectV2Activity.class); + intent.putExtra("url", importData); + intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); + startActivity(intent); } else { - intent = new Intent(this, WalletConnectV2Activity.class); - intent.putExtra("url", importData); + walletConnectRequestPending(); } - - intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); - - startActivity(intent); } else if (importPath != null) { @@ -1416,4 +1414,24 @@ private void importedSmartPass() dialog.show(); }); } + + //WalletConnect progress + private void walletConnectRequestPending() + { + hideDialog(); + runOnUiThread(() -> { + wcProgressDialog = new AWalletAlertDialog(this); + wcProgressDialog.setProgressMode(); + wcProgressDialog.setTitle(R.string.title_wallet_connect); + wcProgressDialog.setCancelable(false); + wcProgressDialog.show(); + handler.postDelayed(this::hideDialog, 10000); + }); + } + + public void clearWalletConnectRequest() + { + handler.removeCallbacksAndMessages(null); + runOnUiThread(this::hideDialog); + } } diff --git a/app/src/main/java/com/alphawallet/app/util/BalanceUtils.java b/app/src/main/java/com/alphawallet/app/util/BalanceUtils.java index 0c21f15ea7..cd79ac6597 100644 --- a/app/src/main/java/com/alphawallet/app/util/BalanceUtils.java +++ b/app/src/main/java/com/alphawallet/app/util/BalanceUtils.java @@ -49,7 +49,7 @@ public static String displayDigitPrecisionValue(BigDecimal value, int decimalRed value = value.divide(BigDecimal.valueOf(10).pow(decimalReduction)); if (value.compareTo(BigDecimal.ONE) > 0) { - return getScaledValue(value, 18, 2); + return getScaledValue(value, 0, 2); } else { diff --git a/app/src/main/java/com/alphawallet/app/walletconnect/WalletConnectV2SessionRequestHandler.java b/app/src/main/java/com/alphawallet/app/walletconnect/WalletConnectV2SessionRequestHandler.java index e08e3233b5..ae27440d9c 100644 --- a/app/src/main/java/com/alphawallet/app/walletconnect/WalletConnectV2SessionRequestHandler.java +++ b/app/src/main/java/com/alphawallet/app/walletconnect/WalletConnectV2SessionRequestHandler.java @@ -14,6 +14,7 @@ import com.alphawallet.app.entity.walletconnect.SignType; import com.alphawallet.app.entity.walletconnect.WalletConnectV2SessionItem; import com.alphawallet.app.repository.EthereumNetworkBase; +import com.alphawallet.app.ui.HomeActivity; import com.alphawallet.app.ui.WalletConnectV2Activity; import com.alphawallet.app.ui.widget.entity.ActionSheetCallback; import com.alphawallet.app.walletconnect.entity.BaseRequest; @@ -139,6 +140,11 @@ private List getChainListFromSession() private void showActionSheet(ActionSheetCallback aCallback, BaseRequest signRequest, Signable signable) { + if (activity instanceof HomeActivity homeActivity) + { + homeActivity.clearWalletConnectRequest(); + } + if (actionSheet != null && actionSheet.isShowing()) { actionSheet.forceDismiss(); diff --git a/app/src/main/java/com/alphawallet/app/widget/GasWidget2.java b/app/src/main/java/com/alphawallet/app/widget/GasWidget2.java index 123a46ef20..fc5c313f73 100644 --- a/app/src/main/java/com/alphawallet/app/widget/GasWidget2.java +++ b/app/src/main/java/com/alphawallet/app/widget/GasWidget2.java @@ -270,7 +270,9 @@ private void initGasSpeeds(Realm1559Gas gs) { try { + GasSpeed custom = getCustomGasSpeed(); gasSpread = new GasPriceSpread(getContext(), gs.getResult()); + gasSpread.setCustom(custom); //if we have mainnet then show timings, otherwise no timing, if the token has fiat value, show fiat value of gas, so we need the ticker handler.post(this); @@ -357,8 +359,15 @@ public BigInteger getGasPrice() @Override public BigInteger getGasPrice(BigInteger defaultPrice) { - GasSpeed gs = gasSpread.getSelectedGasFee(currentGasSpeedIndex); - return gs.gasPrice.maxFeePerGas; + if (gasSpread != null) + { + GasSpeed gs = gasSpread.getSelectedGasFee(currentGasSpeedIndex); + return gs.gasPrice.maxFeePerGas; + } + else + { + return defaultPrice; + } } @Override @@ -512,5 +521,17 @@ public void setGasEstimate(BigInteger estimate) //now update speeds handler.post(this); } + + private GasSpeed getCustomGasSpeed() + { + if (gasSpread != null) + { + return gasSpread.hasCustom() ? gasSpread.getCustom() : null; + } + else + { + return null; + } + } } diff --git a/app/src/main/res/layout/item_gas_slider.xml b/app/src/main/res/layout/item_gas_slider.xml index 97140cf219..17035f7828 100644 --- a/app/src/main/res/layout/item_gas_slider.xml +++ b/app/src/main/res/layout/item_gas_slider.xml @@ -47,7 +47,7 @@ @@ -63,27 +63,27 @@ android:padding="@dimen/tiny_8"> + android:id="@+id/priority_fee_slider" + style="?android:attr/progressBarStyleHorizontal" + android:layout_width="0dp" + android:layout_height="36dp" + android:layout_weight="4" + android:max="90" + android:paddingTop="@dimen/tiny_8" + android:paddingBottom="@dimen/tiny_8" + android:progress="10" /> + android:id="@+id/priority_fee_entry" + style="@style/Aw.Typography.Caption" + android:layout_width="0dp" + android:layout_height="match_parent" + android:layout_weight="1" + android:background="@drawable/background_password_entry" + android:gravity="end|center_vertical" + android:inputType="numberDecimal" + android:paddingEnd="@dimen/tiny_8" + tools:text="20" /> @@ -157,4 +157,4 @@ android:padding="@dimen/small_12" /> - \ No newline at end of file + From a9a24be30f7a06b5c7c1741a3c99db1befffa338 Mon Sep 17 00:00:00 2001 From: James Brown Date: Mon, 11 Sep 2023 18:57:10 +1000 Subject: [PATCH 2/3] fix build report issue --- .../main/java/com/alphawallet/app/App.java | 13 +++--------- .../com/alphawallet/app/util/TimberInit.kt | 20 +++++++++++++++++++ 2 files changed, 23 insertions(+), 10 deletions(-) create mode 100644 app/src/main/java/com/alphawallet/app/util/TimberInit.kt diff --git a/app/src/main/java/com/alphawallet/app/App.java b/app/src/main/java/com/alphawallet/app/App.java index 77224ad23d..164099bc51 100644 --- a/app/src/main/java/com/alphawallet/app/App.java +++ b/app/src/main/java/com/alphawallet/app/App.java @@ -13,6 +13,7 @@ import androidx.preference.PreferenceManager; import com.alphawallet.app.util.ReleaseTree; +import com.alphawallet.app.util.TimberUtils; import com.alphawallet.app.walletconnect.AWWalletConnectClient; import java.util.EmptyStackException; @@ -24,7 +25,6 @@ import io.reactivex.plugins.RxJavaPlugins; import io.realm.Realm; import timber.log.Timber; -import timber.log.Timber.DebugTree; @HiltAndroidApp public class App extends Application @@ -54,20 +54,13 @@ public Activity getTopActivity() } @Override + @SuppressWarnings("unchecked") public void onCreate() { super.onCreate(); mInstance = this; Realm.init(this); - - if (BuildConfig.DEBUG) - { - Timber.plant(new Timber.DebugTree()); - } - else - { - Timber.plant(new ReleaseTree()); - } + TimberUtils.configTimber(); int defaultTheme = PreferenceManager.getDefaultSharedPreferences(this) .getInt("theme", C.THEME_AUTO); diff --git a/app/src/main/java/com/alphawallet/app/util/TimberInit.kt b/app/src/main/java/com/alphawallet/app/util/TimberInit.kt new file mode 100644 index 0000000000..d00a066251 --- /dev/null +++ b/app/src/main/java/com/alphawallet/app/util/TimberInit.kt @@ -0,0 +1,20 @@ +package com.alphawallet.app.util + +import com.alphawallet.app.BuildConfig +import timber.log.Timber + +object TimberUtils +{ + @JvmStatic + fun configTimber() + { + if (BuildConfig.DEBUG) + { + Timber.plant(Timber.DebugTree()) + } + else + { + Timber.plant(ReleaseTree()) + } + } +} From f3c66e7d769881e95dcd9f6100877a7a0405edb9 Mon Sep 17 00:00:00 2001 From: James Brown Date: Mon, 11 Sep 2023 19:16:48 +1000 Subject: [PATCH 3/3] Update build --- app/src/main/java/com/alphawallet/app/App.java | 5 ++--- app/src/main/java/com/alphawallet/app/util/TimberInit.kt | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/alphawallet/app/App.java b/app/src/main/java/com/alphawallet/app/App.java index 164099bc51..f10177e5b7 100644 --- a/app/src/main/java/com/alphawallet/app/App.java +++ b/app/src/main/java/com/alphawallet/app/App.java @@ -12,8 +12,7 @@ import androidx.appcompat.app.AppCompatDelegate; import androidx.preference.PreferenceManager; -import com.alphawallet.app.util.ReleaseTree; -import com.alphawallet.app.util.TimberUtils; +import com.alphawallet.app.util.TimberInit; import com.alphawallet.app.walletconnect.AWWalletConnectClient; import java.util.EmptyStackException; @@ -60,7 +59,7 @@ public void onCreate() super.onCreate(); mInstance = this; Realm.init(this); - TimberUtils.configTimber(); + TimberInit.configTimber(); int defaultTheme = PreferenceManager.getDefaultSharedPreferences(this) .getInt("theme", C.THEME_AUTO); diff --git a/app/src/main/java/com/alphawallet/app/util/TimberInit.kt b/app/src/main/java/com/alphawallet/app/util/TimberInit.kt index d00a066251..9e37e4510f 100644 --- a/app/src/main/java/com/alphawallet/app/util/TimberInit.kt +++ b/app/src/main/java/com/alphawallet/app/util/TimberInit.kt @@ -3,7 +3,7 @@ package com.alphawallet.app.util import com.alphawallet.app.BuildConfig import timber.log.Timber -object TimberUtils +object TimberInit { @JvmStatic fun configTimber()