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 JS popup #3327

Merged
merged 1 commit into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;

import static androidx.core.content.ContentProviderCompat.requireContext;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
Expand Down Expand Up @@ -40,6 +42,7 @@
import com.alphawallet.app.ui.widget.divider.ListDivider;
import com.alphawallet.app.viewmodel.WalletConnectViewModel;
import com.alphawallet.app.walletconnect.AWWalletConnectClient;
import com.alphawallet.app.widget.AWalletAlertDialog;
import com.bumptech.glide.Glide;

import java.util.List;
Expand Down Expand Up @@ -231,27 +234,23 @@ private void setStatusIconActive(final CustomAdapter.CustomViewHolder holder, bo

private void dialogConfirmDelete(WalletConnectSessionItem session)
{
AlertDialog.Builder builder = new AlertDialog.Builder(this);
AlertDialog dialog = builder.setTitle(R.string.title_delete_session)
.setMessage(getString(R.string.delete_session, session.name))
.setPositiveButton(R.string.delete, (d, w) -> {
viewModel.deleteSession(session, new AWWalletConnectClient.WalletConnectV2Callback()
{
@Override
public void onSessionDisconnected()
{
runOnUiThread(() -> {
awWalletConnectClient.updateNotification();
});
}
});
})
.setNegativeButton(R.string.action_cancel, (d, w) -> {
d.dismiss();
})
.setCancelable(false)
.create();
dialog.show();
AWalletAlertDialog cDialog = new AWalletAlertDialog(this);
cDialog.setCancelable(true);
cDialog.setTitle(R.string.title_delete_session);
cDialog.setMessage(getString(R.string.delete_session, session.name));
cDialog.setButtonText(R.string.delete);
cDialog.setButtonListener(v -> viewModel.deleteSession(session, new AWWalletConnectClient.WalletConnectV2Callback()
{
@Override
public void onSessionDisconnected()
{
runOnUiThread(() -> awWalletConnectClient.updateNotification());
}
}));
cDialog.setSecondaryButtonText(R.string.action_cancel);
cDialog.setSecondaryButtonListener(view -> cDialog.dismiss());
cDialog.setCancelable(false);
cDialog.show();
}

private void startConnectionCheck()
Expand Down
50 changes: 29 additions & 21 deletions app/src/main/java/com/alphawallet/app/web3/Web3TokenView.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static androidx.webkit.WebSettingsCompat.FORCE_DARK_OFF;
import static androidx.webkit.WebSettingsCompat.FORCE_DARK_ON;
import static androidx.webkit.WebSettingsCompat.setAlgorithmicDarkeningAllowed;
import static com.alphawallet.app.service.AssetDefinitionService.ASSET_DETAIL_VIEW_NAME;
import static com.alphawallet.app.service.AssetDefinitionService.ASSET_SUMMARY_VIEW_NAME;
import static com.alphawallet.token.tools.TokenDefinition.TOKENSCRIPT_ERROR;
Expand All @@ -16,6 +17,8 @@
import android.view.View;
import android.webkit.ConsoleMessage;
import android.webkit.JavascriptInterface;
import android.webkit.JsPromptResult;
import android.webkit.JsResult;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceError;
import android.webkit.WebResourceRequest;
Expand Down Expand Up @@ -125,18 +128,9 @@ private void init() {
+ "AlphaWallet(Platform=Android&AppVersion=" + BuildConfig.VERSION_NAME + ")");
WebView.setWebContentsDebuggingEnabled(true);

if (WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK))
if (WebViewFeature.isFeatureSupported(WebViewFeature.ALGORITHMIC_DARKENING))
{
switch (getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK)
{
case Configuration.UI_MODE_NIGHT_YES:
WebSettingsCompat.setForceDark(getSettings(), FORCE_DARK_ON);
break;
case Configuration.UI_MODE_NIGHT_NO:
case Configuration.UI_MODE_NIGHT_UNDEFINED:
WebSettingsCompat.setForceDark(getSettings(), FORCE_DARK_OFF);
break;
}
WebSettingsCompat.setAlgorithmicDarkeningAllowed(getSettings(), true);
}

setScrollBarSize(0);
Expand All @@ -153,8 +147,6 @@ private void init() {
innerOnSignPersonalMessageListener,
innerOnSetValuesListener), "alpha");

super.setWebViewClient(tokenScriptClient);

setWebChromeClient(new WebChromeClient()
{
@Override
Expand Down Expand Up @@ -191,7 +183,16 @@ public boolean onConsoleMessage(ConsoleMessage msg)
}
return true;
}

@Override
public boolean onJsAlert(WebView view, String url, String message, JsResult result)
{
result.cancel();
return true;
}
});

setWebViewClient(tokenScriptClient);
}

public void showError(String error)
Expand All @@ -201,12 +202,6 @@ public void showError(String error)
loadData(error, "text/html", "utf-8");
}

@Override
public void setWebChromeClient(WebChromeClient client)
{
super.setWebChromeClient(client);
}

@JavascriptInterface
public void onValue(String data)
{
Expand All @@ -228,6 +223,19 @@ public void onCloseWindow(WebView window)
{
callback.functionSuccess();
}

@Override
public boolean onConsoleMessage(ConsoleMessage msg)
{
return true;
}

@Override
public boolean onJsAlert(WebView view, String url, String message, JsResult result)
{
result.cancel();
return true;
}
}
);
}
Expand Down Expand Up @@ -385,11 +393,11 @@ public void onUnhandledKeyEvent(WebView view, KeyEvent event)
}

@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request)
{
if (assetHolder != null)
{
return assetHolder.overridePageLoad(view, url);
return assetHolder.overridePageLoad(view, request.getUrl().toString());
}
else
{
Expand Down
Loading