Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for some WalletConnect handling issues #3290

Merged
merged 3 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions app/src/main/java/com/alphawallet/app/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import java.util.HashMap;
import java.util.Map;

import javax.annotation.Nullable;

/**
* Created by JB on 20/01/2022.
*/
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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; }
Expand Down Expand Up @@ -373,4 +388,9 @@ public int findItem(TXSpeed currentGasSpeedIndex)

return 0;
}

public GasSpeed getCustom()
{
return fees.get(TXSpeed.CUSTOM);
}
}
50 changes: 34 additions & 16 deletions app/src/main/java/com/alphawallet/app/ui/HomeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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<String> requestPermissionLauncher =
registerForActivityResult(new ActivityResultContracts.RequestPermission(), isGranted -> {
if (isGranted)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -953,6 +951,10 @@ private void hideDialog()
{
dialog.dismiss();
}
if (wcProgressDialog != null && wcProgressDialog.isShowing())
{
wcProgressDialog.dismiss();
}
}

private boolean checkNotificationPermission(int permissionTag)
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
20 changes: 20 additions & 0 deletions app/src/main/java/com/alphawallet/app/util/TimberInit.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.alphawallet.app.util

import com.alphawallet.app.BuildConfig
import timber.log.Timber

object TimberUtils
JamesSmartCell marked this conversation as resolved.
Show resolved Hide resolved
{
@JvmStatic
fun configTimber()
{
if (BuildConfig.DEBUG)
{
Timber.plant(Timber.DebugTree())
}
else
{
Timber.plant(ReleaseTree())
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -139,6 +140,11 @@ private List<Long> getChainListFromSession()

private void showActionSheet(ActionSheetCallback aCallback, BaseRequest signRequest, Signable signable)
{
if (activity instanceof HomeActivity homeActivity)
{
homeActivity.clearWalletConnectRequest();
}

if (actionSheet != null && actionSheet.isShowing())
{
actionSheet.forceDismiss();
Expand Down
25 changes: 23 additions & 2 deletions app/src/main/java/com/alphawallet/app/widget/GasWidget2.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
}
}

42 changes: 21 additions & 21 deletions app/src/main/res/layout/item_gas_slider.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

<LinearLayout
android:id="@+id/layout_priority_fee"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

Expand All @@ -63,27 +63,27 @@
android:padding="@dimen/tiny_8">

<androidx.appcompat.widget.AppCompatSeekBar
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_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" />

<EditText
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" />
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" />

</LinearLayout>

Expand Down Expand Up @@ -157,4 +157,4 @@
android:padding="@dimen/small_12" />


</LinearLayout>
</LinearLayout>
Loading