Detect EIP-4361 messages (#3193)

pull/3205/head
justindg 2 years ago committed by GitHub
parent 1a9b7a4be9
commit 1d0a3a2c5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 63
      app/src/main/java/com/alphawallet/app/widget/ActionSheetSignDialog.java
  2. 55
      app/src/main/java/com/alphawallet/app/widget/SignDataWidget.java
  3. 2
      app/src/main/res/color/selector_button_primary.xml
  4. 1
      app/src/main/res/values-es/strings.xml
  5. 1
      app/src/main/res/values-fr/strings.xml
  6. 1
      app/src/main/res/values-id/strings.xml
  7. 1
      app/src/main/res/values-my/strings.xml
  8. 1
      app/src/main/res/values-vi/strings.xml
  9. 1
      app/src/main/res/values-zh/strings.xml
  10. 1
      app/src/main/res/values/strings.xml

@ -38,10 +38,12 @@ public class ActionSheetSignDialog extends ActionSheet implements StandardFuncti
private final ConfirmationWidget confirmationWidget;
private final AddressDetailView requesterDetail;
private final AddressDetailView addressDetail;
private final SignDataWidget signWidget;
private final FunctionButtonBar functionBar;
private final ActionSheetCallback actionSheetCallback;
private final Activity activity;
private final long callbackId;
private final Signable signable;
private boolean actionCompleted;
private WalletType walletType;
@ -50,34 +52,55 @@ public class ActionSheetSignDialog extends ActionSheet implements StandardFuncti
super(callingActivity);
View view = View.inflate(callingActivity, R.layout.dialog_action_sheet_sign, null);
setContentView(view);
toolbar = findViewById(R.id.bottom_sheet_toolbar);
confirmationWidget = findViewById(R.id.confirmation_view);
requesterDetail = findViewById(R.id.requester);
addressDetail = findViewById(R.id.wallet);
functionBar = findViewById(R.id.layoutButtons);
toolbar = view.findViewById(R.id.bottom_sheet_toolbar);
confirmationWidget = view.findViewById(R.id.confirmation_view);
requesterDetail = view.findViewById(R.id.requester);
addressDetail = view.findViewById(R.id.wallet);
signWidget = view.findViewById(R.id.sign_widget);
functionBar = view.findViewById(R.id.layoutButtons);
callbackId = message.getCallbackId();
activity = callingActivity;
actionSheetCallback = aCallback;
signable = message;
requesterDetail.setupRequester(message.getOrigin());
SignDataWidget signWidget = findViewById(R.id.sign_widget);
signWidget.setupSignData(message);
viewModel = new ViewModelProvider((ViewModelStoreOwner) activity).get(SignDialogViewModel.class);
viewModel.completed().observe((LifecycleOwner) activity, this::signComplete);
viewModel.message().observe((LifecycleOwner) activity, this::onMessage);
viewModel.onWallet().observe((LifecycleOwner) activity, this::onWallet);
toolbar.setTitle(Utils.getSigningTitle(message));
setCanceledOnTouchOutside(false);
}
private void setupView()
{
requesterDetail.setupRequester(signable.getOrigin());
signWidget.setLockCallback(this);
if (isEip4361(signable))
{
functionBar.setPrimaryButtonEnabled(false);
toolbar.setTitle(R.string.dialog_title_sign_in_with_ethereum);
signWidget.setupSignData(signable, () -> {
functionBar.setPrimaryButtonEnabled(true);
});
}
else
{
toolbar.setTitle(Utils.getSigningTitle(signable));
signWidget.setupSignData(signable);
}
setupCancelListeners();
actionCompleted = false;
//ensure view fully expanded when locking scroll. Otherwise we may not be able to see our expanded view
fullExpand();
}
viewModel = new ViewModelProvider((ViewModelStoreOwner) activity).get(SignDialogViewModel.class);
viewModel.completed().observe((LifecycleOwner) activity, this::signComplete);
viewModel.message().observe((LifecycleOwner) activity, this::onMessage);
viewModel.onWallet().observe((LifecycleOwner) activity, this::onWallet);
setCanceledOnTouchOutside(false);
private boolean isEip4361(Signable message)
{
String userMsg = message.getUserMessage().toString();
String domain = Utils.getDomainName(message.getOrigin());
return userMsg.contains(domain + " wants you to sign in with your Ethereum account");
}
private void onWallet(Wallet wallet)
@ -96,6 +119,8 @@ public class ActionSheetSignDialog extends ActionSheet implements StandardFuncti
}
functionBar.revealButtons();
setupView();
}
@Override
@ -103,9 +128,9 @@ public class ActionSheetSignDialog extends ActionSheet implements StandardFuncti
{
ImageView iconView = findViewById(R.id.logo);
Glide.with(activity)
.load(icon)
.circleCrop()
.into(iconView);
.load(icon)
.circleCrop()
.into(iconView);
}
@Override

@ -4,6 +4,7 @@ import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
@ -13,8 +14,6 @@ import androidx.annotation.Nullable;
import com.alphawallet.app.R;
import com.alphawallet.app.entity.ActionSheetInterface;
import com.alphawallet.app.util.Hex;
import com.alphawallet.token.entity.SignMessageType;
import com.alphawallet.token.entity.Signable;
/**
@ -29,6 +28,8 @@ public class SignDataWidget extends LinearLayout
private final ScrollView scrollView;
private ActionSheetInterface sheetInterface;
private Signable signable;
private ScrollListener listener;
private boolean isScrollToBottomRequired;
public SignDataWidget(Context context, @Nullable AttributeSet attrs)
{
@ -48,17 +49,51 @@ public class SignDataWidget extends LinearLayout
}
}
private void requireScroll()
{
scrollView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener()
{
@Override
public void onGlobalLayout()
{
if (scrollView.canScrollVertically(1) || scrollView.canScrollVertically(-1))
{
scrollView.getViewTreeObserver()
.addOnScrollChangedListener(() -> {
if (scrollView.getChildAt(0).getBottom()
== (scrollView.getHeight() + scrollView.getScrollY()))
{
listener.hasScrolledToBottom();
}
});
}
else
{
listener.hasScrolledToBottom();
}
scrollView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
});
}
private boolean getAttribute(Context context, AttributeSet attrs)
{
TypedArray a = context.getTheme().obtainStyledAttributes(
attrs,
R.styleable.SignDataWidget,
0, 0
attrs,
R.styleable.SignDataWidget,
0, 0
);
return a.getBoolean(R.styleable.SignDataWidget_noTitle, false);
}
public void setupSignData(Signable signable, ScrollListener listener)
{
this.listener = listener;
isScrollToBottomRequired = true;
setupSignData(signable);
}
public void setupSignData(Signable signable)
{
this.signable = signable;
@ -74,6 +109,11 @@ public class SignDataWidget extends LinearLayout
scrollView.setEnabled(true);
moreArrow.setImageResource(R.drawable.ic_expand_less_black);
if (sheetInterface != null) sheetInterface.lockDragging(true);
if (isScrollToBottomRequired)
{
requireScroll();
}
}
else
{
@ -95,4 +135,9 @@ public class SignDataWidget extends LinearLayout
{
return signable;
}
public interface ScrollListener
{
void hasScrolledToBottom();
}
}

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="?colorOnSurface" android:state_enabled="true" />
<item android:color="@color/button_primary_disabled" android:state_enabled="false" />
<item android:color="?colorOnSurface" android:alpha="0.3" android:state_enabled="false" />
</selector>

@ -957,4 +957,5 @@
<string name="action_view_session">Ver sesión</string>
<string name="error_walletconnect_session_request_unsupported_network">No se puede manejar la solicitud de sesión de una cadena no admitida. (ID: %s)</string>
<string name="spam_header">Spam</string>
<string name="dialog_title_sign_in_with_ethereum">Iniciar sesión con Ethereum</string>
</resources>

@ -971,4 +971,5 @@
<string name="action_view_session">Voir la session</string>
<string name="error_walletconnect_session_request_unsupported_network">Impossible de gérer la demande de session d\'une chaîne non prise en charge. (ID: %s)</string>
<string name="spam_header">Pourriel</string>
<string name="dialog_title_sign_in_with_ethereum">Connectez-vous avec Ethereum</string>
</resources>

@ -961,4 +961,5 @@
<string name="action_view_session">Lihat Sesi</string>
<string name="error_walletconnect_session_request_unsupported_network">Tidak dapat menangani permintaan sesi dari rantai yang tidak didukung. (ID: %s)</string>
<string name="spam_header">Spam</string>
<string name="dialog_title_sign_in_with_ethereum">Masuk dengan Ethereum</string>
</resources>

@ -992,4 +992,5 @@
<string name="action_view_session">Session ကက</string>
<string name="error_walletconnect_session_request_unsupported_network">မထ ကဆကတစ ဆကက မက။ (ID: %s)</string>
<string name="spam_header">မဟ</string>
<string name="dialog_title_sign_in_with_ethereum">Ethereum ဖ ဝငက</string>
</resources>

@ -971,4 +971,5 @@
<string name="action_view_session">Xem phiên</string>
<string name="error_walletconnect_session_request_unsupported_network">Không thể xử lý yêu cầu phiên từ một chuỗi không được hỗ trợ. (ID: %s)</string>
<string name="spam_header">Thư rác</string>
<string name="dialog_title_sign_in_with_ethereum">Đăng nhập bằng Ethereum</string>
</resources>

@ -958,4 +958,5 @@
<string name="action_view_session">查看会话</string>
<string name="error_walletconnect_session_request_unsupported_network">无法处理来自不受支持的链的会话请求。(ID: %s)</string>
<string name="spam_header">垃圾邮件</string>
<string name="dialog_title_sign_in_with_ethereum">使用以太坊登录</string>
</resources>

@ -1033,4 +1033,5 @@
<string name="action_view_session">View Session</string>
<string name="error_walletconnect_session_request_unsupported_network">Unable to handle session request from an unsupported chain. (ID: %s)</string>
<string name="spam_header">Spam</string>
<string name="dialog_title_sign_in_with_ethereum">Sign in with Ethereum</string>
</resources>

Loading…
Cancel
Save