Merge pull request #2104 from AlphaWallet/allow-zero-value-tx-on-eth

allow zero value native transactions so data can be attached
pull/2106/head
James Sangalli 4 years ago committed by GitHub
commit b5ebff059c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      AlphaWallet/Transfer/ViewControllers/SendViewController.swift
  2. 4
      AlphaWallet/Transfer/ViewModels/SendViewModel.swift

@ -283,8 +283,15 @@ class SendViewController: UIViewController, CanScanQRCode {
let input = targetAddressTextField.value.trimmed
targetAddressTextField.errorState = .none
amountTextField.errorState = .none
guard let value = viewModel.validatedAmount(value: amountTextField.ethCost) else {
let checkIfGreaterThanZero: Bool
// allow users to input zero on native transactions as they may want to send custom data
switch transferType {
case .nativeCryptocurrency, .dapp:
checkIfGreaterThanZero = false
case .ERC20Token, .ERC875Token, .ERC875TokenOrder, .ERC721Token, .ERC721ForTicketToken:
checkIfGreaterThanZero = true
}
guard let value = viewModel.validatedAmount(value: amountTextField.ethCost, checkIfGreaterThanZero: checkIfGreaterThanZero) else {
amountTextField.errorState = .error
return
}
@ -454,7 +461,7 @@ extension SendViewController: AmountTextFieldDelegate {
textField.statusLabel.text = viewModel.availableLabelText
textField.availableTextHidden = viewModel.availableTextHidden
guard viewModel.validatedAmount(value: textField.ethCost, checkIfGreaterThenZero: false) != nil else {
guard viewModel.validatedAmount(value: textField.ethCost, checkIfGreaterThanZero: false) != nil else {
textField.errorState = .error
return
}

@ -117,7 +117,7 @@ struct SendViewModel {
return true
}
func validatedAmount(value amountString: String, checkIfGreaterThenZero: Bool = true) -> BigInt? {
func validatedAmount(value amountString: String, checkIfGreaterThanZero: Bool = true) -> BigInt? {
let parsedValue: BigInt? = {
switch transferType {
case .nativeCryptocurrency, .dapp:
@ -135,7 +135,7 @@ struct SendViewModel {
}
}()
guard let value = parsedValue, checkIfGreaterThenZero ? value > 0 : true else {
guard let value = parsedValue, checkIfGreaterThanZero ? value > 0 : true else {
return nil
}

Loading…
Cancel
Save