[Refactor] Replace TokensCardCollectionCoordinator with TokensCardCoordinator #4493

pull/4494/head
Krypto Pank 3 years ago
parent 42f1f184e0
commit 4c0d0177f3
  1. 4
      AlphaWallet.xcodeproj/project.pbxproj
  2. 2
      AlphaWallet/ActiveWalletCoordinator.swift
  3. 3
      AlphaWallet/Sell/ViewControllers/EnterSellTokensCardPriceQuantityViewController.swift
  4. 3
      AlphaWallet/Sell/ViewControllers/SetSellTokensCardExpiryDateViewController.swift
  5. 295
      AlphaWallet/Tokens/Collectibles/Coordinators/TokensCardCollectionCoordinator.swift
  6. 164
      AlphaWallet/Tokens/Collectibles/Coordinators/TokensCardCoordinator.swift
  7. 1
      AlphaWallet/Tokens/Collectibles/ViewControllers/NFTAssetListViewController.swift
  8. 53
      AlphaWallet/Tokens/Coordinators/SingleChainTokenCoordinator.swift

@ -918,7 +918,6 @@
879E1E42264BFB9B006CD362 /* TokenHistoryPeriodSelectorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 879E1E41264BFB9B006CD362 /* TokenHistoryPeriodSelectorView.swift */; };
879E1E44264C0717006CD362 /* TickerFieldValueView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 879E1E43264C0717006CD362 /* TickerFieldValueView.swift */; };
879E1E46264C072D006CD362 /* TokenInfoHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 879E1E45264C072D006CD362 /* TokenInfoHeaderView.swift */; };
879F184026E73B79000602F2 /* TokensCardCollectionCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 879F183F26E73B79000602F2 /* TokensCardCollectionCoordinator.swift */; };
879F184226E73BCF000602F2 /* SelectableNFTAssetContainerTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 879F184126E73BCF000602F2 /* SelectableNFTAssetContainerTableViewCell.swift */; };
879F184426E73BFF000602F2 /* SingleNFTAssetSelectionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 879F184326E73BFF000602F2 /* SingleNFTAssetSelectionView.swift */; };
879F184626E73CAA000602F2 /* NFTAssetListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 879F184526E73CAA000602F2 /* NFTAssetListViewController.swift */; };
@ -2061,7 +2060,6 @@
879E1E41264BFB9B006CD362 /* TokenHistoryPeriodSelectorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TokenHistoryPeriodSelectorView.swift; sourceTree = "<group>"; };
879E1E43264C0717006CD362 /* TickerFieldValueView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TickerFieldValueView.swift; sourceTree = "<group>"; };
879E1E45264C072D006CD362 /* TokenInfoHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TokenInfoHeaderView.swift; sourceTree = "<group>"; };
879F183F26E73B79000602F2 /* TokensCardCollectionCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TokensCardCollectionCoordinator.swift; sourceTree = "<group>"; };
879F184126E73BCF000602F2 /* SelectableNFTAssetContainerTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectableNFTAssetContainerTableViewCell.swift; sourceTree = "<group>"; };
879F184326E73BFF000602F2 /* SingleNFTAssetSelectionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingleNFTAssetSelectionView.swift; sourceTree = "<group>"; };
879F184526E73CAA000602F2 /* NFTAssetListViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NFTAssetListViewController.swift; sourceTree = "<group>"; };
@ -4958,7 +4956,6 @@
isa = PBXGroup;
children = (
442FCC8150042FE9179D574A /* TokensCardCoordinator.swift */,
879F183F26E73B79000602F2 /* TokensCardCollectionCoordinator.swift */,
8739BBD326CD2A820045CFED /* NFTAssetSelectionCoordinator.swift */,
);
path = Coordinators;
@ -6595,7 +6592,6 @@
87442BD827D615B500EA2209 /* CheckTransactionStateViewController.swift in Sources */,
5E7C7A67B6143DFB9B1CF02B /* ConfirmSignMessageTableViewCell.swift in Sources */,
5E7C74C6110D4E93C759D5DB /* ConfirmSignMessageTableViewCellViewModel.swift in Sources */,
879F184026E73B79000602F2 /* TokensCardCollectionCoordinator.swift in Sources */,
5E7C7A928412AF3E16CDA038 /* AmountTextField.swift in Sources */,
5E7C7131E338A806132D989B /* DateEntryField.swift in Sources */,
5E7C7E7AEF01B9D170228342 /* TimeEntryField.swift in Sources */,

@ -855,7 +855,7 @@ extension ActiveWalletCoordinator: TokensCoordinatorDelegate {
extension ActiveWalletCoordinator: PaymentCoordinatorDelegate {
func didSelectTokenHolder(tokenHolder: TokenHolder, in coordinator: PaymentCoordinator) {
guard let coordinator = coordinatorOfType(type: TokensCardCollectionCoordinator.self) else { return }
guard let coordinator = coordinatorOfType(type: TokensCardCoordinator.self) else { return }
coordinator.showNFTAsset(tokenHolder: tokenHolder, mode: .preview)
}

@ -11,7 +11,6 @@ protocol EnterSellTokensCardPriceQuantityViewControllerDelegate: class, CanOpenU
class EnterSellTokensCardPriceQuantityViewController: UIViewController, TokenVerifiableStatusViewController {
private let analyticsCoordinator: AnalyticsCoordinator
private let storage: TokensDataStore
private let roundedBackground = RoundedBackground()
private let scrollView = UIScrollView()
private let header = TokensCardViewControllerTitleHeader()
@ -60,7 +59,6 @@ class EnterSellTokensCardPriceQuantityViewController: UIViewController, TokenVer
// swiftlint:disable function_body_length
init(
analyticsCoordinator: AnalyticsCoordinator,
storage: TokensDataStore,
paymentFlow: PaymentFlow,
viewModel: EnterSellTokensCardPriceQuantityViewControllerViewModel,
assetDefinitionStore: AssetDefinitionStore,
@ -68,7 +66,6 @@ class EnterSellTokensCardPriceQuantityViewController: UIViewController, TokenVer
keystore: Keystore
) {
self.analyticsCoordinator = analyticsCoordinator
self.storage = storage
self.paymentFlow = paymentFlow
self.walletSession = walletSession
self.viewModel = viewModel

@ -9,7 +9,6 @@ protocol SetSellTokensCardExpiryDateViewControllerDelegate: class, CanOpenURL {
class SetSellTokensCardExpiryDateViewController: UIViewController, TokenVerifiableStatusViewController {
private let analyticsCoordinator: AnalyticsCoordinator
private let storage: TokensDataStore
private let roundedBackground = RoundedBackground()
private let scrollView = UIScrollView()
private let header = TokensCardViewControllerTitleHeader()
@ -56,7 +55,6 @@ class SetSellTokensCardExpiryDateViewController: UIViewController, TokenVerifiab
// swiftlint:disable function_body_length
init(
analyticsCoordinator: AnalyticsCoordinator,
storage: TokensDataStore,
paymentFlow: PaymentFlow,
tokenHolder: TokenHolder,
ethCost: Ether,
@ -66,7 +64,6 @@ class SetSellTokensCardExpiryDateViewController: UIViewController, TokenVerifiab
session: WalletSession
) {
self.analyticsCoordinator = analyticsCoordinator
self.storage = storage
self.paymentFlow = paymentFlow
self.tokenHolder = tokenHolder
self.ethCost = ethCost

@ -1,295 +0,0 @@
//
// TokensCardCollectionCoordinator.swift
// AlphaWallet
//
// Created by Vladyslav Shepitko on 07.09.2021.
//
import Foundation
import UIKit
import SafariServices
import MessageUI
import BigInt
import Combine
protocol TokensCardCollectionCoordinatorDelegate: class, CanOpenURL {
func didTap(for type: PaymentFlow, in coordinator: TokensCardCollectionCoordinator, viewController: UIViewController)
func didTap(transaction: TransactionInstance, in coordinator: TokensCardCollectionCoordinator)
func didTap(activity: Activity, in coordinator: TokensCardCollectionCoordinator)
func didClose(in coordinator: TokensCardCollectionCoordinator)
}
class TokensCardCollectionCoordinator: NSObject, Coordinator {
private let keystore: Keystore
private let token: TokenObject
private (set) lazy var rootViewController: NFTCollectionViewController = {
return makeTokensCardCollectionViewController()
}()
private let session: WalletSession
private let tokensStorage: TokensDataStore
private let assetDefinitionStore: AssetDefinitionStore
private let eventsDataStore: NonActivityEventsDataStore
private (set) var analyticsCoordinator: AnalyticsCoordinator
private let activitiesService: ActivitiesServiceType
weak var delegate: TokensCardCollectionCoordinatorDelegate?
let navigationController: UINavigationController
var coordinators: [Coordinator] = []
private let paymantFlow: PaymentFlow
private var cancelable = Set<AnyCancellable>()
init(
session: WalletSession,
navigationController: UINavigationController,
keystore: Keystore,
tokensStorage: TokensDataStore,
token: TokenObject,
assetDefinitionStore: AssetDefinitionStore,
eventsDataStore: NonActivityEventsDataStore,
analyticsCoordinator: AnalyticsCoordinator,
activitiesService: ActivitiesServiceType,
paymantFlow: PaymentFlow
) {
self.paymantFlow = paymantFlow
self.session = session
self.keystore = keystore
self.navigationController = navigationController
self.tokensStorage = tokensStorage
self.token = token
self.assetDefinitionStore = assetDefinitionStore
self.eventsDataStore = eventsDataStore
self.analyticsCoordinator = analyticsCoordinator
self.activitiesService = activitiesService
navigationController.navigationBar.isTranslucent = false
}
func start() {
let viewModel = NFTCollectionViewModel(token: token, forWallet: session.account, assetDefinitionStore: assetDefinitionStore, eventsDataStore: eventsDataStore)
rootViewController.configure(viewModel: viewModel)
navigationController.pushViewController(rootViewController, animated: true)
refreshUponEthereumEventChanges()
}
private func refreshUponEthereumEventChanges() {
eventsDataStore
.recentEvents(forTokenContract: token.contractAddress)
.receive(on: DispatchQueue.main)
.sink(receiveValue: { [weak self] _ in
self?.refreshScreen()
}).store(in: &cancelable)
assetDefinitionStore.assetsSignatureOrBodyChange(for: token.contractAddress)
.receive(on: DispatchQueue.main)
.sink(receiveValue: { [weak self] _ in
self?.refreshScreen()
}).store(in: &cancelable)
}
private func refreshScreen() {
for each in navigationController.viewControllers {
switch each {
case let vc as NFTCollectionViewController:
let viewModel = NFTCollectionViewModel(token: token, forWallet: session.account, assetDefinitionStore: assetDefinitionStore, eventsDataStore: eventsDataStore)
vc.configure(viewModel: viewModel)
case let vc as NFTAssetViewController:
let updatedTokenHolders = token.getTokenHolders(assetDefinitionStore: assetDefinitionStore, eventsDataStore: eventsDataStore, forWallet: session.account)
if let selection = vc.viewModel.isMatchingTokenHolder(fromTokenHolders: updatedTokenHolders) {
let viewModel: NFTAssetViewModel = .init(account: session.account, tokenId: selection.tokenId, token: token, tokenHolder: selection.tokenHolder, assetDefinitionStore: assetDefinitionStore)
vc.configure(viewModel: viewModel)
}
default:
break
}
}
}
private func makeTokensCardCollectionViewController() -> NFTCollectionViewController {
let viewModel = NFTCollectionViewModel(token: token, forWallet: session.account, assetDefinitionStore: assetDefinitionStore, eventsDataStore: eventsDataStore)
let activitiesFilterStrategy: ActivitiesFilterStrategy = .operationTypes(operationTypes: [.erc1155TokenTransfer], contract: token.contractAddress)
let activitiesService = self.activitiesService.copy(activitiesFilterStrategy: activitiesFilterStrategy, transactionsFilterStrategy: TransactionDataStore.functional.transactionsFilter(for: activitiesFilterStrategy, tokenObject: token))
let controller = NFTCollectionViewController(keystore: keystore, session: session, assetDefinition: assetDefinitionStore, analyticsCoordinator: analyticsCoordinator, viewModel: viewModel, activitiesService: activitiesService, eventsDataStore: eventsDataStore)
controller.hidesBottomBarWhenPushed = true
controller.delegate = self
controller.navigationItem.leftBarButtonItem = .backBarButton(self, selector: #selector(didCloseSelected))
return controller
}
@objc private func didCloseSelected(_ sender: UIBarButtonItem) {
navigationController.popViewController(animated: true)
delegate?.didClose(in: self)
}
func stop() {
session.stop()
}
private func showNFTAssetViewController(tokenHolder: TokenHolder, tokenId: TokenId, mode: TokenInstanceViewMode) -> NFTAssetViewController {
let viewModel = NFTAssetViewModel(account: session.account, tokenId: tokenHolder.tokenId, token: token, tokenHolder: tokenHolder, assetDefinitionStore: assetDefinitionStore)
let vc = NFTAssetViewController(analyticsCoordinator: analyticsCoordinator, assetDefinitionStore: assetDefinitionStore, viewModel: viewModel, mode: .interactive)
vc.delegate = self
vc.navigationItem.largeTitleDisplayMode = .never
vc.navigationItem.leftBarButtonItem = .backBarButton(self, selector: #selector(tokenInstanceViewControllerDidCloseSelected))
return vc
}
@objc private func tokenInstanceViewControllerDidCloseSelected(_ sender: UIBarButtonItem) {
navigationController.popViewController(animated: true)
}
}
extension TokensCardCollectionCoordinator: NFTCollectionViewControllerDelegate {
func didCancel(in viewController: NFTCollectionViewController) {
delegate?.didClose(in: self)
}
private func showTokenInstanceActionView(forAction action: TokenInstanceAction, tokenHolder: TokenHolder, viewController: UIViewController) {
delegate?.didTap(for: .send(type: .tokenScript(action: action, tokenObject: token, tokenHolder: tokenHolder)), in: self, viewController: viewController)
}
func didSelectTokenHolder(in viewController: NFTCollectionViewController, didSelectTokenHolder tokenHolder: TokenHolder) {
switch tokenHolder.type {
case .collectible:
let viewModel = NFTAssetListViewModel(tokenHolder: tokenHolder)
let viewController = NFTAssetListViewController(viewModel: viewModel, tokenObject: token, assetDefinitionStore: assetDefinitionStore, analyticsCoordinator: analyticsCoordinator, server: session.server)
viewController.delegate = self
navigationController.pushViewController(viewController, animated: true)
case .single:
showNFTAsset(tokenHolder: tokenHolder)
}
}
func didTap(transaction: TransactionInstance, in viewController: NFTCollectionViewController) {
delegate?.didTap(transaction: transaction, in: self)
}
func didTap(activity: Activity, in viewController: NFTCollectionViewController) {
delegate?.didTap(activity: activity, in: self)
}
func didSelectAssetSelection(in viewController: NFTCollectionViewController) {
showTokenCardSelection(tokenHolders: viewController.viewModel.tokenHolders)
}
private func showTokenCardSelection(tokenHolders: [TokenHolder]) {
let coordinator = NFTAssetSelectionCoordinator(navigationController: navigationController, tokenObject: token, tokenHolders: tokenHolders, assetDefinitionStore: assetDefinitionStore, analyticsCoordinator: analyticsCoordinator, server: session.server)
addCoordinator(coordinator)
coordinator.delegate = self
coordinator.start()
}
func showNFTAsset(tokenHolder: TokenHolder, mode: TokenInstanceViewMode = .interactive) {
let viewController = showNFTAssetViewController(tokenHolder: tokenHolder, tokenId: tokenHolder.tokenId, mode: mode)
viewController.navigationItem.leftBarButtonItem = .backBarButton(self, selector: #selector(didCloseTokenInstanceSelected))
navigationController.pushViewController(viewController, animated: true)
}
@objc private func didCloseTokenInstanceSelected(_ sender: UIBarButtonItem) {
navigationController.popViewController(animated: true)
}
private func showViewRedemptionInfo(in viewController: UIViewController) {
let controller = TokenCardRedemptionInfoViewController(delegate: self)
controller.navigationItem.largeTitleDisplayMode = .never
viewController.navigationController?.pushViewController(controller, animated: true)
}
}
extension TokensCardCollectionCoordinator: TokenCardRedemptionViewControllerDelegate {
}
extension TokensCardCollectionCoordinator: StaticHTMLViewControllerDelegate {
}
extension TokensCardCollectionCoordinator: NFTAssetListViewControllerDelegate {
func selectTokenCardsSelected(in viewController: NFTAssetListViewController) {
showTokenCardSelection(tokenHolders: [viewController.tokenHolder])
}
func didSelectTokenCard(in viewController: NFTAssetListViewController, tokenId: TokenId) {
let viewController = showNFTAssetViewController(tokenHolder: viewController.tokenHolder, tokenId: tokenId, mode: .interactive)
navigationController.pushViewController(viewController, animated: true)
}
}
extension TokensCardCollectionCoordinator: NFTAssetSelectionCoordinatorDelegate {
func didTapSend(in coordinator: NFTAssetSelectionCoordinator, tokenObject: TokenObject, tokenHolders: [TokenHolder]) {
removeCoordinator(coordinator)
let filteredTokenHolders = tokenHolders.filter { $0.totalSelectedCount > 0 }
guard let vc = navigationController.visibleViewController else { return }
let transactionType: TransactionType = .erc1155Token(tokenObject, transferType: .singleTransfer, tokenHolders: filteredTokenHolders)
delegate?.didTap(for: .send(type: .transaction(transactionType)), in: self, viewController: vc)
}
func didFinish(in coordinator: NFTAssetSelectionCoordinator) {
removeCoordinator(coordinator)
}
}
extension TokensCardCollectionCoordinator: NonFungibleTokenViewControllerDelegate {
func didPressViewRedemptionInfo(in viewController: NFTAssetViewController) {
showViewRedemptionInfo(in: viewController)
}
func didPressRedeem(token: TokenObject, tokenHolder: TokenHolder, in viewController: NFTAssetViewController) {
//no-op
}
func didPressSell(tokenHolder: TokenHolder, for paymentFlow: PaymentFlow, in viewController: NFTAssetViewController) {
//no-op
}
func didPressTransfer(token: TokenObject, tokenHolder: TokenHolder, forPaymentFlow paymentFlow: PaymentFlow, in viewController: NFTAssetViewController) {
let transactionType: TransactionType = .erc1155Token(token, transferType: .singleTransfer, tokenHolders: [tokenHolder])
delegate?.didTap(for: .send(type: .transaction(transactionType)), in: self, viewController: viewController)
}
func didTapURL(url: URL, in viewController: NFTAssetViewController) {
let controller = SFSafariViewController(url: url)
// Don't attempt to change tint colors for SFSafariViewController. It doesn't well correctly especially because the controller sets more than 1 color for the title
controller.makePresentationFullScreenForiOS13Migration()
viewController.present(controller, animated: true)
}
func didTap(action: TokenInstanceAction, tokenHolder: TokenHolder, viewController: NFTAssetViewController) {
showTokenInstanceActionView(forAction: action, tokenHolder: tokenHolder, viewController: viewController)
}
}
extension TokensCardCollectionCoordinator: CanOpenURL {
func didPressViewContractWebPage(forContract contract: AlphaWallet.Address, server: RPCServer, in viewController: UIViewController) {
delegate?.didPressViewContractWebPage(forContract: contract, server: server, in: viewController)
}
func didPressViewContractWebPage(_ url: URL, in viewController: UIViewController) {
delegate?.didPressViewContractWebPage(url, in: viewController)
}
func didPressOpenWebPage(_ url: URL, in viewController: UIViewController) {
delegate?.didPressOpenWebPage(url, in: viewController)
}
}
extension Collection where Element == TokenHolder {
var valuesAll: [TokenId: [AttributeId: AssetAttributeSyntaxValue]] {
var valuesAll: [TokenId: [AttributeId: AssetAttributeSyntaxValue]] = [:]
for each in self {
valuesAll.merge(each.valuesAll) { (current, _) in current }
}
return valuesAll
}
}
extension Collection where Element == UnconfirmedTransaction.TokenIdAndValue {
var erc1155TokenTransactionType: Erc1155TokenTransactionType {
return count > 1 ? .batchTransfer : .singleTransfer
}
}

@ -24,14 +24,16 @@ class TokensCardCoordinator: NSObject, Coordinator {
private let token: TokenObject
lazy var rootViewController: NFTCollectionViewController = {
let viewModel = NFTCollectionViewModel(token: token, forWallet: session.account, assetDefinitionStore: assetDefinitionStore, eventsDataStore: eventsDataStore)
return makeTokensCardViewController(with: session.account, viewModel: viewModel)
let controller = NFTCollectionViewController(keystore: keystore, session: session, assetDefinition: assetDefinitionStore, analyticsCoordinator: analyticsCoordinator, viewModel: viewModel, activitiesService: activitiesService, eventsDataStore: eventsDataStore)
controller.hidesBottomBarWhenPushed = true
controller.delegate = self
return controller
}()
private let session: WalletSession
private let tokensDataStore: TokensDataStore
private let assetDefinitionStore: AssetDefinitionStore
private let eventsDataStore: NonActivityEventsDataStore
private weak var transferTokensViewController: TransferTokensCardViaWalletAddressViewController?
private let analyticsCoordinator: AnalyticsCoordinator
private let activitiesService: ActivitiesServiceType
weak var delegate: TokensCardCoordinatorDelegate?
@ -43,7 +45,6 @@ class TokensCardCoordinator: NSObject, Coordinator {
session: WalletSession,
navigationController: UINavigationController,
keystore: Keystore,
tokensStorage: TokensDataStore,
token: TokenObject,
assetDefinitionStore: AssetDefinitionStore,
eventsDataStore: NonActivityEventsDataStore,
@ -54,7 +55,6 @@ class TokensCardCoordinator: NSObject, Coordinator {
self.session = session
self.keystore = keystore
self.navigationController = navigationController
self.tokensDataStore = tokensStorage
self.token = token
self.assetDefinitionStore = assetDefinitionStore
self.eventsDataStore = eventsDataStore
@ -64,12 +64,12 @@ class TokensCardCoordinator: NSObject, Coordinator {
func start() {
rootViewController.configure()
rootViewController.navigationItem.leftBarButtonItem = .backBarButton(self, selector: #selector(closeButtonSelected))
rootViewController.navigationItem.leftBarButtonItem = .backBarButton(self, selector: #selector(closeDidSelect))
navigationController.pushViewController(rootViewController, animated: true)
refreshUponEthereumEventChanges()
}
@objc private func closeButtonSelected(_ sender: UIBarButtonItem) {
@objc private func closeDidSelect(_ sender: UIBarButtonItem) {
navigationController.popViewController(animated: true)
delegate?.didCancel(in: self)
}
@ -102,7 +102,7 @@ class TokensCardCoordinator: NSObject, Coordinator {
if let tokenHolder = tokenHolder {
let viewModel = NFTAssetViewModel(account: session.account, tokenId: tokenHolder.tokenId, token: token, tokenHolder: tokenHolder, assetDefinitionStore: assetDefinitionStore)
vc.configure(viewModel: viewModel)
}
}
case let vc as TokenInstanceActionViewController:
//TODO it reloads, but doesn't live-reload the changes because the action contains the HTML and it doesn't change
vc.configure()
@ -112,14 +112,6 @@ class TokensCardCoordinator: NSObject, Coordinator {
}
}
private func makeTokensCardViewController(with account: Wallet, viewModel: NFTCollectionViewModel) -> NFTCollectionViewController {
let controller = NFTCollectionViewController(keystore: keystore, session: session, assetDefinition: assetDefinitionStore, analyticsCoordinator: analyticsCoordinator, viewModel: viewModel, activitiesService: activitiesService, eventsDataStore: eventsDataStore)
controller.hidesBottomBarWhenPushed = true
controller.delegate = self
return controller
}
func stop() {
session.stop()
}
@ -230,7 +222,7 @@ class TokensCardCoordinator: NSObject, Coordinator {
private func makeEnterSellTokensCardPriceQuantityViewController(token: TokenObject, for tokenHolder: TokenHolder, paymentFlow: PaymentFlow) -> EnterSellTokensCardPriceQuantityViewController {
let viewModel = EnterSellTokensCardPriceQuantityViewControllerViewModel(token: token, tokenHolder: tokenHolder, server: session.server, assetDefinitionStore: assetDefinitionStore)
let controller = EnterSellTokensCardPriceQuantityViewController(analyticsCoordinator: analyticsCoordinator, storage: tokensDataStore, paymentFlow: paymentFlow, viewModel: viewModel, assetDefinitionStore: assetDefinitionStore, walletSession: session, keystore: keystore)
let controller = EnterSellTokensCardPriceQuantityViewController(analyticsCoordinator: analyticsCoordinator, paymentFlow: paymentFlow, viewModel: viewModel, assetDefinitionStore: assetDefinitionStore, walletSession: session, keystore: keystore)
controller.configure()
controller.delegate = self
return controller
@ -246,7 +238,7 @@ class TokensCardCoordinator: NSObject, Coordinator {
private func makeEnterSellTokensCardExpiryDateViewController(token: TokenObject, for tokenHolder: TokenHolder, ethCost: Ether, paymentFlow: PaymentFlow) -> SetSellTokensCardExpiryDateViewController {
let viewModel = SetSellTokensCardExpiryDateViewControllerViewModel(token: token, tokenHolder: tokenHolder, ethCost: ethCost, server: session.server, assetDefinitionStore: assetDefinitionStore)
let controller = SetSellTokensCardExpiryDateViewController(analyticsCoordinator: analyticsCoordinator, storage: tokensDataStore, paymentFlow: paymentFlow, tokenHolder: tokenHolder, ethCost: ethCost, viewModel: viewModel, assetDefinitionStore: assetDefinitionStore, keystore: keystore, session: session)
let controller = SetSellTokensCardExpiryDateViewController(analyticsCoordinator: analyticsCoordinator, paymentFlow: paymentFlow, tokenHolder: tokenHolder, ethCost: ethCost, viewModel: viewModel, assetDefinitionStore: assetDefinitionStore, keystore: keystore, session: session)
controller.configure()
controller.delegate = self
return controller
@ -385,29 +377,12 @@ class TokensCardCoordinator: NSObject, Coordinator {
viewController.navigationController?.pushViewController(controller, animated: true)
}
private func showNFTAssetViewController(tokenHolder: TokenHolder, in viewController: NFTCollectionViewController) {
let viewModel = NFTAssetViewModel(account: session.account, tokenId: tokenHolder.tokenId, token: token, tokenHolder: tokenHolder, assetDefinitionStore: assetDefinitionStore)
let vc = NFTAssetViewController(analyticsCoordinator: analyticsCoordinator, assetDefinitionStore: assetDefinitionStore, viewModel: viewModel, mode: .interactive)
vc.delegate = self
vc.navigationItem.largeTitleDisplayMode = .never
vc.navigationItem.leftBarButtonItem = .backBarButton(self, selector: #selector(tokenInstanceViewControllerDidCloseSelected))
viewController.navigationController?.pushViewController(vc, animated: true)
}
@objc private func tokenInstanceViewControllerDidCloseSelected(_ sender: UIBarButtonItem) {
navigationController.popViewController(animated: true)
}
private func showTokenInstanceActionView(forAction action: TokenInstanceAction, tokenHolder: TokenHolder, viewController: UIViewController) {
delegate?.didPress(for: .send(type: .tokenScript(action: action, tokenObject: token, tokenHolder: tokenHolder)), inViewController: viewController, in: self)
}
}
extension TokensCardCoordinator: NFTCollectionViewControllerDelegate {
func didSelectAssetSelection(in viewController: NFTCollectionViewController) {
//no-op
showTokenCardSelection(tokenHolders: viewController.viewModel.tokenHolders)
}
func didTap(transaction: TransactionInstance, in viewController: NFTCollectionViewController) {
@ -419,7 +394,43 @@ extension TokensCardCoordinator: NFTCollectionViewControllerDelegate {
}
func didSelectTokenHolder(in viewController: NFTCollectionViewController, didSelectTokenHolder tokenHolder: TokenHolder) {
showNFTAssetViewController(tokenHolder: tokenHolder, in: viewController)
showNFTAsset(tokenHolder: tokenHolder, navigationController: viewController.navigationController)
}
func showNFTAsset(tokenHolder: TokenHolder, mode: TokenInstanceViewMode = .interactive) {
showNFTAsset(tokenHolder: tokenHolder, mode: mode, navigationController: navigationController)
}
private func showNFTAsset(tokenHolder: TokenHolder, mode: TokenInstanceViewMode = .interactive, navigationController: UINavigationController?) {
let vc: UIViewController
switch tokenHolder.type {
case .collectible:
vc = createNFTAssetListViewController(tokenHolder: tokenHolder)
case .single:
vc = createNFTAssetViewController(tokenHolder: tokenHolder, tokenId: tokenHolder.tokenId, mode: mode)
}
vc.navigationItem.leftBarButtonItem = UIBarButtonItem.backBarButton(selectionClosure: { _ in
navigationController?.popViewController(animated: true)
})
navigationController?.pushViewController(vc, animated: true)
}
private func createNFTAssetListViewController(tokenHolder: TokenHolder) -> NFTAssetListViewController {
let viewModel = NFTAssetListViewModel(tokenHolder: tokenHolder)
let vc = NFTAssetListViewController(viewModel: viewModel, tokenObject: token, assetDefinitionStore: assetDefinitionStore, analyticsCoordinator: analyticsCoordinator, server: session.server)
vc.delegate = self
return vc
}
private func createNFTAssetViewController(tokenHolder: TokenHolder, tokenId: TokenId, mode: TokenInstanceViewMode = .interactive) -> UIViewController {
let viewModel = NFTAssetViewModel(account: session.account, tokenId: tokenId, token: token, tokenHolder: tokenHolder, assetDefinitionStore: assetDefinitionStore)
let vc = NFTAssetViewController(analyticsCoordinator: analyticsCoordinator, assetDefinitionStore: assetDefinitionStore, viewModel: viewModel, mode: mode)
vc.delegate = self
vc.navigationItem.largeTitleDisplayMode = .never
return vc
}
func didPressRedeem(token: TokenObject, tokenHolder: TokenHolder, in viewController: NFTCollectionViewController) {
@ -430,17 +441,6 @@ extension TokensCardCoordinator: NFTCollectionViewControllerDelegate {
showEnterPriceQuantityViewController(tokenHolder: tokenHolder, forPaymentFlow: paymentFlow, in: viewController)
}
func didPressTransfer(token: TokenObject, tokenHolder: TokenHolder, for type: PaymentFlow, in viewController: NFTCollectionViewController) {
switch token.type {
case .erc721:
delegate?.didPress(for: type, inViewController: viewController, in: self)
case .erc875, .erc721ForTickets:
showEnterQuantityViewControllerForTransfer(token: token, for: tokenHolder, forPaymentFlow: type, in: viewController)
case .nativeCryptocurrency, .erc20, .erc1155:
break
}
}
func didCancel(in viewController: NFTCollectionViewController) {
delegate?.didCancel(in: self)
}
@ -457,7 +457,50 @@ extension TokensCardCoordinator: NFTCollectionViewControllerDelegate {
}
func didTapTokenInstanceIconified(tokenHolder: TokenHolder, in viewController: NFTCollectionViewController) {
showNFTAssetViewController(tokenHolder: tokenHolder, in: viewController)
let vc = createNFTAssetViewController(tokenHolder: tokenHolder, tokenId: tokenHolder.tokenId)
vc.navigationItem.leftBarButtonItem = UIBarButtonItem.backBarButton(selectionClosure: { _ in
viewController.navigationController?.popViewController(animated: true)
})
viewController.navigationController?.pushViewController(vc, animated: true)
}
}
extension TokensCardCoordinator: NFTAssetListViewControllerDelegate {
func selectTokenCardsSelected(in viewController: NFTAssetListViewController) {
showTokenCardSelection(tokenHolders: [viewController.tokenHolder])
}
func didSelectTokenCard(in viewController: NFTAssetListViewController, tokenId: TokenId) {
let vc = createNFTAssetViewController(tokenHolder: viewController.tokenHolder, tokenId: tokenId)
vc.navigationItem.leftBarButtonItem = UIBarButtonItem.backBarButton(selectionClosure: { _ in
viewController.navigationController?.popViewController(animated: true)
})
viewController.navigationController?.pushViewController(vc, animated: true)
}
}
extension TokensCardCoordinator: NFTAssetSelectionCoordinatorDelegate {
private func showTokenCardSelection(tokenHolders: [TokenHolder]) {
let coordinator = NFTAssetSelectionCoordinator(navigationController: navigationController, tokenObject: token, tokenHolders: tokenHolders, assetDefinitionStore: assetDefinitionStore, analyticsCoordinator: analyticsCoordinator, server: session.server)
addCoordinator(coordinator)
coordinator.delegate = self
coordinator.start()
}
func didTapSend(in coordinator: NFTAssetSelectionCoordinator, tokenObject: TokenObject, tokenHolders: [TokenHolder]) {
removeCoordinator(coordinator)
let filteredTokenHolders = tokenHolders.filter { $0.totalSelectedCount > 0 }
guard let vc = navigationController.visibleViewController else { return }
let transactionType: TransactionType = .erc1155Token(tokenObject, transferType: .singleTransfer, tokenHolders: filteredTokenHolders)
delegate?.didPress(for: .send(type: .transaction(transactionType)), inViewController: vc, in: self)
}
func didFinish(in coordinator: NFTAssetSelectionCoordinator) {
removeCoordinator(coordinator)
}
}
@ -469,8 +512,11 @@ extension TokensCardCoordinator: NonFungibleTokenViewControllerDelegate {
delegate?.didPress(for: paymentFlow, inViewController: viewController, in: self)
case .erc875, .erc721ForTickets:
showEnterQuantityViewControllerForTransfer(token: token, for: tokenHolder, forPaymentFlow: paymentFlow, in: viewController)
case .nativeCryptocurrency, .erc20, .erc1155:
case .nativeCryptocurrency, .erc20:
break
case .erc1155:
let transactionType: TransactionType = .erc1155Token(token, transferType: .singleTransfer, tokenHolders: [tokenHolder])
delegate?.didPress(for: .send(type: .transaction(transactionType)), inViewController: viewController, in: self)
}
}
@ -482,7 +528,7 @@ extension TokensCardCoordinator: NonFungibleTokenViewControllerDelegate {
}
func didTap(action: TokenInstanceAction, tokenHolder: TokenHolder, viewController: NFTAssetViewController) {
showTokenInstanceActionView(forAction: action, tokenHolder: tokenHolder, viewController: viewController)
delegate?.didPress(for: .send(type: .tokenScript(action: action, tokenObject: token, tokenHolder: tokenHolder)), inViewController: viewController, in: self)
}
func didPressRedeem(token: TokenObject, tokenHolder: TokenHolder, in viewController: NFTAssetViewController) {
@ -604,3 +650,19 @@ extension TokensCardCoordinator: CanOpenURL {
extension TokensCardCoordinator: StaticHTMLViewControllerDelegate {
}
extension Collection where Element == TokenHolder {
var valuesAll: [TokenId: [AttributeId: AssetAttributeSyntaxValue]] {
var valuesAll: [TokenId: [AttributeId: AssetAttributeSyntaxValue]] = [:]
for each in self {
valuesAll.merge(each.valuesAll) { (current, _) in current }
}
return valuesAll
}
}
extension Collection where Element == UnconfirmedTransaction.TokenIdAndValue {
var erc1155TokenTransactionType: Erc1155TokenTransactionType {
return count > 1 ? .batchTransfer : .singleTransfer
}
}

@ -9,7 +9,6 @@ import UIKit
import StatefulViewController
protocol NFTAssetListViewControllerDelegate: class {
func selectTokenCardsSelected(in viewController: NFTAssetListViewController)
func didSelectTokenCard(in viewController: NFTAssetListViewController, tokenId: TokenId)
}

@ -105,39 +105,6 @@ class SingleChainTokenCoordinator: Coordinator {
return
}
switch token.type {
case .erc1155:
showTokensCardCollection(for: type, token: token, navigationController: navigationController)
case .erc721, .nativeCryptocurrency, .erc20, .erc875, .erc721ForTickets:
showTokenCard(for: type, token: token, navigationController: navigationController)
}
}
private func showTokensCardCollection(for type: PaymentFlow, token: TokenObject, navigationController: UINavigationController) {
guard let transactionType = type.transactionType else { return }
let activitiesFilterStrategy = transactionType.activitiesFilterStrategy
let activitiesService = self.activitiesService.copy(activitiesFilterStrategy: activitiesFilterStrategy, transactionsFilterStrategy: TransactionDataStore.functional.transactionsFilter(for: activitiesFilterStrategy, tokenObject: transactionType.tokenObject))
let tokensCardCoordinator = TokensCardCollectionCoordinator(
session: session,
navigationController: navigationController,
keystore: keystore,
tokensStorage: tokensDataStore,
token: token,
assetDefinitionStore: assetDefinitionStore,
eventsDataStore: eventsDataStore,
analyticsCoordinator: analyticsCoordinator,
activitiesService: activitiesService,
paymantFlow: type
)
addCoordinator(tokensCardCoordinator)
tokensCardCoordinator.delegate = self
tokensCardCoordinator.start()
}
private func showTokenCard(for type: PaymentFlow, token: TokenObject, navigationController: UINavigationController) {
guard let transactionType = type.transactionType else { return }
let activitiesFilterStrategy = transactionType.activitiesFilterStrategy
@ -147,7 +114,6 @@ class SingleChainTokenCoordinator: Coordinator {
session: session,
navigationController: navigationController,
keystore: keystore,
tokensStorage: tokensDataStore,
token: token,
assetDefinitionStore: assetDefinitionStore,
eventsDataStore: eventsDataStore,
@ -307,22 +273,3 @@ extension SingleChainTokenCoordinator: CanOpenURL {
delegate?.didPressOpenWebPage(url, in: viewController)
}
}
extension SingleChainTokenCoordinator: TokensCardCollectionCoordinatorDelegate {
func didTap(for type: PaymentFlow, in coordinator: TokensCardCollectionCoordinator, viewController: UIViewController) {
delegate?.didPress(for: type, inViewController: viewController, in: self)
}
func didClose(in coordinator: TokensCardCollectionCoordinator) {
removeCoordinator(coordinator)
}
func didTap(transaction: TransactionInstance, in coordinator: TokensCardCollectionCoordinator) {
delegate?.didTap(transaction: transaction, inViewController: coordinator.rootViewController, in: self)
}
func didTap(activity: Activity, in coordinator: TokensCardCollectionCoordinator) {
delegate?.didTap(activity: activity, inViewController: coordinator.rootViewController, in: self)
}
}

Loading…
Cancel
Save