-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: SendService as separated package, update SolanaSwift, move Repo…
…sitory from Ethe...
- Loading branch information
1 parent
f54fb59
commit d038e32
Showing
48 changed files
with
1,105 additions
and
38 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
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
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
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
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
39 changes: 39 additions & 0 deletions
39
Packages/KeyAppKit/Sources/Repository/Models/LoadingState.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,39 @@ | ||
import Foundation | ||
|
||
/// Loading state for a specific time-consuming operation | ||
public enum LoadingState { | ||
/// Nothing loaded | ||
case initialized | ||
/// Data is loading | ||
case loading | ||
/// Data is loaded | ||
case loaded | ||
/// Error | ||
case error | ||
} | ||
|
||
public enum ListLoadingState { | ||
public enum Status { | ||
case loading | ||
case loaded | ||
case error(Error) | ||
} | ||
|
||
public enum LoadMoreStatus { | ||
case loading | ||
case reachedEndOfList | ||
case error(Error) | ||
} | ||
|
||
case empty(Status) | ||
case nonEmpty(loadMoreStatus: LoadMoreStatus) | ||
|
||
public var isEmpty: Bool { | ||
switch self { | ||
case .empty: | ||
return true | ||
default: | ||
return false | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
Packages/KeyAppKit/Sources/Repository/Provider/ListProvider.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,17 @@ | ||
import Foundation | ||
|
||
/// Repository that is only responsible for fetching list of items | ||
public protocol ListProvider { | ||
/// ListItemType to be fetched | ||
associatedtype ItemType: Hashable & Identifiable | ||
/// Indicate if should fetching item | ||
func shouldFetch() -> Bool | ||
/// Fetch list of item from outside | ||
func fetch() async throws -> [ItemType] | ||
} | ||
|
||
public extension ListProvider { | ||
func shouldFetch() -> Bool { | ||
true | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...es/KeyAppKit/Sources/Repository/Provider/PaginatedListFetcher/PaginatedListProvider.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,13 @@ | ||
import Foundation | ||
|
||
public protocol PaginatedListProvider: ListProvider { | ||
associatedtype PS: PaginationStrategy | ||
/// Pagination strategy | ||
var paginationStrategy: PS { get } | ||
} | ||
|
||
public extension PaginatedListProvider { | ||
@MainActor func shouldFetch() -> Bool { | ||
!paginationStrategy.isLastPageLoaded | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...tory/Provider/PaginatedListFetcher/PaginationStrategy/LimitOffsetPaginationStrategy.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,34 @@ | ||
import Foundation | ||
|
||
/// PaginationStrategy using limit and offset | ||
@MainActor | ||
public class LimitOffsetPaginationStrategy: PaginationStrategy { | ||
// MARK: - Properties | ||
|
||
private let limit: Int | ||
private(set) var offset: Int = 0 | ||
public private(set) var isLastPageLoaded: Bool = false | ||
|
||
// MARK: - Initializer | ||
|
||
public nonisolated init(limit: Int) { | ||
self.limit = limit | ||
} | ||
|
||
public func checkIfLastPageLoaded<ItemType>(lastSnapshot: [ItemType]?) { | ||
guard let lastSnapshot else { | ||
isLastPageLoaded = true | ||
return | ||
} | ||
isLastPageLoaded = lastSnapshot.count < limit | ||
} | ||
|
||
public func resetPagination() { | ||
offset = 0 | ||
isLastPageLoaded = false | ||
} | ||
|
||
public func moveToNextPage() { | ||
offset += limit | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...rces/Repository/Provider/PaginatedListFetcher/PaginationStrategy/PaginationStrategy.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,14 @@ | ||
import Foundation | ||
|
||
/// Strategy of to define how pagination works in ListRepository | ||
@MainActor | ||
public protocol PaginationStrategy { | ||
/// Boolean value to indicate that last page was loaded or not | ||
var isLastPageLoaded: Bool { get } | ||
/// Check if last page loaded | ||
func checkIfLastPageLoaded<ItemType>(lastSnapshot: [ItemType]?) | ||
/// Reset pagination | ||
func resetPagination() | ||
/// Move to next page | ||
func moveToNextPage() | ||
} |
51 changes: 51 additions & 0 deletions
51
Packages/KeyAppKit/Sources/Repository/Provider/Provider.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,51 @@ | ||
import Foundation | ||
|
||
/// Repository that is only responsible for fetching item | ||
public protocol Provider<ItemType> { | ||
/// ItemType to be fetched | ||
associatedtype ItemType | ||
/// Indicate if should fetching item | ||
func shouldFetch() -> Bool | ||
/// Fetch item from outside | ||
func fetch() async throws -> ItemType? | ||
} | ||
|
||
public extension Provider { | ||
func shouldFetch() -> Bool { | ||
true | ||
} | ||
} | ||
|
||
// class ListRepository<ItemType: Hashable & Identifiable>: AnyListRepository { | ||
// // MARK: - Properties | ||
// | ||
// /// Strategy that indicates how pagination works, nil if pagination is disabled | ||
// let paginationStrategy: PaginationStrategy? | ||
// | ||
// // MARK: - Initializer | ||
// init(paginationStrategy: PaginationStrategy? = nil) { | ||
// self.paginationStrategy = paginationStrategy | ||
// } | ||
// | ||
// func shouldFetch() -> Bool { | ||
// var shouldRequest: Bool = true | ||
// | ||
// // check if isLastPageLoaded | ||
// if let paginationStrategy { | ||
// shouldRequest = shouldRequest && !paginationStrategy.isLastPageLoaded | ||
// } | ||
// | ||
// return shouldRequest | ||
// } | ||
// | ||
// func fetch() async throws -> [ItemType] { | ||
// fatalError("Must override") | ||
// } | ||
// } | ||
|
||
// extension AsyncSequence: Repository { | ||
// func fetch() async throws { | ||
// let iterator = makeAsyncIterator() | ||
// return iterator.next() | ||
// } | ||
// } |
Oops, something went wrong.