Skip to content

Commit

Permalink
Common bottom sheet for not allowed operations and signer raw not sup…
Browse files Browse the repository at this point in the history
…ported info (#378)

* Common bottom sheet for not allowed operations and signer raw not supported info
  • Loading branch information
valentunn authored Aug 5, 2022
1 parent 3327c05 commit d363263
Show file tree
Hide file tree
Showing 11 changed files with 160 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package io.novafoundation.nova.common.view.bottomSheet

import android.content.Context
import android.os.Bundle
import android.widget.ImageView
import android.widget.TextView
import androidx.annotation.DrawableRes
import androidx.core.view.setPadding
import com.google.android.material.bottomsheet.BottomSheetDialog
import io.novafoundation.nova.common.R
import io.novafoundation.nova.common.utils.WithContextExtensions
import io.novafoundation.nova.common.view.PrimaryButton
import kotlinx.android.synthetic.main.bottom_sheet_action_not_allowed.actionNotAllowedImage
import kotlinx.android.synthetic.main.bottom_sheet_action_not_allowed.actionNotAllowedOk
import kotlinx.android.synthetic.main.bottom_sheet_action_not_allowed.actionNotAllowedSubtitle
import kotlinx.android.synthetic.main.bottom_sheet_action_not_allowed.actionNotAllowedTitle

open class ActionNotAllowedBottomSheet(
context: Context,
private val onSuccess: () -> Unit,
) : BottomSheetDialog(context, R.style.BottomSheetDialog), WithContextExtensions by WithContextExtensions(context) {

val image: ImageView
get() = actionNotAllowedImage

val title: TextView
get() = actionNotAllowedTitle

val subtitle: TextView
get() = actionNotAllowedSubtitle

val button: PrimaryButton
get() = actionNotAllowedOk

init {
setContentView(R.layout.bottom_sheet_action_not_allowed)
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

setOnDismissListener { onSuccess() }

actionNotAllowedOk.setOnClickListener {
dismiss()
}
}

// make it final so we will be able to call it from constructor without the risk of initialization conflict
final override fun setContentView(layoutResId: Int) {
super.setContentView(layoutResId)
}

protected fun applyBigIconStyle(@DrawableRes src: Int) = with(image) {
setPadding(12.dp)
setBackgroundResource(R.drawable.bg_icon_big)
setImageResource(src)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="vertical"
xmlns:tools="http://schemas.android.com/tools"
android:paddingStart="16dp"
android:paddingEnd="16dp">

Expand All @@ -14,20 +15,23 @@
<ImageView
android:layout_width="88dp"
android:layout_height="88dp"
android:layout_marginTop="20dp"
android:src="@drawable/ic_key_missing" />
tools:src="@color/white"
android:id="@+id/actionNotAllowedImage"
android:layout_marginTop="20dp" />

<TextView
style="@style/TextAppearance.NovaFoundation.SemiBold.Title3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/actionNotAllowedTitle"
android:layout_marginTop="24dp"
android:text="@string/account_watch_key_missing_title" />

<TextView
style="@style/TextAppearance.NovaFoundation.Regular.Footnote"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/actionNotAllowedSubtitle"
android:layout_marginTop="8dp"
android:gravity="center"
android:text="@string/account_watch_key_missing_description"
Expand All @@ -36,7 +40,7 @@
<io.novafoundation.nova.common.view.PrimaryButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/watchOnlySignButton"
android:id="@+id/actionNotAllowedOk"
android:layout_marginTop="24dp"
android:layout_marginBottom="16dp"
android:text="@string/common_ok_back" />
Expand Down
7 changes: 5 additions & 2 deletions common/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<string name="account_parity_signer_not_supported_title">Signing is not supported</string>
<string name="account_parity_signer_not_supported_subtitle">Parity Signer does not support signing arbitrary messages — only transactions</string>

<string name="common_invalid_qr">QR code is invalid</string>
<string name="account_parity_signer_sign_qr_invalid_message">Please make sure you are scanning QR code for currently signing operation</string>

Expand All @@ -26,8 +29,8 @@
<string name="common_permission_permissions_denied_message">Requested permissions are required to use this screen. You should enable them in Settings.</string>
<string name="common_to_settings">Open Settings</string>

<string name="account_parity_signer_scan_from">Scan the QR code provided by Parity Signer</string>
<string name="account_parity_signer_scan_with">Scan the QR code with Parity Signer</string>
<string name="account_parity_signer_scan_from">Scan the QR code from the Parity Signer</string>
<string name="account_parity_signer_scan_with">Scan the QR code with the Parity Signer</string>

<string name="account_welcome_hardware_wallet_title">Connect hardware wallet</string>
<string name="account_welcome_hardware_wallet_subtitle">Use Parity Signer</string>
Expand Down
2 changes: 1 addition & 1 deletion common/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@
<item name="android:layout_width">88dp</item>
<item name="android:layout_height">88dp</item>
<item name="android:background">@drawable/bg_icon_big</item>
<item name="android:padding">16dp</item>
<item name="android:padding">12dp</item>
</style>

<style name="Widget.Nova.Text.Number" parent="">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import io.novafoundation.nova.common.utils.MutableSharedState
import io.novafoundation.nova.feature_account_impl.presentation.paritySigner.ParitySignerSignInterScreenCommunicator
import io.novafoundation.nova.feature_account_impl.presentation.paritySigner.ParitySignerSignInterScreenRequester
import io.novafoundation.nova.feature_account_impl.presentation.paritySigner.awaitConfirmation
import io.novafoundation.nova.feature_account_impl.presentation.paritySigner.sign.notSupported.ParitySignerSigningNotSupportedPresentable
import jp.co.soramitsu.fearless_utils.encrypt.SignatureWrapper
import jp.co.soramitsu.fearless_utils.runtime.extrinsic.signer.Signer
import jp.co.soramitsu.fearless_utils.runtime.extrinsic.signer.SignerPayloadExtrinsic
Expand All @@ -16,6 +17,7 @@ import java.util.UUID
class ParitySignerSigner(
private val signingSharedState: MutableSharedState<SignerPayloadExtrinsic>,
private val signFlowRequester: ParitySignerSignInterScreenRequester,
private val messageSigningNotSupported: ParitySignerSigningNotSupportedPresentable
) : Signer {

override suspend fun signExtrinsic(payloadExtrinsic: SignerPayloadExtrinsic): SignatureWrapper {
Expand All @@ -37,8 +39,9 @@ class ParitySignerSigner(
}

override suspend fun signRaw(payload: SignerPayloadRaw): SignatureWrapper {
// TODO show error bottom sheet
throw IllegalArgumentException("Cannot sign raw messages with Parity Signer")
messageSigningNotSupported.presentSigningNotSupported()

throw SigningCancelledException()
}

private fun createNewRequest(): ParitySignerSignInterScreenCommunicator.Request {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import dagger.Module
import dagger.Provides
import io.novafoundation.nova.common.di.scope.FeatureScope
import io.novafoundation.nova.common.mixin.actionAwaitable.ActionAwaitableMixin
import io.novafoundation.nova.common.resources.ContextManager
import io.novafoundation.nova.common.resources.ResourceManager
import io.novafoundation.nova.common.utils.DefaultMutableSharedState
import io.novafoundation.nova.common.utils.MutableSharedState
Expand All @@ -14,6 +15,8 @@ import io.novafoundation.nova.feature_account_impl.data.repository.RealParitySig
import io.novafoundation.nova.feature_account_impl.presentation.AccountRouter
import io.novafoundation.nova.feature_account_impl.presentation.paritySigner.ParitySignerSignInterScreenCommunicator
import io.novafoundation.nova.feature_account_impl.presentation.paritySigner.sign.common.QrCodeExpiredPresentableFactory
import io.novafoundation.nova.feature_account_impl.presentation.paritySigner.sign.notSupported.ParitySignerSigningNotSupportedPresentable
import io.novafoundation.nova.feature_account_impl.presentation.paritySigner.sign.notSupported.RealParitySignerSigningNotSupportedPresentable
import jp.co.soramitsu.fearless_utils.runtime.extrinsic.signer.SignerPayloadExtrinsic

@Module
Expand Down Expand Up @@ -43,4 +46,10 @@ class ParitySignerModule {
router: AccountRouter,
communicator: ParitySignerSignInterScreenCommunicator
) = QrCodeExpiredPresentableFactory(resourceManager, actionAwaitableMixinFactory, router, communicator)

@Provides
@FeatureScope
fun provideSigningNotSupportedPresentable(
contextManager: ContextManager
): ParitySignerSigningNotSupportedPresentable = RealParitySignerSigningNotSupportedPresentable(contextManager)
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import io.novafoundation.nova.feature_account_impl.data.signer.paritySigner.Pari
import io.novafoundation.nova.feature_account_impl.data.signer.secrets.SecretsSignerFactory
import io.novafoundation.nova.feature_account_impl.data.signer.watchOnly.WatchOnlySigner
import io.novafoundation.nova.feature_account_impl.presentation.paritySigner.ParitySignerSignInterScreenCommunicator
import io.novafoundation.nova.feature_account_impl.presentation.paritySigner.sign.notSupported.ParitySignerSigningNotSupportedPresentable
import jp.co.soramitsu.fearless_utils.runtime.extrinsic.signer.SignerPayloadExtrinsic

@Module
Expand All @@ -31,8 +32,9 @@ class SignersModule {
@FeatureScope
fun provideParitySignerSigner(
signingSharedState: MutableSharedState<SignerPayloadExtrinsic>,
communicator: ParitySignerSignInterScreenCommunicator
) = ParitySignerSigner(signingSharedState, communicator)
communicator: ParitySignerSignInterScreenCommunicator,
signingNotSupportedPresentable: ParitySignerSigningNotSupportedPresentable
) = ParitySignerSigner(signingSharedState, communicator, signingNotSupportedPresentable)

@Provides
@FeatureScope
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.novafoundation.nova.feature_account_impl.presentation.paritySigner.sign.notSupported

import android.content.Context
import android.content.DialogInterface
import android.os.Bundle
import io.novafoundation.nova.common.utils.DialogExtensions
import io.novafoundation.nova.common.view.bottomSheet.ActionNotAllowedBottomSheet
import io.novafoundation.nova.feature_account_impl.R

class AcknowledgeSigningNotSupportedBottomSheet(
context: Context,
private val onConfirm: () -> Unit
) : ActionNotAllowedBottomSheet(
context = context,
onSuccess = onConfirm,
), DialogExtensions {

override val dialogInterface: DialogInterface
get() = this

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

title.setText(R.string.account_parity_signer_not_supported_title)
subtitle.setText(R.string.account_parity_signer_not_supported_subtitle)

applyBigIconStyle(R.drawable.ic_parity_signer)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package io.novafoundation.nova.feature_account_impl.presentation.paritySigner.sign.notSupported

import io.novafoundation.nova.common.resources.ContextManager
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine

interface ParitySignerSigningNotSupportedPresentable {

suspend fun presentSigningNotSupported()
}

class RealParitySignerSigningNotSupportedPresentable(
private val contextManager: ContextManager,
) : ParitySignerSigningNotSupportedPresentable {

override suspend fun presentSigningNotSupported(): Unit = withContext(Dispatchers.Main) {
suspendCoroutine {
AcknowledgeSigningNotSupportedBottomSheet(
context = contextManager.getActivity()!!,
onConfirm = { it.resume(Unit) }
).show()
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,20 @@ package io.novafoundation.nova.feature_account_impl.presentation.watchOnly.sign

import android.content.Context
import android.os.Bundle
import com.google.android.material.bottomsheet.BottomSheetDialog
import io.novafoundation.nova.common.view.bottomSheet.ActionNotAllowedBottomSheet
import io.novafoundation.nova.feature_account_impl.R
import kotlinx.android.synthetic.main.watch_only_sign_bottom_sheet.watchOnlySignButton

class WatchOnlySignBottomSheet(
context: Context,
private val onSuccess: () -> Unit
) : BottomSheetDialog(context, R.style.BottomSheetDialog) {

init {
setContentView(R.layout.watch_only_sign_bottom_sheet)
}
onSuccess: () -> Unit
) : ActionNotAllowedBottomSheet(context, onSuccess) {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

setOnDismissListener { onSuccess() }
title.setText(R.string.account_watch_key_missing_title)
subtitle.setText(R.string.account_watch_key_missing_description)

watchOnlySignButton.setOnClickListener {
dismiss()
}
image.setImageResource(R.drawable.ic_key_missing)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@ package io.novafoundation.nova.feature_dapp_impl.presentation.browser.main.sheet
import android.content.Context
import android.content.DialogInterface
import android.os.Bundle
import com.google.android.material.bottomsheet.BottomSheetDialog
import io.novafoundation.nova.common.utils.DialogExtensions
import io.novafoundation.nova.common.view.bottomSheet.ActionNotAllowedBottomSheet
import io.novafoundation.nova.feature_dapp_impl.R
import io.novafoundation.nova.feature_dapp_impl.presentation.browser.main.DappPendingConfirmation
import kotlinx.android.synthetic.main.bottom_sheet_scam_alert.phishingAlertAcknowledge

class AcknowledgePhishingBottomSheet(
context: Context,
private val confirmation: DappPendingConfirmation<*>,
) : BottomSheetDialog(context, R.style.BottomSheetDialog), DialogExtensions {
) : ActionNotAllowedBottomSheet(
context = context,
onSuccess = { confirmation.onConfirm() }
), DialogExtensions {

override val dialogInterface: DialogInterface
get() = this

override fun onCreate(savedInstanceState: Bundle?) {
setContentView(R.layout.bottom_sheet_scam_alert)
super.onCreate(savedInstanceState)

setCancelable(false)
title.setText(R.string.dapp_phishing_title)
subtitle.setText(R.string.dapp_phishing_subtitle)

phishingAlertAcknowledge.setDismissingClickListener {
confirmation.onConfirm()
}
applyBigIconStyle(R.drawable.ic_warning_filled)
}
}

0 comments on commit d363263

Please sign in to comment.