[Refactoring] clean code style

pull/6390/head
Krypto Pank 2 years ago
parent 5a873f4968
commit 4d6fd86c94
  1. 10
      AlphaWallet/Market/ImportMagicLinkController.swift
  2. 8
      AlphaWallet/Market/ViewControllers/ImportMagicTokenViewController.swift
  3. 50
      AlphaWallet/Market/ViewModels/ImportMagicTokenCardRowViewModel.swift
  4. 2
      AlphaWallet/Market/ViewModels/ImportMagicTokenViewControllerViewModel.swift
  5. 15
      AlphaWallet/Redeem/ViewControllers/RedeemTokenCardQuantitySelectionViewController.swift
  6. 8
      AlphaWallet/Redeem/ViewControllers/TokenCardRedemptionViewController.swift
  7. 19
      AlphaWallet/Sell/ViewControllers/SetSellTokensCardExpiryDateViewController.swift
  8. 17
      AlphaWallet/Transfer/ViewControllers/ChooseTokenCardTransferModeViewController.swift
  9. 17
      AlphaWallet/Transfer/ViewControllers/SetTransferTokensCardExpiryDateViewController.swift
  10. 19
      AlphaWallet/Transfer/ViewControllers/TransferTokensCardQuantitySelectionViewController.swift
  11. 4
      AlphaWalletTests/Market/ViewControllers/ImportTokenViewControllerTests.swift

@ -372,13 +372,13 @@ final class ImportMagicLinkController {
struct ViewState {
var url: URL?
var contract: AlphaWallet.Address?
var state: ImportMagicTokenViewControllerViewModel.State
var state: ImportMagicTokenViewModel.State
var tokenHolder: TokenHolder?
var count: Decimal?
var cost: ImportMagicTokenViewControllerViewModel.Cost?
var cost: ImportMagicTokenViewModel.Cost?
}
private func updateImportTokenState(with state: ImportMagicTokenViewControllerViewModel.State, cost: ImportMagicTokenViewControllerViewModel.Cost? = nil) {
private func updateImportTokenState(with state: ImportMagicTokenViewModel.State, cost: ImportMagicTokenViewModel.Cost? = nil) {
guard !hasCompleted else { return }
viewStateSubject.value.state = state
@ -393,7 +393,7 @@ final class ImportMagicLinkController {
hasCompleted = state.hasCompleted
}
private func promptImportUniversalLink(cost: ImportMagicTokenViewControllerViewModel.Cost) {
private func promptImportUniversalLink(cost: ImportMagicTokenViewModel.Cost) {
updateImportTokenState(with: .promptImport, cost: cost)
}
@ -401,7 +401,7 @@ final class ImportMagicLinkController {
updateImportTokenState(with: .succeeded)
}
private func showImportError(errorMessage: String, cost: ImportMagicTokenViewControllerViewModel.Cost? = nil) {
private func showImportError(errorMessage: String, cost: ImportMagicTokenViewModel.Cost? = nil) {
updateImportTokenState(with: .failed(errorMessage: errorMessage), cost: cost)
}

@ -25,7 +25,7 @@ class ImportMagicTokenViewController: UIViewController, OptionalTokenVerifiableS
private let dollarCostLabelLabel = UILabel()
private let dollarCostLabel = PaddedLabel()
private let buttonsBar = HorizontalButtonsBar(configuration: .custom(types: [.primary, .secondary]))
private (set) var viewModel: ImportMagicTokenViewControllerViewModel
private (set) var viewModel: ImportMagicTokenViewModel
let assetDefinitionStore: AssetDefinitionStore
weak var delegate: ImportMagicTokenViewControllerDelegate?
@ -54,7 +54,7 @@ class ImportMagicTokenViewController: UIViewController, OptionalTokenVerifiableS
assetDefinitionStore: AssetDefinitionStore,
keystore: Keystore,
session: WalletSession,
viewModel: ImportMagicTokenViewControllerViewModel) {
viewModel: ImportMagicTokenViewModel) {
self.viewModel = viewModel
self.analytics = analytics
@ -134,11 +134,11 @@ class ImportMagicTokenViewController: UIViewController, OptionalTokenVerifiableS
fatalError("init(coder:) has not been implemented")
}
func configure(viewModel: ImportMagicTokenViewControllerViewModel) {
func configure(viewModel: ImportMagicTokenViewModel) {
self.viewModel = viewModel
navigationItem.title = viewModel.headerTitle
tokenCardRowView.configure(viewModel: ImportMagicTokenCardRowViewModel(importMagicTokenViewControllerViewModel: viewModel, assetDefinitionStore: assetDefinitionStore))
tokenCardRowView.configure(viewModel: ImportMagicTokenCardRowViewModel(importMagicTokenViewModel: viewModel, assetDefinitionStore: assetDefinitionStore))
tokenCardRowView.isHidden = !viewModel.showTokenRow
tokenCardRowView.stateLabel.isHidden = true

@ -4,64 +4,64 @@ import Foundation
import AlphaWalletFoundation
struct ImportMagicTokenCardRowViewModel: TokenCardRowViewModelProtocol {
private var importMagicTokenViewControllerViewModel: ImportMagicTokenViewControllerViewModel
private var importMagicTokenViewModel: ImportMagicTokenViewModel
private let assetDefinitionStore: AssetDefinitionStore
init(importMagicTokenViewControllerViewModel: ImportMagicTokenViewControllerViewModel, assetDefinitionStore: AssetDefinitionStore) {
self.importMagicTokenViewControllerViewModel = importMagicTokenViewControllerViewModel
init(importMagicTokenViewModel: ImportMagicTokenViewModel, assetDefinitionStore: AssetDefinitionStore) {
self.importMagicTokenViewModel = importMagicTokenViewModel
self.assetDefinitionStore = assetDefinitionStore
}
var tokenHolder: TokenHolder? {
return importMagicTokenViewControllerViewModel.tokenHolder
return importMagicTokenViewModel.tokenHolder
}
var tokenCount: String {
return importMagicTokenViewControllerViewModel.tokenCount
return importMagicTokenViewModel.tokenCount
}
var city: String {
return importMagicTokenViewControllerViewModel.city
return importMagicTokenViewModel.city
}
var category: String {
return importMagicTokenViewControllerViewModel.category
return importMagicTokenViewModel.category
}
var teams: String {
return importMagicTokenViewControllerViewModel.teams
return importMagicTokenViewModel.teams
}
var match: String {
return importMagicTokenViewControllerViewModel.match
return importMagicTokenViewModel.match
}
var venue: String {
return importMagicTokenViewControllerViewModel.venue
return importMagicTokenViewModel.venue
}
var date: String {
return importMagicTokenViewControllerViewModel.date
return importMagicTokenViewModel.date
}
var numero: String {
return importMagicTokenViewControllerViewModel.numero
return importMagicTokenViewModel.numero
}
var time: String {
return importMagicTokenViewControllerViewModel.time
return importMagicTokenViewModel.time
}
var onlyShowTitle: Bool {
return importMagicTokenViewControllerViewModel.onlyShowTitle
return importMagicTokenViewModel.onlyShowTitle
}
var isMeetupContract: Bool {
return importMagicTokenViewControllerViewModel.tokenHolder?.isSpawnableMeetupContract ?? false
return importMagicTokenViewModel.tokenHolder?.isSpawnableMeetupContract ?? false
}
func subscribeBuilding(withBlock block: @escaping (String) -> Void) {
if let subscribable = importMagicTokenViewControllerViewModel.tokenHolder?.values.buildingSubscribableValue {
if let subscribable = importMagicTokenViewModel.tokenHolder?.values.buildingSubscribableValue {
subscribable.subscribe { value in
value?.stringValue.flatMap { block($0) }
}
@ -74,9 +74,9 @@ struct ImportMagicTokenCardRowViewModel: TokenCardRowViewModelProtocol {
let string = values.joined(separator: ", ")
block(string)
}
if let subscribable = importMagicTokenViewControllerViewModel.tokenHolder?.values.streetSubscribableValue {
if let subscribable = importMagicTokenViewModel.tokenHolder?.values.streetSubscribableValue {
subscribable.subscribe { value in
guard let tokenHolder = self.importMagicTokenViewControllerViewModel.tokenHolder else { return }
guard let tokenHolder = self.importMagicTokenViewModel.tokenHolder else { return }
if let value = value?.stringValue {
updateStreetLocalityStateCountry(
street: value,
@ -87,9 +87,9 @@ struct ImportMagicTokenCardRowViewModel: TokenCardRowViewModelProtocol {
}
}
}
if let subscribable = importMagicTokenViewControllerViewModel.tokenHolder?.values.stateSubscribableValue {
if let subscribable = importMagicTokenViewModel.tokenHolder?.values.stateSubscribableValue {
subscribable.subscribe { value in
guard let tokenHolder = self.importMagicTokenViewControllerViewModel.tokenHolder else { return }
guard let tokenHolder = self.importMagicTokenViewModel.tokenHolder else { return }
if let value = value?.stringValue {
updateStreetLocalityStateCountry(
street: tokenHolder.values.streetSubscribableStringValue,
@ -100,9 +100,9 @@ struct ImportMagicTokenCardRowViewModel: TokenCardRowViewModelProtocol {
}
}
}
if let subscribable = importMagicTokenViewControllerViewModel.tokenHolder?.values.localitySubscribableValue {
if let subscribable = importMagicTokenViewModel.tokenHolder?.values.localitySubscribableValue {
subscribable.subscribe { value in
guard let tokenHolder = self.importMagicTokenViewControllerViewModel.tokenHolder else { return }
guard let tokenHolder = self.importMagicTokenViewModel.tokenHolder else { return }
if let value = value?.stringValue {
updateStreetLocalityStateCountry(
street: tokenHolder.values.streetSubscribableStringValue,
@ -113,8 +113,8 @@ struct ImportMagicTokenCardRowViewModel: TokenCardRowViewModelProtocol {
}
}
}
if let country = importMagicTokenViewControllerViewModel.tokenHolder?.values.countryStringValue {
guard let tokenHolder = self.importMagicTokenViewControllerViewModel.tokenHolder else { return }
if let country = importMagicTokenViewModel.tokenHolder?.values.countryStringValue {
guard let tokenHolder = self.importMagicTokenViewModel.tokenHolder else { return }
updateStreetLocalityStateCountry(
street: tokenHolder.values.streetSubscribableStringValue,
locality: tokenHolder.values.localitySubscribableStringValue,
@ -125,7 +125,7 @@ struct ImportMagicTokenCardRowViewModel: TokenCardRowViewModelProtocol {
}
var tokenScriptHtml: String {
guard let tokenHolder = importMagicTokenViewControllerViewModel.tokenHolder else { return "" }
guard let tokenHolder = importMagicTokenViewModel.tokenHolder else { return "" }
let xmlHandler = XMLHandler(contract: tokenHolder.contractAddress, tokenType: tokenHolder.tokenType, assetDefinitionStore: assetDefinitionStore)
let (html: html, style: style) = xmlHandler.tokenViewIconifiedHtml

@ -3,7 +3,7 @@
import UIKit
import AlphaWalletFoundation
struct ImportMagicTokenViewControllerViewModel {
struct ImportMagicTokenViewModel {
enum State {
case validating
case promptImport

@ -54,14 +54,13 @@ class RedeemTokenCardQuantitySelectionViewController: UIViewController, TokenVer
let assetDefinitionStore: AssetDefinitionStore
weak var delegate: RedeemTokenCardQuantitySelectionViewControllerDelegate?
init(
analytics: AnalyticsLogger,
token: Token,
viewModel: RedeemTokenCardQuantitySelectionViewModel,
assetDefinitionStore: AssetDefinitionStore,
keystore: Keystore,
session: WalletSession
) {
init(analytics: AnalyticsLogger,
token: Token,
viewModel: RedeemTokenCardQuantitySelectionViewModel,
assetDefinitionStore: AssetDefinitionStore,
keystore: Keystore,
session: WalletSession) {
self.analytics = analytics
self.token = token
self.viewModel = viewModel

@ -31,7 +31,13 @@ class TokenCardRedemptionViewController: UIViewController, TokenVerifiableStatus
let assetDefinitionStore: AssetDefinitionStore
weak var delegate: TokenCardRedemptionViewControllerDelegate?
init(session: WalletSession, token: Token, viewModel: TokenCardRedemptionViewModel, assetDefinitionStore: AssetDefinitionStore, analytics: AnalyticsLogger, keystore: Keystore) {
init(session: WalletSession,
token: Token,
viewModel: TokenCardRedemptionViewModel,
assetDefinitionStore: AssetDefinitionStore,
analytics: AnalyticsLogger,
keystore: Keystore) {
self.session = session
self.token = token
self.viewModel = viewModel

@ -131,16 +131,15 @@ class SetSellTokensCardExpiryDateViewController: UIViewController, TokenVerifiab
}
// swiftlint:disable function_body_length
init(
analytics: AnalyticsLogger,
paymentFlow: PaymentFlow,
tokenHolder: TokenHolder,
ethCost: Double,
viewModel: SetSellTokensCardExpiryDateViewModel,
assetDefinitionStore: AssetDefinitionStore,
keystore: Keystore,
session: WalletSession
) {
init(analytics: AnalyticsLogger,
paymentFlow: PaymentFlow,
tokenHolder: TokenHolder,
ethCost: Double,
viewModel: SetSellTokensCardExpiryDateViewModel,
assetDefinitionStore: AssetDefinitionStore,
keystore: Keystore,
session: WalletSession) {
self.analytics = analytics
self.paymentFlow = paymentFlow
self.tokenHolder = tokenHolder

@ -27,15 +27,14 @@ class ChooseTokenCardTransferModeViewController: UIViewController, TokenVerifiab
let paymentFlow: PaymentFlow
weak var delegate: ChooseTokenCardTransferModeViewControllerDelegate?
init(
analytics: AnalyticsLogger,
tokenHolder: TokenHolder,
paymentFlow: PaymentFlow,
viewModel: ChooseTokenCardTransferModeViewModel,
assetDefinitionStore: AssetDefinitionStore,
keystore: Keystore,
session: WalletSession
) {
init(analytics: AnalyticsLogger,
tokenHolder: TokenHolder,
paymentFlow: PaymentFlow,
viewModel: ChooseTokenCardTransferModeViewModel,
assetDefinitionStore: AssetDefinitionStore,
keystore: Keystore,
session: WalletSession) {
self.analytics = analytics
self.tokenHolder = tokenHolder
self.paymentFlow = paymentFlow

@ -93,15 +93,14 @@ class SetTransferTokensCardExpiryDateViewController: UIViewController, TokenVeri
return view
}()
init(
analytics: AnalyticsLogger,
tokenHolder: TokenHolder,
paymentFlow: PaymentFlow,
viewModel: SetTransferTokensCardExpiryDateViewModel,
assetDefinitionStore: AssetDefinitionStore,
keystore: Keystore,
session: WalletSession
) {
init(analytics: AnalyticsLogger,
tokenHolder: TokenHolder,
paymentFlow: PaymentFlow,
viewModel: SetTransferTokensCardExpiryDateViewModel,
assetDefinitionStore: AssetDefinitionStore,
keystore: Keystore,
session: WalletSession) {
self.analytics = analytics
self.tokenHolder = tokenHolder
self.paymentFlow = paymentFlow

@ -44,21 +44,20 @@ class TransferTokensCardQuantitySelectionViewController: UIViewController, Token
let paymentFlow: PaymentFlow
weak var delegate: TransferTokenCardQuantitySelectionViewControllerDelegate?
init(
analytics: AnalyticsLogger,
paymentFlow: PaymentFlow,
token: Token,
viewModel: TransferTokensCardQuantitySelectionViewModel,
assetDefinitionStore: AssetDefinitionStore,
keystore: Keystore,
wallet: Wallet
) {
init(analytics: AnalyticsLogger,
paymentFlow: PaymentFlow,
token: Token,
viewModel: TransferTokensCardQuantitySelectionViewModel,
assetDefinitionStore: AssetDefinitionStore,
keystore: Keystore,
wallet: Wallet) {
self.analytics = analytics
self.paymentFlow = paymentFlow
self.token = token
self.viewModel = viewModel
self.assetDefinitionStore = assetDefinitionStore
let tokenType = OpenSeaBackedNonFungibleTokenHandling(token: token, assetDefinitionStore: assetDefinitionStore, tokenViewType: .viewIconified)
switch tokenType {
case .backedByOpenSea:

@ -14,10 +14,10 @@ class ImportTokenViewControllerTests: FBSnapshotTestCase {
// func testImportTokenViewControllerDisplay() {
// let config = Config()
// let controller = ImportMagicTokenViewController(config: config)
// var viewModel: ImportMagicTokenViewControllerViewModel = .init(state: .validating, server: config.server)
// var viewModel: ImportMagicTokenViewModel = .init(state: .validating, server: config.server)
// let token = Token(id: "1", index: 1, name: "", status: .available, values: ["locality": "", "venue": "", "match": 9, "time": GeneralisedTime(string: "20010203160500+0300")!, "numero": 1, "category": "MATCH CLUB", "countryA": "Team A", "countryB": "Team B"])
// let tokenHolder = TokenHolder(tokens: [token], contractAddress: "0x1", hasAssetDefinition: true)
// let cost: ImportMagicTokenViewControllerViewModel.Cost = .paid(eth: Decimal(1), dollar: Decimal(400))
// let cost: ImportMagicTokenViewModel.Cost = .paid(eth: Decimal(1), dollar: Decimal(400))
// viewModel.tokenHolder = tokenHolder
// viewModel.state = .promptImport

Loading…
Cancel
Save