Skip to content

EIP681: parse function must throw errors instead of returning nil #737

Open
@JeneaVranceanu

Description

@JeneaVranceanu

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 throws and return type must be non-optional EIP681Code;
  • Create new enum EIP681ParseError. It will have quite a few cases but that's okay;
  • Replace all return nil with repective throw 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions