HumanReadableErrors.swift (7284B)
1 // 2 // HumanReadableErrors.swift 3 // damus 4 // 5 // Created by Daniel D’Aquino on 2025-05-05. 6 // 7 8 import Foundation 9 10 extension WalletConnect.FullWalletResponse.InitializationError { 11 var humanReadableError: ErrorView.UserPresentableError? { 12 switch self { 13 case .incorrectAuthorPubkey: 14 nil // Anyone can send a response event with an incorrect author pubkey, it is not really an "error". We should silently ignore it. 15 case .missingRequestIdReference: 16 .init( 17 user_visible_description: NSLocalizedString("Wallet provider returned an invalid response.", comment: "Error description shown to the user when a response from the wallet provider is invalid"), 18 tip: NSLocalizedString("Please copy the technical info and send it to our support team.", comment: "Tip on how to resolve issue when wallet returns an invalid response"), 19 technical_info: "Wallet response does not make a reference to any request; No request ID `e` tag was found." 20 ) 21 case .failedToDecodeJSON(let error): 22 .init( 23 user_visible_description: NSLocalizedString("Wallet provider returned a response that we do not understand.", comment: "Error description shown to the user when a response from the wallet provider contains data the app does not understand"), 24 tip: NSLocalizedString("Please copy the technical info and send it to our support team.", comment: "Tip on how to resolve issue when wallet returns an invalid response"), 25 technical_info: "Failed to decode NWC Wallet response JSON. Error: \(error)" 26 ) 27 case .failedToDecrypt(let error): 28 .init( 29 user_visible_description: NSLocalizedString("Wallet provider returned a response that we could not decrypt.", comment: "Error description shown to the user when a response from the wallet provider contains data the app could not decrypt."), 30 tip: NSLocalizedString("Please copy the technical info and send it to our support team.", comment: "Tip on how to resolve issue when wallet returns an invalid response"), 31 technical_info: "Failed to decrypt NWC Wallet response. Error: \(error)" 32 ) 33 } 34 } 35 } 36 37 extension WalletConnect.WalletResponseErr { 38 var humanReadableError: ErrorView.UserPresentableError? { 39 guard let code = self.code else { 40 return .init( 41 user_visible_description: String(format: NSLocalizedString("Your connected wallet raised an unknown error. Message: %s", comment: "Human readable error description for unknown error"), self.message ?? NSLocalizedString("Empty error message", comment: "A human readable placeholder to indicate that the error message is empty")), 42 tip: NSLocalizedString("Please contact the developer of your wallet provider for help.", comment: "Human readable error description for an unknown error raised by a wallet provider."), 43 technical_info: "NWC wallet provider returned an error response without a valid reason code. Message: \(self.message ?? "Empty error message")" 44 ) 45 } 46 switch code { 47 case .rateLimited: 48 return .init( 49 user_visible_description: NSLocalizedString("Your wallet is temporarily being rate limited.", comment: "Error description for rate limit error"), 50 tip: NSLocalizedString("Wait a few moments, and then try again.", comment: "Tip for rate limit error"), 51 technical_info: "Wallet returned a rate limit error with message: \(self.message ?? "No further details provided")" 52 ) 53 case .notImplemented: 54 return .init( 55 user_visible_description: NSLocalizedString("This feature is not implemented by your wallet.", comment: "Error description for not implemented feature"), 56 tip: NSLocalizedString("Please check for updates or contact your wallet provider.", comment: "Tip for not implemented error"), 57 technical_info: "Wallet reported a not implemented error. Message: \(self.message ?? "No further details provided")" 58 ) 59 case .insufficientBalance: 60 return .init( 61 user_visible_description: NSLocalizedString("Your wallet does not have sufficient balance for this transaction.", comment: "Error description for insufficient balance"), 62 tip: NSLocalizedString("Please deposit more funds and try again.", comment: "Tip for insufficient balance errors"), 63 technical_info: "Wallet returned an insufficient balance error. Message: \(self.message ?? "No further details provided")" 64 ) 65 case .quotaExceeded: 66 return .init( 67 user_visible_description: NSLocalizedString("Your transaction quota has been exceeded.", comment: "Error description for quota exceeded"), 68 tip: NSLocalizedString("Wait for the quota to reset, or configure your wallet provider to allow a higher limit.", comment: "Tip for quota exceeded"), 69 technical_info: "Wallet reported a quota exceeded error. Message: \(self.message ?? "No further details provided")" 70 ) 71 case .restricted: 72 return .init( 73 user_visible_description: NSLocalizedString("This operation is restricted by your wallet.", comment: "Error description for restricted operation"), 74 tip: NSLocalizedString("Check your account permissions or contact support.", comment: "Tip for restricted operation"), 75 technical_info: "Wallet returned a restricted error. Message: \(self.message ?? "No further details provided")" 76 ) 77 case .unauthorized: 78 return .init( 79 user_visible_description: NSLocalizedString("You are not authorized to perform this action with your wallet.", comment: "Error description for unauthorized access"), 80 tip: NSLocalizedString("Please verify your credentials or permissions.", comment: "Tip for unauthorized access"), 81 technical_info: "Wallet returned an unauthorized error. Message: \(self.message ?? "No further details provided")" 82 ) 83 case .internalError: 84 return .init( 85 user_visible_description: NSLocalizedString("An internal error occurred in your wallet.", comment: "Error description for an internal error"), 86 tip: NSLocalizedString("Try restarting your wallet or contacting support if the problem persists.", comment: "Tip for internal error"), 87 technical_info: "Wallet reported an internal error. Message: \(self.message ?? "No further details provided")" 88 ) 89 case .other: 90 return .init( 91 user_visible_description: NSLocalizedString("An unspecified error occurred in your wallet.", comment: "Error description for an unspecified error"), 92 tip: NSLocalizedString("Please try again or contact your wallet provider for further assistance.", comment: "Tip for unspecified error"), 93 technical_info: "Wallet returned an error: \(self.message ?? "No further details provided")" 94 ) 95 } 96 } 97 }