Skip to content

Commit

Permalink
Bump Abacus, Cartera and improve MetaMask transactions.
Browse files Browse the repository at this point in the history
  • Loading branch information
ruixhuang committed Dec 17, 2024
1 parent 9f3ed65 commit 039e4d4
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 8 deletions.
2 changes: 1 addition & 1 deletion v4/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}
}
},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
}
Expand Down

0 comments on commit 039e4d4

Please sign in to comment.