Remove tab bar appearing briefly after tapping "Go to Token" to show token #2342

pull/2349/head
Vladyslav shepitko 4 years ago committed by Hwee-Boon Yar
parent 4b9f54fff8
commit ee701f1959
  1. 6
      AlphaWallet/InCoordinator.swift
  2. 37
      AlphaWallet/Tokens/Coordinators/SingleChainTokenCoordinator.swift
  3. 20
      AlphaWallet/Tokens/Coordinators/TokensCoordinator.swift
  4. 10
      AlphaWallet/Transfer/Coordinators/TransactionConfirmationCoordinator.swift
  5. 27
      AlphaWallet/Transfer/ViewControllers/ConfigureTransactionViewController.swift

@ -840,7 +840,6 @@ extension InCoordinator: TokensCoordinatorDelegate {
private func openSwapToken(for url: URL, coordinator: TokensCoordinator) {
guard let dappBrowserCoordinator = dappBrowserCoordinator else { return }
coordinator.navigationController.popViewController(animated: false)
showTab(.browser)
@ -937,10 +936,9 @@ extension InCoordinator: ActivitiesCoordinatorDelegate {
}
func show(tokenObject: TokenObject, fromCoordinator coordinator: ActivitiesCoordinator) {
//TODO way better UX if we can just open the token without switching tabs
showTab(.wallet)
guard let tokensCoordinator = tokensCoordinator else { return }
tokensCoordinator.didSelect(token: tokenObject, in: tokensCoordinator.rootViewController)
tokensCoordinator.showSingleChainToken(token: tokenObject, in: coordinator.navigationController)
}
func show(transactionWithId transactionId: String, server: RPCServer, inViewController viewController: UIViewController, fromCoordinator coordinator: ActivitiesCoordinator) {

@ -35,7 +35,6 @@ class SingleChainTokenCoordinator: Coordinator {
private let assetDefinitionStore: AssetDefinitionStore
private let eventsDataStore: EventsDataStoreProtocol
private let analyticsCoordinator: AnalyticsCoordinator?
private let navigationController: UINavigationController
private let autoDetectTransactedTokensQueue: OperationQueue
private let autoDetectTokensQueue: OperationQueue
private var isAutoDetectingTransactedTokens = false
@ -53,7 +52,6 @@ class SingleChainTokenCoordinator: Coordinator {
assetDefinitionStore: AssetDefinitionStore,
eventsDataStore: EventsDataStoreProtocol,
analyticsCoordinator: AnalyticsCoordinator?,
navigationController: UINavigationController,
withAutoDetectTransactedTokensQueue autoDetectTransactedTokensQueue: OperationQueue,
withAutoDetectTokensQueue autoDetectTokensQueue: OperationQueue,
swapTokenActionsService: SwapTokenActionsService
@ -65,7 +63,6 @@ class SingleChainTokenCoordinator: Coordinator {
self.assetDefinitionStore = assetDefinitionStore
self.eventsDataStore = eventsDataStore
self.analyticsCoordinator = analyticsCoordinator
self.navigationController = navigationController
self.autoDetectTransactedTokensQueue = autoDetectTransactedTokensQueue
self.autoDetectTokensQueue = autoDetectTokensQueue
self.swapTokenActionsService = swapTokenActionsService
@ -337,7 +334,7 @@ class SingleChainTokenCoordinator: Coordinator {
fetchContractDataFor(address: address, storage: storage, assetDefinitionStore: assetDefinitionStore, completion: completion)
}
func showTokenList(for type: PaymentFlow, token: TokenObject) {
func showTokenList(for type: PaymentFlow, token: TokenObject, navigationController: UINavigationController) {
guard !token.nonZeroBalance.isEmpty else {
navigationController.displayError(error: NoTokenError())
return
@ -392,14 +389,17 @@ class SingleChainTokenCoordinator: Coordinator {
return try! Realm(configuration: migration.config)
}
func show(fungibleToken token: TokenObject, transactionType: TransactionType) {
func show(fungibleToken token: TokenObject, transactionType: TransactionType, navigationController: UINavigationController) {
guard let transactionsStore = createTransactionsStore() else { return }
let viewController = TokenViewController(session: session, tokensDataStore: storage, assetDefinition: assetDefinitionStore, transactionType: transactionType, token: token)
viewController.delegate = self
let viewModel = TokenViewControllerViewModel(transactionType: transactionType, session: session, tokensStore: storage, transactionsStore: transactionsStore, assetDefinitionStore: assetDefinitionStore, swapTokenActionsService: swapTokenActionsService)
viewController.configure(viewModel: viewModel)
viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(image: R.image.backWhite(), style: .plain, target: self, action: #selector(dismiss))
viewController.navigationItem.leftBarButtonItem = UIBarButtonItem.backBarButton(selectionClosure: {
navigationController.popToRootViewController(animated: true)
})
navigationController.pushViewController(viewController, animated: true)
@ -421,10 +421,6 @@ class SingleChainTokenCoordinator: Coordinator {
}
}
@objc func dismiss() {
navigationController.popToRootViewController(animated: true)
}
func delete(token: TokenObject) {
assetDefinitionStore.contractDeleted(token.contractAddress)
storage.add(hiddenContracts: [HiddenContract(contractAddress: token.contractAddress, server: session.server)])
@ -433,13 +429,13 @@ class SingleChainTokenCoordinator: Coordinator {
}
func updateOrderedTokens(with orderedTokens: [TokenObject]) {
self.storage.updateOrderedTokens(with: orderedTokens)
storage.updateOrderedTokens(with: orderedTokens)
delegate?.tokensDidChange(inCoordinator: self)
}
func mark(token: TokenObject, isHidden: Bool) {
self.storage.update(token: token, action: .isHidden(isHidden))
storage.update(token: token, action: .isHidden(isHidden))
}
func add(token: ERCToken) -> TokenObject {
@ -524,7 +520,7 @@ class SingleChainTokenCoordinator: Coordinator {
}
}
private func showTokenInstanceActionView(forAction action: TokenInstanceAction, fungibleTokenObject tokenObject: TokenObject, viewController: UIViewController) {
private func showTokenInstanceActionView(forAction action: TokenInstanceAction, fungibleTokenObject tokenObject: TokenObject, navigationController: UINavigationController) {
//TODO id 1 for fungibles. Might come back to bite us?
let hardcodedTokenIdForFungibles = BigUInt(1)
let xmlHandler = XMLHandler(token: tokenObject, assetDefinitionStore: assetDefinitionStore)
@ -536,14 +532,15 @@ class SingleChainTokenCoordinator: Coordinator {
vc.delegate = self
vc.configure()
vc.navigationItem.largeTitleDisplayMode = .never
viewController.navigationController?.pushViewController(vc, animated: true)
navigationController.pushViewController(vc, animated: true)
}
}
// swiftlint:enable type_body_length
extension SingleChainTokenCoordinator: TokensCardCoordinatorDelegate {
func didCancel(in coordinator: TokensCardCoordinator) {
navigationController.popToRootViewController(animated: true)
coordinator.navigationController.popToRootViewController(animated: true)
removeCoordinator(coordinator)
}
@ -571,6 +568,8 @@ extension SingleChainTokenCoordinator: TokenViewControllerDelegate {
}
func didTap(action: TokenInstanceAction, transactionType: TransactionType, viewController: TokenViewController) {
guard let navigationController = viewController.navigationController else { return }
let token: TokenObject
switch transactionType {
case .ERC20Token(let erc20Token, _, _):
@ -579,12 +578,12 @@ extension SingleChainTokenCoordinator: TokenViewControllerDelegate {
return
case .nativeCryptocurrency:
token = TokensDataStore.etherToken(forServer: session.server)
showTokenInstanceActionView(forAction: action, fungibleTokenObject: token, viewController: viewController)
showTokenInstanceActionView(forAction: action, fungibleTokenObject: token, navigationController: navigationController)
return
}
switch action.type {
case .tokenScript:
showTokenInstanceActionView(forAction: action, fungibleTokenObject: token, viewController: viewController)
showTokenInstanceActionView(forAction: action, fungibleTokenObject: token, navigationController: navigationController)
case .erc20Send, .erc20Receive, .nftRedeem, .nftSell, .nonFungibleTransfer, .swap:
//Couldn't have reached here
break
@ -621,7 +620,7 @@ extension SingleChainTokenCoordinator: TransactionConfirmationCoordinatorDelegat
guard let strongSelf = self else { return }
strongSelf.removeCoordinator(coordinator)
let coordinator = TransactionInProgressCoordinator(navigationController: strongSelf.navigationController)
let coordinator = TransactionInProgressCoordinator(navigationController: coordinator.presentationNavigationController)
coordinator.delegate = strongSelf
strongSelf.addCoordinator(coordinator)
@ -632,6 +631,8 @@ extension SingleChainTokenCoordinator: TransactionConfirmationCoordinatorDelegat
extension SingleChainTokenCoordinator: TokenInstanceActionViewControllerDelegate {
func confirmTransactionSelected(in viewController: TokenInstanceActionViewController, tokenObject: TokenObject, contract: AlphaWallet.Address, tokenId: TokenId, values: [AttributeId: AssetInternalValue], localRefs: [AttributeId: AssetInternalValue], server: RPCServer, session: WalletSession, keystore: Keystore, transactionFunction: FunctionOrigin) {
guard let navigationController = viewController.navigationController else { return }
switch transactionFunction.makeUnConfirmedTransaction(withTokenObject: tokenObject, tokenId: tokenId, attributeAndValues: values, localRefs: localRefs, server: server, session: session) {
case .success(let transaction, let functionCallMetaData):
let coordinator = TransactionConfirmationCoordinator(navigationController: navigationController, session: session, transaction: transaction, configuration: .tokenScriptTransaction(confirmType: .signThenSend, contract: contract, keystore: keystore, functionCallMetaData: functionCallMetaData, ethPrice: cryptoPrice), analyticsCoordinator: analyticsCoordinator)

@ -122,7 +122,7 @@ class TokensCoordinator: Coordinator {
let server = each.server
let session = sessions[server]
let price = nativeCryptoCurrencyPrices[server]
let coordinator = SingleChainTokenCoordinator(session: session, keystore: keystore, tokensStorage: each, ethPrice: price, assetDefinitionStore: assetDefinitionStore, eventsDataStore: eventsDataStore, analyticsCoordinator: analyticsCoordinator, navigationController: navigationController, withAutoDetectTransactedTokensQueue: autoDetectTransactedTokensQueue, withAutoDetectTokensQueue: autoDetectTokensQueue, swapTokenActionsService: swapTokenService)
let coordinator = SingleChainTokenCoordinator(session: session, keystore: keystore, tokensStorage: each, ethPrice: price, assetDefinitionStore: assetDefinitionStore, eventsDataStore: eventsDataStore, analyticsCoordinator: analyticsCoordinator, withAutoDetectTransactedTokensQueue: autoDetectTransactedTokensQueue, withAutoDetectTokensQueue: autoDetectTokensQueue, swapTokenActionsService: swapTokenService)
coordinator.delegate = self
addCoordinator(coordinator)
}
@ -182,21 +182,25 @@ extension TokensCoordinator: TokensViewControllerDelegate {
coordinator.start()
}
func didSelect(token: TokenObject, in viewController: UIViewController) {
let server = token.server
guard let coordinator = singleChainTokenCoordinator(forServer: server) else { return }
func showSingleChainToken(token: TokenObject, in navigationController: UINavigationController) {
guard let coordinator = singleChainTokenCoordinator(forServer: token.server) else { return }
switch token.type {
case .nativeCryptocurrency:
coordinator.show(fungibleToken: token, transactionType: .nativeCryptocurrency(token, destination: .none, amount: nil))
coordinator.show(fungibleToken: token, transactionType: .nativeCryptocurrency(token, destination: .none, amount: nil), navigationController: navigationController)
case .erc20:
coordinator.show(fungibleToken: token, transactionType: .ERC20Token(token, destination: nil, amount: nil))
coordinator.show(fungibleToken: token, transactionType: .ERC20Token(token, destination: nil, amount: nil), navigationController: navigationController)
case .erc721:
coordinator.showTokenList(for: .send(type: .ERC721Token(token)), token: token)
coordinator.showTokenList(for: .send(type: .ERC721Token(token)), token: token, navigationController: navigationController)
case .erc875, .erc721ForTickets:
coordinator.showTokenList(for: .send(type: .ERC875Token(token)), token: token)
coordinator.showTokenList(for: .send(type: .ERC875Token(token)), token: token, navigationController: navigationController)
}
}
func didSelect(token: TokenObject, in viewController: UIViewController) {
showSingleChainToken(token: token, in: navigationController)
}
func didHide(token: TokenObject, in viewController: UIViewController) {
guard let coordinator = singleChainTokenCoordinator(forServer: token.server) else { return }
coordinator.mark(token: token, isHidden: true)

@ -60,12 +60,8 @@ protocol TransactionConfirmationCoordinatorDelegate: class {
}
class TransactionConfirmationCoordinator: Coordinator {
private struct Parent {
let navigationController: UINavigationController
}
private let configuration: TransactionConfirmationConfiguration
private let parent: Parent
let presentationNavigationController: UINavigationController
private lazy var viewModel: TransactionConfirmationViewModel = .init(configurator: configurator, configuration: configuration)
private lazy var confirmationViewController: TransactionConfirmationViewController = {
let controller = TransactionConfirmationViewController(viewModel: viewModel)
@ -90,11 +86,11 @@ class TransactionConfirmationCoordinator: Coordinator {
configurator = TransactionConfigurator(session: session, transaction: transaction)
self.configuration = configuration
self.analyticsCoordinator = analyticsCoordinator
parent = Parent(navigationController: navigationController)
presentationNavigationController = navigationController
}
func start() {
parent.navigationController.present(navigationController, animated: false)
presentationNavigationController.present(navigationController, animated: false)
configurator.delegate = self
configurator.start()
confirmationViewController.reloadView()

@ -405,6 +405,7 @@ extension ConfigureTransactionViewController: TextFieldDelegate {
}
extension UIBarButtonItem {
static func saveBarButton(_ target: AnyObject, selector: Selector) -> UIBarButtonItem {
.init(title: R.string.localizable.save(), style: .plain, target: target, action: selector)
}
@ -412,4 +413,30 @@ extension UIBarButtonItem {
static func backBarButton(_ target: AnyObject, selector: Selector) -> UIBarButtonItem {
.init(image: R.image.backWhite(), style: .plain, target: target, action: selector)
}
static func backBarButton(selectionClosure: @escaping () -> Void) -> UIBarButtonItem {
let barButton = UIBarButtonItem(image: R.image.backWhite(), style: .plain, target: nil, action: nil)
barButton.selectionClosure = selectionClosure
return barButton
}
private struct AssociatedObject {
static var key = "action_closure_key"
}
var selectionClosure: (() -> Void)? {
get {
return objc_getAssociatedObject(self, &AssociatedObject.key) as? () -> Void
}
set {
objc_setAssociatedObject(self, &AssociatedObject.key, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
target = self
action = #selector(didTapButton)
}
}
@objc func didTapButton(_ sender: Any) {
selectionClosure?()
}
}

Loading…
Cancel
Save