-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
115 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
RadixWallet/Clients/CardCarouselClient/CardCarouselClient+Interface.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// MARK: - CardCarouselClient | ||
public struct CardCarouselClient: Sendable { | ||
public var cards: Cards | ||
public var closeCard: CloseCard | ||
|
||
init( | ||
cards: @escaping Cards, | ||
closeCard: @escaping CloseCard | ||
) { | ||
self.cards = cards | ||
self.closeCard = closeCard | ||
} | ||
} | ||
|
||
// MARK: - CarouselCard | ||
public enum CarouselCard: Hashable, Sendable { | ||
case threeSixtyDegrees | ||
case connect | ||
case somethingElse | ||
} | ||
|
||
extension CardCarouselClient { | ||
public typealias Cards = @Sendable () -> AnyAsyncSequence<[CarouselCard]> | ||
public typealias CloseCard = @Sendable (CarouselCard) -> Void | ||
} | ||
|
||
extension DependencyValues { | ||
public var cardCarouselClient: CardCarouselClient { | ||
get { self[CardCarouselClient.self] } | ||
set { self[CardCarouselClient.self] = newValue } | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
RadixWallet/Clients/CardCarouselClient/CardCarouselClient+Live.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import ComposableArchitecture | ||
|
||
extension CardCarouselClient: DependencyKey { | ||
public static let liveValue: Self = { | ||
let cardSubject = AsyncCurrentValueSubject<[CarouselCard]>([.threeSixtyDegrees, .connect, .somethingElse]) | ||
|
||
@Dependency(\.errorQueue) var errorQueue | ||
@Dependency(\.appPreferencesClient) var appPreferencesClient | ||
@Dependency(\.cacheClient) var cacheClient | ||
@Dependency(\.radixConnectClient) var radixConnectClient | ||
@Dependency(\.userDefaults) var userDefaults | ||
|
||
return Self( | ||
cards: { | ||
cardSubject.eraseToAnyAsyncSequence() | ||
}, | ||
closeCard: { card in | ||
guard let index = cardSubject.value.firstIndex(of: card) else { return } | ||
cardSubject.value.remove(at: index) | ||
} | ||
) | ||
}() | ||
} |
16 changes: 16 additions & 0 deletions
16
RadixWallet/Clients/CardCarouselClient/CardCarouselClient+Test.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// MARK: - CardCarouselClient + TestDependencyKey | ||
extension CardCarouselClient: TestDependencyKey { | ||
public static let previewValue = Self.noop | ||
|
||
public static let testValue = Self( | ||
cards: unimplemented("\(Self.self).cards"), | ||
closeCard: unimplemented("\(Self.self).closeCard") | ||
) | ||
} | ||
|
||
extension CardCarouselClient { | ||
public static let noop = Self( | ||
cards: { AsyncLazySequence([]).eraseToAnyAsyncSequence() }, | ||
closeCard: { _ in } | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters