Skip to content

Commit

Permalink
set abacus historical trading reward period properly
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-dydx committed Jun 6, 2024
1 parent b518a89 commit 421b27a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ public class dydxRewardsHistoryViewPresenter: HostedViewPresenter<dydxRewardsHis
}
}

var abacusPeriod: Abacus.HistoricalTradingRewardsPeriod {
switch self {
case .monthly:
return .monthly
case .weekly:
return .weekly
case .daily:
return .daily
}
}

var text: String? {
switch self {
case .monthly: return DataLocalizer.shared?.localize(path: "APP.GENERAL.TIME_STRINGS.MONTHLY", params: nil)
Expand All @@ -45,7 +56,8 @@ public class dydxRewardsHistoryViewPresenter: HostedViewPresenter<dydxRewardsHis
}
}

@Published private var selectedPeriodIndex: Int = 0
@Published private var selectedPeriodIndex: Int = 1
private var period: Period { Period.allCases[selectedPeriodIndex] }

override init() {

Expand All @@ -65,20 +77,22 @@ public class dydxRewardsHistoryViewPresenter: HostedViewPresenter<dydxRewardsHis
public override func start() {
super.start()

AbacusStateManager.shared.setHistoricalTradingRewardPeriod(period: self.period.abacusPeriod)
AbacusStateManager.shared.state.account
.map(\.?.tradingRewards?.historical)
.sink { [weak self] historicalRewards in
self?.viewModel?.onSelectionChanged = {[weak self] index in
self?.selectedPeriodIndex = index
self?.updateItems(from: historicalRewards)
guard let self = self else { return }
self.selectedPeriodIndex = index
AbacusStateManager.shared.setHistoricalTradingRewardPeriod(period: self.period.abacusPeriod)
self.updateItems(from: historicalRewards)
}
self?.updateItems(from: historicalRewards)
}
.store(in: &subscriptions)
}

private func updateItems(from historicalRewards: [String: [HistoricalTradingReward]]?) {
let period = Period.allCases[selectedPeriodIndex]
viewModel?.items = historicalRewards?[period.historicalMapKey]?
.map { reward in
let startedAt = dydxFormatter.shared.millisecondsToDate(reward.startedAtInMilliseconds, format: .MMM_d_yyyy)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,10 @@ public final class AbacusStateManager: NSObject {
asyncStateManager.historicalPnlPeriod = period
}

public func setHistoricalTradingRewardPeriod(period: HistoricalTradingRewardsPeriod) {
asyncStateManager.historicalTradingRewardPeriod = period
}

public func startTrade() {
asyncStateManager.trade(data: nil, type: nil)
}
Expand Down

0 comments on commit 421b27a

Please sign in to comment.