diff --git a/v4/build.gradle b/v4/build.gradle index f43c5934..e313289d 100644 --- a/v4/build.gradle +++ b/v4/build.gradle @@ -89,7 +89,7 @@ ext { // App dependencies abacusVersion = '1.13.42' - carteraVersion = '0.1.16' + carteraVersion = '0.1.17' //carteraVersion = '0.1.16-local-debug' // Use this for local testing kollectionsVersion = '2.0.16' diff --git a/v4/integration/dydxCartera/src/main/java/exchange/dydx/dydxCartera/steps/WalletSendTransactionStep.kt b/v4/integration/dydxCartera/src/main/java/exchange/dydx/dydxCartera/steps/WalletSendTransactionStep.kt index e1a53f3e..5d72ebe9 100644 --- a/v4/integration/dydxCartera/src/main/java/exchange/dydx/dydxCartera/steps/WalletSendTransactionStep.kt +++ b/v4/integration/dydxCartera/src/main/java/exchange/dydx/dydxCartera/steps/WalletSendTransactionStep.kt @@ -53,7 +53,31 @@ class WalletSendTransactionStep( if (signed != null) { continuation.resume(Result.success(signed)) } else { - continuation.resume(errorEvent(error?.message ?: "Unknown error")) + if (provider.walletStatus?.connectedWallet?.peerName == "MetaMask Wallet" && + error?.message == "User rejected." + ) { + // MetaMask wallet will send a "User rejected" response when switching chain... let's catch it and resend + provider.send( + request = transactionRequest, + connected = { info -> + if (info == null) { + continuation.resume(errorEvent("Wallet not connected")) + } + }, + status = { status -> + Log.d("AsyncStep", "Status: $status") + }, + completion = { signed, error -> + if (signed != null) { + continuation.resume(Result.success(signed)) + } else { + continuation.resume(errorEvent(error?.message ?: "Unknown error")) + } + }, + ) + } else { + continuation.resume(errorEvent(error?.message ?: "Unknown error")) + } } }, ) diff --git a/v4/integration/dydxCartera/src/main/java/exchange/dydx/dydxCartera/v4/DydxV4WalletSetup.kt b/v4/integration/dydxCartera/src/main/java/exchange/dydx/dydxCartera/v4/DydxV4WalletSetup.kt index 53a7cb4e..a709ac15 100644 --- a/v4/integration/dydxCartera/src/main/java/exchange/dydx/dydxCartera/v4/DydxV4WalletSetup.kt +++ b/v4/integration/dydxCartera/src/main/java/exchange/dydx/dydxCartera/v4/DydxV4WalletSetup.kt @@ -27,13 +27,14 @@ class DydxV4WalletSetup @Inject constructor( _status.value = Status.createError(message = "Request address is null") return } + val typedDataProvider = typedData( + action = signTypedDataAction, + chainId = parser.asInt(request.chainId), + signTypedDataDomainName = signTypedDataDomainName, + ) provider.sign( request = request, - typedDataProvider = typedData( - action = signTypedDataAction, - chainId = parser.asInt(request.chainId), - signTypedDataDomainName = signTypedDataDomainName, - ), + typedDataProvider = typedDataProvider, status = { requireAppSwitching -> if (requireAppSwitching) { _status.value = Status.InProgress(showSwitchWalletName = connectedWallet.peerName) @@ -44,7 +45,29 @@ class DydxV4WalletSetup @Inject constructor( if (signed != null && error == null) { generatePrivateKey(request.wallet, signed, address) } else if (error != null) { - _status.value = Status.Error(error) + if (provider.walletStatus?.connectedWallet?.peerName == "MetaMask Wallet" && + error.message == "User rejected." + ) { + // MetaMask wallet will send a "User rejected" response when switching chain... let's catch it and resend + provider.sign( + request = request, + typedDataProvider = typedDataProvider, + status = { requireAppSwitching -> + if (requireAppSwitching) { + _status.value = Status.InProgress(showSwitchWalletName = connectedWallet.peerName) + } + }, + connected = null, + ) { signed, error -> + if (signed != null && error == null) { + generatePrivateKey(request.wallet, signed, address) + } else if (error != null) { + _status.value = Status.Error(error) + } + } + } else { + _status.value = Status.Error(error) + } } provider.disconnect() }