Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle custom WC pending requests topics #6779

Merged
merged 1 commit into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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