Skip to content

Commit

Permalink
fix: account error handling and refactoring (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
bouassaba authored Nov 23, 2024
1 parent d1068db commit 82e41c9
Show file tree
Hide file tree
Showing 57 changed files with 594 additions and 419 deletions.
8 changes: 4 additions & 4 deletions Sources/Helpers/ErrorHandling.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func withErrorHandling(
before: (() -> Void)? = nil,
success: (() -> Void)? = nil,
failure: @escaping (String) -> Void,
invalidCreditentials: (() -> Void)? = nil,
invalidCredentials: (() -> Void)? = nil,
anyways: (() -> Void)? = nil
) {
if let before {
Expand All @@ -39,7 +39,7 @@ func withErrorHandling(
} catch let error as VOErrorResponse {
DispatchQueue.main.async {
if error.code == .invalidCredentials {
invalidCreditentials?()
invalidCredentials?()
} else {
failure(error.userMessage)
}
Expand All @@ -60,7 +60,7 @@ func withErrorHandling(
before: (() -> Void)? = nil,
success: (() -> Void)? = nil,
failure: @escaping (String) -> Void,
invalidCreditentials: (() -> Void)? = nil,
invalidCredentials: (() -> Void)? = nil,
anyways: (() -> Void)? = nil
) {
Timer.scheduledTimer(withTimeInterval: delaySeconds, repeats: false) { _ in
Expand All @@ -69,7 +69,7 @@ func withErrorHandling(
before: before,
success: success,
failure: failure,
invalidCreditentials: invalidCreditentials,
invalidCredentials: invalidCredentials,
anyways: anyways
)
}
Expand Down
8 changes: 4 additions & 4 deletions Sources/Library/Views/Avatar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
import SwiftUI

struct VOAvatar: View {
var name: String
var size: CGFloat
var url: URL?
private let name: String
private let size: CGFloat
private let url: URL?

public init(name: String, size: CGFloat, url: URL? = nil) {
init(name: String, size: CGFloat, url: URL? = nil) {
self.name = name
self.size = size
self.url = url
Expand Down
8 changes: 4 additions & 4 deletions Sources/Library/Views/ButtonLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
import SwiftUI

struct VOButtonLabel: View {
var text: String
var systemImage: String?
var isLoading: Bool
var progressViewTint: Color
private let text: String
private let systemImage: String?
private let isLoading: Bool
private let progressViewTint: Color

init(_ text: String, systemImage: String? = nil, isLoading: Bool = false, progressViewTint: Color = .primary) {
self.text = text
Expand Down
6 changes: 3 additions & 3 deletions Sources/Library/Views/ColorBadge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
import SwiftUI

struct VOColorBadge: View {
var text: String
var color: Color
var style: Style
private let text: String
private let color: Color
private let style: Style

init(_ text: String, color: Color, style: Style) {
self.text = text
Expand Down
2 changes: 1 addition & 1 deletion Sources/Library/Views/ErrorMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import SwiftUI

struct VOErrorMessage: View {
let message: String?
private let message: String?

init() {
message = nil
Expand Down
40 changes: 40 additions & 0 deletions Sources/Library/Views/FormButtonLabel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) 2024 Anass Bouassaba.
//
// Use of this software is governed by the Business Source License
// included in the file LICENSE in the root of this repository.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the GNU Affero General Public License v3.0 only, included in the file
// AGPL-3.0-only in the root of this repository.

import SwiftUI

struct VOFormButtonLabel: View {
private let text: String
private let isLoading: Bool

init(_ text: String, isLoading: Bool = false) {
self.text = text
self.isLoading = isLoading
}

var body: some View {
HStack {
Text(text)
if isLoading {
Spacer()
ProgressView()
}
}
}
}

#Preview {
Form {
Button {} label: {
VOFormButtonLabel("Lorem Ipsum", isLoading: true)
}
.disabled(true)
}
}
11 changes: 8 additions & 3 deletions Sources/Library/Views/Logo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@
import SwiftUI

struct VOLogo: View {
@Environment(\.colorScheme) var colorScheme
var isGlossy = false
var size: CGSize
@Environment(\.colorScheme) private var colorScheme
private let isGlossy: Bool
private let size: CGSize

init(isGlossy: Bool = false, size: CGSize) {
self.isGlossy = isGlossy
self.size = size
}

var body: some View {
if colorScheme == .dark {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Library/Views/PermissionBadge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import SwiftUI
import VoltaserveCore

struct VOPermissionBadge: View {
var permission: VOPermission.Value
private let permission: VOPermission.Value

init(_ permission: VOPermission.Value) {
self.permission = permission
Expand Down
2 changes: 1 addition & 1 deletion Sources/Library/Views/SectionHeader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import SwiftUI

struct VOSectionHeader: View {
var text: String
private let text: String

init(_ text: String) {
self.text = text
Expand Down
2 changes: 1 addition & 1 deletion Sources/Library/Views/WarningMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import SwiftUI

struct VOWarningMessage: View {
let message: String?
private let message: String?

init() {
message = nil
Expand Down
16 changes: 16 additions & 0 deletions Sources/Protocol/ErrorPresentable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) 2024 Anass Bouassaba.
//
// Use of this software is governed by the Business Source License
// included in the file LICENSE in the root of this repository.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the GNU Affero General Public License v3.0 only, included in the file
// AGPL-3.0-only in the root of this repository.

import Foundation

protocol ErrorPresentable {
var errorIsPresented: Bool { get set }
var errorMessage: String? { get set }
}
15 changes: 15 additions & 0 deletions Sources/Protocol/FormValidatable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) 2024 Anass Bouassaba.
//
// Use of this software is governed by the Business Source License
// included in the file LICENSE in the root of this repository.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the GNU Affero General Public License v3.0 only, included in the file
// AGPL-3.0-only in the root of this repository.

import Foundation

protocol FormValidatable {
func isValid() -> Bool
}
16 changes: 16 additions & 0 deletions Sources/Protocol/LoadStateProvider.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) 2024 Anass Bouassaba.
//
// Use of this software is governed by the Business Source License
// included in the file LICENSE in the root of this repository.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the GNU Affero General Public License v3.0 only, included in the file
// AGPL-3.0-only in the root of this repository.

import Foundation

protocol LoadStateProvider {
var isLoading: Bool { get }
var error: String? { get }
}
16 changes: 16 additions & 0 deletions Sources/Protocol/TimerLifecycle.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) 2024 Anass Bouassaba.
//
// Use of this software is governed by the Business Source License
// included in the file LICENSE in the root of this repository.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the GNU Affero General Public License v3.0 only, included in the file
// AGPL-3.0-only in the root of this repository.

import Foundation

protocol TimerLifecycle {
func startTimers()
func stopTimers()
}
16 changes: 16 additions & 0 deletions Sources/Protocol/TokenDistributing.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) 2024 Anass Bouassaba.
//
// Use of this software is governed by the Business Source License
// included in the file LICENSE in the root of this repository.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the GNU Affero General Public License v3.0 only, included in the file
// AGPL-3.0-only in the root of this repository.

import Foundation
import VoltaserveCore

protocol TokenDistributing {
func assignTokenToStores(_ token: VOToken.Value)
}
16 changes: 16 additions & 0 deletions Sources/Protocol/ViewDataProvider.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) 2024 Anass Bouassaba.
//
// Use of this software is governed by the Business Source License
// included in the file LICENSE in the root of this repository.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the GNU Affero General Public License v3.0 only, included in the file
// AGPL-3.0-only in the root of this repository.

import Foundation

protocol ViewDataProvider: LoadStateProvider {
func onAppearOrChange()
func fetchData()
}
Loading

0 comments on commit 82e41c9

Please sign in to comment.