Display ENS name or local wallet name in Wallet tab #2266

pull/2298/head
Vladyslav shepitko 4 years ago committed by Hwee-Boon Yar
parent a60dfb5182
commit 1ce89b82c0
  1. 1
      AlphaWallet/Tokens/Coordinators/ENSReverseLookupCoordinator.swift
  2. 3
      AlphaWallet/Tokens/Coordinators/TokensCoordinator.swift
  3. 29
      AlphaWallet/Tokens/ViewControllers/TokensViewController.swift
  4. 2
      AlphaWallet/Tokens/ViewModels/TokensViewModel.swift
  5. 8
      AlphaWalletTests/Settings/ConfigTests.swift

@ -22,6 +22,7 @@ class ENSReverseLookupCoordinator {
self.server = server
}
//TODO make calls from multiple callers at the same time for the same address more efficient
func getENSNameFromResolver(
forAddress input: AlphaWallet.Address,
completion: @escaping (Result<String, AnyError>) -> Void

@ -56,7 +56,8 @@ class TokensCoordinator: Coordinator {
tokenCollection: tokenCollection,
assetDefinitionStore: assetDefinitionStore,
eventsDataStore: eventsDataStore,
filterTokensCoordinator: filterTokensCoordinator
filterTokensCoordinator: filterTokensCoordinator,
config: config
)
controller.delegate = self
return controller

@ -3,6 +3,7 @@
import UIKit
import Result
import StatefulViewController
import PromiseKit
protocol TokensViewControllerDelegate: class {
func didPressAddHideTokens(viewModel: TokensViewModel)
@ -105,7 +106,7 @@ class TokensViewController: UIViewController {
private let hideTokenWidth: CGFloat = 170
private var bottomConstraint: NSLayoutConstraint!
private lazy var keyboardChecker = KeyboardChecker(self, resetHeightDefaultValue: 0, ignoreBottomSafeArea: true)
private let config: Config
var isConsoleButtonHidden: Bool {
get {
return consoleButton.isHidden
@ -164,13 +165,15 @@ class TokensViewController: UIViewController {
tokenCollection: TokenCollection,
assetDefinitionStore: AssetDefinitionStore,
eventsDataStore: EventsDataStoreProtocol,
filterTokensCoordinator: FilterTokensCoordinator
filterTokensCoordinator: FilterTokensCoordinator,
config: Config
) {
self.sessions = sessions
self.account = account
self.tokenCollection = tokenCollection
self.assetDefinitionStore = assetDefinitionStore
self.eventsDataStore = eventsDataStore
self.config = config
self.viewModel = TokensViewModel(filterTokensCoordinator: filterTokensCoordinator, tokens: [], tickers: .init())
searchController = UISearchController(searchResultsController: nil)
@ -206,12 +209,11 @@ class TokensViewController: UIViewController {
self?.tokenCollection.fetch()
})
loadingView = LoadingView()
emptyView = EmptyView(
title: R.string.localizable.emptyViewNoTokensLabelTitle(),
onRetry: { [weak self] in
self?.startLoading()
self?.tokenCollection.fetch()
emptyView = EmptyView(title: R.string.localizable.emptyViewNoTokensLabelTitle(), onRetry: { [weak self] in
self?.startLoading()
self?.tokenCollection.fetch()
})
refreshView(viewModel: viewModel)
setupFilteringWithKeyword()
@ -229,6 +231,7 @@ class TokensViewController: UIViewController {
fetch()
fixNavigationBarAndStatusBarBackgroundColorForiOS13Dot1()
keyboardChecker.viewWillAppear()
getWalletName()
}
override func viewWillDisappear(_ animated: Bool) {
@ -240,6 +243,17 @@ class TokensViewController: UIViewController {
delegate?.scanQRCodeSelected(in: self)
}
private func getWalletName() {
title = viewModel.walletDefaultTitle
firstly {
GetWalletNameCoordinator(config: config).getName(forAddress: account.address)
}.done { [weak self] name in
guard let strongSelf = self else { return }
strongSelf.navigationItem.title = name ?? strongSelf.viewModel.walletDefaultTitle
}.cauterize()
}
@objc func pullToRefresh() {
tableViewRefreshControl.beginRefreshing()
collectiblesCollectionViewRefreshControl.beginRefreshing()
@ -287,7 +301,6 @@ class TokensViewController: UIViewController {
}
func refreshView(viewModel: TokensViewModel) {
title = viewModel.title
view.backgroundColor = viewModel.backgroundColor
tableView.backgroundColor = viewModel.backgroundColor
}

@ -26,7 +26,7 @@ class TokensViewModel {
return .white
}
var title: String {
var walletDefaultTitle: String {
return R.string.localizable.walletTokensTabbarItemTitle()
}

@ -24,8 +24,10 @@ class ConfigTests: XCTestCase {
tokenCollection: .init(filterTokensCoordinator: FilterTokensCoordinator(assetDefinitionStore: assetDefinitionStore), tokenDataStores: [FakeTokensDataStore()]),
assetDefinitionStore: assetDefinitionStore,
eventsDataStore: FakeEventsDataStore(),
filterTokensCoordinator: FilterTokensCoordinator(assetDefinitionStore: assetDefinitionStore)
filterTokensCoordinator: FilterTokensCoordinator(assetDefinitionStore: assetDefinitionStore),
config: .make()
)
vc1.viewWillAppear(false)
XCTAssertEqual(vc1.title, "Wallet")
Config.setLocale(AppLocale.simplifiedChinese)
@ -35,8 +37,10 @@ class ConfigTests: XCTestCase {
tokenCollection: .init(filterTokensCoordinator: FilterTokensCoordinator(assetDefinitionStore: assetDefinitionStore), tokenDataStores: [FakeTokensDataStore()]),
assetDefinitionStore: assetDefinitionStore,
eventsDataStore: FakeEventsDataStore(),
filterTokensCoordinator: FilterTokensCoordinator(assetDefinitionStore: assetDefinitionStore)
filterTokensCoordinator: FilterTokensCoordinator(assetDefinitionStore: assetDefinitionStore),
config: .make()
)
vc2.viewWillAppear(false)
XCTAssertEqual(vc2.title, "我的钱包")
//Must change this back to system, otherwise other tests will break either immediately or the next run

Loading…
Cancel
Save