Fix: Gracefully ignore unsupported NWC response types (e.g. get_info)

When another NWC client (e.g. Alby) connected to the same relay calls
`get_info`, Damus receives the response and previously threw a
DecodingError.typeMismatch, causing an "Oops" error dialog to be shown.

Fix: Make `result_type` optional in `WalletConnect.Response`. Unknown
result types now decode without throwing — `result_type` and `result`
are set to `nil`, and the rest of the existing nil-guarded code paths
handle this silently.

Adds a test to verify `get_info` (and any future unknown result type)
is decoded gracefully.

Closes: #2204
Changelog-Fixed: Fixed issue where the app could display an error message when using another NWC wallet in parallel
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: danieldaquino <24692108+danieldaquino@users.noreply.github.com>
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
This commit is contained in:
Copilot
2026-02-23 12:50:25 -08:00
committed by GitHub
co-authored by copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> danieldaquino
parent 84ef5ecf53
commit 7be75f37c6
2 changed files with 35 additions and 5 deletions
@@ -10,7 +10,8 @@ import Combine
extension WalletConnect {
/// Models a response from the NWC provider
struct Response: Decodable {
let result_type: Response.Result.ResultType
/// The type of the result. `nil` if the result type is unsupported/unknown.
let result_type: Response.Result.ResultType?
let error: WalletResponseErr?
let result: Response.Result?
@@ -21,14 +22,17 @@ extension WalletConnect {
init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
let result_type_str = try container.decode(String.self, forKey: .result_type)
guard let result_type = Response.Result.ResultType(rawValue: result_type_str) else {
throw DecodingError.typeMismatch(Response.Result.ResultType.self, .init(codingPath: decoder.codingPath, debugDescription: "result_type \(result_type_str) is unknown"))
}
let result_type = Response.Result.ResultType(rawValue: result_type_str)
self.result_type = result_type
self.error = try container.decodeIfPresent(WalletResponseErr.self, forKey: .error)
guard let result_type else {
// Unknown/unsupported result type gracefully ignore without an error
self.result = nil
return
}
guard self.error == nil else {
self.result = nil
return