Skip to content

Commit

Permalink
Merge pull request #100 from nimblehq/release/0.7.0
Browse files Browse the repository at this point in the history
Release - 0.7.0
  • Loading branch information
Thieurom authored Jan 17, 2023
2 parents 8f21688 + 1b6ffde commit a7f28bc
Show file tree
Hide file tree
Showing 35 changed files with 600 additions and 197 deletions.
8 changes: 4 additions & 4 deletions CryptoPrices.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 0.6.0;
MARKETING_VERSION = 0.7.0;
PRODUCT_BUNDLE_IDENTIFIER = "co.nimblehq.crypto-prices.staging";
PRODUCT_MODULE_NAME = CryptoPrices;
PRODUCT_NAME = "$(TARGET_NAME) Staging";
Expand Down Expand Up @@ -682,7 +682,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 0.6.0;
MARKETING_VERSION = 0.7.0;
PRODUCT_BUNDLE_IDENTIFIER = "co.nimblehq.crypto-prices.staging";
PRODUCT_MODULE_NAME = CryptoPrices;
PRODUCT_NAME = "$(TARGET_NAME) Staging";
Expand Down Expand Up @@ -871,7 +871,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 0.6.0;
MARKETING_VERSION = 0.7.0;
PRODUCT_BUNDLE_IDENTIFIER = "co.nimblehq.crypto-prices";
PRODUCT_MODULE_NAME = CryptoPrices;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down Expand Up @@ -908,7 +908,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 0.6.0;
MARKETING_VERSION = 0.7.0;
PRODUCT_BUNDLE_IDENTIFIER = "co.nimblehq.crypto-prices";
PRODUCT_MODULE_NAME = CryptoPrices;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ extension Container {
}
static let myCoinViewModel = Factory {
MyCoinViewModel(
coinDetailUseCase: coinDetailUseCase.callAsFunction()
coinDetailUseCase: coinDetailUseCase.callAsFunction(),
getChartPricesUseCase: getChartPricesUseCase.callAsFunction()
)
}

Expand All @@ -50,4 +51,7 @@ extension Container {
static let coinDetailUseCase = Factory<CoinDetailUseCaseProtocol> {
CoinDetailUseCase(repository: coinRepository.callAsFunction())
}
static let getChartPricesUseCase = Factory<GetChartPricesUseCaseProtocol> {
GetChartPricesUseCase(repository: coinRepository.callAsFunction())
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public struct MockCoinDetail: CoinDetail, Equatable {
public let marketData: MarketData

public static func == (lhs: MockCoinDetail, rhs: MockCoinDetail) -> Bool {
lhs.id == rhs.id
lhs.id == rhs.id &&
MockMarketData(marketData: lhs.marketData) == MockMarketData(marketData: rhs.marketData)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//
// MockMarketData.swift
// Domain
//
// Created by Khanh on 28/12/2022.
//

import Entities

public struct MockMarketData: MarketData, Equatable {

public let currentPrice: USDDecimalable
public let priceChangePercentage24H: Double
public let marketCap: USDDecimalable
public let marketCapChangePercentage24H: Double
public let ath: USDDecimalable
public let athChangePercentage: USDDoublable
public let atl: USDDecimalable
public let atlChangePercentage: USDDoublable

public init(marketData: MarketData) {
self.currentPrice = marketData.currentPrice
self.priceChangePercentage24H = marketData.priceChangePercentage24H
self.marketCap = marketData.marketCap
self.marketCapChangePercentage24H = marketData.marketCapChangePercentage24H
self.ath = marketData.ath
self.athChangePercentage = marketData.athChangePercentage
self.atl = marketData.atl
self.atlChangePercentage = marketData.atlChangePercentage
}

public init(
currentPrice: USDDecimalable,
priceChangePercentage24H: Double,
marketCap: USDDecimalable,
marketCapChangePercentage24H: Double,
ath: USDDecimalable,
athChangePercentage: USDDoublable,
atl: USDDecimalable,
atlChangePercentage: USDDoublable
) {
self.currentPrice = currentPrice
self.priceChangePercentage24H = priceChangePercentage24H
self.marketCap = marketCap
self.marketCapChangePercentage24H = marketCapChangePercentage24H
self.ath = ath
self.athChangePercentage = athChangePercentage
self.atl = atl
self.atlChangePercentage = atlChangePercentage
}

public static func == (lhs: MockMarketData, rhs: MockMarketData) -> Bool {
lhs.currentPrice.usd == rhs.currentPrice.usd &&
lhs.priceChangePercentage24H == rhs.priceChangePercentage24H &&
lhs.marketCap.usd == rhs.marketCap.usd &&
lhs.marketCapChangePercentage24H == rhs.marketCapChangePercentage24H &&
lhs.ath.usd == rhs.ath.usd &&
lhs.athChangePercentage.usd == rhs.athChangePercentage.usd &&
lhs.atl.usd == rhs.atl.usd &&
lhs.atlChangePercentage.usd == rhs.atlChangePercentage.usd
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import UseCaseProtocol
import Styleguide
import SwiftUI

private typealias Section = Styleguide.Section

public struct HomeView: View {

public var body: some View {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public struct MyCoinItem: Identifiable, Equatable {
public let iconUrl: URL
public let currentPrice: Decimal
public let priceChangePercentage: Double
public let isPriceUp: Bool

public init(coin: Coin) {
self.id = coin.id
Expand All @@ -26,7 +25,6 @@ public struct MyCoinItem: Identifiable, Equatable {
self.iconUrl = coin.image
self.currentPrice = coin.currentPrice
self.priceChangePercentage = coin.priceChangePercentage24H
self.isPriceUp = coin.priceChangePercentage24H > 0.0
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,8 @@ private extension MyCoinItemView {
}

var priceChangePercentage: some View {
HStack {
coinItem.isPriceUp
? Images.icArrowUpGreen.swiftUIImage
: Images.icArrowDownRed.swiftUIImage

Text(coinItem.priceChangePercentage, format: .percentage)
.font(Fonts.Inter.medium.textStyle(.body))
.foregroundColor(
coinItem.isPriceUp
? Colors.guppieGreen.swiftUIColor
: Colors.carnation.swiftUIColor
)
}
PercentageView(coinItem.priceChangePercentage)
.font(Fonts.Inter.medium.textStyle(.body))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@ public struct TrendingCoinItem: Identifiable, Equatable {
public let name: String
public let iconUrl: URL
public let priceChangePercentage: Double
public let isPriceUp: Bool

public init(coin: Coin) {
id = coin.id
symbol = coin.symbol.uppercased()
name = coin.name
iconUrl = coin.image
priceChangePercentage = coin.priceChangePercentage24H
isPriceUp = coin.priceChangePercentage24H > 0.0
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,8 @@ private extension TrendingCoinItemView {
}

var priceChangePercentage: some View {
HStack {
coinItem.isPriceUp
? Images.icArrowUpGreen.swiftUIImage
: Images.icArrowDownRed.swiftUIImage

Text(coinItem.priceChangePercentage, format: .percentage)
.font(Fonts.Inter.medium.textStyle(.body))
.foregroundColor(
coinItem.isPriceUp
? Colors.guppieGreen.swiftUIColor
: Colors.carnation.swiftUIColor
)
}
PercentageView(coinItem.priceChangePercentage)
.font(Fonts.Inter.medium.textStyle(.body))
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// ChartDataPointUIModel.swift
// MyCoin
//
// Created by Minh Pham on 10/01/2023.
//

import Entities
import Charts
import Foundation

public struct ChartDataPointUIModel: Equatable {

public let price: Decimal
public let timestamp: TimeInterval

public init(dataPoint: ChartDataPoint) {
self.price = dataPoint.price
self.timestamp = dataPoint.timestamp
}

public func toChartDataEntry() -> ChartDataEntry {
let priceInDouble = NSDecimalNumber(decimal: price).doubleValue
return ChartDataEntry(x: timestamp, y: priceInDouble)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,53 +14,57 @@ struct PriceLineChartSection: View {
@State private var highestPriceOffsetX: CGFloat = 0.0
@State private var lowestPriceOffsetX: CGFloat = 0.0

// TODO: Update to use real data in the integrate task
// swiftlint:disable number_separator
let testData = [
ChartDataEntry(x: 1640649600000, y: 50774.067814743),
ChartDataEntry(x: 1640736000000, y: 47725.14804631933),
ChartDataEntry(x: 1640822400000, y: 46506.99464767938),
ChartDataEntry(x: 1640908800000, y: 47191.86838983951),
ChartDataEntry(x: 1640995200000, y: 46319.65108805251),
ChartDataEntry(x: 1641081600000, y: 47816.07767640849),
ChartDataEntry(x: 1641168000000, y: 47387.212167697246),
ChartDataEntry(x: 1641254400000, y: 46531.140860530526),
ChartDataEntry(x: 1641340800000, y: 45938.02427172366),
ChartDataEntry(x: 1641427200000, y: 43647.147508068054)
]
private let chartData: [ChartDataPointUIModel]

private var chartDataEntry: [ChartDataEntry] {
chartData.map { $0.toChartDataEntry() }
}
private var maxPrice: Decimal {
guard let maxDataPoint = chartData.max(by: { $0.price < $1.price })?.price else { return 0.0 }
return maxDataPoint
}
private var minPrice: Decimal {
guard let minDataPoint = chartData.min(by: { $0.price < $1.price })?.price else { return 0.0 }
return minDataPoint
}

var body: some View {

// TODO: Update to use real data in the integrate task
GeometryReader { geometry in
VStack(alignment: .center, spacing: 0.0) {
Text("$50,774.06")
Text(maxPrice, format: .dollarCurrency)
.font(Fonts.Inter.medium.textStyle(.caption))
.foregroundColor(Colors.guppieGreen.swiftUIColor)
.readSize { textSize in
highestPriceOffsetX = calculateDataPointOffsetX(
data: testData,
data: chartDataEntry,
parentViewWidth: geometry.size.width,
labelWidth: textSize.width
)
}
.offset(x: highestPriceOffsetX)
PriceLineChartView(entries: testData)
Text("$43,647.14")
.renderIf(!chartData.isEmpty)
PriceLineChartView(entries: chartDataEntry)
Text(minPrice, format: .dollarCurrency)
.font(Fonts.Inter.medium.textStyle(.caption))
.foregroundColor(Colors.carnation.swiftUIColor)
.readSize { textSize in
lowestPriceOffsetX = calculateDataPointOffsetX(
data: testData,
data: chartDataEntry,
parentViewWidth: geometry.size.width,
labelWidth: textSize.width,
isHighest: false
)
}
.offset(x: lowestPriceOffsetX)
.renderIf(!chartData.isEmpty)
}
}
}

init(_ chartData: [ChartDataPointUIModel]) {
self.chartData = chartData
}
}

private extension PriceLineChartSection {
Expand Down Expand Up @@ -98,11 +102,14 @@ private extension PriceLineChartSection {
}

#if DEBUG
import DomainTestHelpers

struct PriceLineChartSection_Previews: PreviewProvider {

static var previews: some View {
Preview {
PriceLineChartSection()
let mockData = MockDataPoint.array.map { ChartDataPointUIModel(dataPoint: $0) }
PriceLineChartSection(mockData)
}
}
}
Expand Down
Loading

0 comments on commit a7f28bc

Please sign in to comment.