-
Notifications
You must be signed in to change notification settings - Fork 391
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle custom WC pending requests topics
- Loading branch information
1 parent
83ef3a8
commit 5edc800
Showing
4 changed files
with
53 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...orizontalsystems/bankwallet/modules/walletconnect/version2/SessionRequestFilterManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters