Add code that auto populates the Add Custom Token screen when the search string is a valid address

pull/3664/head
Jerome Chan 3 years ago
parent d32896d2be
commit f713896d3c
  1. 9
      AlphaWallet/Tokens/Coordinators/AddHideTokensCoordinator.swift
  2. 8
      AlphaWallet/Tokens/ViewControllers/AddHideTokensViewController.swift

@ -93,13 +93,20 @@ extension AddHideTokensCoordinator: AddHideTokensViewControllerDelegate {
coordinator.mark(token: token, isHidden: isHidden)
}
func didPressAddToken(in viewController: UIViewController) {
func didPressAddToken(in viewController: UIViewController, with addressString: String) {
let initialState: NewTokenInitialState
if let walletAddress = AlphaWallet.Address(string: addressString.trimmingCharacters(in: .whitespacesAndNewlines)) {
initialState = .address(walletAddress)
} else {
initialState = .empty
}
let coordinator = NewTokenCoordinator(
analyticsCoordinator: analyticsCoordinator,
navigationController: navigationController,
tokenCollection: tokenCollection,
config: config,
singleChainTokenCoordinators: singleChainTokenCoordinators,
initialState: initialState,
sessions: sessions
)
coordinator.delegate = self

@ -5,7 +5,7 @@ import StatefulViewController
import PromiseKit
protocol AddHideTokensViewControllerDelegate: AnyObject {
func didPressAddToken(in viewController: UIViewController)
func didPressAddToken(in viewController: UIViewController, with addressString: String)
func didMark(token: TokenObject, in viewController: UIViewController, isHidden: Bool)
func didChangeOrder(tokens: [TokenObject], in viewController: UIViewController)
func didClose(viewController: AddHideTokensViewController)
@ -53,8 +53,8 @@ class AddHideTokensViewController: UIViewController {
emptyView = EmptyView.filterTokensEmptyView(completion: { [weak self] in
guard let strongSelf = self, let delegate = strongSelf.delegate else { return }
delegate.didPressAddToken(in: strongSelf)
let addressString = strongSelf.searchController.searchBar.text ?? ""
delegate.didPressAddToken(in: strongSelf, with: addressString)
})
view.addSubview(tableView)
@ -106,7 +106,7 @@ class AddHideTokensViewController: UIViewController {
}
@objc private func addToken() {
delegate?.didPressAddToken(in: self)
delegate?.didPressAddToken(in: self, with: "")
}
private func configure(viewModel: AddHideTokensViewModel) {

Loading…
Cancel
Save