Move send amount validation to view model #4108

pull/4109/head
Krypto Pank 3 years ago
parent 9c2d240a9d
commit 025ffd96e9
  1. 11
      AlphaWallet/Transfer/ViewControllers/SendViewController.swift
  2. 9
      AlphaWallet/Transfer/ViewModels/SendViewModel.swift

@ -55,7 +55,7 @@ class SendViewController: UIViewController {
private let tokensDataStore: TokensDataStore
@objc private (set) dynamic var isAllFunds: Bool = false
private var observation: NSKeyValueObservation!
private lazy var containerView: ScrollableStackView = {
let view = ScrollableStackView()
return view
@ -181,15 +181,8 @@ class SendViewController: UIViewController {
let input = targetAddressTextField.value.trimmed
targetAddressTextField.errorState = .none
amountTextField.errorState = .none
let checkIfGreaterThanZero: Bool
switch transactionType {
case .nativeCryptocurrency, .dapp, .tokenScript, .claimPaidErc875MagicLink:
checkIfGreaterThanZero = false
case .erc20Token, .erc875Token, .erc875TokenOrder, .erc721Token, .erc721ForTicketToken, .erc1155Token:
checkIfGreaterThanZero = true
}
guard let value = viewModel.validatedAmount(value: amountTextField.ethCost, checkIfGreaterThanZero: checkIfGreaterThanZero) else {
guard let value = viewModel.validatedAmount(value: amountTextField.ethCost, checkIfGreaterThanZero: viewModel.checkIfGreaterThanZero) else {
amountTextField.errorState = .error
return
}

@ -120,6 +120,15 @@ struct SendViewModel {
return true
}
var checkIfGreaterThanZero: Bool {
switch transactionType {
case .nativeCryptocurrency, .dapp, .tokenScript, .claimPaidErc875MagicLink:
return false
case .erc20Token, .erc875Token, .erc875TokenOrder, .erc721Token, .erc721ForTicketToken, .erc1155Token:
return true
}
}
var allFundsFormattedValues: (allFundsFullValue: NSDecimalNumber?, allFundsShortValue: String)? {
switch transactionType {
case .nativeCryptocurrency:

Loading…
Cancel
Save