Updated on 2026-08-14
This commit is contained in:
parent
82d8417160
commit
94192eba68
8 changed files with 40 additions and 8 deletions
|
|
@ -6,6 +6,7 @@ import com.tangem.tap.common.redux.global.GlobalState
|
|||
import com.tangem.tap.features.details.redux.walletconnect.WalletConnectDialog
|
||||
import com.tangem.tap.features.details.ui.walletconnect.dialogs.*
|
||||
import com.tangem.tap.store
|
||||
import com.tangem.wallet.R
|
||||
import org.rekotlin.StoreSubscriber
|
||||
|
||||
class DialogManager : StoreSubscriber<GlobalState> {
|
||||
|
|
@ -38,7 +39,18 @@ class DialogManager : StoreSubscriber<GlobalState> {
|
|||
|
||||
when (state.dialog) {
|
||||
is WalletConnectDialog.UnsupportedCard ->
|
||||
dialog = UnsupportedCardDialog.create(context)
|
||||
dialog = SimpleAlertDialog.create(
|
||||
titleRes = R.string.wallet_connect,
|
||||
messageRes = R.string.wallet_connect_scanner_error_no_ethereum_wallet,
|
||||
context = context
|
||||
)
|
||||
is WalletConnectDialog.OpeningSessionRejected -> {
|
||||
dialog = SimpleAlertDialog.create(
|
||||
titleRes = R.string.wallet_connect,
|
||||
messageRes = R.string.wallet_connect_same_wcuri,
|
||||
context = context
|
||||
)
|
||||
}
|
||||
is WalletConnectDialog.ApproveWcSession ->
|
||||
dialog = ApproveWcSessionDialog.create(state.dialog.session, context)
|
||||
is WalletConnectDialog.ClipboardOrScanQr ->
|
||||
|
|
|
|||
|
|
@ -44,6 +44,10 @@ class WalletConnectManager {
|
|||
|
||||
fun connect(wcUri: String, wallet: WalletForSession) {
|
||||
val session = WCSession.from(wcUri) ?: return
|
||||
if (sessions[session] != null) {
|
||||
store.dispatchOnMain(WalletConnectAction.RefuseOpeningSession)
|
||||
return
|
||||
}
|
||||
val client = WCClient(httpClient = okHttpClient)
|
||||
setListeners(client)
|
||||
val peerId = UUID.randomUUID().toString()
|
||||
|
|
|
|||
|
|
@ -29,6 +29,8 @@ sealed class WalletConnectAction : Action {
|
|||
val wallet: WalletForSession,
|
||||
) : WalletConnectAction()
|
||||
|
||||
object RefuseOpeningSession : WalletConnectAction()
|
||||
|
||||
data class AcceptOpeningSession(val session: WalletConnectSession) : WalletConnectAction()
|
||||
|
||||
data class ApproveSession(
|
||||
|
|
|
|||
|
|
@ -115,6 +115,12 @@ class WalletConnectMiddleware {
|
|||
)
|
||||
}
|
||||
|
||||
is WalletConnectAction.RefuseOpeningSession -> {
|
||||
store.dispatch(GlobalAction.ShowDialog(
|
||||
WalletConnectDialog.OpeningSessionRejected
|
||||
))
|
||||
}
|
||||
|
||||
is WalletConnectAction.AcceptOpeningSession -> {
|
||||
store.dispatchOnMain(GlobalAction.ShowDialog(WalletConnectDialog.ApproveWcSession(
|
||||
action.session)))
|
||||
|
|
|
|||
|
|
@ -25,8 +25,9 @@ class WalletConnectReducer {
|
|||
state.copy(sessions = sessions)
|
||||
}
|
||||
is WalletConnectAction.ScanCard -> state.copy(loading = true)
|
||||
is WalletConnectAction.UnsupportedCard -> state.copy(loading = false)
|
||||
|
||||
is WalletConnectAction.UnsupportedCard -> state.copy(loading = false)
|
||||
is WalletConnectAction.RefuseOpeningSession -> state.copy(loading = false)
|
||||
is WalletConnectAction.FailureEstablishingSession -> state.copy(loading = false)
|
||||
|
||||
else -> state
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ data class WalletForSession(
|
|||
sealed class WalletConnectDialog : StateDialog {
|
||||
data class ClipboardOrScanQr(val clipboardUri: String) : WalletConnectDialog()
|
||||
object UnsupportedCard : WalletConnectDialog()
|
||||
object OpeningSessionRejected : WalletConnectDialog()
|
||||
data class ApproveWcSession(val session: WalletConnectSession) : WalletConnectDialog()
|
||||
data class RequestTransaction(val dialogData: TransactionRequestDialogData) :
|
||||
WalletConnectDialog()
|
||||
|
|
|
|||
|
|
@ -6,15 +6,19 @@ import com.tangem.tap.common.redux.global.GlobalAction
|
|||
import com.tangem.tap.store
|
||||
import com.tangem.wallet.R
|
||||
|
||||
class UnsupportedCardDialog {
|
||||
class SimpleAlertDialog {
|
||||
companion object {
|
||||
fun create(context: Context): AlertDialog {
|
||||
fun create(
|
||||
titleRes: Int,
|
||||
messageRes: Int,
|
||||
buttonRes: Int = R.string.common_ok,
|
||||
context: Context,
|
||||
): AlertDialog {
|
||||
|
||||
return AlertDialog.Builder(context).apply {
|
||||
setTitle(context.getString(R.string.wallet_connect))
|
||||
setMessage(context.getText(R.string.wallet_connect_scanner_error_no_ethereum_wallet))
|
||||
setPositiveButton(context.getText(R.string.common_ok)) { _, _ -> }
|
||||
// setNegativeButton(context.getText(R.string.common_reject)) { _, _ -> }
|
||||
setTitle(context.getString(titleRes))
|
||||
setMessage(context.getText(messageRes))
|
||||
setPositiveButton(context.getText(buttonRes)) { _, _ -> }
|
||||
setOnDismissListener {
|
||||
store.dispatch(GlobalAction.HideDialog)
|
||||
}
|
||||
|
|
@ -154,4 +154,6 @@ this wallet.
|
|||
<string name="wallet_connect_paste_from_clipboard" translatable="false">Paste from clipboard</string>
|
||||
<string name="wallet_connect_scan_new_code" translatable="false">Scan new code</string>
|
||||
<string name="wallet_connect_scanner_error_no_ethereum_wallet" translatable="false">This card can’t be used to establish WalletConnect session</string>
|
||||
<string name="wallet_connect_could_not_complete" translatable="false">The operation couldn\'t be completed</string>
|
||||
<string name="wallet_connect_same_wcuri" translatable="false">The operation couldn\'t be completed. \n\nYou have already established a WalletConnect session with this parameters.</string>
|
||||
</resources>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue