SwiftFormat

master
Hwee-Boon Yar 4 months ago
parent 7e43aebf57
commit 0aebcd12a8
  1. 19
      AlphaWallet/Common/Services/Application.swift
  2. 2
      AlphaWallet/Settings/ViewModels/ServerViewModel.swift
  3. 18
      AlphaWallet/Tokens/Collectibles/ViewModels/FungibleTokenHeaderViewModel.swift
  4. 10
      AlphaWallet/Tokens/ViewControllers/TokensViewController.swift
  5. 10
      AlphaWallet/Tokens/ViewModels/AttestationViewCellViewModel.swift
  6. 21
      AlphaWallet/Tokens/ViewModels/EthTokenViewCellViewModel.swift
  7. 21
      AlphaWallet/Tokens/ViewModels/FungibleTokenViewCellViewModel.swift
  8. 13
      AlphaWallet/Tokens/ViewModels/NonFungibleTokenViewCellViewModel.swift
  9. 8
      AlphaWallet/Tokens/ViewModels/OpenSea/OpenSeaNonFungibleTokenViewCellViewModel.swift
  10. 51
      AlphaWallet/Tokens/ViewModels/TokensViewModel.swift
  11. 11
      AlphaWallet/Tokens/ViewModels/WalletTokenViewCellViewModel.swift
  12. 4
      AlphaWallet/Tokens/Views/OpenSea/OpenSeaNonFungibleTokenViewCell.swift
  13. 15
      modules/AlphaWalletFoundation/AlphaWalletFoundation/Tokens/Helpers/JsonFromTokenUri.swift
  14. 3
      modules/AlphaWalletFoundation/AlphaWalletFoundation/Tokens/TokensService.swift
  15. 11
      modules/AlphaWalletFoundation/AlphaWalletFoundation/Tokens/Types/TokenViewModel.swift
  16. 7
      modules/AlphaWalletFoundation/AlphaWalletFoundation/Types/WalletBalance.swift

@ -7,13 +7,14 @@
import Combine
import UIKit
import AlphaWalletAddress
import AlphaWalletCore
import AlphaWalletFoundation
import AlphaWalletLogger
import AlphaWalletTrackAPICalls
import AlphaWalletNotifications
import AlphaWalletTokenScript
import AlphaWalletTrackAPICalls
extension TokenScript {
static let baseTokenScriptFiles: [TokenType: String] = [
@ -134,8 +135,8 @@ class Application: WalletDependenciesProvidable {
self.tokenGroupIdentifier = TokenGroupIdentifier.identifier(tokenJsonUrl: R.file.tokensJson()!)!
self.systemSettingsRequestableDelegate = SystemSettingsRequestableDelegate()
self.blockchainsProvider = BlockchainsProviderImplementation(
serversProvider: serversProvider,
blockchainFactory: BaseBlockchainFactory(analytics: analytics))
serversProvider: serversProvider,
blockchainFactory: BaseBlockchainFactory(analytics: analytics))
let tokenScriptFeatures = TokenScriptFeatures()
Self.copyFeatures(Features.current, toTokenScriptFeatures: tokenScriptFeatures)
self.tokenScriptFeatures = tokenScriptFeatures
@ -208,12 +209,12 @@ class Application: WalletDependenciesProvidable {
self.shortcutHandler = ShortcutHandler()
self.launchOptionsService = LaunchOptionsService(handlers: [
shortcutHandler,
PushNotificationLaunchOptionsHandler(pushNotificationsService: pushNotificationsService)
PushNotificationLaunchOptionsHandler(pushNotificationsService: pushNotificationsService),
])
self.donationUserActivityHandler = DonationUserActivityHandler(analytics: analytics)
self.userActivityService = UserActivityService(handlers: [
donationUserActivityHandler
donationUserActivityHandler,
])
Features.delegate = self
@ -395,7 +396,7 @@ class Application: WalletDependenciesProvidable {
ReportUsersActiveChains(serversProvider: serversProvider),
MigrateToSupportEip1559Transactions(
serversProvider: serversProvider,
keychain: keystore)
keychain: keystore),
]
services.forEach { $0.perform() }
}
@ -419,7 +420,7 @@ class Application: WalletDependenciesProvidable {
}
func buildDependencies(for wallet: Wallet) -> WalletDependencies {
if let dep = dependencies[wallet] { return dep }
if let dep = dependencies[wallet] { return dep }
let tokensDataStore: TokensDataStore = MultipleChainsTokensDataStore(store: .storage(for: wallet))
let eventsDataStore: NonActivityEventsDataStore = NonActivityMultiChainEventsDataStore(store: .storage(for: wallet))
@ -539,7 +540,7 @@ extension Application: WalletApiCoordinatorDelegate {
}
}
extension Application: ShortcutNavigatable { }
extension Application: ShortcutNavigatable {}
extension Application: FeaturesDelegate {
func featuresModified(_ features: Features) {
@ -585,7 +586,6 @@ extension AlphaWalletNotificationHandler {
static func instance(dependencies: WalletDependenciesProvidable,
navigationHandler: ApplicationNavigationHandler,
keystore: Keystore) -> NotificationHandler {
return AlphaWalletNotificationHandler(
application: .shared,
notificationCenter: .default,
@ -599,7 +599,6 @@ extension BasePushNotificationsService {
static func instance(keystore: Keystore,
notificationHandler: NotificationHandler,
systemSettingsRequestable: SystemSettingsRequestable) -> PushNotificationsService {
let unUserNotificationService = UNUserNotificationsService(
application: .shared,
systemSettingsRequestable: systemSettingsRequestable)

@ -2,6 +2,7 @@
import Foundation
import UIKit
import AlphaWalletFoundation
protocol ServerTableViewCellViewModelType {
@ -32,7 +33,6 @@ protocol ServerImageTableViewCellViewModelType {
}
struct ServerImageViewModel: ServerImageTableViewCellViewModelType, Hashable {
let isSelected: Bool
let server: RPCServerOrAuto
let isTopSeparatorHidden: Bool

@ -5,8 +5,9 @@
// Created by Vladyslav Shepitko on 20.05.2022.
//
import UIKit
import Combine
import UIKit
import AlphaWalletFoundation
struct FungibleTokenHeaderViewModelInput {
@ -38,7 +39,6 @@ final class FungibleTokenHeaderViewModel {
init(token: Token,
tokensService: TokensProcessingPipeline,
tokenImageFetcher: TokenImageFetcher) {
self.tokenImageFetcher = tokenImageFetcher
self.token = token
self.tokensService = tokensService
@ -70,7 +70,7 @@ final class FungibleTokenHeaderViewModel {
private func runRefreshHeaderTimer() {
let timer = Timer(timeInterval: headerViewRefreshInterval, repeats: true) { [weak self] _ in
self?.tiggleIsShowingValue()
self?.tiggleIsShowingValue()
}
RunLoop.main.add(timer, forMode: .default)
@ -143,21 +143,21 @@ fileprivate extension FungibleTokenHeaderViewModel.functional {
return NSAttributedString(string: R.string.localizable.aWalletTokenValue(string), attributes: [
.font: Screen.TokenCard.Font.placeholderLabel,
.foregroundColor: Configuration.Color.Semantic.defaultSubtitleText
.foregroundColor: Configuration.Color.Semantic.defaultSubtitleText,
])
}
static var testnetValueHintLabelAttributedString: NSAttributedString {
return NSAttributedString(string: R.string.localizable.tokenValueTestnetWarning(), attributes: [
.font: Screen.TokenCard.Font.placeholderLabel,
.foregroundColor: Configuration.Color.Semantic.defaultSubtitleText
.foregroundColor: Configuration.Color.Semantic.defaultSubtitleText,
])
}
static func asTitleAttributedString(_ title: String) -> NSAttributedString {
return NSAttributedString(string: title, attributes: [
.font: Fonts.regular(size: ScreenChecker().isNarrowScreen ? 26 : 36),
.foregroundColor: Configuration.Color.Semantic.defaultForegroundText
.foregroundColor: Configuration.Color.Semantic.defaultForegroundText,
])
}
@ -172,13 +172,13 @@ fileprivate extension FungibleTokenHeaderViewModel.functional {
let mutableAttributedString = NSMutableAttributedString(string: string, attributes: [
.font: Screen.TokenCard.Font.placeholderLabel,
.foregroundColor: Configuration.Color.Semantic.defaultSubtitleText
.foregroundColor: Configuration.Color.Semantic.defaultSubtitleText,
])
let range = NSRange(valuePercentageChangeRange, in: string)
mutableAttributedString.setAttributes([
.font: Fonts.semibold(size: ScreenChecker().isNarrowScreen ? 14 : 17),
.foregroundColor: Screen.TokenCard.Color.valueChangeValue(ticker: balance.ticker)
.foregroundColor: Screen.TokenCard.Color.valueChangeValue(ticker: balance.ticker),
], range: range)
return mutableAttributedString
@ -205,4 +205,4 @@ fileprivate extension FungibleTokenHeaderViewModel.functional {
}
}
extension FungibleTokenHeaderViewModel.ViewState: Equatable { }
extension FungibleTokenHeaderViewModel.ViewState: Equatable {}

@ -1,10 +1,10 @@
// Copyright © 2018 Stormbird PTE. LTD.
import UIKit
import Combine
import AlphaWalletAttestation
import AlphaWalletFoundation
import AlphaWalletLogger
import Combine
import UIKit
protocol TokensViewControllerDelegate: AnyObject {
func viewWillAppear(in viewController: UIViewController)
@ -409,14 +409,12 @@ extension TokensViewController: UITableViewDelegate {
}
extension TokensViewController: ActiveWalletSessionViewDelegate {
func view(_ view: ActiveWalletSessionView, didSelectTap sender: UITapGestureRecognizer) {
delegate?.walletConnectSelected(in: self)
}
}
extension TokensViewController {
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return viewModel.cellHeight(for: indexPath)
}
@ -526,7 +524,7 @@ extension TokensViewController {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { [filterView] in
//Important to update the segmented control (and hence add the segmented control back to the table) after they have been re-added to the table header through the table reload. Otherwise adding to the table header will break the animation for segmented control
if let selection = selection, case let ControlSelection.selected(index) = selection {
if let selection = selection, case ControlSelection.selected(let index) = selection {
filterView.setSelection(cellIndex: Int(index))
}
}
@ -545,7 +543,6 @@ extension TokensViewController {
}
extension TokensViewController: UISearchControllerDelegate {
func didDismissSearchController(_ searchController: UISearchController) {
guard viewModel.isSearchActive else { return }
@ -591,7 +588,6 @@ extension TokensViewController: UISearchResultsUpdating {
}
extension TokensViewController: OpenSeaNonFungibleTokenPairTableCellDelegate {
func didSelect(cell: OpenSeaNonFungibleTokenPairTableCell, indexPath: IndexPath, isLeftCardSelected: Bool) {
selection.send(.gridItem(indexPath: indexPath, isLeftCardSelected: isLeftCardSelected))
}

@ -1,8 +1,9 @@
// Copyright © 2023 Stormbird PTE. LTD.
import Combine
import AlphaWalletAttestation
import AlphaWalletFoundation
import Combine
struct AttestationViewCellViewModel {
private let attestation: Attestation
@ -36,8 +37,7 @@ struct AttestationViewCellViewModel {
}
}
extension AttestationViewCellViewModel: Hashable {
}
extension AttestationViewCellViewModel: Hashable {}
extension AttestationViewCellViewModel {
enum functional {}
@ -57,7 +57,7 @@ fileprivate extension AttestationViewCellViewModel.functional {
}
return NSAttributedString(string: subtitle.trimmed, attributes: [
.foregroundColor: Configuration.Color.Semantic.defaultSubtitleText,
.font: Screen.TokenCard.Font.subtitle
.font: Screen.TokenCard.Font.subtitle,
])
}
@ -65,7 +65,7 @@ fileprivate extension AttestationViewCellViewModel.functional {
let name = assetDefinitionStore.xmlHandler(forAttestation: attestation)?.getAttestationName() ?? attestation.name
return NSAttributedString(string: name, attributes: [
.foregroundColor: Configuration.Color.Semantic.defaultForegroundText,
.font: Screen.TokenCard.Font.title
.font: Screen.TokenCard.Font.title,
])
}
}

@ -1,10 +1,12 @@
// Copyright © 2018 Stormbird PTE. LTD.
import Combine
import Foundation
import UIKit
import BigInt
import AlphaWalletFoundation
import Combine
import BigInt
struct EthTokenViewCellViewModel: TokenIdentifiable {
private let safeShortTitleInPluralForm: String
@ -25,7 +27,6 @@ struct EthTokenViewCellViewModel: TokenIdentifiable {
isVisible: Bool = true,
accessoryType: UITableViewCell.AccessoryType = .none,
tokenImageFetcher: TokenImageFetcher) {
self.type = token.type
self.safeShortTitleInPluralForm = token.tokenScriptOverrides?.safeShortTitleInPluralForm ?? ""
self.amountShort = token.balance.amountShort
@ -43,14 +44,14 @@ struct EthTokenViewCellViewModel: TokenIdentifiable {
var titleAttributedString: NSAttributedString {
return NSAttributedString(string: safeShortTitleInPluralForm, attributes: [
.foregroundColor: Configuration.Color.Semantic.defaultForegroundText,
.font: Screen.TokenCard.Font.title
.font: Screen.TokenCard.Font.title,
])
}
var cryptoValueAttributedString: NSAttributedString {
return NSAttributedString(string: amountShort + " " + symbolInPluralForm, attributes: [
.foregroundColor: Configuration.Color.Semantic.defaultSubtitleText,
.font: Screen.TokenCard.Font.subtitle
.font: Screen.TokenCard.Font.subtitle,
])
}
@ -92,7 +93,7 @@ struct EthTokenViewCellViewModel: TokenIdentifiable {
return NSAttributedString(string: changePercentage, attributes: [
.foregroundColor: valuePercentageChangeColor,
.font: Screen.TokenCard.Font.valueChangeLabel
.font: Screen.TokenCard.Font.valueChangeLabel,
])
}
@ -110,7 +111,7 @@ struct EthTokenViewCellViewModel: TokenIdentifiable {
var priceChangeAttributedString: NSAttributedString {
return NSAttributedString(string: priceChange, attributes: [
.foregroundColor: valuePercentageChangeColor,
.font: Screen.TokenCard.Font.valueChangeLabel
.font: Screen.TokenCard.Font.valueChangeLabel,
])
}
@ -129,7 +130,7 @@ struct EthTokenViewCellViewModel: TokenIdentifiable {
return NSAttributedString(string: amountAccordingRPCServer ?? UiTweaks.noPriceMarker, attributes: [
.foregroundColor: Configuration.Color.Semantic.defaultForegroundText,
.font: Screen.TokenCard.Font.valueChangeValue
.font: Screen.TokenCard.Font.valueChangeValue,
])
}
@ -152,7 +153,7 @@ struct EthTokenViewCellViewModel: TokenIdentifiable {
func fiatValueAttributedString(currencyAmount: String?) -> NSAttributedString {
return NSAttributedString(string: amountAccordingRPCServer(currencyAmount: currencyAmount) ?? "-", attributes: [
.foregroundColor: Screen.TokenCard.Color.title,
.font: Screen.TokenCard.Font.valueChangeValue
.font: Screen.TokenCard.Font.valueChangeValue,
])
}
@ -176,7 +177,7 @@ struct EthTokenViewCellViewModel: TokenIdentifiable {
}
}
extension EthTokenViewCellViewModel: Hashable { }
extension EthTokenViewCellViewModel: Hashable {}
extension AnyPublisher: Equatable {
public static func == (lhs: AnyPublisher, rhs: AnyPublisher) -> Bool {

@ -1,8 +1,9 @@
// Copyright © 2018 Stormbird PTE. LTD.
import Combine
import UIKit
import AlphaWalletFoundation
import Combine
struct FungibleTokenViewCellViewModel: TokenIdentifiable {
private let safeShortTitleInPluralForm: String
@ -18,11 +19,7 @@ struct FungibleTokenViewCellViewModel: TokenIdentifiable {
let iconImage: TokenImagePublisher
let accessoryType: UITableViewCell.AccessoryType
init(token: TokenViewModel,
isVisible: Bool = true,
accessoryType: UITableViewCell.AccessoryType = .none,
tokenImageFetcher: TokenImageFetcher) {
init(token: TokenViewModel, isVisible: Bool = true, accessoryType: UITableViewCell.AccessoryType = .none, tokenImageFetcher: TokenImageFetcher) {
self.type = token.type
self.safeShortTitleInPluralForm = token.tokenScriptOverrides?.safeShortTitleInPluralForm ?? ""
self.amountShort = token.balance.amountShort
@ -39,14 +36,14 @@ struct FungibleTokenViewCellViewModel: TokenIdentifiable {
var titleAttributedString: NSAttributedString {
return NSAttributedString(string: safeShortTitleInPluralForm, attributes: [
.foregroundColor: Configuration.Color.Semantic.defaultForegroundText,
.font: Screen.TokenCard.Font.title
.font: Screen.TokenCard.Font.title,
])
}
var cryptoValueAttributedString: NSAttributedString {
return NSAttributedString(string: amountShort + " " + symbolInPluralForm, attributes: [
.foregroundColor: Configuration.Color.Semantic.defaultSubtitleText,
.font: Screen.TokenCard.Font.subtitle
.font: Screen.TokenCard.Font.subtitle,
])
}
@ -90,7 +87,7 @@ struct FungibleTokenViewCellViewModel: TokenIdentifiable {
return NSAttributedString(string: apprecation24hours, attributes: [
.foregroundColor: valuePercentageChangeColor,
.font: Screen.TokenCard.Font.valueChangeLabel
.font: Screen.TokenCard.Font.valueChangeLabel,
])
}
@ -118,7 +115,7 @@ struct FungibleTokenViewCellViewModel: TokenIdentifiable {
var priceChangeAttributedString: NSAttributedString {
return NSAttributedString(string: priceChange, attributes: [
.foregroundColor: valuePercentageChangeColor,
.font: Screen.TokenCard.Font.valueChangeLabel
.font: Screen.TokenCard.Font.valueChangeLabel,
])
}
@ -135,7 +132,7 @@ struct FungibleTokenViewCellViewModel: TokenIdentifiable {
return NSAttributedString(string: fiatValue, attributes: [
.foregroundColor: Configuration.Color.Semantic.defaultForegroundText,
.font: Screen.TokenCard.Font.valueChangeValue
.font: Screen.TokenCard.Font.valueChangeValue,
])
}
@ -148,4 +145,4 @@ struct FungibleTokenViewCellViewModel: TokenIdentifiable {
}
}
extension FungibleTokenViewCellViewModel: Hashable { }
extension FungibleTokenViewCellViewModel: Hashable {}

@ -1,10 +1,12 @@
// Copyright © 2018 Stormbird PTE. LTD.
import Combine
import Foundation
import UIKit
import BigInt
import AlphaWalletFoundation
import Combine
import BigInt
struct NonFungibleTokenViewCellViewModel: TokenIdentifiable {
private let safeShortTitleInPluralForm: String
@ -22,7 +24,6 @@ struct NonFungibleTokenViewCellViewModel: TokenIdentifiable {
isVisible: Bool = true,
accessoryType: UITableViewCell.AccessoryType = .none,
tokenImageFetcher: TokenImageFetcher) {
self.type = token.type
self.contractAddress = token.contractAddress
self.server = token.server
@ -41,14 +42,14 @@ struct NonFungibleTokenViewCellViewModel: TokenIdentifiable {
var titleAttributedString: NSAttributedString {
return .init(string: safeShortTitleInPluralForm, attributes: [
.font: Screen.TokenCard.Font.title,
.foregroundColor: Configuration.Color.Semantic.defaultForegroundText
.foregroundColor: Configuration.Color.Semantic.defaultForegroundText,
])
}
var tickersAmountAttributedString: NSAttributedString {
return .init(string: "\(nonZeroBalanceCount) \(symbol)", attributes: [
.font: Screen.TokenCard.Font.subtitle,
.foregroundColor: Configuration.Color.Semantic.defaultSubtitleText
.foregroundColor: Configuration.Color.Semantic.defaultSubtitleText,
])
}
@ -62,4 +63,4 @@ struct NonFungibleTokenViewCellViewModel: TokenIdentifiable {
}
extension NonFungibleTokenViewCellViewModel: Hashable { }
extension NonFungibleTokenViewCellViewModel: Hashable {}

@ -1,9 +1,10 @@
// Copyright © 2018 Stormbird PTE. LTD.
import Combine
import Foundation
import UIKit
import AlphaWalletFoundation
import Combine
struct OpenSeaNonFungibleTokenViewCellViewModel {
private let token: TokenViewModel
@ -11,21 +12,20 @@ struct OpenSeaNonFungibleTokenViewCellViewModel {
var assetsCountAttributedString: NSAttributedString {
return .init(string: "\(token.nonZeroBalance.count.toString()) \(token.symbol)", attributes: [
.font: Fonts.regular(size: 15),
.foregroundColor: Configuration.Color.Semantic.defaultSubtitleText
.foregroundColor: Configuration.Color.Semantic.defaultSubtitleText,
])
}
var titleAttributedString: NSAttributedString {
return .init(string: token.tokenScriptOverrides?.titleInPluralForm ?? "", attributes: [
.font: Fonts.regular(size: 20),
.foregroundColor: Configuration.Color.Semantic.defaultForegroundText
.foregroundColor: Configuration.Color.Semantic.defaultForegroundText,
])
}
let tokenIcon: TokenImagePublisher
init(token: TokenViewModel,
tokenImageFetcher: TokenImageFetcher) {
self.token = token
self.tokenIcon = tokenImageFetcher.image(token: token, size: .s750)
}

@ -1,8 +1,9 @@
// Copyright © 2018 Stormbird PTE. LTD.
import Combine
import Foundation
import UIKit
import Combine
import AlphaWalletAttestation
import AlphaWalletCore
import AlphaWalletFoundation
@ -111,7 +112,7 @@ final class TokensViewModel {
}
var shouldShowBackupPromptViewHolder: Bool {
//TODO show the prompt in both ASSETS and COLLECTIBLES tab too
//TODO show the prompt in both ASSETS and COLLECTIBLES tab too
switch filterInUserInterface {
case .all, .keyword:
return true
@ -256,7 +257,7 @@ final class TokensViewModel {
.map { $0 ?? wallet.address.truncateMiddle }
.eraseToAnyPublisher()
}.prepend(wallet.address.truncateMiddle)
.eraseToAnyPublisher()
.eraseToAnyPublisher()
}
private func pullToRefreshState(input pullToRefresh: AnyPublisher<Void, Never>) -> AnyPublisher<RefreshControlState, Never> {
@ -438,24 +439,24 @@ final class TokensViewModel {
return tokenOrServer(at: current.next).isRemovable
}()
switch (canRemovePreviousItem, canRemoveCurrentItem, canRemoveNextItem) {
// Truth table for deletion
// previous, current, next
// 0, 0, 0
// return []
// 0, 0, 1
// return []
// 0, 1, 0
// return [current.previous, current]
// 0, 1, 1
// return [current]
// 1, 0, 0
// return []
// 1, 0, 1
// return []
// 1, 1, 0
// return [current]
// 1, 1, 1
// return [current]
// Truth table for deletion
// previous, current, next
// 0, 0, 0
// return []
// 0, 0, 1
// return []
// 0, 1, 0
// return [current.previous, current]
// 0, 1, 1
// return [current]
// 1, 0, 0
// return []
// 1, 0, 1
// return []
// 1, 1, 0
// return [current]
// 1, 1, 1
// return [current]
case (_, false, _):
return []
case (false, true, false):
@ -641,9 +642,9 @@ extension TokensViewModel {
}
}
extension TokensViewModel.ViewState: Hashable { }
extension TokensViewModel.SectionViewModel: Hashable { }
extension TokensViewModel.ViewModelType: Hashable { }
extension TokensViewModel.ViewState: Hashable {}
extension TokensViewModel.SectionViewModel: Hashable {}
extension TokensViewModel.ViewModelType: Hashable {}
extension WalletFilter {
static var orderedTabs: [WalletFilter] {
@ -766,7 +767,7 @@ fileprivate extension TokensViewModel.functional {
return TokensViewModel.SectionViewModel(section: section, views: [])
}
let viewModels = (0 ..< numberOfItems).map { row -> TokensViewModel.ViewModelType in
let viewModels = (0..<numberOfItems).map { row -> TokensViewModel.ViewModelType in
let indexPath = IndexPath(row: row, section: sectionIndex)
return TokensViewModel.functional.viewModel(for: indexPath, sections: sections, filteredTokens: filteredTokens, collectiblePairs: collectiblePairs, tokenImageFetcher: tokenImageFetcher, assetDefinitionStore: assetDefinitionStore)
}

@ -5,10 +5,12 @@
// Created by Vladyslav Shepitko on 07.06.2021.
//
import Combine
import UIKit
import BigInt
import AlphaWalletFoundation
import Combine
import BigInt
struct WalletTokenViewCellViewModel {
private let token: TokenViewModel
@ -18,7 +20,6 @@ struct WalletTokenViewCellViewModel {
init(token: TokenViewModel,
isVisible: Bool = true,
tokenImageFetcher: TokenImageFetcher) {
self.tokenImageFetcher = tokenImageFetcher
self.token = token
self.isVisible = isVisible
@ -27,14 +28,14 @@ struct WalletTokenViewCellViewModel {
var cryptoValueAttributedString: NSAttributedString {
return NSAttributedString(string: String(), attributes: [
.foregroundColor: Screen.TokenCard.Color.title,
.font: Screen.TokenCard.Font.title
.font: Screen.TokenCard.Font.title,
])
}
var titleAttributedString: NSAttributedString {
return NSAttributedString(string: token.tokenScriptOverrides?.safeShortTitleInPluralForm ?? "", attributes: [
.foregroundColor: Configuration.Color.Semantic.defaultForegroundText,
.font: Screen.TokenCard.Font.title
.font: Screen.TokenCard.Font.title,
])
}

@ -58,7 +58,7 @@ class OpenSeaNonFungibleTokenView: UIView {
background.anchorsConstraint(to: self, edgeInsets: .zero),
stackView.anchorsConstraint(to: background),
tokenImageView.anchorsConstraint(to: imageHolder)
tokenImageView.anchorsConstraint(to: imageHolder),
])
translatesAutoresizingMaskIntoConstraints = false
@ -149,7 +149,7 @@ class OpenSeaNonFungibleTokenPairTableCell: UITableViewCell {
right.bottomAnchor.constraint(equalTo: background.bottomAnchor),
right.widthAnchor.constraint(equalToConstant: cellSize.width),
right.leadingAnchor.constraint(equalTo: left.trailingAnchor, constant: 16)
right.leadingAnchor.constraint(equalTo: left.trailingAnchor, constant: 16),
])
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(cellSelected))

@ -5,14 +5,14 @@
// Created by Vladyslav Shepitko on 20.07.2022.
//
import Foundation
import AlphaWalletCore
import AlphaWalletLogger
import AlphaWalletOpenSea
import AlphaWalletWeb3
import SwiftyJSON
import Combine
import BigInt
import Combine
import Foundation
import SwiftyJSON
final class JsonFromTokenUri {
typealias Publisher = AnyPublisher<NonFungibleBalanceAndItsSource<JsonString>, SessionTaskError>
@ -28,7 +28,6 @@ final class JsonFromTokenUri {
public init(blockchainProvider: BlockchainProvider,
tokensDataStore: TokensDataStore,
transporter: ApiTransporter) {
self.transporter = transporter
self.blockchainProvider = blockchainProvider
self.tokensDataStore = tokensDataStore
@ -36,7 +35,7 @@ final class JsonFromTokenUri {
self.uriMapper = TokenUriMapper(hostMappers: [
HostBasedTokenUriMapper(host: "api.mintkudos.xyz"),
HostBasedTokenUriMapper(host: "api.walletads.io"),
HostBasedTokenUriMapper(host: "gateway.pinata.cloud")
HostBasedTokenUriMapper(host: "gateway.pinata.cloud"),
])
}
@ -51,7 +50,6 @@ final class JsonFromTokenUri {
func fetchJsonFromTokenUri(for tokenId: String,
tokenType: NonFungibleFromJsonTokenType,
address: AlphaWallet.Address) -> Publisher {
return Just(tokenId)
.setFailureType(to: SessionTaskError.self)
.flatMap { [weak self, weak getTokenUri] tokenId -> AnyPublisher<NonFungibleBalanceAndItsSource<JsonString>, SessionTaskError> in
@ -134,7 +132,7 @@ final class JsonFromTokenUri {
var jsonDictionary = json
if let token = await tokensDataStore.token(for: address, server: blockchainProvider.server) {
jsonDictionary["tokenType"] = JSON(tokenType.rawValue)
//We must make sure the value stored is at least an empty string, never nil because we need to deserialise/decode it
//We must make sure the value stored is at least an empty string, never nil because we need to deserialise/decode it
jsonDictionary["contractName"] = JSON(token.name)
jsonDictionary["symbol"] = JSON(token.symbol)
jsonDictionary["tokenId"] = JSON(tokenId)
@ -142,7 +140,7 @@ final class JsonFromTokenUri {
jsonDictionary["name"] = JSON(json["name"].stringValue)
jsonDictionary["imageUrl"] = JSON(json["image"].string ?? json["image_url"].stringValue)
jsonDictionary["thumbnailUrl"] = JSON(json["thumbnail_url"].string ?? json["imageUrl"].stringValue)
//POAP tokens (https://blockscout.com/xdai/mainnet/address/0x22C1f6050E56d2876009903609a2cC3fEf83B415/transactions), eg. https://api.poap.xyz/metadata/2503/278569, use `home_url` as the key for what they should use `external_url` for and they use `external_url` to point back to the token URI
//POAP tokens (https://blockscout.com/xdai/mainnet/address/0x22C1f6050E56d2876009903609a2cC3fEf83B415/transactions), eg. https://api.poap.xyz/metadata/2503/278569, use `home_url` as the key for what they should use `external_url` for and they use `external_url` to point back to the token URI
jsonDictionary["externalLink"] = JSON(json["home_url"].string ?? json["external_url"].string ?? "")
jsonDictionary["animationUrl"] = JSON(jsonDictionary["animation_url"].stringValue)
}
@ -160,7 +158,6 @@ final class JsonFromTokenUri {
tokenType: NonFungibleFromJsonTokenType,
uri originalUri: URL,
address: AlphaWallet.Address) -> Publisher {
let uri = originalUri.rewrittenIfIpfs
verboseLog("Fetching token URI: \(originalUri.absoluteString)… with: \(uri.absoluteString)")
return asFutureThrowable {

@ -5,8 +5,9 @@
// Created by Vladyslav Shepitko on 08.07.2022.
//
import Foundation
import Combine
import Foundation
import AlphaWalletWeb3
public protocol TokensService {

@ -6,7 +6,9 @@
//
import Foundation
import AlphaWalletTokenScript
import BigInt
public protocol TokenIdentifiable {
@ -54,9 +56,9 @@ public struct TokenScriptOverrides {
}
}
extension TokenViewModel: BalanceRepresentable { }
extension TokenViewModel: BalanceRepresentable {}
extension TokenScriptOverrides: Hashable { }
extension TokenScriptOverrides: Hashable {}
extension TokenViewModel: TokenFilterable {
public var balanceNft: [TokenBalanceValue] { balance.balance }
@ -67,8 +69,8 @@ extension TokenViewModel: TokenSortable {
public var value: BigUInt { balance.value }
}
extension TokenViewModel: TokenScriptOverridesSupportable { }
extension TokenViewModel: TokenBalanceSupportable { }
extension TokenViewModel: TokenScriptOverridesSupportable {}
extension TokenViewModel: TokenBalanceSupportable {}
extension TokenViewModel: Equatable {
public static func == (lhs: TokenViewModel, rhs: TokenViewModel) -> Bool {
@ -81,7 +83,6 @@ extension TokenViewModel: Equatable {
}
extension TokenViewModel: Hashable {
public var nonZeroBalance: [TokenBalanceValue] {
return Array(balance.balance.filter { isNonZeroBalance($0.balance, tokenType: self.type) })
}

@ -6,9 +6,11 @@
//
import Foundation
import BigInt
import AlphaWalletWeb3
import BigInt
public struct WalletBalance {
fileprivate struct BalanceRepresentable: Hashable {
let balance: Double
@ -89,7 +91,7 @@ extension Balance: CustomStringConvertible {
}
}
extension WalletBalance: Hashable { }
extension WalletBalance: Hashable {}
public extension WalletBalance {
public struct ValueForCurrency: Equatable, Hashable {
@ -128,7 +130,6 @@ fileprivate extension WalletBalance.functional {
var totalAmount: Double? = 0
for token in tokens {
if totalAmount == nil {
totalAmount = 0.0
}

Loading…
Cancel
Save