-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #388 from nova-wallet/develop
v3.6
- Loading branch information
Showing
313 changed files
with
7,673 additions
and
1,454 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,6 @@ excluded: | |
- R.generated.swift | ||
- novawalletTests | ||
- novawalletIntegrationTests | ||
identifier_name: | ||
excluded: | ||
- id |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
source 'https://cdn.cocoapods.org/' | ||
platform :ios, '13.0' | ||
|
||
abstract_target 'novawalletAll' do | ||
|
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
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
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
20 changes: 20 additions & 0 deletions
20
novawallet/Assets.xcassets/colorWhite100.colorset/Contents.json
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,20 @@ | ||
{ | ||
"colors" : [ | ||
{ | ||
"color" : { | ||
"color-space" : "srgb", | ||
"components" : { | ||
"alpha" : "1.000", | ||
"blue" : "1.000", | ||
"green" : "1.000", | ||
"red" : "1.000" | ||
} | ||
}, | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
novawallet/Assets.xcassets/colorWhite64.colorset/Contents.json
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,20 @@ | ||
{ | ||
"colors" : [ | ||
{ | ||
"color" : { | ||
"color-space" : "srgb", | ||
"components" : { | ||
"alpha" : "0.640", | ||
"blue" : "1.000", | ||
"green" : "1.000", | ||
"red" : "1.000" | ||
} | ||
}, | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
novawallet/Assets.xcassets/iconUsers.imageset/Contents.json
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,15 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "users.pdf", | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
}, | ||
"properties" : { | ||
"template-rendering-intent" : "template" | ||
} | ||
} |
Binary file not shown.
12 changes: 12 additions & 0 deletions
12
novawallet/Assets.xcassets/iconsSettings/iconCurrency.imageset/Contents.json
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,12 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "Currency.pdf", | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
Binary file added
BIN
+3.14 KB
novawallet/Assets.xcassets/iconsSettings/iconCurrency.imageset/Currency.pdf
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import Foundation | ||
|
||
@propertyWrapper | ||
struct Atomic<Value> { | ||
private let lock = NSLock() | ||
private var value: Value | ||
|
||
init(defaultValue: Value) { | ||
value = defaultValue | ||
} | ||
|
||
var wrappedValue: Value { | ||
get { | ||
lock.lock() | ||
defer { lock.unlock() } | ||
return value | ||
} | ||
set { | ||
lock.lock() | ||
value = newValue | ||
lock.unlock() | ||
} | ||
} | ||
} |
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 | ||
|
||
extension Currency { | ||
static let usd = Currency( | ||
id: 0, | ||
code: "USD", | ||
name: "United States Dollar", | ||
symbol: "$", | ||
category: .fiat, | ||
isPopular: true, | ||
coingeckoId: "usd" | ||
) | ||
} |
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,28 @@ | ||
import Foundation | ||
|
||
struct Currency: Codable, Equatable { | ||
let id: Int | ||
let code: String | ||
let name: String | ||
let symbol: String? | ||
let category: Category | ||
let isPopular: Bool | ||
let coingeckoId: String | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case id | ||
case code | ||
case name | ||
case symbol | ||
case category | ||
case isPopular = "popular" | ||
case coingeckoId | ||
} | ||
} | ||
|
||
extension Currency { | ||
enum Category: String, Codable { | ||
case fiat | ||
case crypto | ||
} | ||
} |
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,91 @@ | ||
import Foundation | ||
import SoraKeystore | ||
|
||
protocol CurrencyManagerProtocol: AnyObject { | ||
var availableCurrencies: [Currency] { get } | ||
var selectedCurrency: Currency { get set } | ||
|
||
func addObserver( | ||
with owner: AnyObject, | ||
queue: DispatchQueue?, | ||
closure: @escaping (Currency, Currency) -> Void | ||
) | ||
func addObserver( | ||
with owner: AnyObject, | ||
closure: @escaping (Currency, Currency) -> Void | ||
) | ||
func removeObserver(by owner: AnyObject) | ||
} | ||
|
||
final class CurrencyManager: Observable<Currency>, CurrencyManagerProtocol { | ||
let availableCurrencies: [Currency] | ||
var selectedCurrency: Currency { | ||
get { | ||
state | ||
} | ||
set { | ||
state = newValue | ||
} | ||
} | ||
|
||
private let settingsManager: SettingsManagerProtocol | ||
|
||
init( | ||
currencyRepository: CurrencyRepositoryProtocol, | ||
settingsManager: SettingsManagerProtocol, | ||
queue: OperationQueue | ||
) throws { | ||
self.settingsManager = settingsManager | ||
|
||
let currenciesOperationWrapper = currencyRepository.fetchAvailableCurrenciesWrapper() | ||
queue.addOperations(currenciesOperationWrapper.allOperations, waitUntilFinished: true) | ||
|
||
let currencies = try currenciesOperationWrapper.targetOperation.extractNoCancellableResultData() | ||
let selectedCurrencyId = settingsManager.selectedCurrencyId | ||
let currency = currencies.first(where: { $0.id == selectedCurrencyId }) ?? currencies.min { $0.id < $1.id } | ||
guard let currency = currency else { | ||
throw CurrencyManagerError.currencyListIsEmpty | ||
} | ||
|
||
availableCurrencies = currencies | ||
super.init(state: currency) | ||
sideEffectOnChangeState = { [weak self] in | ||
self?.saveCurrencyInSettings() | ||
} | ||
} | ||
|
||
init( | ||
settingsManager: SettingsManagerProtocol, | ||
availableCurrencies: [Currency], | ||
selectedCurrency: Currency | ||
) { | ||
self.availableCurrencies = availableCurrencies | ||
self.settingsManager = settingsManager | ||
super.init(state: selectedCurrency) | ||
sideEffectOnChangeState = saveCurrencyInSettings | ||
} | ||
|
||
private func saveCurrencyInSettings() { | ||
settingsManager.selectedCurrencyId = selectedCurrency.id | ||
} | ||
} | ||
|
||
// MARK: - Shared instance | ||
|
||
extension CurrencyManager { | ||
static let shared = CurrencyManager() | ||
|
||
private convenience init?() { | ||
try? self.init( | ||
currencyRepository: CurrencyRepository.shared, | ||
settingsManager: SettingsManager.shared, | ||
queue: OperationManagerFacade.sharedDefaultQueue | ||
) | ||
} | ||
} | ||
|
||
// MARK: - Error | ||
|
||
enum CurrencyManagerError: Error { | ||
case currencyListIsEmpty | ||
} |
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,36 @@ | ||
import Foundation | ||
import RobinHood | ||
|
||
protocol CurrencyRepositoryProtocol { | ||
func fetchAvailableCurrenciesWrapper() -> CompoundOperationWrapper<[Currency]> | ||
} | ||
|
||
final class CurrencyRepository: JsonFileRepository<[Currency]> { | ||
static let shared = CurrencyRepository() | ||
|
||
@Atomic(defaultValue: []) | ||
private var currencies: [Currency] | ||
} | ||
|
||
extension CurrencyRepository: CurrencyRepositoryProtocol { | ||
func fetchAvailableCurrenciesWrapper() -> CompoundOperationWrapper<[Currency]> { | ||
guard currencies.isEmpty else { | ||
return CompoundOperationWrapper.createWithResult(currencies) | ||
} | ||
let fetchCurrenciesOperation = fetchOperation( | ||
by: R.file.currenciesJson(), | ||
defaultValue: [] | ||
) | ||
let cacheOperation: BaseOperation<[Currency]> = ClosureOperation { [weak self] in | ||
let currencies = try fetchCurrenciesOperation.extractNoCancellableResultData() | ||
self?.currencies = currencies | ||
return currencies | ||
} | ||
cacheOperation.addDependency(fetchCurrenciesOperation) | ||
|
||
return CompoundOperationWrapper( | ||
targetOperation: cacheOperation, | ||
dependencies: [fetchCurrenciesOperation] | ||
) | ||
} | ||
} |
Oops, something went wrong.