Skip to content

Commit

Permalink
Handle custom WC pending requests topics
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelekol committed Oct 26, 2023
1 parent 83ef3a8 commit 5edc800
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ android {
compileSdk compile_sdk_version
minSdkVersion min_sdk_version
targetSdkVersion compile_sdk_version
versionCode 91
versionName "0.36.0"
versionCode 92
versionName "0.36.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

kapt {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ import io.horizontalsystems.bankwallet.modules.settings.appearance.LaunchScreenS
import io.horizontalsystems.bankwallet.modules.theme.ThemeService
import io.horizontalsystems.bankwallet.modules.theme.ThemeType
import io.horizontalsystems.bankwallet.modules.walletconnect.storage.WC2SessionStorage
import io.horizontalsystems.bankwallet.modules.walletconnect.version2.SessionRequestFilterManager
import io.horizontalsystems.bankwallet.modules.walletconnect.version2.WC2Manager
import io.horizontalsystems.bankwallet.modules.walletconnect.version2.WC2Service
import io.horizontalsystems.bankwallet.modules.walletconnect.version2.WC2SessionManager
Expand Down Expand Up @@ -398,7 +399,7 @@ class App : CoreApp(), WorkConfiguration.Provider, ImageLoaderFactory {

initializeWalletConnectV2(appConfig)

wc2Service = WC2Service()
wc2Service = WC2Service(SessionRequestFilterManager())
wc2SessionManager = WC2SessionManager(accountManager, WC2SessionStorage(appDatabase), wc2Service, wc2Manager)

baseTokenManager = BaseTokenManager(coinManager, localStorage)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package io.horizontalsystems.bankwallet.modules.walletconnect.version2

import android.util.Log
import com.walletconnect.sign.client.Sign
import com.walletconnect.sign.client.SignClient

class SessionRequestFilterManager() {
private val TAG = "SessionRequestFilterManager"
private val rejectList = setOf(
// custom methods
"personal_ecRecover",
"eth_getCode",
"wallet_switchEthereumChain",
"wallet_addEthereumChain"
)

private fun reject(request: Sign.Model.SessionRequest) {
try {
val response = Sign.Params.Response(
sessionTopic = request.topic,
jsonRpcResponse = Sign.Model.JsonRpcResponse.JsonRpcError(
id = request.request.id,
code = 500,
message = "Rejected by user"
)
)

SignClient.respond(response) {
Log.e(TAG, "rejectRequest onError: ", it.throwable)
}
} catch (error: Throwable) {
println(error)
}
}

fun canHandle(request: Sign.Model.SessionRequest): Boolean {
if (rejectList.contains(request.request.method)) {
reject(request)
return true
}
return false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import java.util.concurrent.CopyOnWriteArrayList

class WC2Service : SignClient.WalletDelegate {
class WC2Service(
private val sessionRequestFilterManager: SessionRequestFilterManager
) : SignClient.WalletDelegate {

private val TAG = "WC2Service"

Expand Down Expand Up @@ -215,6 +217,9 @@ class WC2Service : SignClient.WalletDelegate {
}

override fun onSessionRequest(sessionRequest: Sign.Model.SessionRequest, verifyContext: Sign.Model.VerifyContext) {
if (sessionRequestFilterManager.canHandle(sessionRequest)) {
return
}
sessionsRequestReceivedSubject.onNext(sessionRequest)
pendingRequestUpdatedSubject.onNext(Unit)
}
Expand Down

0 comments on commit 5edc800

Please sign in to comment.