Skip to content

Commit

Permalink
Run swiftformat
Browse files Browse the repository at this point in the history
  • Loading branch information
esen committed Dec 30, 2024
1 parent 329b7a7 commit 00a802c
Show file tree
Hide file tree
Showing 42 changed files with 248 additions and 270 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public struct Client: APIProtocol {
} else {
throw converter.makeUnexpectedContentTypeError(contentType: contentType)
}
return .ok(.init(body: .json(try bodyPayload.json)))
return try .ok(.init(body: .json(bodyPayload.json)))
default:
let contentType = converter.extractContentTypeIfPresent(in: response.headerFields)
let body: Components.Responses.Response.Body
Expand All @@ -169,7 +169,6 @@ public struct Client: APIProtocol {
}

enum BodyUniversalData: Sendable, Hashable {

case json(JsonPayload)
public var json: Components.Responses.Response.Body.jsonPayload {
get throws {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import MarketKit
import RxSwift

class BitcoinBaseAdapter {
static let confirmationsThreshold = 1 // Number of confirmations for coins in transaction to be available for spending
static let txStatusConfirmationsThreshold = 3 // Number of confirmations for transaction status displayed
static let confirmationsThreshold = 1 // Number of confirmations for coins in transaction to be available for spending
static let txStatusConfirmationsThreshold = 3 // Number of confirmations for transaction status displayed
private let abstractKit: AbstractKit

var coinRate: Decimal { 100_000_000 } // pow(10, 8)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class BitcoinAddressParserItem {
case .p2tr: return .derived(derivation: .bip86)
default: return nil
}

default: return nil
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class PurchaseManager: NSObject {
@PostPublished private(set) var products: [Product] = []
@PostPublished private(set) var purchasedProductIds = Set<String>()

@PostPublished private(set) var subscription: Subscription? //STUB
@PostPublished private(set) var subscription: Subscription? // STUB

private var updatesTask: Task<Void, Never>?

Expand Down Expand Up @@ -112,7 +112,7 @@ extension PurchaseManager: SKPaymentTransactionObserver {
}

func paymentQueue(_: SKPaymentQueue, shouldAddStorePayment _: SKPayment, for _: SKProduct) -> Bool {
return true
true
}
}

Expand All @@ -121,7 +121,7 @@ extension PurchaseManager {
private static let subscriptionTypeKey = "subscription_type"
private static let subscriptionPeriodKey = "subscription_period"
private static let subscriptionTimeKey = "subscription_time"

func check(promocode: String) async throws -> PromoData {
if promocode == "" {
return .empty
Expand All @@ -135,7 +135,7 @@ extension PurchaseManager {
throw PromoCodeError.invalid
}
}

func purchase(type: SubscriptionType, period: SubscriptionPeriod) async throws {
let storage = App.shared.userDefaultsStorage
let current = Date().timeIntervalSince1970
Expand All @@ -146,25 +146,25 @@ extension PurchaseManager {
subscription = Subscription(type: type, period: period, timestamp: current)
try await Task.sleep(for: .seconds(2))
}

func deactivate() {
let storage = App.shared.userDefaultsStorage
storage.set(value: String?._createNil, for: Self.subscriptionTypeKey)
storage.set(value: String?._createNil, for: Self.subscriptionPeriodKey)
storage.set(value: String?._createNil, for: Self.subscriptionTimeKey)

subscription = nil
}

func loadSubscription() {
let storage = UserDefaultsStorage()
if let subscriptionType: String = storage.value(for: Self.subscriptionTypeKey),
let subscriptionPeriod: String = storage.value(for: Self.subscriptionPeriodKey),
let subscriptionTimeString: String = storage.value(for: Self.subscriptionTimeKey),
let featureType = SubscriptionType(rawValue: subscriptionType),
let featurePeriod = SubscriptionPeriod(rawValue: subscriptionPeriod),
let subscriptionTime = TimeInterval(subscriptionTimeString) {
let subscriptionTime = TimeInterval(subscriptionTimeString)
{
subscription = Subscription(type: featureType, period: featurePeriod, timestamp: subscriptionTime)
} else {
subscription = nil
Expand All @@ -178,17 +178,17 @@ extension PurchaseManager {
case pro
case vip
}

enum SubscriptionPeriod: String, CaseIterable {
case annually
case monthly
}

struct Subscription: Identifiable {
let type: SubscriptionType
let period: SubscriptionPeriod
let timestamp: TimeInterval

var id: String {
[type.rawValue, period.rawValue].joined(separator: "|")
}
Expand All @@ -198,9 +198,9 @@ extension PurchaseManager {
case invalid
case used
}

struct PromoData {
static let empty = Self.init(promocode: "", discount: 0)
static let empty = Self(promocode: "", discount: 0)

let promocode: String
let discount: Int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -734,9 +734,9 @@ enum StorageMigrator {

let updatedWallet = EnabledWallet_v_0_40(
tokenQueryId: tokenQueryId,
accountId: row["accountId"],
accountId: row["accountId"],
coinName: row["coinName"],
coinCode: row["coinCode"],
coinCode: row["coinCode"],
tokenDecimals: row["tokenDecimals"]
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ enum AccountType {
}
case let .btcAddress(_, blockchainType, tokenType):
return token.blockchainType == blockchainType && token.type == tokenType

default:
return false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ struct RankView: View {

@ViewBuilder private func loadingList() -> some View {
Section {
ListForEach(Array(0 ... 10)) { index in
ListForEach(Array(0 ... 10)) { _ in
ListRow {
itemContent(
index: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct EducationView: View {
case let .loaded(categories):
VStack(spacing: 0) {
ScrollableTabHeaderView(
tabs: categories.map { $0.title },
tabs: categories.map(\.title),
currentTabIndex: $currentTabIndex
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ struct MarketAdvancedSearchView: View {
}
}
}

private func openPremiumSubscription() {
subscriptionPresented = true
}
Expand Down Expand Up @@ -198,7 +198,6 @@ struct MarketAdvancedSearchView: View {
}
}


@ViewBuilder private func premiumRow(_ view: some View) -> some View {
if viewModel.premiumEnabled {
ListRow {
Expand All @@ -212,7 +211,7 @@ struct MarketAdvancedSearchView: View {
}
}
}

@ViewBuilder private func listedOnTopExchangesRow() -> some View {
Toggle(isOn: $viewModel.listedOnTopExchanges) {
Text("market.advanced_search.listed_on_top_exchanges".localized).themeBody()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class MarketAdvancedSearchViewModel: ObservableObject {
private let currencyManager = App.shared.currencyManager
private let priceChangeModeManager = App.shared.priceChangeModeManager
private let purchaseManager = App.shared.purchaseManager

private var cancellables = Set<AnyCancellable>()
private var tasks = Set<AnyTask>()

Expand Down Expand Up @@ -212,7 +212,7 @@ class MarketAdvancedSearchViewModel: ObservableObject {
(!outperformedBtc || outperformed(value: priceChangeValue, coinUid: "bitcoin")) &&
(!outperformedEth || outperformed(value: priceChangeValue, coinUid: "ethereum")) &&
(!outperformedBnb || outperformed(value: priceChangeValue, coinUid: "binancecoin")) &&
(closedToAllTime(closedTo: priceCloseTo, ath: marketInfo.athPercentage, atl: marketInfo.atlPercentage))
closedToAllTime(closedTo: priceCloseTo, ath: marketInfo.athPercentage, atl: marketInfo.atlPercentage)
}
}

Expand Down Expand Up @@ -554,4 +554,3 @@ extension MarketAdvancedSearchViewModel {
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ struct PromoCodeBottomSheetView: View {
@Binding private var isPresented: Bool
@FocusState private var focusField: FocusField?

init(promo: String, isPresented: Binding<Bool>, onApplyPromo: @escaping ((PurchaseManager.PromoData) -> ())) {
init(promo: String, isPresented: Binding<Bool>, onApplyPromo: @escaping ((PurchaseManager.PromoData) -> Void)) {
_viewModel = StateObject(wrappedValue: PromoCodeBottomSheetViewModel(promo: promo, onApplyPromo: onApplyPromo))

_isPresented = isPresented
}

Expand All @@ -19,7 +19,7 @@ struct PromoCodeBottomSheetView: View {
HStack(spacing: .margin16) {
Image("percent_24").themeIcon(color: .themeJacob)
Text("purchases.promocode.title".localized).themeHeadline2()

Button(action: {
isPresented = false
}) {
Expand All @@ -29,7 +29,7 @@ struct PromoCodeBottomSheetView: View {
.padding(.horizontal, .margin32)
.padding(.top, .margin24)
.padding(.bottom, .margin12)

InputTextRow(vertical: .margin8) {
ShortcutButtonsView(
content: {
Expand All @@ -38,7 +38,6 @@ struct PromoCodeBottomSheetView: View {
text: $viewModel.promocode
)
.focused($focusField, equals: .promocode)

.accentColor(.themeYellow)
.autocapitalization(.none)
.autocorrectionDisabled()
Expand All @@ -55,7 +54,7 @@ struct PromoCodeBottomSheetView: View {
}
.modifier(CautionBorder(cautionState: $viewModel.promocodeCautionState))
.padding(EdgeInsets(top: .margin24, leading: .margin16, bottom: 0, trailing: .margin16))

VStack(spacing: .margin12) {
buttonView()
}
Expand All @@ -65,7 +64,7 @@ struct PromoCodeBottomSheetView: View {
focusField = .promocode
}
}

@ViewBuilder private func buttonView() -> some View {
let (title, disabled, showProgress) = buttonState()

Expand All @@ -86,7 +85,7 @@ struct PromoCodeBottomSheetView: View {
}

private func buttonState() -> (String, Bool, Bool) {
var title: String = "button.apply".localized
var title = "button.apply".localized
var disabled = true
var showProgress = false

Expand All @@ -104,7 +103,6 @@ struct PromoCodeBottomSheetView: View {

return (title, disabled, showProgress)
}

}

extension PromoCodeBottomSheetView {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import UIKit

class PromoCodeBottomSheetViewModel: ObservableObject {
private let purchaseManager = App.shared.purchaseManager

private let initialPromo: String
private let onApplyPromo: ((PurchaseManager.PromoData) -> ())
private let onApplyPromo: (PurchaseManager.PromoData) -> Void
private var currentTask: Task<Void, Never>?

@Published var buttonState: ButtonState = .idle
@Published var promocodeCautionState: CautionState = .none
@Published var promocode: String {
Expand All @@ -18,33 +18,33 @@ class PromoCodeBottomSheetViewModel: ObservableObject {
}
}
}

var promoData: PurchaseManager.PromoData?
init(promo: String, onApplyPromo: @escaping ((PurchaseManager.PromoData) -> ())) {
self.initialPromo = promo

init(promo: String, onApplyPromo: @escaping ((PurchaseManager.PromoData) -> Void)) {
initialPromo = promo
self.onApplyPromo = onApplyPromo

promocode = promo
}

@MainActor private func update(state: ButtonState, caution: CautionState) async {
await MainActor.run { [weak self] in
self?.buttonState = state
self?.promocodeCautionState = caution
}
}

private func validatePromo() async {
currentTask?.cancel()
currentTask = nil

let promo = promocode.trimmingCharacters(in: .whitespacesAndNewlines)
if promo == initialPromo {
await update(state: .idle, caution: .none)
return
}

currentTask = Task {
do {
await update(state: .loading, caution: .none)
Expand All @@ -68,17 +68,16 @@ class PromoCodeBottomSheetViewModel: ObservableObject {
}
}
}

func applyPromo() {
if let promoData {
onApplyPromo(promoData)
}
}

deinit {
currentTask?.cancel()
}

}

extension PromoCodeBottomSheetViewModel {
Expand All @@ -89,10 +88,10 @@ extension PromoCodeBottomSheetViewModel {

func onTap(index _: Int) {
if let text = UIPasteboard.general.string?.replacingOccurrences(of: "\n", with: " ") {
self.promocode = text.trimmingCharacters(in: .whitespacesAndNewlines)
promocode = text.trimmingCharacters(in: .whitespacesAndNewlines)
}
}

func onTapDelete() {
promocode = ""
}
Expand Down
Loading

0 comments on commit 00a802c

Please sign in to comment.