Skip to content

Commit

Permalink
Clean up MarketInfo data and add SwiftLint action
Browse files Browse the repository at this point in the history
  • Loading branch information
ruixhuang committed Nov 6, 2023
1 parent 6bbae21 commit 3541147
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 28 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/SwiftLint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: SwiftLint on Changed Files

on: [pull_request]

jobs:
swiftlint:
name: Run SwiftLint
runs-on: macos-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v3
with:
fetch-depth: 0 # fetch all history so that we can get the proper list of changed files

- name: Install SwiftLint
run: brew install swiftlint

- name: List all changed files
id: files
uses: jitterbit/get-changed-files@v1
with:
format: space-delimited

- name: Run SwiftLint on changed files
run: |
# Extract changed files and filter for Swift files
FILES="${{ steps.files.outputs.all }}"
SWIFT_FILES=$(echo "$FILES" | grep -E '\.(swift)$' | xargs)
# Run SwiftLint on each changed Swift file
# If no Swift files changed, skip the step
if [ -z "$SWIFT_FILES" ]; then
echo "No Swift files to lint."
else
echo "Linting changed Swift files..."
swiftlint lint -- $SWIFT_FILES
fi
1 change: 1 addition & 0 deletions dydx/Pods/Abacus
Submodule Abacus added at 60873f
Original file line number Diff line number Diff line change
Expand Up @@ -32,40 +32,54 @@ class dydxMarketConfigsViewPresenter: HostedViewPresenter<dydxMarketConfigsViewM
override func start() {
super.start()

let marketConfigsPublisher = $marketId
$marketId
.compactMap { $0 }
.flatMap { AbacusStateManager.shared.state.market(of: $0) }
.compactMap(\.?.configs)
.compactMap { $0 }

marketConfigsPublisher
.sink { [weak self] marketConfigs in
self?.updateConfigs(marketConfigs: marketConfigs)
.sink { [weak self] market in
self?.updateConfigs(market: market)
}
.store(in: &subscriptions)
}

private func updateConfigs(marketConfigs: MarketConfigs) {
private func updateConfigs(market: PerpetualMarket) {
let marketConfigs = market.configs

let maxLeverageText: String?
if let imf = marketConfigs.initialMarginFraction?.doubleValue {
if let imf = marketConfigs?.initialMarginFraction?.doubleValue {
maxLeverageText = dydxFormatter.shared.naturalLocalFormatted(number: NSNumber(value: 1.0 / imf))
} else {
maxLeverageText = nil
}

let tickSize = dydxFormatter.shared.format(decimal: marketConfigs.tickSize?.decimalValue)
let tickSize = dydxFormatter.shared.format(decimal: marketConfigs?.tickSize?.decimalValue)
viewModel?.items = [
dydxMarketConfigsViewModel.Item(title: DataLocalizer.localize(path: "APP.GENERAL.MARKET_NAME"), value: marketId ?? "-"),
dydxMarketConfigsViewModel.Item(title: DataLocalizer.localize(path: "APP.GENERAL.TICK_SIZE"), value: tickSize ?? "-"),
dydxMarketConfigsViewModel.Item(title: DataLocalizer.localize(path: "APP.GENERAL.STEP_SIZE"), value: "\(marketConfigs.stepSize?.doubleValue ?? 0)"),
dydxMarketConfigsViewModel.Item(title: DataLocalizer.localize(path: "APP.GENERAL.MINIMUM_ORDER_SIZE"), value: "\(marketConfigs.minOrderSize?.doubleValue ?? 0)"),
dydxMarketConfigsViewModel.Item(title: DataLocalizer.localize(path: "APP.GENERAL.MAXIMUM_LEVERAGE"), value: maxLeverageText ?? "-"),
dydxMarketConfigsViewModel.Item(title: DataLocalizer.localize(path: "APP.GENERAL.MAINTENANCE_MARGIN_FRACTION"), value: "\(marketConfigs.maintenanceMarginFraction?.doubleValue ?? 0)"),
dydxMarketConfigsViewModel.Item(title: DataLocalizer.localize(path: "APP.GENERAL.INITIAL_MARGIN_FRACTION"), value: "\(marketConfigs.initialMarginFraction?.doubleValue ?? 0)"),
dydxMarketConfigsViewModel.Item(title: DataLocalizer.localize(path: "APP.TRADE.INCREMENTAL_INITIAL_MARGIN_FRACTION"), value: "\(marketConfigs.incrementalInitialMarginFraction?.doubleValue ?? 0)"),
dydxMarketConfigsViewModel.Item(title: DataLocalizer.localize(path: "APP.TRADE.INCREMENTAL_POSITION_SIZE"), value: "\(marketConfigs.incrementalPositionSize?.doubleValue ?? 0)"),
dydxMarketConfigsViewModel.Item(title: DataLocalizer.localize(path: "APP.TRADE.BASELINE_POSITION_SIZE"), value: "\(marketConfigs.baselinePositionSize?.doubleValue ?? 0)"),
dydxMarketConfigsViewModel.Item(title: DataLocalizer.localize(path: "APP.TRADE.MAXIMUM_POSITION_SIZE"), value: "\(marketConfigs.maxPositionSize?.doubleValue ?? 0)")
dydxMarketConfigsViewModel.Item(title: DataLocalizer.localize(path: "APP.GENERAL.MARKET_NAME"),
value: marketId ?? "-"),
dydxMarketConfigsViewModel.Item(title: DataLocalizer.localize(path: "APP.GENERAL.TICK_SIZE"),
value: tickSize != nil ? "$" + (tickSize ?? "") : "-"),
dydxMarketConfigsViewModel.Item(title: DataLocalizer.localize(path: "APP.GENERAL.STEP_SIZE"),
value: marketConfigs?.stepSize?.doubleValue != nil ? "\(marketConfigs?.stepSize?.doubleValue ?? 0)" : "-",
token: marketConfigs?.stepSize?.doubleValue != nil ? TokenTextViewModel(symbol: market.assetId) : nil),
dydxMarketConfigsViewModel.Item(title: DataLocalizer.localize(path: "APP.GENERAL.MINIMUM_ORDER_SIZE"),
value: marketConfigs?.minOrderSize?.doubleValue != nil ? "\(marketConfigs?.minOrderSize?.doubleValue ?? 0)" : "-",
token: marketConfigs?.minOrderSize?.doubleValue != nil ? TokenTextViewModel(symbol: market.assetId) : nil),
dydxMarketConfigsViewModel.Item(title: DataLocalizer.localize(path: "APP.GENERAL.MAXIMUM_LEVERAGE"),
value: maxLeverageText ?? "-"),
dydxMarketConfigsViewModel.Item(title: DataLocalizer.localize(path: "APP.GENERAL.MAINTENANCE_MARGIN_FRACTION"),
value: dydxFormatter.shared.percent(number: marketConfigs?.maintenanceMarginFraction?.doubleValue, digits: 4) ?? "-"),
dydxMarketConfigsViewModel.Item(title: DataLocalizer.localize(path: "APP.GENERAL.INITIAL_MARGIN_FRACTION"),
value: dydxFormatter.shared.percent(number: marketConfigs?.initialMarginFraction?.doubleValue, digits: 4) ?? "-"),
dydxMarketConfigsViewModel.Item(title: DataLocalizer.localize(path: "APP.TRADE.INCREMENTAL_INITIAL_MARGIN_FRACTION"),
value: dydxFormatter.shared.percent(number: marketConfigs?.incrementalInitialMarginFraction?.doubleValue, digits: 4) ?? "-"),
dydxMarketConfigsViewModel.Item(title: DataLocalizer.localize(path: "APP.GENERAL.BASE_POSITION_NOTIONAL"),
value: dydxFormatter.shared.localFormatted(number: marketConfigs?.basePositionNotional?.doubleValue, digits: 0) ?? "-"),
dydxMarketConfigsViewModel.Item(title: DataLocalizer.localize(path: "APP.TRADE.INCREMENTAL_POSITION_SIZE"),
value: marketConfigs?.incrementalPositionSize?.doubleValue != nil ? "\(marketConfigs?.incrementalPositionSize?.doubleValue ?? 0)" : "-"),
dydxMarketConfigsViewModel.Item(title: DataLocalizer.localize(path: "APP.TRADE.BASELINE_POSITION_SIZE"),
value: marketConfigs?.baselinePositionSize?.doubleValue != nil ? "\(marketConfigs?.baselinePositionSize?.doubleValue ?? 0)" : "-"),
dydxMarketConfigsViewModel.Item(title: DataLocalizer.localize(path: "APP.TRADE.MAXIMUM_POSITION_SIZE"),
value: marketConfigs?.maxPositionSize?.doubleValue != nil ? "\(marketConfigs?.maxPositionSize?.doubleValue ?? 0)" : "-")
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class dydxMarketPositionViewPresenter: HostedViewPresenter<dydxMarketPositionVie
} else {
sign = .none
}
let pnl = dydxFormatter.shared.dollarVolume(number: abs(position.realizedPnlPercent?.current?.doubleValue ?? 0), digits: 2)
let pnl = dydxFormatter.shared.dollarVolume(number: abs(position.realizedPnl?.current?.doubleValue ?? 0), digits: 2)
viewModel?.realizedPNLAmount = SignedAmountViewModel(text: pnl, sign: sign, coloringOption: .signOnly)

viewModel?.leverage = sharedOrderViewModel.leverage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@ import Utilities

public class dydxMarketConfigsViewModel: PlatformViewModel {
public struct Item: Hashable {
public init(title: String, value: String) {
public init(title: String, value: String, token: TokenTextViewModel? = nil) {
self.title = title
self.value = value
self.token = token
}

let title: String
let value: String
let token: TokenTextViewModel?
}

@Published public var items: [Item]?
Expand All @@ -30,7 +32,7 @@ public class dydxMarketConfigsViewModel: PlatformViewModel {
vm.items = [
Item(title: "Title", value: "Value"),
Item(title: "Title", value: "Value"),
Item(title: "Title", value: "Value")
Item(title: "Title", value: "Value", token: .previewValue)
]
return vm
}
Expand All @@ -46,8 +48,10 @@ public class dydxMarketConfigsViewModel: PlatformViewModel {
Text(item.title)
.themeColor(foreground: .textTertiary)
Spacer()
Text(item.value)
.themeFont(fontType: .number)
HStack(spacing: 4) {
Text(item.value)
item.token?.createView(parentStyle: style.themeFont(fontSize: .smaller))
}
}

if item != self.items?.last {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public class dydxMarketPositionViewModel: PlatformViewModel {
Spacer()

Text(openPrice ?? "-")
.themeFont(fontType: .number, fontSize: .medium)
.themeFont(fontSize: .medium)
}

DividerModel().createView(parentStyle: parentStyle)
Expand All @@ -249,7 +249,7 @@ public class dydxMarketPositionViewModel: PlatformViewModel {
Spacer()

Text(closePrice ?? "-")
.themeFont(fontType: .number, fontSize: .medium)
.themeFont(fontSize: .medium)
}

DividerModel().createView(parentStyle: parentStyle)
Expand All @@ -261,7 +261,7 @@ public class dydxMarketPositionViewModel: PlatformViewModel {

Spacer()

funding?.createView(parentStyle: parentStyle.themeFont(fontType: .number, fontSize: .medium))
funding?.createView(parentStyle: parentStyle.themeFont(fontSize: .medium))
}
}
.padding(.horizontal, 8)
Expand Down

0 comments on commit 3541147

Please sign in to comment.