-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- replace name field with market cap value - adopt widgets for new Watchlist manager
- Loading branch information
Showing
57 changed files
with
1,109 additions
and
983 deletions.
There are no files selected for viewing
110 changes: 64 additions & 46 deletions
110
UnstoppableWallet/UnstoppableWallet.xcodeproj/project.pbxproj
Large diffs are not rendered by default.
Oops, something went wrong.
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
99 changes: 99 additions & 0 deletions
99
UnstoppableWallet/UnstoppableWallet/Core/Managers/WatchlistManager.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,99 @@ | ||
import Combine | ||
import WidgetKit | ||
|
||
class WatchlistManager { | ||
private let keyCoinUids = "watchlist-coin-uids" | ||
private let keySortBy = "watchlist-sort-by" | ||
private let keyTimePeriod = "watchlist-time-period" | ||
private let keyShowSignals = "watchlist-show-signals" | ||
|
||
private let storage: SharedLocalStorage | ||
|
||
private let coinUidsSubject = PassthroughSubject<[String], Never>() | ||
|
||
var coinUids: [String] { | ||
didSet { | ||
coinUidSet = Set(coinUids) | ||
coinUidsSubject.send(coinUids) | ||
|
||
storage.set(value: coinUids, for: keyCoinUids) | ||
|
||
WidgetCenter.shared.reloadTimelines(ofKind: AppWidgetConstants.watchlistWidgetKind) | ||
} | ||
} | ||
|
||
private var coinUidSet: Set<String> | ||
|
||
var sortBy: WatchlistSortBy { | ||
didSet { | ||
storage.set(value: sortBy.rawValue, for: keySortBy) | ||
WidgetCenter.shared.reloadTimelines(ofKind: AppWidgetConstants.watchlistWidgetKind) | ||
} | ||
} | ||
|
||
var timePeriod: WatchlistTimePeriod { | ||
didSet { | ||
storage.set(value: timePeriod.rawValue, for: keyTimePeriod) | ||
WidgetCenter.shared.reloadTimelines(ofKind: AppWidgetConstants.watchlistWidgetKind) | ||
} | ||
} | ||
|
||
var showSignals: Bool { | ||
didSet { | ||
storage.set(value: showSignals, for: keyShowSignals) | ||
// WidgetCenter.shared.reloadTimelines(ofKind: AppWidgetConstants.watchlistWidgetKind) | ||
} | ||
} | ||
|
||
init(storage: SharedLocalStorage) { | ||
self.storage = storage | ||
|
||
coinUids = storage.value(for: keyCoinUids) ?? [] | ||
coinUidSet = Set(coinUids) | ||
|
||
let sortByRaw: String? = storage.value(for: keySortBy) | ||
sortBy = sortByRaw.flatMap { WatchlistSortBy(rawValue: $0) } ?? .manual | ||
|
||
let timePeriodRaw: String? = storage.value(for: keyTimePeriod) | ||
timePeriod = timePeriodRaw.flatMap { WatchlistTimePeriod(rawValue: $0) } ?? .day1 | ||
|
||
showSignals = storage.value(for: keyShowSignals) ?? true | ||
|
||
WidgetCenter.shared.reloadTimelines(ofKind: AppWidgetConstants.watchlistWidgetKind) | ||
} | ||
} | ||
|
||
extension WatchlistManager { | ||
var coinUidsPublisher: AnyPublisher<[String], Never> { | ||
coinUidsSubject.eraseToAnyPublisher() | ||
} | ||
|
||
func add(coinUid: String) { | ||
guard !coinUids.contains(coinUid) else { | ||
return | ||
} | ||
|
||
coinUids.append(coinUid) | ||
} | ||
|
||
func add(coinUids: [String]) { | ||
let coinUids = coinUids.filter { !self.coinUids.contains($0) } | ||
self.coinUids.append(contentsOf: coinUids) | ||
} | ||
|
||
func removeAll() { | ||
coinUids = [] | ||
} | ||
|
||
func remove(coinUid: String) { | ||
guard let index = coinUids.firstIndex(of: coinUid) else { | ||
return | ||
} | ||
|
||
coinUids.remove(at: index) | ||
} | ||
|
||
func isWatched(coinUid: String) -> Bool { | ||
coinUidSet.contains(coinUid) | ||
} | ||
} |
54 changes: 0 additions & 54 deletions
54
UnstoppableWallet/UnstoppableWallet/Core/Storage/FavoriteCoinRecordStorage.swift
This file was deleted.
Oops, something went wrong.
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
32 changes: 0 additions & 32 deletions
32
UnstoppableWallet/UnstoppableWallet/Models/Deprecated/FavoriteCoinRecord_v_0_22.swift
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...bleWallet/Models/FavoriteCoinRecord.swift → ...eprecated/FavoriteCoinRecord_v_0_38.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
7 changes: 7 additions & 0 deletions
7
UnstoppableWallet/UnstoppableWallet/Models/WatchlistSortBy.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,7 @@ | ||
enum WatchlistSortBy: String, CaseIterable { | ||
case manual | ||
case highestCap | ||
case lowestCap | ||
case gainers | ||
case losers | ||
} |
6 changes: 6 additions & 0 deletions
6
UnstoppableWallet/UnstoppableWallet/Models/WatchlistTimePeriod.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,6 @@ | ||
enum WatchlistTimePeriod: String, CaseIterable { | ||
case day1 = "1d" | ||
case week1 = "1w" | ||
case month1 = "1m" | ||
case month3 = "3m" | ||
} |
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
Oops, something went wrong.