Skip to content

Commit

Permalink
Merge pull request #388 from nova-wallet/develop
Browse files Browse the repository at this point in the history
v3.6
  • Loading branch information
ERussel authored Sep 6, 2022
2 parents 4848266 + c1a2fed commit cf1386e
Show file tree
Hide file tree
Showing 313 changed files with 7,673 additions and 1,454 deletions.
1 change: 1 addition & 0 deletions .github/workflows/deploy_staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ jobs:
${{ runner.os }}-pods-
- name: Install Cocoapods
if: steps.cache-cocoapods.outputs.cache-hit != 'true'
run: pod install --repo-update

- name: Set env BUILD_PROVISION_PROFILE_BASE64
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
${{ runner.os }}-pods-
- name: Install Cocoapods
# if: steps.cache-cocoapods.outputs.cache-hit != 'true'
if: steps.cache-cocoapods.outputs.cache-hit != 'true'
run: pod install --repo-update

- name: Set Default Scheme
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/push_develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
${{ runner.os }}-pods-
- name: Install Cocoapods
# if: steps.cache-cocoapods.outputs.cache-hit != 'true'
if: steps.cache-cocoapods.outputs.cache-hit != 'true'
run: pod install --repo-update

# Source https://docs.github.com/en/actions/deployment/installing-an-apple-certificate-on-macos-runners-for-xcode-development#add-a-step-to-your-workflow
Expand Down
3 changes: 3 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ excluded:
- R.generated.swift
- novawalletTests
- novawalletIntegrationTests
identifier_name:
excluded:
- id
1 change: 1 addition & 0 deletions Podfile
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
Expand Down
4 changes: 2 additions & 2 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,6 @@ SPEC CHECKSUMS:
TweetNacl: 3abf4d1d2082b0114e7a67410e300892448951e6
xxHash-Swift: 30bd6a7507b3b7348a277c49b1cb6346c2905ec7

PODFILE CHECKSUM: c77a344ca52461c9928594f5bec896982db9f99d
PODFILE CHECKSUM: 025707058333b98cf537c9612cc7b2efc5e099aa

COCOAPODS: 1.11.2
COCOAPODS: 1.11.3
304 changes: 298 additions & 6 deletions novawallet.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions novawallet.xcodeproj/xcshareddata/xcschemes/novawallet.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,15 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldUseLaunchSchemeArgsEnv = "NO"
codeCoverageEnabled = "YES"
onlyGenerateCoverageForSpecifiedTargets = "YES">
<CommandLineArguments>
<CommandLineArgument
argument = "-UNITTEST"
isEnabled = "YES">
</CommandLineArgument>
</CommandLineArguments>
<CodeCoverageTargets>
<BuildableReference
BuildableIdentifier = "primary"
Expand Down Expand Up @@ -88,7 +94,7 @@
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Dev"
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
shouldUseLaunchSchemeArgsEnv = "NO">
<CommandLineArguments>
<CommandLineArgument
argument = "-UNITTEST"
isEnabled = "YES">
</CommandLineArgument>
</CommandLineArguments>
<Testables>
<TestableReference
skipped = "NO">
Expand Down
20 changes: 20 additions & 0 deletions novawallet/Assets.xcassets/colorWhite100.colorset/Contents.json
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 novawallet/Assets.xcassets/colorWhite64.colorset/Contents.json
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 novawallet/Assets.xcassets/iconUsers.imageset/Contents.json
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.
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 not shown.
11 changes: 11 additions & 0 deletions novawallet/Common/Crypto/NoKeysSigningWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ extension Error {
}
}

var isHardwareWalletSigningCancelled: Bool {
guard let hardwareWalletError = self as? HardwareSigningError else {
return false
}

switch hardwareWalletError {
case .signingCancelled:
return true
}
}

var isNotSupportedByParitySigner: Bool {
guard let notSupportedError = self as? NoSigningSupportError else {
return false
Expand Down
24 changes: 24 additions & 0 deletions novawallet/Common/Currency/Atomic.swift
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()
}
}
}
13 changes: 13 additions & 0 deletions novawallet/Common/Currency/Currency+usd.swift
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"
)
}
28 changes: 28 additions & 0 deletions novawallet/Common/Currency/Currency.swift
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
}
}
91 changes: 91 additions & 0 deletions novawallet/Common/Currency/CurrencyManager.swift
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
}
36 changes: 36 additions & 0 deletions novawallet/Common/Currency/CurrencyRepository.swift
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]
)
}
}
Loading

0 comments on commit cf1386e

Please sign in to comment.