Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .swiftpm/xcode/xcshareddata/xcschemes/Modules-Package.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,20 @@
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "SSFPrices"
BuildableName = "SSFPrices"
BlueprintName = "SSFPrices"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
Expand Down
61 changes: 53 additions & 8 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ let package = Package(
.library(name: "SSFBalances", targets: ["SSFBalances"]),
.library(name: "SSFBalancesStorage", targets: ["SSFBalancesStorage"]),
.library(name: "SSFSubstrateBalances", targets: ["SSFSubstrateBalances"]),
.library(name: "SSFTransactionHistory", targets: ["SSFTransactionHistory"])
.library(name: "SSFTransactionHistory", targets: ["SSFTransactionHistory"]),
.library(name: "SSFPrices", targets: ["SSFPrices"]),
.library(name: "SSFChainlinkProvider", targets: ["SSFChainlinkProvider"]),
.library(name: "SSFCoingeckoProvider", targets: ["SSFCoingeckoProvider"]),
.library(name: "SSFSoraSubqueryProvider", targets: ["SSFSoraSubqueryProvider"]),
],
dependencies: [
.package(url: "https://github.com/Boilertalk/secp256k1.swift.git", from: "0.1.7"),
Expand All @@ -63,7 +67,7 @@ let package = Package(
.package(url: "https://github.com/daisuke-t-jp/xxHash-Swift", from: "1.1.1"),
.package(url: "https://github.com/SwiftyBeaver/SwiftyBeaver.git", .upToNextMajor(from: "2.0.0")),
.package(url: "https://github.com/nicklockwood/SwiftFormat", from: "0.50.4"),
.package(url: "https://github.com/soramitsu/web3-swift", exact: "7.7.7")
.package(url: "https://github.com/bnsports/Web3.swift.git", exact: "7.7.7")
],
targets: [
.binaryTarget(name: "blake2lib", path: "Binaries/blake2lib.xcframework"),
Expand Down Expand Up @@ -149,7 +153,7 @@ let package = Package(
.target(
name: "SSFChainConnection",
dependencies: [
.product(name: "Web3", package: "web3-swift"),
.product(name: "Web3", package: "Web3.swift"),
"SSFUtils"
]
),
Expand Down Expand Up @@ -336,7 +340,7 @@ let package = Package(
.target(
name: "SSFChainRegistry",
dependencies: [
.product(name: "Web3", package: "web3-swift"),
.product(name: "Web3", package: "Web3.swift"),
"SSFUtils",
"RobinHood",
"SSFModels",
Expand Down Expand Up @@ -394,6 +398,47 @@ let package = Package(
"SSFPools"
]
),
.target(
name: "SSFPrices",
dependencies: [
"SSFModels",
"RobinHood",
"SSFAssetManagment"
]
),
.target(
name: "SSFChainlinkProvider",
dependencies: [
.product(name: "Web3", package: "Web3.swift"),
.product(name: "Web3ContractABI", package: "Web3.swift"),
"SSFPrices",
"SSFModels",
"RobinHood",
"SSFUtils",
"SSFNetwork",
"SSFChainRegistry",
]
),
.target(
name: "SSFCoingeckoProvider",
dependencies: [
"SSFPrices",
"SSFModels",
"RobinHood",
"SSFUtils",
]
),
.target(
name: "SSFSoraSubqueryProvider",
dependencies: [
"SSFPrices",
"SSFModels",
"RobinHood",
"SSFUtils",
"SSFIndexers",
"SSFNetwork"
]
),

//Tests targets
.testTarget(
Expand All @@ -411,8 +456,8 @@ let package = Package(
dependencies: ["SSFSingleValueCache"]
),
.target(name: "SSFTransferService", dependencies: [
.product(name: "Web3", package: "web3-swift"),
.product(name: "Web3ContractABI", package: "web3-swift"),
.product(name: "Web3", package: "Web3.swift"),
.product(name: "Web3ContractABI", package: "Web3.swift"),
"SSFModels",
"BigInt",
"SSFUtils",
Expand All @@ -425,8 +470,8 @@ let package = Package(
.testTarget(
name: "SSFTransferServiceTests",
dependencies: [
.product(name: "Web3", package: "web3-swift"),
.product(name: "Web3ContractABI", package: "web3-swift"),
.product(name: "Web3", package: "Web3.swift"),
.product(name: "Web3ContractABI", package: "Web3.swift"),
"SSFTransferService",
"SSFModels",
"BigInt",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public enum DataProviderChange<T> {

/// Returns item if bounded as associated value.

var item: T? {
public var item: T? {
switch self {
case let .insert(newItem):
return newItem
Expand All @@ -46,6 +46,41 @@ public enum DataProviderChange<T> {
}
}

enum DataProviderDiff<T> {
/// New items has been added.
/// Item is passed as associated value.
case insert(newItem: T)

/// Existing item has been updated
/// Item is passed as associated value.
case update(newItem: T)

/// New remote items.
case remote(newItem: T)

/// Existing local item
case local(newItem: T)

/// Existing item has been removed.
/// Identifier of the item is passed as associated value.
case delete(deletedIdentifier: String)

var item: T? {
switch self {
case let .remote(newItem):
return newItem
case let .local(newItem):
return nil
case .delete:
return nil
case let .insert(newItem):
return newItem
case let .update(newItem):
return newItem
}
}
}

/**
* Struct designed to store options needed to describe how an observer should be handled by data provider.
*/
Expand All @@ -65,6 +100,12 @@ public struct DataProviderObserverOptions {
/// mechanism.
public var waitsInProgressSyncOnAdd: Bool

/// Asks data provider to notify observer if no difference from remote.
/// If this value is `false` (default value) then observer is only notified when
/// there are difference from remote source.
/// if this value is `true` and no diff observer will notify with local source values
public var notifyIfNoDiff: Bool

/// - parameters:
/// - alwaysNotifyOnRefresh: Asks data provider to notify observer in any case after
/// synchronization completes.
Expand All @@ -80,10 +121,12 @@ public struct DataProviderObserverOptions {

public init(
alwaysNotifyOnRefresh: Bool = false,
waitsInProgressSyncOnAdd: Bool = true
waitsInProgressSyncOnAdd: Bool = true,
notifyIfNoDiff: Bool = false
) {
self.alwaysNotifyOnRefresh = alwaysNotifyOnRefresh
self.waitsInProgressSyncOnAdd = waitsInProgressSyncOnAdd
self.notifyIfNoDiff = notifyIfNoDiff
}
}

Expand Down Expand Up @@ -117,6 +160,10 @@ public struct StreamableProviderObserverOptions {
/// By default ```true```.
public var refreshWhenEmpty: Bool

/// Will notify just when local repository was updated.
/// By default ```false```.
public var notifyJustWhenUpdated: Bool

/// - parameters:
/// - alwaysNotifyOnRefresh: Asks data provider to notify observer in any case
/// after synchronization completes.
Expand All @@ -143,12 +190,14 @@ public struct StreamableProviderObserverOptions {
alwaysNotifyOnRefresh: Bool = false,
waitsInProgressSyncOnAdd: Bool = true,
initialSize: Int = 0,
refreshWhenEmpty: Bool = true
refreshWhenEmpty: Bool = true,
notifyJustWhenUpdated: Bool = false
) {
self.alwaysNotifyOnRefresh = alwaysNotifyOnRefresh
self.waitsInProgressSyncOnAdd = waitsInProgressSyncOnAdd
self.initialSize = initialSize
self.refreshWhenEmpty = refreshWhenEmpty
self.notifyJustWhenUpdated = notifyJustWhenUpdated
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ public final class ListDifferenceCalculator<T: Identifiable>: ListDifferenceCalc
switch change {
case let .insert(newItem):
insertItems[newItem.identifier] = newItem

case let .update(newItem):
if let oldItemIndex = allItems
.firstIndex(where: { $0.identifier == newItem.identifier })
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import Foundation

public class AnySingleValueProvider<T>: SingleValueProviderProtocol {
public typealias Model = T

private let fetchClosure: (((Result<T?, Error>?) -> Void)?) -> CompoundOperationWrapper<T?>

private let addObserverClosure: (
AnyObject,
DispatchQueue?,
@escaping ([DataProviderChange<T>]) -> Void,
@escaping (Error) -> Void,
DataProviderObserverOptions
) -> Void

private let removeObserverClosure: (AnyObject) -> Void

private let refreshClosure: () -> Void

public var executionQueue: OperationQueue

public init<U: SingleValueProviderProtocol>(_ dataProvider: U) where U.Model == Model {
fetchClosure = dataProvider.fetch(with:)
addObserverClosure = dataProvider.addObserver
removeObserverClosure = dataProvider.removeObserver
refreshClosure = dataProvider.refresh
executionQueue = dataProvider.executionQueue
}

public func fetch(with completionBlock: ((Result<T?, Error>?) -> Void)?)
-> CompoundOperationWrapper<T?>
{
fetchClosure(completionBlock)
}

public func addObserver(
_ observer: AnyObject,
deliverOn queue: DispatchQueue?,
executing updateBlock: @escaping ([DataProviderChange<Model>]) -> Void,
failing failureBlock: @escaping (Error) -> Void,
options: DataProviderObserverOptions
) {
addObserverClosure(observer, queue, updateBlock, failureBlock, options)
}

public func removeObserver(_ observer: AnyObject) {
removeObserverClosure(observer)
}

public func refresh() {
refreshClosure()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public final class AccountImportService {

case let .failure(error):
continuation.resume(throwing: error)

case .none:
let error = BaseOperationError.parentOperationCancelled
continuation.resume(throwing: error)
Expand Down Expand Up @@ -124,6 +125,7 @@ extension AccountImportService: AccountCreatable {

case let .failure(error):
continuation.resume(throwing: error)

case .none:
let error = BaseOperationError.parentOperationCancelled
continuation.resume(throwing: error)
Expand Down Expand Up @@ -195,6 +197,7 @@ extension AccountImportService: AccountImportable {

case let .failure(error):
continuation.resume(throwing: error)

case .none:
let error = BaseOperationError.parentOperationCancelled
continuation.resume(throwing: error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,19 @@ private extension ChainAssetsFetchingService {

func sortByPrice(chainAssets: [ChainAsset], order: AssetSortOrder) -> [ChainAsset] {
chainAssets.sorted {
let firstPriceDataSorted = $0.asset.priceData
.sorted { $0.currencyId < $1.currencyId }
let firstPriceString = firstPriceDataSorted.first?.price ?? ""
let firstPrice = Decimal(string: firstPriceString)
let secondPriceDataSorted = $1.asset.priceData
.sorted { $0.currencyId < $1.currencyId }
let secondPriceString = secondPriceDataSorted.first?.price ?? ""
let secondPrice = Decimal(string: secondPriceString)
switch order {
case .ascending:
return $0.asset.price ?? 0 < $1.asset.price ?? 0
return firstPrice ?? 0 < secondPrice ?? 0
case .descending:
return $0.asset.price ?? 0 > $1.asset.price ?? 0
return secondPrice ?? 0 > firstPrice ?? 0
}
}
}
Expand Down
Loading