Skip to content

Commit

Permalink
Merge pull request #864 from novasamatech/fix/swaps-slippage
Browse files Browse the repository at this point in the history
Swaps: Slippage bugfixes
  • Loading branch information
ERussel authored Oct 26, 2023
2 parents c740243 + a0f9894 commit c8f88c9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
14 changes: 8 additions & 6 deletions novawallet/Modules/Swaps/Slippage/SwapSlippagePresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,16 @@ final class SwapSlippagePresenter {
amount: amountInput,
limit: 100,
formatter: numberFormatter,
inputLocale: selectedLocale,
precision: 1
)

view?.didReceiveInput(viewModel: inputViewModel)
}

private func provideResetButtonState() {
private func provideButtonStates() {
let amountChanged = amountInput != initialPercent()
view?.didReceiveResetState(available: amountChanged)
view?.didReceiveButtonState(available: amountChanged)
}

private func provideErrors() {
Expand All @@ -79,8 +79,10 @@ final class SwapSlippagePresenter {
preferredLanguages: selectedLocale.rLanguages
)
view?.didReceiveInput(error: error)
view?.didReceiveButtonState(available: false)
} else {
view?.didReceiveInput(error: nil)
view?.didReceiveButtonState(available: amountInput != initialPercent())
}
}

Expand Down Expand Up @@ -115,7 +117,7 @@ extension SwapSlippagePresenter: SwapSlippagePresenterProtocol {
}

amountInput = initialPercent()
provideResetButtonState()
provideButtonStates()
provideAmountViewModel()
provideWarnings()
view?.didReceivePreFilledPercents(viewModel: viewModel)
Expand All @@ -124,14 +126,14 @@ extension SwapSlippagePresenter: SwapSlippagePresenterProtocol {
func select(percent: SlippagePercentViewModel) {
amountInput = percent.value
provideAmountViewModel()
provideResetButtonState()
provideButtonStates()
provideErrors()
provideWarnings()
}

func updateAmount(_ amount: Decimal?) {
amountInput = amount
provideResetButtonState()
provideButtonStates()
provideErrors()
provideWarnings()
}
Expand All @@ -153,7 +155,7 @@ extension SwapSlippagePresenter: SwapSlippagePresenterProtocol {
func reset() {
amountInput = initialPercent()
provideAmountViewModel()
provideResetButtonState()
provideButtonStates()
provideErrors()
provideWarnings()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ protocol SwapSlippageViewProtocol: ControllerBackedProtocol {
func didReceiveInput(error: String?)
func didReceiveInput(warning: String?)
func didReceiveResetState(available: Bool)
func didReceiveButtonState(available: Bool)
}

protocol SwapSlippagePresenterProtocol: AnyObject {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ final class SwapSlippageViewController: UIViewController, ViewHolder {
typealias RootViewType = SwapSlippageViewLayout

let presenter: SwapSlippagePresenterProtocol
private var isApplyAvailable: Bool = false

init(
presenter: SwapSlippagePresenterProtocol,
Expand Down Expand Up @@ -74,7 +75,7 @@ final class SwapSlippageViewController: UIViewController, ViewHolder {

private func updateActionButton() {
let inputValid = rootView.amountInput.inputViewModel?.isValid == true
rootView.actionButton.isEnabled = inputValid && rootView.errorLabel.isHidden
rootView.actionButton.isEnabled = isApplyAvailable && inputValid
}

@objc private func applyButtonAction() {
Expand Down Expand Up @@ -114,6 +115,11 @@ extension SwapSlippageViewController: SwapSlippageViewProtocol {
navigationItem.rightBarButtonItem?.isEnabled = available
}

func didReceiveButtonState(available: Bool) {
isApplyAvailable = available
updateActionButton()
}

func didReceiveInput(error: String?) {
rootView.set(error: error)
updateActionButton()
Expand Down

0 comments on commit c8f88c9

Please sign in to comment.