Skip to content

Commit

Permalink
Dismiss duplicate event within 5 sec in swap view (KYRDTeam#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrQKyber authored Sep 23, 2020
1 parent b68457c commit 5fcc2fb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ class KAdvancedSettingsView: XibLoaderView {
self.viewModel.updateIsUsingReverseRouting(value: !self.viewModel.isUsingReverseRouting)
self.updateIsUsingReverseRoutingCheckBox()
self.delegate?.kAdvancedSettingsView(self, run: .changeIsUsingReverseRouting(value: self.viewModel.isUsingReverseRouting))
KNCrashlyticsUtil.logCustomEvent(withName: "advanced_select_reverse-routing_select", customAttributes: ["value": self.viewModel.isUsingReverseRouting])
KNCrashlyticsUtil.logCustomEvent(withName: self.viewModel.isUsingReverseRouting ? "advanced_select_reverse_routing_select" : "advanced_select_reverse_routing_unselect", customAttributes: nil)
}

@IBAction func reverseRoutingHelpButtonTapped(_ sender: UIButton) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Moya

//swiftlint:disable file_length

enum KSwapViewEvent {
enum KSwapViewEvent: Equatable {
case searchToken(from: TokenObject, to: TokenObject, isSource: Bool)
case estimateRate(from: TokenObject, to: TokenObject, amount: BigInt, hint: String, showError: Bool)
case estimateComparedRate(from: TokenObject, to: TokenObject, hint: String) // compare to show warning
Expand All @@ -19,6 +19,15 @@ enum KSwapViewEvent {
case quickTutorial(step: Int, pointsAndRadius: [(CGPoint, CGFloat)])
case referencePrice(from: TokenObject, to: TokenObject)
case swapHint(from: TokenObject, to: TokenObject, amount: String?)

static public func == (left: KSwapViewEvent, right: KSwapViewEvent) -> Bool {
switch (left, right) {
case let (.estimateGas(fromL, toL, amountL, gasPriceL, hintL), .estimateGas(fromR, toR, amountR, gasPriceR, hintR)):
return fromL == fromR && toL == toR && amountL == amountR && gasPriceL == gasPriceR && hintL == hintR
default:
return false //Not implement
}
}
}

protocol KSwapViewControllerDelegate: class {
Expand Down Expand Up @@ -82,6 +91,8 @@ class KSwapViewController: KNBaseViewController {
@IBOutlet weak var hasUnreadNotification: UIView!
fileprivate var estRateTimer: Timer?
fileprivate var estGasLimitTimer: Timer?
fileprivate var previousCallEvent: KSwapViewEvent?
fileprivate var previousCallTimeStamp: TimeInterval = 0

lazy var hamburgerMenu: KNBalanceTabHamburgerMenuViewController = {
let viewModel = KNBalanceTabHamburgerMenuViewModel(
Expand Down Expand Up @@ -604,6 +615,12 @@ class KSwapViewController: KNBaseViewController {
gasPrice: self.viewModel.gasPrice,
hint: self.viewModel.getHint(from: self.viewModel.from.address, to: self.viewModel.to.address)
)
//Dismiss event call if the same parameter call within 5 sec
if let previousEvent = self.previousCallEvent, previousEvent == event, Date().timeIntervalSince1970 - self.previousCallTimeStamp < 5 {
return
}
self.previousCallEvent = event
self.previousCallTimeStamp = Date().timeIntervalSince1970
self.delegate?.kSwapViewController(self, run: event)
}
/*
Expand Down

0 comments on commit 5fcc2fb

Please sign in to comment.