-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
695 additions
and
6 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import UIKit | ||
|
||
extension UIImage { | ||
func invertedImage() -> UIImage? { | ||
guard let cgImage = self.cgImage else { return nil } | ||
let ciImage = CoreImage.CIImage(cgImage: cgImage) | ||
guard let filter = CIFilter(name: "CIColorInvert") else { return nil } | ||
filter.setDefaults() | ||
filter.setValue(ciImage, forKey: kCIInputImageKey) | ||
let context = CIContext(options: nil) | ||
guard let outputImage = filter.outputImage else { return nil } | ||
guard let outputImageCopy = context.createCGImage(outputImage, from: outputImage.extent) else { return nil } | ||
return UIImage(cgImage: outputImageCopy, scale: scale, orientation: .up) | ||
} | ||
} |
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
6 changes: 6 additions & 0 deletions
6
fearless/Modules/MultichainAssetSelection/AssetFetching/MultichainAssetFetching.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 @@ | ||
import Foundation | ||
import SSFModels | ||
|
||
protocol MultichainAssetFetching { | ||
func fetchAssets(for chain: ChainModel) async throws -> [ChainAsset] | ||
} |
8 changes: 8 additions & 0 deletions
8
fearless/Modules/MultichainAssetSelection/AssetFetching/OKXMultichainAssetSelection.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,8 @@ | ||
import Foundation | ||
import SSFModels | ||
|
||
class OKXMultichainAssetFetching: MultichainAssetFetching { | ||
func fetchAssets(for _: ChainModel) async throws -> [ChainAsset] { | ||
[] | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
fearless/Modules/MultichainAssetSelection/ChainSelection/MultichainChainFetching.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,11 @@ | ||
import Foundation | ||
import SSFModels | ||
|
||
enum MultichainChainFetchingFlow { | ||
case okx | ||
case preset(chainIds: [ChainModel.Id]) | ||
} | ||
|
||
protocol MultichainChainFetching { | ||
func fetchChains() async throws -> [ChainModel] | ||
} |
15 changes: 15 additions & 0 deletions
15
fearless/Modules/MultichainAssetSelection/ChainSelection/OKXMultichainChainFetching.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,15 @@ | ||
import Foundation | ||
import SSFModels | ||
import RobinHood | ||
|
||
class OKXMultichainChainFetching: MultichainChainFetching { | ||
private let chainsRepository: AsyncCoreDataRepositoryDefault<ChainModel, CDChain> | ||
|
||
init(chainsRepository: AsyncCoreDataRepositoryDefault<ChainModel, CDChain>) { | ||
self.chainsRepository = chainsRepository | ||
} | ||
|
||
func fetchChains() async throws -> [ChainModel] { | ||
try await chainsRepository.fetchAll().filter { $0.rank != nil } | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
fearless/Modules/MultichainAssetSelection/MultichainAssetSelectionAssembly.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,49 @@ | ||
import UIKit | ||
import SoraFoundation | ||
|
||
final class MultichainAssetSelectionAssembly { | ||
static func configureModule(flow: MultichainChainFetchingFlow, wallet: MetaAccountModel, selectAssetModuleOutput: SelectAssetModuleOutput?) -> MultichainAssetSelectionModuleCreationResult? { | ||
let localizationManager = LocalizationManager.shared | ||
|
||
let interactor = MultichainAssetSelectionInteractor( | ||
chainFetching: buildChainFetching(flow: flow), | ||
assetFetching: buildAssetFetching(flow: flow) | ||
) | ||
let router = MultichainAssetSelectionRouter() | ||
|
||
let presenter = MultichainAssetSelectionPresenter( | ||
interactor: interactor, | ||
router: router, | ||
localizationManager: localizationManager, | ||
viewModelFactory: MultichainAssetSelectionViewModelFactoryImpl(), | ||
logger: Logger.shared, | ||
selectAssetModuleOutput: selectAssetModuleOutput | ||
) | ||
guard let selectAssetModule = createSelectAssetModule(wallet: wallet, moduleOutput: presenter) else { | ||
return nil | ||
} | ||
|
||
presenter.selectAssetModuleInput = selectAssetModule.input | ||
|
||
let view = MultichainAssetSelectionViewController( | ||
output: presenter, | ||
localizationManager: localizationManager, | ||
selectAssetViewController: selectAssetModule.view.controller | ||
) | ||
|
||
return (view, presenter) | ||
} | ||
|
||
private static func buildChainFetching(flow _: MultichainChainFetchingFlow) -> MultichainChainFetching { | ||
let chainsRepository = ChainRepositoryFactory().createAsyncRepository() | ||
return OKXMultichainChainFetching(chainsRepository: chainsRepository) | ||
} | ||
|
||
private static func buildAssetFetching(flow _: MultichainChainFetchingFlow) -> MultichainAssetFetching { | ||
OKXMultichainAssetFetching() | ||
} | ||
|
||
private static func createSelectAssetModule(wallet: MetaAccountModel, moduleOutput: SelectAssetModuleOutput) -> SelectAssetModuleCreationResult? { | ||
SelectAssetAssembly.configureModule(wallet: wallet, selectedAssetId: nil, chainAssets: nil, searchTextsViewModel: .searchAssetPlaceholder, output: moduleOutput, isEmbed: true) | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
fearless/Modules/MultichainAssetSelection/MultichainAssetSelectionInteractor.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,33 @@ | ||
import UIKit | ||
import SSFModels | ||
|
||
protocol MultichainAssetSelectionInteractorOutput: AnyObject {} | ||
|
||
final class MultichainAssetSelectionInteractor { | ||
// MARK: - Private properties | ||
|
||
private weak var output: MultichainAssetSelectionInteractorOutput? | ||
private let chainFetching: MultichainChainFetching | ||
private let assetFetching: MultichainAssetFetching | ||
|
||
init(chainFetching: MultichainChainFetching, assetFetching: MultichainAssetFetching) { | ||
self.chainFetching = chainFetching | ||
self.assetFetching = assetFetching | ||
} | ||
} | ||
|
||
// MARK: - MultichainAssetSelectionInteractorInput | ||
|
||
extension MultichainAssetSelectionInteractor: MultichainAssetSelectionInteractorInput { | ||
func setup(with output: MultichainAssetSelectionInteractorOutput) { | ||
self.output = output | ||
} | ||
|
||
func fetchChains() async throws -> [ChainModel] { | ||
try await chainFetching.fetchChains() | ||
} | ||
|
||
func fetchAssets(for chain: ChainModel) async throws -> [ChainAsset] { | ||
try await assetFetching.fetchAssets(for: chain) | ||
} | ||
} |
114 changes: 114 additions & 0 deletions
114
fearless/Modules/MultichainAssetSelection/MultichainAssetSelectionPresenter.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,114 @@ | ||
import Foundation | ||
import SoraFoundation | ||
import SSFModels | ||
|
||
@MainActor | ||
protocol MultichainAssetSelectionViewInput: ControllerBackedProtocol { | ||
func didReceive(viewModels: [ChainSelectionCollectionCellModel]) | ||
} | ||
|
||
protocol MultichainAssetSelectionInteractorInput: AnyObject { | ||
func setup(with output: MultichainAssetSelectionInteractorOutput) | ||
func fetchChains() async throws -> [ChainModel] | ||
func fetchAssets(for chain: ChainModel) async throws -> [ChainAsset] | ||
} | ||
|
||
final class MultichainAssetSelectionPresenter { | ||
// MARK: Private properties | ||
|
||
private weak var view: MultichainAssetSelectionViewInput? | ||
private let router: MultichainAssetSelectionRouterInput | ||
private let interactor: MultichainAssetSelectionInteractorInput | ||
private let viewModelFactory: MultichainAssetSelectionViewModelFactory | ||
private let logger: LoggerProtocol | ||
private let selectAssetModuleOutput: SelectAssetModuleOutput? | ||
weak var selectAssetModuleInput: SelectAssetModuleInput? | ||
private var selectedChainId: ChainModel.Id? | ||
private var chains: [ChainModel]? | ||
|
||
// MARK: - Constructors | ||
|
||
init( | ||
interactor: MultichainAssetSelectionInteractorInput, | ||
router: MultichainAssetSelectionRouterInput, | ||
localizationManager: LocalizationManagerProtocol, | ||
viewModelFactory: MultichainAssetSelectionViewModelFactory, | ||
logger: LoggerProtocol, | ||
selectAssetModuleOutput: SelectAssetModuleOutput? | ||
) { | ||
self.interactor = interactor | ||
self.router = router | ||
self.viewModelFactory = viewModelFactory | ||
self.logger = logger | ||
self.selectAssetModuleOutput = selectAssetModuleOutput | ||
|
||
self.localizationManager = localizationManager | ||
} | ||
|
||
// MARK: - Private methods | ||
|
||
private func provideViewModel() { | ||
Task { | ||
let viewModels = viewModelFactory.buildViewModels(chains: chains.or([]), selectedChainId: selectedChainId) | ||
await view?.didReceive(viewModels: viewModels) | ||
} | ||
} | ||
|
||
private func fetchChains() { | ||
Task { | ||
do { | ||
let chains = try await interactor.fetchChains() | ||
self.chains = chains | ||
|
||
if selectedChainId == nil { | ||
selectedChainId = chains.first?.chainId | ||
selectAssetModuleInput?.update(with: (chains.first?.chainAssets).or([])) | ||
} | ||
|
||
let viewModels = viewModelFactory.buildViewModels(chains: chains, selectedChainId: selectedChainId) | ||
await view?.didReceive(viewModels: viewModels) | ||
} catch { | ||
logger.customError(error) | ||
} | ||
} | ||
} | ||
} | ||
|
||
// MARK: - MultichainAssetSelectionViewOutput | ||
|
||
extension MultichainAssetSelectionPresenter: MultichainAssetSelectionViewOutput { | ||
func didLoad(view: MultichainAssetSelectionViewInput) { | ||
self.view = view | ||
interactor.setup(with: self) | ||
|
||
fetchChains() | ||
} | ||
|
||
func didSelect(chain: ChainModel) { | ||
selectAssetModuleInput?.update(with: chain.chainAssets) | ||
selectedChainId = chain.chainId | ||
provideViewModel() | ||
} | ||
|
||
func didTapCloseButton() { | ||
router.dismiss(view: view) | ||
} | ||
} | ||
|
||
// MARK: - MultichainAssetSelectionInteractorOutput | ||
|
||
extension MultichainAssetSelectionPresenter: MultichainAssetSelectionInteractorOutput {} | ||
|
||
// MARK: - Localizable | ||
|
||
extension MultichainAssetSelectionPresenter: Localizable { | ||
func applyLocalization() {} | ||
} | ||
|
||
extension MultichainAssetSelectionPresenter: MultichainAssetSelectionModuleInput {} | ||
|
||
extension MultichainAssetSelectionPresenter: SelectAssetModuleOutput { | ||
func assetSelection(didCompleteWith chainAsset: ChainAsset?, contextTag: Int?) { | ||
selectAssetModuleOutput?.assetSelection(didCompleteWith: chainAsset, contextTag: contextTag) | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
fearless/Modules/MultichainAssetSelection/MultichainAssetSelectionProtocols.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,10 @@ | ||
typealias MultichainAssetSelectionModuleCreationResult = ( | ||
view: MultichainAssetSelectionViewInput, | ||
input: MultichainAssetSelectionModuleInput | ||
) | ||
|
||
protocol MultichainAssetSelectionRouterInput: AnyObject, AnyDismissable {} | ||
|
||
protocol MultichainAssetSelectionModuleInput: AnyObject {} | ||
|
||
protocol MultichainAssetSelectionModuleOutput: AnyObject {} |
3 changes: 3 additions & 0 deletions
3
fearless/Modules/MultichainAssetSelection/MultichainAssetSelectionRouter.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,3 @@ | ||
import Foundation | ||
|
||
final class MultichainAssetSelectionRouter: MultichainAssetSelectionRouterInput {} |
Oops, something went wrong.