Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ public protocol ConnectivityObserver {

/// Publisher for connectivity availability.
var statusPublisher: AnyPublisher<ConnectivityStatus, Never> { get }

/// Starts the observer.
func startObserving()

/// Stops the observer.
func stopObserving()
}

/// Defines the various states of network connectivity.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ public final class DefaultConnectivityObserver: ConnectivityObserver {
}
}

public func startObserving() {
private func startObserving() {
networkMonitor.start(queue: observingQueue)
}

public func stopObserving() {
func stopObserving() {
networkMonitor.cancel()
}

Expand Down
16 changes: 0 additions & 16 deletions Modules/Sources/Yosemite/PointOfSale/POSSearchHistoryService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import Storage
public protocol POSSearchHistoryProviding {
func saveSuccessfulSearch(term: String, for itemType: POSItemType)
func searchHistory(for itemType: POSItemType) -> [String]
func clearSearchHistory(for itemType: POSItemType)
func clearAllSearchHistory()
}

/// Service for managing search history in the Point of Sale
Expand Down Expand Up @@ -60,18 +58,4 @@ public final class POSSearchHistoryService: POSSearchHistoryProviding {
public func searchHistory(for itemType: POSItemType) -> [String] {
return siteSpecificAppSettingsStoreMethods.getSearchTerms(for: itemType, siteID: siteID)
}

/// Clears the search history for a specific item type
/// - Parameter itemType: The type of item to clear search history for
public func clearSearchHistory(for itemType: POSItemType) {
siteSpecificAppSettingsStoreMethods.setSearchTerms([], for: itemType, siteID: siteID)
}

/// Clears all search history
public func clearAllSearchHistory() {
// Clear search history for all item types
POSItemType.allCases.forEach { itemType in
clearSearchHistory(for: itemType)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,38 +89,6 @@ struct POSSearchHistoryServiceTests {
#expect(history.isEmpty)
}

@Test func clearSearchHistory_clears_history_for_specific_item_type() throws {
// Given
sut.saveSuccessfulSearch(term: "product", for: .product)
sut.saveSuccessfulSearch(term: "coupon", for: .coupon)

// When
sut.clearSearchHistory(for: .product)

// Then
let productsSearchHistory = try #require(mockStoreMethods.mockSearchTerms[.product])
let couponsSearchHistory = try #require(mockStoreMethods.mockSearchTerms[.coupon])
#expect(productsSearchHistory.isEmpty)
#expect(couponsSearchHistory.count == 1)
#expect(couponsSearchHistory.first == "coupon")
}

@Test func clearAllSearchHistory_clears_all_history() throws {
// Given
mockStoreMethods.mockSearchTerms[.product] = ["product"]
mockStoreMethods.mockSearchTerms[.coupon] = ["coupon"]

// When
sut.clearAllSearchHistory()

// Then
#expect(mockStoreMethods.setSearchTermsCalled)
let productsSearchHistory = try #require(mockStoreMethods.mockSearchTerms[.product])
let couponsSearchHistory = try #require(mockStoreMethods.mockSearchTerms[.coupon])
#expect(productsSearchHistory.isEmpty)
#expect(couponsSearchHistory.isEmpty)
}

@Test func search_history_is_separate_for_different_item_types() {
// Given
mockStoreMethods.mockSearchTerms[.product] = ["product"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ final class CardPresentPaymentCollectOrderPaymentUseCaseAdaptor {
CardPresentPaymentTapToPayReaderConnectionAlertsProvider,
CardPresentPaymentBluetoothReaderConnectionAlertsProvider,
CardPresentPaymentsAlertPresenterAdaptor>,
onboardingPresenter: CardPresentPaymentsOnboardingPresenting,
configuration: CardPresentPaymentsConfiguration,
alertsPresenter: CardPresentPaymentsAlertPresenterAdaptor,
paymentEventSubject: any Subject<CardPresentPaymentEvent, Never>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ final class CardPresentPaymentService: CardPresentPaymentFacade {
let connectedReaderPublisher = await Self.createCardReaderConnectionPublisher(stores: stores)
self.connectedReaderPublisher = connectedReaderPublisher

readerConnectionStatusPublisher = connectedReaderPublisher
readerConnectionStatusPublisher = self.connectedReaderPublisher
.map({ reader -> CardPresentPaymentReaderConnectionStatus in
guard let reader else {
return .disconnected
Expand Down Expand Up @@ -146,7 +146,6 @@ final class CardPresentPaymentService: CardPresentPaymentFacade {
using: connectionMethod,
siteID: siteID,
preflightController: preflightController,
onboardingPresenter: onboardingAdaptor,
configuration: cardPresentPaymentsConfiguration,
alertsPresenter: paymentAlertsPresenterAdaptor,
paymentEventSubject: paymentEventSubject,
Expand All @@ -157,7 +156,7 @@ final class CardPresentPaymentService: CardPresentPaymentFacade {
switch try await paymentTask.value {
case .success:
// TODO: fetch the receipt URL to return an accurate value.
let transaction = CardPresentPaymentTransaction(receiptURL: URL(string: "https://example.com")!)
let transaction = CardPresentPaymentTransaction()
return .success(transaction)
case .cancellation:
return .cancellation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ public protocol POSCollectOrderPaymentAnalyticsTracking {
func trackCardReaderReady()
func trackCardReaderTapped()
func trackCheckoutTapped()
func resetCheckoutTapCountTracker()
func trackSuccessfulCashPayment()
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Foundation
import WooFoundation
import enum Yosemite.POSItemType
import protocol Yosemite.POSItemFetchAnalyticsTracking

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ extension WooAnalyticsEvent {
properties: [Key.scanner: scanner.analyticsName])
}

static func barcodeScannerSetupScannerConnected(scanner: PointOfSaleBarcodeScannerType, step: String) -> WooAnalyticsEvent {
static func barcodeScannerSetupScannerConnected(scanner: PointOfSaleBarcodeScannerType) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .pointOfSaleBarcodeScannerSetupScannerConnected,
properties: [Key.scanner: scanner.analyticsName])
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ final class CardPresentPaymentPreviewService: CardPresentPaymentFacade {
func collectPayment(for order: Yosemite.Order,
using connectionMethod: CardReaderConnectionMethod,
channel: PaymentChannel) async throws -> CardPresentPaymentResult {
.success(CardPresentPaymentTransaction(receiptURL: URL(string: "https://example.net/receipts/123")!))
.success(CardPresentPaymentTransaction())
}

func cancelPayment() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import Foundation

/// A completed, paid transaction.
public struct CardPresentPaymentTransaction {
let receiptURL: URL
public init() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ extension PointOfSaleInternalOrderState: Equatable {

extension PointOfSaleOrderController {
enum PointOfSaleOrderControllerError: Error {
case noSiteID
case noOrder
}
}
Expand Down
15 changes: 3 additions & 12 deletions WooCommerce/Classes/POS/Models/Cart.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,6 @@ extension Cart {
case loaded(POSOrderableItem)
case loading
case error

var isLoading: Bool {
switch self {
case .loading:
return true
default:
return false
}
}
}

var formattedPrice: String? {
Expand Down Expand Up @@ -95,15 +86,15 @@ extension Cart {

extension Cart {
mutating func add(_ posItem: POSItem) {
if let purchasableItem = createPurchasableItem(id: UUID(), from: posItem) {
if let purchasableItem = createPurchasableItem(from: posItem) {
purchasableItems.insert(purchasableItem, at: purchasableItems.startIndex)
} else if case .coupon(let coupon) = posItem {
let couponItem = Cart.CouponItem(id: coupon.id, code: coupon.code, summary: coupon.summary)
coupons.insert(couponItem, at: coupons.startIndex)
}
}

private func createPurchasableItem(id: UUID, from posItem: POSItem) -> Cart.PurchasableItem? {
private func createPurchasableItem(from posItem: POSItem) -> Cart.PurchasableItem? {
switch posItem {
case .simpleProduct(let simpleProduct):
return PurchasableItem(id: UUID(), item: simpleProduct, title: simpleProduct.name, subtitle: nil, quantity: 1)
Expand All @@ -125,7 +116,7 @@ extension Cart {
mutating func updateLoadingItem(id: UUID, with posItem: POSItem) -> Cart.PurchasableItem? {
guard let index = purchasableItems.firstIndex(where: { $0.id == id }) else { return nil }

if let productItem = createPurchasableItem(id: id, from: posItem) {
if let productItem = createPurchasableItem(from: posItem) {
purchasableItems[index] = productItem
return productItem
} else {
Expand Down
27 changes: 0 additions & 27 deletions WooCommerce/Classes/POS/Models/ItemListState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,6 @@ enum ItemListState {
case pagination
}

var isLoading: Bool {
switch self {
case .loading:
return true
default:
return false
}
}

var isLoaded: Bool {
switch self {
case .loaded:
Expand All @@ -30,24 +21,6 @@ enum ItemListState {
}
}

var isInlineError: Bool {
switch self {
case .inlineError:
return true
default:
return false
}
}

var isError: Bool {
switch self {
case .error:
return true
default:
return false
}
}

var isEmpty: Bool {
switch self {
case .empty:
Expand Down
37 changes: 0 additions & 37 deletions WooCommerce/Classes/POS/Models/PointOfSaleAggregateModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,10 @@ import protocol Yosemite.PointOfSaleBarcodeScanServiceProtocol
import enum Yosemite.PointOfSaleBarcodeScanError

protocol PointOfSaleAggregateModelProtocol {
var orderStage: PointOfSaleOrderStage { get }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I guess it's a fair call from Periphery. We include many of these in the protocol, but never really use them when injecting aggregate modal as a protocol. We can always included when needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, I think it's good to only include what's used. It could also help break up the big protocol into smaller ones for different use cases from the aggregate model.


var cardReaderConnectionStatus: CardPresentPaymentReaderConnectionStatus { get }
func connectCardReader()
func disconnectCardReader()
var paymentState: PointOfSalePaymentState { get }
var cardPresentPaymentAlertViewModel: PointOfSaleCardPresentPaymentAlertType? { get set }
var cardPresentPaymentInlineMessage: PointOfSaleCardPresentPaymentMessageType? { get }
func cancelCardPaymentsOnboarding()
func trackCardPaymentsOnboardingShown()

var purchasableItemsController: PointOfSaleItemsControllerProtocol { get }
var purchasableItemsSearchController: PointOfSaleSearchingItemsControllerProtocol { get }
var couponsController: PointOfSaleCouponsControllerProtocol { get }
var couponsSearchController: PointOfSaleSearchingItemsControllerProtocol { get }

var cart: Cart { get }
func barcodeScanned(_ result: Result<String, HIDBarcodeParserError>)
func addToCart(_ item: POSItem)
func remove(cartItem: CartItem)
func removeAllItemsFromCart(types: [CartItemType])
func addMoreToCart()
func startNewCart()

func saveSearchTerm(_ term: String, for itemType: POSItemType)
func searchHistory(for itemType: POSItemType) -> [String]

var orderState: PointOfSaleOrderState { get }
func checkOut() async

func pointOfSaleClosed()
}

@Observable final class PointOfSaleAggregateModel: PointOfSaleAggregateModelProtocol {
Expand Down Expand Up @@ -265,10 +238,6 @@ extension PointOfSaleAggregateModel {
func saveSearchTerm(_ term: String, for itemType: POSItemType) {
searchHistoryService.saveSuccessfulSearch(term: term, for: itemType)
}

func searchHistory(for itemType: POSItemType) -> [String] {
return searchHistoryService.searchHistory(for: itemType)
}
}

// MARK: - Track events
Expand Down Expand Up @@ -622,12 +591,6 @@ extension PointOfSaleAggregateModel {
}
}

private extension PointOfSaleAggregateModel {
enum Constants {
static let initialPage: Int = 1
}
}

#if DEBUG
extension PointOfSaleAggregateModel {
func setPreviewState(paymentState: PointOfSalePaymentState, inlineMessage: PointOfSaleCardPresentPaymentMessageType?) {
Expand Down
1 change: 0 additions & 1 deletion WooCommerce/Classes/POS/Models/PointOfSaleErrorState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ struct PointOfSaleErrorState: Equatable {
case variationsLoadError
case productsNextPageError
case variationsNextPageError
case couponsNotFound
case couponsLoadError
case couponsDisabled
case couponsNextPageError
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,21 @@ protocol PointOfSaleBarcodeScannerButtonCustomization {
}

// MARK: - Transition Types
public enum PointOfSaleBarcodeScannerTransitionType: Hashable {
enum PointOfSaleBarcodeScannerTransitionType: Hashable {
case next
case retry
case back
}

// MARK: - Setup Step
struct PointOfSaleBarcodeScannerSetupStep {
let title: String
let content: any View
let buttonCustomization: PointOfSaleBarcodeScannerButtonCustomization?
let transitions: [PointOfSaleBarcodeScannerTransitionType: PointOfSaleBarcodeScannerStepID]

init(title: String = "",
@ViewBuilder content: () -> any View,
init(@ViewBuilder content: () -> any View,
buttonCustomization: PointOfSaleBarcodeScannerButtonCustomization? = nil,
transitions: [PointOfSaleBarcodeScannerTransitionType: PointOfSaleBarcodeScannerStepID] = [:]) {
self.title = title
self.content = content()
self.buttonCustomization = buttonCustomization
self.transitions = transitions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ class PointOfSaleBarcodeScannerSetupFlow {
}
}

func restartFlow() {
currentStepKey = .setupBarcodeHID
}

// MARK: - Generic Transition Methods

func transition(to transitionType: PointOfSaleBarcodeScannerTransitionType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,6 @@ class PointOfSaleBarcodeScannerSetupFlowManager {
currentFlow = nil
}

func nextStep() {
currentFlow?.nextStep()
}

func previousStep() {
currentFlow?.previousStep()
}

func getCurrentStep() -> PointOfSaleBarcodeScannerSetupStep? {
currentFlow?.currentStep
}
Expand Down Expand Up @@ -102,6 +94,6 @@ class PointOfSaleBarcodeScannerSetupFlowManager {

private func handleKeyboardConnected() {
guard case .setupFlow(let scannerType) = currentState, let step = getCurrentSetupStepValue() else { return }
analytics.track(event: WooAnalyticsEvent.PointOfSale.barcodeScannerSetupScannerConnected(scanner: scannerType, step: step))
analytics.track(event: WooAnalyticsEvent.PointOfSale.barcodeScannerSetupScannerConnected(scanner: scannerType))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ final class GameControllerBarcodeObserver {
}

/// Handles the disconnection of the keyboard (coalesced).
@objc private func handleKeyboardDidDisconnect(_ notification: Notification) {
@objc private func handleKeyboardDidDisconnect() {
cleanupKeyboard()
}

Expand Down
Loading