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

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

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

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

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

@ -31,7 +31,13 @@ class TokenCardRedemptionViewController: UIViewController, TokenVerifiableStatus
let assetDefinitionStore: AssetDefinitionStore let assetDefinitionStore: AssetDefinitionStore
weak var delegate: TokenCardRedemptionViewControllerDelegate? 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.session = session
self.token = token self.token = token
self.viewModel = viewModel self.viewModel = viewModel

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

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

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

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

@ -14,10 +14,10 @@ class ImportTokenViewControllerTests: FBSnapshotTestCase {
// func testImportTokenViewControllerDisplay() { // func testImportTokenViewControllerDisplay() {
// let config = Config() // let config = Config()
// let controller = ImportMagicTokenViewController(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 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 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.tokenHolder = tokenHolder
// viewModel.state = .promptImport // viewModel.state = .promptImport

Loading…
Cancel
Save