Skip to content

Commit

Permalink
do not render svgs (#185)
Browse files Browse the repository at this point in the history
* do not render svgs

* remove trading rewards feature flag

* set abacus historical trading reward period properly
  • Loading branch information
mike-dydx authored Jun 6, 2024
1 parent 88f979e commit e89aaba
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import Utilities
public enum dydxBoolFeatureFlag: String, CaseIterable {
case push_notification
case force_mainnet
case enable_trading_rewards
case enable_app_rating
case enable_isolated_margins

Expand All @@ -25,7 +24,7 @@ public enum dydxBoolFeatureFlag: String, CaseIterable {
switch self {
case .enable_app_rating:
return Self.obj.parser.asBoolean(FeatureService.shared?.flag(feature: rawValue))?.boolValue ?? true
case .push_notification, .force_mainnet, .enable_trading_rewards, .enable_isolated_margins:
case .push_notification, .force_mainnet, .enable_isolated_margins:
return Self.obj.parser.asBoolean(FeatureService.shared?.flag(feature: rawValue))?.boolValue ?? false
}
}
Expand Down
20 changes: 0 additions & 20 deletions dydx/dydxPresenters/dydxPresenters/_Features/features.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,26 +33,6 @@
]
}
},
{
"title":{
"text":"Enable Trading Rewards"
},
"field":{
"field":"enable_trading_rewards",
"optional":true,
"type" : "text",
"options" : [
{
"text": "yes",
"value" : "1"
},
{
"text": "no",
"value" : "0"
}
]
}
},
{
"title":{
"text":"Push Notification"
Expand Down
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 @@ -112,16 +112,21 @@ private extension dydxTransferSearchItemViewModel {
}
self.isSelected = selected
if let iconUrl = option.iconUrl, let url = URL(string: iconUrl) {
self.icon = PlatformIconViewModel(
type: .url(url: url, placeholderContent: {
Text(option.localizedString?.prefix(1) ?? "")
.frame(width: 32, height: 32)
.themeColor(foreground: .textTertiary)
.themeColor(background: .layer5)
.borderAndClip(style: .circle, borderColor: .layer7, lineWidth: 1)
.wrappedInAnyView()
}),
size: CGSize(width: 32, height: 32))
let type: PlatformIconViewModel.IconType
let placeholderText = Text(option.localizedString?.prefix(1) ?? "")
.frame(width: 32, height: 32)
.themeColor(foreground: .textTertiary)
.themeColor(background: .layer5)
.borderAndClip(style: .circle, borderColor: .layer7, lineWidth: 1)
.wrappedInAnyView()
// SwiftUI does not process svgs well
if url.absoluteString.ends(with: ".svg") {
self.icon = placeholderText.wrappedViewModel
} else {
self.icon = PlatformIconViewModel(
type: .url(url: url, placeholderContent: { placeholderText }),
size: CGSize(width: 32, height: 32))
}
}
self.onTapAction = onTapAction
}
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
6 changes: 2 additions & 4 deletions dydx/dydxViews/dydxViews/_v4/Profile/dydxProfileView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,8 @@ public class dydxProfileViewModel: PlatformViewModel {
HStack(spacing: 14) {
self.fees?
.createView(parentStyle: style)
if dydxBoolFeatureFlag.enable_trading_rewards.isEnabled {
self.rewards?
.createView(parentStyle: style)
}
self.rewards?
.createView(parentStyle: style)
}

self.history?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Utilities

public class dydxTransferSearchItemViewModel: PlatformViewModel {
@Published public var onTapAction: (() -> Void)?
@Published public var icon: PlatformIconViewModel?
@Published public var icon: PlatformViewModel?
@Published public var text: String?
@Published public var tokenText: TokenTextViewModel?
@Published public var isSelected: Bool = false
Expand Down

0 comments on commit e89aaba

Please sign in to comment.