Refactor: pass AnalyticsCoordinator around for future logging support

pull/2645/head
Hwee-Boon Yar 4 years ago
parent 1fe24dfcc5
commit 3bc045999e
  1. 5
      AlphaWallet/Activities/Coordinators/ActivitiesCoordinator.swift
  2. 6
      AlphaWallet/Activities/ViewControllers/ActivityViewController.swift
  3. 3
      AlphaWallet/Activities/Views/ActivityViewCell.swift
  4. 1
      AlphaWallet/AppCoordinator.swift
  5. 2
      AlphaWallet/Browser/Coordinators/DappBrowserCoordinator.swift
  6. 1
      AlphaWallet/InCoordinator.swift
  7. 8
      AlphaWallet/Market/Coordinators/UniversalLinkCoordinator.swift
  8. 6
      AlphaWallet/Market/ViewControllers/ImportMagicTokenViewController.swift
  9. 6
      AlphaWallet/Redeem/ViewControllers/RedeemTokenCardQuantitySelectionViewController.swift
  10. 2
      AlphaWallet/Redeem/ViewControllers/TokenCardRedemptionViewController.swift
  11. 5
      AlphaWallet/Sell/ViewControllers/EnterSellTokensCardPriceQuantityViewController.swift
  12. 5
      AlphaWallet/Sell/ViewControllers/SetSellTokensCardExpiryDateViewController.swift
  13. 4
      AlphaWallet/Tokens/Coordinators/SingleChainTokenCoordinator.swift
  14. 6
      AlphaWallet/Tokens/ViewControllers/TokenInstanceActionViewController.swift
  15. 6
      AlphaWallet/Tokens/ViewControllers/TokenInstanceViewController.swift
  16. 8
      AlphaWallet/Tokens/ViewControllers/TokensCardViewController.swift
  17. 6
      AlphaWallet/Tokens/Views/TokenInstanceWebView.swift
  18. 20
      AlphaWallet/Transactions/Coordinators/TokensCardCoordinator.swift
  19. 6
      AlphaWallet/Transfer/Coordinators/SignMessageCoordinator.swift
  20. 5
      AlphaWallet/Transfer/ViewControllers/ChooseTokenCardTransferModeViewController.swift
  21. 5
      AlphaWallet/Transfer/ViewControllers/SetTransferTokensCardExpiryDateViewController.swift
  22. 5
      AlphaWallet/Transfer/ViewControllers/TransferTokensCardQuantitySelectionViewController.swift
  23. 6
      AlphaWallet/Transfer/ViewControllers/TransferTokensCardViaWalletAddressViewController.swift
  24. 6
      AlphaWallet/UI/Views/TokenCardRowView.swift
  25. 15
      AlphaWallet/WalletConnect/Controllers/SignMessageCoordinatorBridgeToPromise.swift
  26. 2
      AlphaWallet/WalletConnect/Coordinator/WalletConnectCoordinator.swift

@ -10,6 +10,7 @@ protocol ActivitiesCoordinatorDelegate: class {
}
class ActivitiesCoordinator: Coordinator {
private let analyticsCoordinator: AnalyticsCoordinator
private let config: Config
private let keystore: Keystore
private let sessions: ServerDictionary<WalletSession>
@ -50,6 +51,7 @@ class ActivitiesCoordinator: Coordinator {
private let queue = DispatchQueue(label: "com.activities.updateQueue")
init(
analyticsCoordinator: AnalyticsCoordinator,
config: Config,
sessions: ServerDictionary<WalletSession>,
navigationController: UINavigationController = UINavigationController(),
@ -60,6 +62,7 @@ class ActivitiesCoordinator: Coordinator {
eventsDataStore: EventsDataStoreProtocol,
transactionCoordinator: TransactionCoordinator?
) {
self.analyticsCoordinator = analyticsCoordinator
self.config = config
self.sessions = sessions
self.keystore = keystore
@ -84,7 +87,7 @@ class ActivitiesCoordinator: Coordinator {
}
func showActivity(_ activity: Activity) {
let controller = ActivityViewController(wallet: wallet, assetDefinitionStore: assetDefinitionStore, viewModel: .init(activity: activity))
let controller = ActivityViewController(analyticsCoordinator: analyticsCoordinator, wallet: wallet, assetDefinitionStore: assetDefinitionStore, viewModel: .init(activity: activity))
controller.delegate = self
activityViewController = controller
controller.hidesBottomBarWhenPushed = true

@ -10,6 +10,7 @@ protocol ActivityViewControllerDelegate: class {
}
class ActivityViewController: UIViewController {
private let analyticsCoordinator: AnalyticsCoordinator
private let roundedBackground = RoundedBackground()
private let wallet: Wallet
private let assetDefinitionStore: AssetDefinitionStore
@ -22,7 +23,7 @@ class ActivityViewController: UIViewController {
private let separator = UIView()
private let bottomFiller = UIView.spacerWidth()
lazy private var tokenScriptRendererView: TokenInstanceWebView = {
let webView = TokenInstanceWebView(server: server, wallet: wallet, assetDefinitionStore: assetDefinitionStore)
let webView = TokenInstanceWebView(analyticsCoordinator: analyticsCoordinator, server: server, wallet: wallet, assetDefinitionStore: assetDefinitionStore)
webView.isWebViewInteractionEnabled = true
webView.delegate = self
webView.isStandalone = true
@ -40,7 +41,8 @@ class ActivityViewController: UIViewController {
weak var delegate: ActivityViewControllerDelegate?
init(wallet: Wallet, assetDefinitionStore: AssetDefinitionStore, viewModel: ActivityViewModel) {
init(analyticsCoordinator: AnalyticsCoordinator, wallet: Wallet, assetDefinitionStore: AssetDefinitionStore, viewModel: ActivityViewModel) {
self.analyticsCoordinator = analyticsCoordinator
self.wallet = wallet
self.assetDefinitionStore = assetDefinitionStore
self.viewModel = viewModel

@ -9,7 +9,8 @@ class ActivityViewCell: UITableViewCell {
//TODO pass in keystore or wallet address instead. Have to think about initialization of cells
let wallet = EtherKeystore.currentWallet
//TODO server value doesn't matter since we will change it later. But we should improve this
let webView = TokenInstanceWebView(server: .main, wallet: wallet, assetDefinitionStore: AssetDefinitionStore.instance)
//TODO We aren't going to log analytics in a cell (for now), but we might, at any time
let webView = TokenInstanceWebView(analyticsCoordinator: NoOpAnalyticsService(), server: .main, wallet: wallet, assetDefinitionStore: AssetDefinitionStore.instance)
//TODO needed? Seems like scary, performance-wise
//webView.delegate = self
return webView

@ -223,6 +223,7 @@ class AppCoordinator: NSObject, Coordinator {
if config.enabledServers.contains(server) {
let universalLinkCoordinator = UniversalLinkCoordinator(
analyticsCoordinator: analyticsService,
wallet: keystore.currentWallet,
config: config,
ethPrice: inCoordinator.nativeCryptoCurrencyPrices[server],

@ -198,7 +198,7 @@ final class DappBrowserCoordinator: NSObject, Coordinator {
func signMessage(with type: SignMessageType, account: AlphaWallet.Address, callbackID: Int) {
firstly {
SignMessageCoordinator.promise(navigationController, keystore: keystore, coordinator: self, signType: type, account: account)
SignMessageCoordinator.promise(analyticsCoordinator: analyticsCoordinator, navigationController: navigationController, keystore: keystore, coordinator: self, signType: type, account: account, source: .dappBrowser)
}.done { data in
let callback: DappCallback
switch type {

@ -423,6 +423,7 @@ class InCoordinator: NSObject, Coordinator {
private func createActivityCoordinator() -> ActivitiesCoordinator {
let coordinator = ActivitiesCoordinator(
analyticsCoordinator: analyticsCoordinator,
config: config,
sessions: walletSessions,
keystore: keystore,

@ -24,6 +24,7 @@ class UniversalLinkCoordinator: Coordinator {
static let walletConnectPath = "/wc"
private let analyticsCoordinator: AnalyticsCoordinator
private let wallet: Wallet
private let config: Config
private var importTokenViewController: ImportMagicTokenViewController?
@ -81,7 +82,8 @@ class UniversalLinkCoordinator: Coordinator {
}
}
init(wallet: Wallet, config: Config, ethPrice: Subscribable<Double>, ethBalance: Subscribable<BigInt>, tokensDatastore: TokensDataStore, assetDefinitionStore: AssetDefinitionStore, url: URL, server: RPCServer) {
init(analyticsCoordinator: AnalyticsCoordinator, wallet: Wallet, config: Config, ethPrice: Subscribable<Double>, ethBalance: Subscribable<BigInt>, tokensDatastore: TokensDataStore, assetDefinitionStore: AssetDefinitionStore, url: URL, server: RPCServer) {
self.analyticsCoordinator = analyticsCoordinator
self.wallet = wallet
self.config = config
self.ethPrice = ethPrice
@ -522,7 +524,7 @@ class UniversalLinkCoordinator: Coordinator {
}
private func makeTokenHolderImpl(name: String, symbol: String, type: TokenType? = nil, bytes32Tokens: [String], contractAddress: AlphaWallet.Address) {
//TODO pass in the wallet instead
//TODO pass in the wallet instead
guard let tokenType = type ?? (tokensDatastore.token(forContract: contractAddress)?.type) else { return }
var tokens = [Token]()
let xmlHandler = XMLHandler(contract: contractAddress, tokenType: tokenType, assetDefinitionStore: assetDefinitionStore)
@ -542,7 +544,7 @@ class UniversalLinkCoordinator: Coordinator {
private func preparingToImportUniversalLink() {
guard let viewController = delegate?.viewControllerForPresenting(in: self) else { return }
importTokenViewController = ImportMagicTokenViewController(server: server, assetDefinitionStore: assetDefinitionStore)
importTokenViewController = ImportMagicTokenViewController(analyticsCoordinator: analyticsCoordinator, server: server, assetDefinitionStore: assetDefinitionStore)
guard let vc = importTokenViewController else { return }
vc.delegate = self
vc.configure(viewModel: .init(state: .validating, server: server))

@ -14,9 +14,10 @@ class ImportMagicTokenViewController: UIViewController, OptionalTokenVerifiableS
case notReady
}
private let analyticsCoordinator: AnalyticsCoordinator
private let roundedBackground = RoundedBackground()
private let header = TokensCardViewControllerTitleHeader()
lazy private var tokenCardRowView = TokenCardRowView(server: server, tokenView: .viewIconified, assetDefinitionStore: assetDefinitionStore)
lazy private var tokenCardRowView = TokenCardRowView(analyticsCoordinator: analyticsCoordinator, server: server, tokenView: .viewIconified, assetDefinitionStore: assetDefinitionStore)
private let statusLabel = UILabel()
private let activityIndicator = UIActivityIndicatorView(style: .whiteLarge)
private var costStackView: UIStackView?
@ -50,7 +51,8 @@ class ImportMagicTokenViewController: UIViewController, OptionalTokenVerifiableS
}
}
init(server: RPCServer, assetDefinitionStore: AssetDefinitionStore) {
init(analyticsCoordinator: AnalyticsCoordinator, server: RPCServer, assetDefinitionStore: AssetDefinitionStore) {
self.analyticsCoordinator = analyticsCoordinator
self.server = server
self.assetDefinitionStore = assetDefinitionStore
super.init(nibName: nil, bundle: nil)

@ -14,6 +14,7 @@ protocol RedeemTokenCardQuantitySelectionViewControllerDelegate: class, CanOpenU
}
class RedeemTokenCardQuantitySelectionViewController: UIViewController, TokenVerifiableStatusViewController {
private let analyticsCoordinator: AnalyticsCoordinator
private let token: TokenObject
private let roundedBackground = RoundedBackground()
private let header = TokensCardViewControllerTitleHeader()
@ -32,7 +33,8 @@ class RedeemTokenCardQuantitySelectionViewController: UIViewController, TokenVer
let assetDefinitionStore: AssetDefinitionStore
weak var delegate: RedeemTokenCardQuantitySelectionViewControllerDelegate?
init(token: TokenObject, viewModel: RedeemTokenCardQuantitySelectionViewModel, assetDefinitionStore: AssetDefinitionStore) {
init(analyticsCoordinator: AnalyticsCoordinator, token: TokenObject, viewModel: RedeemTokenCardQuantitySelectionViewModel, assetDefinitionStore: AssetDefinitionStore) {
self.analyticsCoordinator = analyticsCoordinator
self.token = token
self.viewModel = viewModel
self.assetDefinitionStore = assetDefinitionStore
@ -42,7 +44,7 @@ class RedeemTokenCardQuantitySelectionViewController: UIViewController, TokenVer
case .backedByOpenSea:
tokenRowView = OpenSeaNonFungibleTokenCardRowView(tokenView: .viewIconified)
case .notBackedByOpenSea:
tokenRowView = TokenCardRowView(server: token.server, tokenView: .viewIconified, assetDefinitionStore: assetDefinitionStore)
tokenRowView = TokenCardRowView(analyticsCoordinator: analyticsCoordinator, server: token.server, tokenView: .viewIconified, assetDefinitionStore: assetDefinitionStore)
}
super.init(nibName: nil, bundle: nil)

@ -43,7 +43,7 @@ class TokenCardRedemptionViewController: UIViewController, TokenVerifiableStatus
case .backedByOpenSea:
tokenRowView = OpenSeaNonFungibleTokenCardRowView(tokenView: .viewIconified)
case .notBackedByOpenSea:
tokenRowView = TokenCardRowView(server: token.server, tokenView: .viewIconified, assetDefinitionStore: assetDefinitionStore)
tokenRowView = TokenCardRowView(analyticsCoordinator: analyticsCoordinator, server: token.server, tokenView: .viewIconified, assetDefinitionStore: assetDefinitionStore)
}
super.init(nibName: nil, bundle: nil)

@ -9,6 +9,7 @@ protocol EnterSellTokensCardPriceQuantityViewControllerDelegate: class, CanOpenU
}
class EnterSellTokensCardPriceQuantityViewController: UIViewController, TokenVerifiableStatusViewController {
private let analyticsCoordinator: AnalyticsCoordinator
private let storage: TokensDataStore
private let roundedBackground = RoundedBackground()
private let scrollView = UIScrollView()
@ -56,12 +57,14 @@ class EnterSellTokensCardPriceQuantityViewController: UIViewController, TokenVer
// swiftlint:disable function_body_length
init(
analyticsCoordinator: AnalyticsCoordinator,
storage: TokensDataStore,
paymentFlow: PaymentFlow,
cryptoPrice: Subscribable<Double>,
viewModel: EnterSellTokensCardPriceQuantityViewControllerViewModel,
assetDefinitionStore: AssetDefinitionStore
) {
self.analyticsCoordinator = analyticsCoordinator
self.storage = storage
self.paymentFlow = paymentFlow
self.ethPrice = cryptoPrice
@ -73,7 +76,7 @@ class EnterSellTokensCardPriceQuantityViewController: UIViewController, TokenVer
case .backedByOpenSea:
tokenRowView = OpenSeaNonFungibleTokenCardRowView(tokenView: .viewIconified)
case .notBackedByOpenSea:
tokenRowView = TokenCardRowView(server: viewModel.token.server, tokenView: .viewIconified, assetDefinitionStore: assetDefinitionStore)
tokenRowView = TokenCardRowView(analyticsCoordinator: analyticsCoordinator, server: viewModel.token.server, tokenView: .viewIconified, assetDefinitionStore: assetDefinitionStore)
}
super.init(nibName: nil, bundle: nil)

@ -8,6 +8,7 @@ protocol SetSellTokensCardExpiryDateViewControllerDelegate: class, CanOpenURL {
}
class SetSellTokensCardExpiryDateViewController: UIViewController, TokenVerifiableStatusViewController {
private let analyticsCoordinator: AnalyticsCoordinator
private let storage: TokensDataStore
private let roundedBackground = RoundedBackground()
private let scrollView = UIScrollView()
@ -54,6 +55,7 @@ class SetSellTokensCardExpiryDateViewController: UIViewController, TokenVerifiab
// swiftlint:disable function_body_length
init(
analyticsCoordinator: AnalyticsCoordinator,
storage: TokensDataStore,
paymentFlow: PaymentFlow,
tokenHolder: TokenHolder,
@ -61,6 +63,7 @@ class SetSellTokensCardExpiryDateViewController: UIViewController, TokenVerifiab
viewModel: SetSellTokensCardExpiryDateViewControllerViewModel,
assetDefinitionStore: AssetDefinitionStore
) {
self.analyticsCoordinator = analyticsCoordinator
self.storage = storage
self.paymentFlow = paymentFlow
self.tokenHolder = tokenHolder
@ -73,7 +76,7 @@ class SetSellTokensCardExpiryDateViewController: UIViewController, TokenVerifiab
case .backedByOpenSea:
tokenRowView = OpenSeaNonFungibleTokenCardRowView(tokenView: .viewIconified)
case .notBackedByOpenSea:
tokenRowView = TokenCardRowView(server: viewModel.token.server, tokenView: .viewIconified, assetDefinitionStore: assetDefinitionStore)
tokenRowView = TokenCardRowView(analyticsCoordinator: analyticsCoordinator, server: viewModel.token.server, tokenView: .viewIconified, assetDefinitionStore: assetDefinitionStore)
}
super.init(nibName: nil, bundle: nil)

@ -385,7 +385,7 @@ class SingleChainTokenCoordinator: Coordinator {
coordinator.isReadOnly = true
}
}
}
}
func show(fungibleToken token: TokenObject, transactionType: TransactionType, navigationController: UINavigationController) {
let viewController = TokenViewController(session: session, tokensDataStore: storage, assetDefinition: assetDefinitionStore, transactionType: transactionType, analyticsCoordinator: analyticsCoordinator, token: token)
@ -523,7 +523,7 @@ class SingleChainTokenCoordinator: Coordinator {
let values = xmlHandler.resolveAttributesBypassingCache(withTokenIdOrEvent: .tokenId(tokenId: hardcodedTokenIdForFungibles), server: self.session.server, account: self.session.account)
let token = Token(tokenIdOrEvent: .tokenId(tokenId: hardcodedTokenIdForFungibles), tokenType: tokenObject.type, index: 0, name: tokenObject.name, symbol: tokenObject.symbol, status: .available, values: values)
let tokenHolder = TokenHolder(tokens: [token], contractAddress: tokenObject.contractAddress, hasAssetDefinition: true)
let vc = TokenInstanceActionViewController(tokenObject: tokenObject, tokenHolder: tokenHolder, tokensStorage: storage, assetDefinitionStore: assetDefinitionStore, action: action, session: session, keystore: keystore)
let vc = TokenInstanceActionViewController(analyticsCoordinator: analyticsCoordinator, tokenObject: tokenObject, tokenHolder: tokenHolder, tokensStorage: storage, assetDefinitionStore: assetDefinitionStore, action: action, session: session, keystore: keystore)
vc.delegate = self
vc.configure()
vc.navigationItem.largeTitleDisplayMode = .never

@ -12,6 +12,7 @@ protocol TokenInstanceActionViewControllerDelegate: class, CanOpenURL {
}
class TokenInstanceActionViewController: UIViewController, TokenVerifiableStatusViewController {
private let analyticsCoordinator: AnalyticsCoordinator
private let tokenObject: TokenObject
private let tokenHolder: TokenHolder
private let action: TokenInstanceAction
@ -20,7 +21,7 @@ class TokenInstanceActionViewController: UIViewController, TokenVerifiableStatus
private let tokensStorage: TokensDataStore
private let roundedBackground = RoundedBackground()
lazy private var tokenScriptRendererView: TokenInstanceWebView = {
let webView = TokenInstanceWebView(server: server, wallet: keystore.currentWallet, assetDefinitionStore: assetDefinitionStore)
let webView = TokenInstanceWebView(analyticsCoordinator: analyticsCoordinator, server: server, wallet: keystore.currentWallet, assetDefinitionStore: assetDefinitionStore)
webView.isWebViewInteractionEnabled = true
webView.delegate = self
webView.isStandalone = true
@ -73,7 +74,8 @@ class TokenInstanceActionViewController: UIViewController, TokenVerifiableStatus
}
}
init(tokenObject: TokenObject, tokenHolder: TokenHolder, tokensStorage: TokensDataStore, assetDefinitionStore: AssetDefinitionStore, action: TokenInstanceAction, session: WalletSession, keystore: Keystore) {
init(analyticsCoordinator: AnalyticsCoordinator, tokenObject: TokenObject, tokenHolder: TokenHolder, tokensStorage: TokensDataStore, assetDefinitionStore: AssetDefinitionStore, action: TokenInstanceAction, session: WalletSession, keystore: Keystore) {
self.analyticsCoordinator = analyticsCoordinator
self.tokenObject = tokenObject
self.tokenHolder = tokenHolder
self.tokensStorage = tokensStorage

@ -13,6 +13,7 @@ protocol TokenInstanceViewControllerDelegate: class, CanOpenURL {
}
class TokenInstanceViewController: UIViewController, TokenVerifiableStatusViewController {
private let analyticsCoordinator: AnalyticsCoordinator
private let tokenObject: TokenObject
private var viewModel: TokenInstanceViewModel
private let tokensStorage: TokensDataStore
@ -51,7 +52,8 @@ class TokenInstanceViewController: UIViewController, TokenVerifiableStatusViewCo
}
}
init(tokenObject: TokenObject, tokenHolder: TokenHolder, account: Wallet, tokensStorage: TokensDataStore, assetDefinitionStore: AssetDefinitionStore) {
init(analyticsCoordinator: AnalyticsCoordinator, tokenObject: TokenObject, tokenHolder: TokenHolder, account: Wallet, tokensStorage: TokensDataStore, assetDefinitionStore: AssetDefinitionStore) {
self.analyticsCoordinator = analyticsCoordinator
self.tokenObject = tokenObject
self.account = account
self.tokensStorage = tokensStorage
@ -203,7 +205,7 @@ class TokenInstanceViewController: UIViewController, TokenVerifiableStatusViewCo
}()
case .notBackedByOpenSea:
rowView = {
let view = TokenCardRowView(server: .main, tokenView: .view, showCheckbox: false, assetDefinitionStore: assetDefinitionStore)
let view = TokenCardRowView(analyticsCoordinator: analyticsCoordinator, server: .main, tokenView: .view, showCheckbox: false, assetDefinitionStore: assetDefinitionStore)
view.isStandalone = true
view.tokenScriptRendererView.isWebViewInteractionEnabled = true
return view

@ -26,6 +26,7 @@ class TokensCardViewController: UIViewController, TokenVerifiableStatusViewContr
static let anArbitraryRowHeightSoAutoSizingCellsWorkIniOS10 = CGFloat(100)
private var sizingCell: TokenCardTableViewCellWithCheckbox?
private let analyticsCoordinator: AnalyticsCoordinator
private let tokenObject: TokenObject
private var viewModel: TokensCardViewModel
private let tokensStorage: TokensDataStore
@ -76,7 +77,8 @@ class TokensCardViewController: UIViewController, TokenVerifiableStatusViewContr
}
}
init(tokenObject: TokenObject, account: Wallet, tokensStorage: TokensDataStore, assetDefinitionStore: AssetDefinitionStore, viewModel: TokensCardViewModel) {
init(analyticsCoordinator: AnalyticsCoordinator, tokenObject: TokenObject, account: Wallet, tokensStorage: TokensDataStore, assetDefinitionStore: AssetDefinitionStore, viewModel: TokensCardViewModel) {
self.analyticsCoordinator = analyticsCoordinator
self.tokenObject = tokenObject
self.account = account
self.tokensStorage = tokensStorage
@ -325,7 +327,7 @@ class TokensCardViewController: UIViewController, TokenVerifiableStatusViewContr
//Reuse for performance (because webviews are created)
return rowView
} else {
let rowView = TokenCardRowView(server: .main, tokenView: .viewIconified, showCheckbox: cell.showCheckbox(), assetDefinitionStore: assetDefinitionStore)
let rowView = TokenCardRowView(analyticsCoordinator: analyticsCoordinator, server: .main, tokenView: .viewIconified, showCheckbox: cell.showCheckbox(), assetDefinitionStore: assetDefinitionStore)
rowView.delegate = self
return rowView
}
@ -393,7 +395,7 @@ extension TokensCardViewController: UITableViewDelegate, UITableViewDataSource {
//Reuse for performance (because webviews are created)
return rowView
} else {
let rowView = TokenCardRowView(server: .main, tokenView: .viewIconified, showCheckbox: cell.showCheckbox(), assetDefinitionStore: assetDefinitionStore)
let rowView = TokenCardRowView(analyticsCoordinator: analyticsCoordinator, server: .main, tokenView: .viewIconified, showCheckbox: cell.showCheckbox(), assetDefinitionStore: assetDefinitionStore)
//Important not to assign a delegate because we don't use actual cells to figure out the height. We use a sizing cell instead
return rowView
}

@ -45,6 +45,7 @@ class TokenInstanceWebView: UIView {
}
}
private let analyticsCoordinator: AnalyticsCoordinator
//TODO see if we can be smarter about just subscribing to the attribute once. Note that this is not `Subscribable.subscribeOnce()`
private let wallet: Wallet
private let assetDefinitionStore: AssetDefinitionStore
@ -93,7 +94,8 @@ class TokenInstanceWebView: UIView {
return results
}
init(server: RPCServer, wallet: Wallet, assetDefinitionStore: AssetDefinitionStore) {
init(analyticsCoordinator: AnalyticsCoordinator, server: RPCServer, wallet: Wallet, assetDefinitionStore: AssetDefinitionStore) {
self.analyticsCoordinator = analyticsCoordinator
self.server = server
self.wallet = wallet
self.assetDefinitionStore = assetDefinitionStore
@ -485,7 +487,7 @@ extension TokenInstanceWebView {
let keystore = try! EtherKeystore(analyticsCoordinator: NoOpAnalyticsService())
firstly {
SignMessageCoordinator.promise(navigationController, keystore: keystore, signType: type, account: account)
SignMessageCoordinator.promise(analyticsCoordinator: analyticsCoordinator, navigationController: navigationController, keystore: keystore, signType: type, account: account, source: .tokenScript)
}.done { data in
let callback: DappCallback
switch type {

@ -115,7 +115,7 @@ class TokensCardCoordinator: NSObject, Coordinator {
}
private func makeTokensCardViewController(with account: Wallet, viewModel: TokensCardViewModel) -> TokensCardViewController {
let controller = TokensCardViewController(tokenObject: token, account: account, tokensStorage: tokensStorage, assetDefinitionStore: assetDefinitionStore, viewModel: viewModel)
let controller = TokensCardViewController(analyticsCoordinator: analyticsCoordinator, tokenObject: token, account: account, tokensStorage: tokensStorage, assetDefinitionStore: assetDefinitionStore, viewModel: viewModel)
controller.hidesBottomBarWhenPushed = true
controller.delegate = self
return controller
@ -224,7 +224,7 @@ class TokensCardCoordinator: NSObject, Coordinator {
private func makeRedeemTokensCardQuantitySelectionViewController(token: TokenObject, for tokenHolder: TokenHolder) -> RedeemTokenCardQuantitySelectionViewController {
let viewModel = RedeemTokenCardQuantitySelectionViewModel(token: token, tokenHolder: tokenHolder, assetDefinitionStore: assetDefinitionStore)
let controller = RedeemTokenCardQuantitySelectionViewController(token: token, viewModel: viewModel, assetDefinitionStore: assetDefinitionStore)
let controller = RedeemTokenCardQuantitySelectionViewController(analyticsCoordinator: analyticsCoordinator, token: token, viewModel: viewModel, assetDefinitionStore: assetDefinitionStore)
controller.configure()
controller.delegate = self
return controller
@ -232,7 +232,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(storage: tokensStorage, paymentFlow: paymentFlow, cryptoPrice: ethPrice, viewModel: viewModel, assetDefinitionStore: assetDefinitionStore)
let controller = EnterSellTokensCardPriceQuantityViewController(analyticsCoordinator: analyticsCoordinator, storage: tokensStorage, paymentFlow: paymentFlow, cryptoPrice: ethPrice, viewModel: viewModel, assetDefinitionStore: assetDefinitionStore)
controller.configure()
controller.delegate = self
return controller
@ -240,7 +240,7 @@ class TokensCardCoordinator: NSObject, Coordinator {
private func makeEnterTransferTokensCardExpiryDateViewController(token: TokenObject, for tokenHolder: TokenHolder, paymentFlow: PaymentFlow) -> SetTransferTokensCardExpiryDateViewController {
let viewModel = SetTransferTokensCardExpiryDateViewControllerViewModel(token: token, tokenHolder: tokenHolder, assetDefinitionStore: assetDefinitionStore)
let controller = SetTransferTokensCardExpiryDateViewController(tokenHolder: tokenHolder, paymentFlow: paymentFlow, viewModel: viewModel, assetDefinitionStore: assetDefinitionStore)
let controller = SetTransferTokensCardExpiryDateViewController(analyticsCoordinator: analyticsCoordinator, tokenHolder: tokenHolder, paymentFlow: paymentFlow, viewModel: viewModel, assetDefinitionStore: assetDefinitionStore)
controller.configure()
controller.delegate = self
return controller
@ -248,7 +248,7 @@ class TokensCardCoordinator: NSObject, Coordinator {
private func makeTransferTokensCardViaWalletAddressViewController(token: TokenObject, for tokenHolder: TokenHolder, paymentFlow: PaymentFlow) -> TransferTokensCardViaWalletAddressViewController {
let viewModel = TransferTokensCardViaWalletAddressViewControllerViewModel(token: token, tokenHolder: tokenHolder, assetDefinitionStore: assetDefinitionStore)
let controller = TransferTokensCardViaWalletAddressViewController(token: token, tokenHolder: tokenHolder, paymentFlow: paymentFlow, viewModel: viewModel, assetDefinitionStore: assetDefinitionStore)
let controller = TransferTokensCardViaWalletAddressViewController(analyticsCoordinator: analyticsCoordinator, token: token, tokenHolder: tokenHolder, paymentFlow: paymentFlow, viewModel: viewModel, assetDefinitionStore: assetDefinitionStore)
controller.configure()
controller.delegate = self
return controller
@ -256,7 +256,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(storage: tokensStorage, paymentFlow: paymentFlow, tokenHolder: tokenHolder, ethCost: ethCost, viewModel: viewModel, assetDefinitionStore: assetDefinitionStore)
let controller = SetSellTokensCardExpiryDateViewController(analyticsCoordinator: analyticsCoordinator, storage: tokensStorage, paymentFlow: paymentFlow, tokenHolder: tokenHolder, ethCost: ethCost, viewModel: viewModel, assetDefinitionStore: assetDefinitionStore)
controller.configure()
controller.delegate = self
return controller
@ -272,7 +272,7 @@ class TokensCardCoordinator: NSObject, Coordinator {
private func makeTransferTokensCardQuantitySelectionViewController(token: TokenObject, for tokenHolder: TokenHolder, paymentFlow: PaymentFlow) -> TransferTokensCardQuantitySelectionViewController {
let viewModel = TransferTokensCardQuantitySelectionViewModel(token: token, tokenHolder: tokenHolder, assetDefinitionStore: assetDefinitionStore)
let controller = TransferTokensCardQuantitySelectionViewController(paymentFlow: paymentFlow, token: token, viewModel: viewModel, assetDefinitionStore: assetDefinitionStore)
let controller = TransferTokensCardQuantitySelectionViewController(analyticsCoordinator: analyticsCoordinator, paymentFlow: paymentFlow, token: token, viewModel: viewModel, assetDefinitionStore: assetDefinitionStore)
controller.configure()
controller.delegate = self
return controller
@ -280,7 +280,7 @@ class TokensCardCoordinator: NSObject, Coordinator {
private func makeChooseTokenCardTransferModeViewController(token: TokenObject, for tokenHolder: TokenHolder, paymentFlow: PaymentFlow) -> ChooseTokenCardTransferModeViewController {
let viewModel = ChooseTokenCardTransferModeViewControllerViewModel(token: token, tokenHolder: tokenHolder, assetDefinitionStore: assetDefinitionStore)
let controller = ChooseTokenCardTransferModeViewController(tokenHolder: tokenHolder, paymentFlow: paymentFlow, viewModel: viewModel, assetDefinitionStore: assetDefinitionStore)
let controller = ChooseTokenCardTransferModeViewController(analyticsCoordinator: analyticsCoordinator, tokenHolder: tokenHolder, paymentFlow: paymentFlow, viewModel: viewModel, assetDefinitionStore: assetDefinitionStore)
controller.configure()
controller.delegate = self
return controller
@ -398,7 +398,7 @@ class TokensCardCoordinator: NSObject, Coordinator {
}
private func showTokenInstanceViewController(tokenHolder: TokenHolder, in viewController: TokensCardViewController) {
let vc = TokenInstanceViewController(tokenObject: token, tokenHolder: tokenHolder, account: session.account, tokensStorage: tokensStorage, assetDefinitionStore: assetDefinitionStore)
let vc = TokenInstanceViewController(analyticsCoordinator: analyticsCoordinator, tokenObject: token, tokenHolder: tokenHolder, account: session.account, tokensStorage: tokensStorage, assetDefinitionStore: assetDefinitionStore)
vc.delegate = self
vc.configure()
vc.navigationItem.largeTitleDisplayMode = .never
@ -407,7 +407,7 @@ class TokensCardCoordinator: NSObject, Coordinator {
}
private func showTokenInstanceActionView(forAction action: TokenInstanceAction, tokenHolder: TokenHolder, viewController: UIViewController) {
let vc = TokenInstanceActionViewController(tokenObject: token, tokenHolder: tokenHolder, tokensStorage: tokensStorage, assetDefinitionStore: assetDefinitionStore, action: action, session: session, keystore: keystore)
let vc = TokenInstanceActionViewController(analyticsCoordinator: analyticsCoordinator, tokenObject: token, tokenHolder: tokenHolder, tokensStorage: tokensStorage, assetDefinitionStore: assetDefinitionStore, action: action, session: session, keystore: keystore)
vc.delegate = self
vc.configure()
vc.navigationItem.largeTitleDisplayMode = .never

@ -18,10 +18,12 @@ protocol SignMessageCoordinatorDelegate: class {
}
class SignMessageCoordinator: Coordinator {
private let analyticsCoordinator: AnalyticsCoordinator
private let presentationNavigationController: UINavigationController
private let keystore: Keystore
private let account: AlphaWallet.Address
private var message: SignMessageType
private let source: Analytics.SignMessageRequestSource
var coordinators: [Coordinator] = []
weak var delegate: SignMessageCoordinatorDelegate?
@ -41,11 +43,13 @@ class SignMessageCoordinator: Coordinator {
return controller
}()
init(navigationController: UINavigationController, keystore: Keystore, account: AlphaWallet.Address, message: SignMessageType) {
init(analyticsCoordinator: AnalyticsCoordinator, navigationController: UINavigationController, keystore: Keystore, account: AlphaWallet.Address, message: SignMessageType, source: Analytics.SignMessageRequestSource) {
self.analyticsCoordinator = analyticsCoordinator
self.presentationNavigationController = navigationController
self.keystore = keystore
self.account = account
self.message = message
self.source = source
}
func start() {

@ -15,6 +15,7 @@ class ChooseTokenCardTransferModeViewController: UIViewController, TokenVerifiab
private let tokenRowView: TokenRowView & UIView
private let buttonsBar = ButtonsBar(configuration: .green(buttons: 2))
private var viewModel: ChooseTokenCardTransferModeViewControllerViewModel
private let analyticsCoordinator: AnalyticsCoordinator
private let tokenHolder: TokenHolder
var contract: AlphaWallet.Address {
@ -28,11 +29,13 @@ class ChooseTokenCardTransferModeViewController: UIViewController, TokenVerifiab
weak var delegate: ChooseTokenCardTransferModeViewControllerDelegate?
init(
analyticsCoordinator: AnalyticsCoordinator,
tokenHolder: TokenHolder,
paymentFlow: PaymentFlow,
viewModel: ChooseTokenCardTransferModeViewControllerViewModel,
assetDefinitionStore: AssetDefinitionStore
) {
self.analyticsCoordinator = analyticsCoordinator
self.tokenHolder = tokenHolder
self.paymentFlow = paymentFlow
self.viewModel = viewModel
@ -43,7 +46,7 @@ class ChooseTokenCardTransferModeViewController: UIViewController, TokenVerifiab
case .backedByOpenSea:
tokenRowView = OpenSeaNonFungibleTokenCardRowView(tokenView: .viewIconified)
case .notBackedByOpenSea:
tokenRowView = TokenCardRowView(server: viewModel.token.server, tokenView: .viewIconified, assetDefinitionStore: assetDefinitionStore)
tokenRowView = TokenCardRowView(analyticsCoordinator: analyticsCoordinator, server: viewModel.token.server, tokenView: .viewIconified, assetDefinitionStore: assetDefinitionStore)
}
super.init(nibName: nil, bundle: nil)

@ -24,6 +24,7 @@ class SetTransferTokensCardExpiryDateViewController: UIViewController, TokenVeri
private let noteBorderView = UIView()
private let buttonsBar = ButtonsBar(configuration: .green(buttons: 1))
private var viewModel: SetTransferTokensCardExpiryDateViewControllerViewModel
private let analyticsCoordinator: AnalyticsCoordinator
private let tokenHolder: TokenHolder
var contract: AlphaWallet.Address {
@ -38,11 +39,13 @@ class SetTransferTokensCardExpiryDateViewController: UIViewController, TokenVeri
// swiftlint:disable function_body_length
init(
analyticsCoordinator: AnalyticsCoordinator,
tokenHolder: TokenHolder,
paymentFlow: PaymentFlow,
viewModel: SetTransferTokensCardExpiryDateViewControllerViewModel,
assetDefinitionStore: AssetDefinitionStore
) {
self.analyticsCoordinator = analyticsCoordinator
self.tokenHolder = tokenHolder
self.paymentFlow = paymentFlow
self.viewModel = viewModel
@ -53,7 +56,7 @@ class SetTransferTokensCardExpiryDateViewController: UIViewController, TokenVeri
case .backedByOpenSea:
tokenRowView = OpenSeaNonFungibleTokenCardRowView(tokenView: .viewIconified)
case .notBackedByOpenSea:
tokenRowView = TokenCardRowView(server: viewModel.token.server, tokenView: .viewIconified, assetDefinitionStore: assetDefinitionStore)
tokenRowView = TokenCardRowView(analyticsCoordinator: analyticsCoordinator, server: viewModel.token.server, tokenView: .viewIconified, assetDefinitionStore: assetDefinitionStore)
}
super.init(nibName: nil, bundle: nil)

@ -24,15 +24,18 @@ class TransferTokensCardQuantitySelectionViewController: UIViewController, Token
return token.server
}
let assetDefinitionStore: AssetDefinitionStore
let analyticsCoordinator: AnalyticsCoordinator
let paymentFlow: PaymentFlow
weak var delegate: TransferTokenCardQuantitySelectionViewControllerDelegate?
init(
analyticsCoordinator: AnalyticsCoordinator,
paymentFlow: PaymentFlow,
token: TokenObject,
viewModel: TransferTokensCardQuantitySelectionViewModel,
assetDefinitionStore: AssetDefinitionStore
) {
self.analyticsCoordinator = analyticsCoordinator
self.paymentFlow = paymentFlow
self.token = token
self.viewModel = viewModel
@ -43,7 +46,7 @@ class TransferTokensCardQuantitySelectionViewController: UIViewController, Token
case .backedByOpenSea:
tokenRowView = OpenSeaNonFungibleTokenCardRowView(tokenView: .viewIconified)
case .notBackedByOpenSea:
tokenRowView = TokenCardRowView(server: token.server, tokenView: .viewIconified, assetDefinitionStore: assetDefinitionStore)
tokenRowView = TokenCardRowView(analyticsCoordinator: analyticsCoordinator, server: token.server, tokenView: .viewIconified, assetDefinitionStore: assetDefinitionStore)
}
super.init(nibName: nil, bundle: nil)

@ -9,6 +9,7 @@ protocol TransferTokensCardViaWalletAddressViewControllerDelegate: class, CanOpe
}
class TransferTokensCardViaWalletAddressViewController: UIViewController, TokenVerifiableStatusViewController {
private let analyticsCoordinator: AnalyticsCoordinator
private let token: TokenObject
private let roundedBackground = RoundedBackground()
private let header = TokensCardViewControllerTitleHeader()
@ -31,7 +32,8 @@ class TransferTokensCardViaWalletAddressViewController: UIViewController, TokenV
weak var delegate: TransferTokensCardViaWalletAddressViewControllerDelegate?
// swiftlint:disable function_body_length
init(token: TokenObject, tokenHolder: TokenHolder, paymentFlow: PaymentFlow, viewModel: TransferTokensCardViaWalletAddressViewControllerViewModel, assetDefinitionStore: AssetDefinitionStore) {
init(analyticsCoordinator: AnalyticsCoordinator, token: TokenObject, tokenHolder: TokenHolder, paymentFlow: PaymentFlow, viewModel: TransferTokensCardViaWalletAddressViewControllerViewModel, assetDefinitionStore: AssetDefinitionStore) {
self.analyticsCoordinator = analyticsCoordinator
self.token = token
self.tokenHolder = tokenHolder
self.paymentFlow = paymentFlow
@ -43,7 +45,7 @@ class TransferTokensCardViaWalletAddressViewController: UIViewController, TokenV
case .backedByOpenSea:
tokenRowView = OpenSeaNonFungibleTokenCardRowView(tokenView: .viewIconified)
case .notBackedByOpenSea:
tokenRowView = TokenCardRowView(server: token.server, tokenView: .viewIconified, assetDefinitionStore: assetDefinitionStore)
tokenRowView = TokenCardRowView(analyticsCoordinator: analyticsCoordinator, server: token.server, tokenView: .viewIconified, assetDefinitionStore: assetDefinitionStore)
}
super.init(nibName: nil, bundle: nil)

@ -8,6 +8,7 @@ protocol TokenCardRowViewDelegate: class {
}
class TokenCardRowView: UIView, TokenCardRowViewProtocol {
private let analyticsCoordinator: AnalyticsCoordinator
private let server: RPCServer
private let assetDefinitionStore: AssetDefinitionStore
private let tokenCountLabel = UILabel()
@ -59,7 +60,7 @@ class TokenCardRowView: UIView, TokenCardRowViewProtocol {
lazy var tokenScriptRendererView: TokenInstanceWebView = {
//TODO pass in keystore or wallet instead
let wallet = EtherKeystore.currentWallet
let webView = TokenInstanceWebView(server: server, wallet: wallet, assetDefinitionStore: assetDefinitionStore)
let webView = TokenInstanceWebView(analyticsCoordinator: analyticsCoordinator, server: server, wallet: wallet, assetDefinitionStore: assetDefinitionStore)
webView.delegate = self
return webView
}()
@ -98,7 +99,8 @@ class TokenCardRowView: UIView, TokenCardRowViewProtocol {
}
}
init(server: RPCServer, tokenView: TokenView, showCheckbox: Bool = false, assetDefinitionStore: AssetDefinitionStore) {
init(analyticsCoordinator: AnalyticsCoordinator, server: RPCServer, tokenView: TokenView, showCheckbox: Bool = false, assetDefinitionStore: AssetDefinitionStore) {
self.analyticsCoordinator = analyticsCoordinator
self.server = server
self.tokenView = tokenView
self.showCheckbox = showCheckbox

@ -9,18 +9,21 @@ import UIKit
import PromiseKit
private class SignMessageCoordinatorBridgeToPromise {
private let analyticsCoordinator: AnalyticsCoordinator
private let navigationController: UINavigationController
private let keystore: Keystore
private let coordinator: Coordinator?
private let source: Analytics.SignMessageRequestSource
private weak var signMessageCoordinator: SignMessageCoordinator?
private let (promise, seal) = Promise<Data>.pending()
private var retainCycle: SignMessageCoordinatorBridgeToPromise?
init(_ navigationController: UINavigationController, keystore: Keystore, coordinator: Coordinator?) {
init(analyticsCoordinator: AnalyticsCoordinator, navigationController: UINavigationController, keystore: Keystore, coordinator: Coordinator?, source: Analytics.SignMessageRequestSource) {
self.analyticsCoordinator = analyticsCoordinator
self.navigationController = navigationController
self.keystore = keystore
self.coordinator = coordinator
self.source = source
retainCycle = self
@ -35,10 +38,10 @@ private class SignMessageCoordinatorBridgeToPromise {
}
func promise(signType: SignMessageType, account: AlphaWallet.Address) -> Promise<Data> {
let coordinator = SignMessageCoordinator(navigationController: navigationController, keystore: keystore, account: account, message: signType)
let coordinator = SignMessageCoordinator(analyticsCoordinator: analyticsCoordinator, navigationController: navigationController, keystore: keystore, account: account, message: signType, source: source)
coordinator.delegate = self
coordinator.start()
self.signMessageCoordinator = coordinator
self.coordinator?.addCoordinator(coordinator)
@ -62,8 +65,8 @@ extension SignMessageCoordinatorBridgeToPromise: SignMessageCoordinatorDelegate
}
extension SignMessageCoordinator {
static func promise(_ navigationController: UINavigationController, keystore: Keystore, coordinator: Coordinator? = nil, signType: SignMessageType, account: AlphaWallet.Address) -> Promise<Data> {
let bridge = SignMessageCoordinatorBridgeToPromise(navigationController, keystore: keystore, coordinator: coordinator)
static func promise(analyticsCoordinator: AnalyticsCoordinator, navigationController: UINavigationController, keystore: Keystore, coordinator: Coordinator? = nil, signType: SignMessageType, account: AlphaWallet.Address, source: Analytics.SignMessageRequestSource) -> Promise<Data> {
let bridge = SignMessageCoordinatorBridgeToPromise(analyticsCoordinator: analyticsCoordinator, navigationController: navigationController, keystore: keystore, coordinator: coordinator, source: source)
return bridge.promise(signType: signType, account: account)
}
}

@ -210,7 +210,7 @@ extension WalletConnectCoordinator: WalletConnectServerDelegate {
private func signMessage(with type: SignMessageType, account: AlphaWallet.Address, callbackID id: WalletConnectRequestID, url: WalletConnectURL) -> Promise<WalletConnectServer.Callback> {
firstly {
SignMessageCoordinator.promise(navigationController, keystore: keystore, coordinator: self, signType: type, account: account)
SignMessageCoordinator.promise(analyticsCoordinator: analyticsCoordinator, navigationController: navigationController, keystore: keystore, coordinator: self, signType: type, account: account, source: .walletConnect)
}.map { data -> WalletConnectServer.Callback in
return .init(id: id, url: url, value: data)
}

Loading…
Cancel
Save