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 private let tokensDataStore: TokensDataStore
@objc private (set) dynamic var isAllFunds: Bool = false @objc private (set) dynamic var isAllFunds: Bool = false
private var observation: NSKeyValueObservation! private var observation: NSKeyValueObservation!
private lazy var containerView: ScrollableStackView = { private lazy var containerView: ScrollableStackView = {
let view = ScrollableStackView() let view = ScrollableStackView()
return view return view
@ -181,15 +181,8 @@ class SendViewController: UIViewController {
let input = targetAddressTextField.value.trimmed let input = targetAddressTextField.value.trimmed
targetAddressTextField.errorState = .none targetAddressTextField.errorState = .none
amountTextField.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 amountTextField.errorState = .error
return return
} }

@ -120,6 +120,15 @@ struct SendViewModel {
return true 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)? { var allFundsFormattedValues: (allFundsFullValue: NSDecimalNumber?, allFundsShortValue: String)? {
switch transactionType { switch transactionType {
case .nativeCryptocurrency: case .nativeCryptocurrency:

Loading…
Cancel
Save