web3swift
web3swift copied to clipboard
EIP681: parse function must throw errors instead of returning nil
What context is your feature request related to?
EIP681CodeParser.parse function returns nil if something is wrong in the encoded raw EIP681 given as input parameter. It doesn't help people understand what is wrong with the EIP681 URL
What solution would you like?
- Make this function
async throwsand return type must be non-optionalEIP681Code; - Create new
enum EIP681ParseError. It will have quite a few cases but that's okay; - Replace all
return nilwith repectivethrow EIP681ParseError.xyz.
This will be good enough enum EIP681ParseError to start with (please, extend it with new cases as you see fit, we will discuss them in detail in the PR):
enum EIP681ParseError: LocalizableError {
/// Doesn't start with `ethereum:` scheme.
case notEIP681
/// Failed to extract address from the URL.
case invalidAddressFormat
/// Value to transfer is not valid.
case invalidTransferValue
/// Gas is invalid. It must be decimal value.
case invalidGas
/// Gas limit is invalid. It must be decimal value.
case invalidGasLimit
/// Gas price is invalid. It must be decimal value.
case invalidGasPrice
/// Generic error for non-specific EIP681 cases.
/// For example, the given value consists of only `"ethereum:"`.
case invalidEIP681(_ errorMessage: String? = nil)
}
Any additional context?
No response