Merge pull request #3429 from vladyslav-iosdev/#3420

When selecting/deselecting networks on the chain list screen, enable/disable changes are not saved if the new chain is saved #3420
pull/3441/head
Hwee-Boon Yar 3 years ago committed by GitHub
commit 5fe7ea98a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      AlphaWallet/InCoordinator.swift
  2. 1
      AlphaWallet/Models/RestartTaskQueue.swift
  3. 30
      AlphaWallet/Settings/Coordinators/EnabledServersCoordinator.swift
  4. 31
      AlphaWallet/Settings/Coordinators/SettingsCoordinator.swift
  5. 25
      AlphaWallet/Settings/ViewControllers/EnabledServersViewController.swift
  6. 3
      AlphaWalletTests/Settings/Coordinators/SettingsCoordinatorTests.swift

@ -708,7 +708,7 @@ class InCoordinator: NSObject, Coordinator {
case .addServer(let server):
restartQueue.remove(each)
RPCServer.customRpcs.append(server)
case .editServer(original: let original, edited: let edited):
case .editServer(let original, let edited):
restartQueue.remove(each)
replaceServer(original: original, edited: edited)
case .removeServer(let server):
@ -727,6 +727,10 @@ class InCoordinator: NSObject, Coordinator {
Config.setChainId(server.chainID)
case .loadUrlInDappBrowser:
break
case .reloadServers(let servers):
restartQueue.remove(each)
var c = config
c.enabledServers = servers
}
}
}
@ -763,7 +767,7 @@ class InCoordinator: NSObject, Coordinator {
private func processRestartQueueAfterRestart(config: Config, coordinator: InCoordinator, restartQueue: RestartTaskQueue) {
for each in restartQueue.queue {
switch each {
case .addServer, .editServer, .removeServer, .enableServer, .switchDappServer:
case .addServer, .reloadServers, .editServer, .removeServer, .enableServer, .switchDappServer:
break
case .loadUrlInDappBrowser(let url):
restartQueue.remove(each)
@ -879,11 +883,7 @@ extension InCoordinator: SettingsCoordinatorDelegate {
TransactionsStorage.deleteAllTransactions(realm: Wallet.functional.realm(forAccount: account))
}
func restartToAddEnableAndSwitchBrowserToServer(in coordinator: SettingsCoordinator) {
processRestartQueueAndRestartUI()
}
func restartToRemoveServer(in coordinator: SettingsCoordinator) {
func restartToReloadServersQueued(in coordinator: SettingsCoordinator) {
processRestartQueueAndRestartUI()
}
}

@ -13,6 +13,7 @@ class RestartTaskQueue {
case enableServer(RPCServer)
case switchDappServer(server: RPCServer)
case loadUrlInDappBrowser(URL)
case reloadServers([RPCServer])
}
init() {

@ -3,10 +3,7 @@
import UIKit
protocol EnabledServersCoordinatorDelegate: AnyObject {
func didSelectServers(servers: [RPCServer], in coordinator: EnabledServersCoordinator)
func didSelectDismiss(in coordinator: EnabledServersCoordinator)
func restartToAddEnableAndSwitchBrowserToServer(in coordinator: EnabledServersCoordinator)
func restartToRemoveServer(in coordinator: EnabledServersCoordinator)
func restartToReloadServersQueued(in coordinator: EnabledServersCoordinator)
}
class EnabledServersCoordinator: Coordinator {
@ -46,10 +43,6 @@ class EnabledServersCoordinator: Coordinator {
navigationController.pushViewController(enabledServersViewController, animated: true)
}
func stop() {
navigationController.popViewController(animated: true)
}
@objc private func addRPCSelected() {
let coordinator = AddRPCServerCoordinator(navigationController: navigationController, config: Config(), restartQueue: restartQueue, analyticsCoordinator: analyticsCoordinator)
coordinator.delegate = self
@ -68,20 +61,13 @@ class EnabledServersCoordinator: Coordinator {
}
extension EnabledServersCoordinator: EnabledServersViewControllerDelegate {
func didEditSelectedServer(customRpc: CustomRPC, in viewController: EnabledServersViewController) {
self.edit(customRpc: customRpc, in: viewController)
}
func didSelectServers(servers: [RPCServer], in viewController: EnabledServersViewController) {
delegate?.didSelectServers(servers: servers, in: self)
func notifyReloadServersQueued(in viewController: EnabledServersViewController) {
delegate?.restartToReloadServersQueued(in: self)
}
func didDismiss(viewController: EnabledServersViewController) {
delegate?.didSelectDismiss(in: self)
}
func notifyRemoveCustomChainQueued(in viewController: EnabledServersViewController) {
delegate?.restartToRemoveServer(in: self)
func didEditSelectedServer(customRpc: CustomRPC, in viewController: EnabledServersViewController) {
self.edit(customRpc: customRpc, in: viewController)
}
}
@ -91,7 +77,8 @@ extension EnabledServersCoordinator: AddRPCServerCoordinatorDelegate {
}
func restartToAddEnableAndSwitchBrowserToServer(in coordinator: AddRPCServerCoordinator) {
delegate?.restartToAddEnableAndSwitchBrowserToServer(in: self)
enabledServersViewController.pushReloadServersIfNeeded()
delegate?.restartToReloadServersQueued(in: self)
}
}
@ -101,6 +88,7 @@ extension EnabledServersCoordinator: EditCustomRpcCoordinatorDelegate {
}
func restartToEdit(in coordinator: EditCustomRpcCoordinator) {
delegate?.restartToAddEnableAndSwitchBrowserToServer(in: self)
enabledServersViewController.pushReloadServersIfNeeded()
delegate?.restartToReloadServersQueued(in: self)
}
}

@ -18,8 +18,7 @@ protocol SettingsCoordinatorDelegate: class, CanOpenURL {
func assetDefinitionsOverrideViewController(for: SettingsCoordinator) -> UIViewController?
func showConsole(in coordinator: SettingsCoordinator)
func delete(account: Wallet, in coordinator: SettingsCoordinator)
func restartToAddEnableAndSwitchBrowserToServer(in coordinator: SettingsCoordinator)
func restartToRemoveServer(in coordinator: SettingsCoordinator)
func restartToReloadServersQueued(in coordinator: SettingsCoordinator)
}
class SettingsCoordinator: Coordinator {
@ -239,34 +238,12 @@ extension SettingsCoordinator: LocalesCoordinatorDelegate {
}
extension SettingsCoordinator: EnabledServersCoordinatorDelegate {
func didSelectServers(servers: [RPCServer], in coordinator: EnabledServersCoordinator) {
//Defensive. Shouldn't allow no server to be selected
guard !servers.isEmpty else { return }
let isUnchanged = config.enabledServers.sorted(by: { $0.chainID < $1.chainID }) == servers.sorted(by: { $0.chainID < $1.chainID })
if isUnchanged {
coordinator.stop()
removeCoordinator(coordinator)
} else {
config.enabledServers = servers
restart(for: account, reason: .serverChange)
}
}
func didSelectDismiss(in coordinator: EnabledServersCoordinator) {
coordinator.stop()
removeCoordinator(coordinator)
}
func restartToAddEnableAndSwitchBrowserToServer(in coordinator: EnabledServersCoordinator) {
delegate?.restartToAddEnableAndSwitchBrowserToServer(in: self)
func restartToReloadServersQueued(in coordinator: EnabledServersCoordinator) {
delegate?.restartToReloadServersQueued(in: self)
removeCoordinator(coordinator)
}
func restartToRemoveServer(in coordinator: EnabledServersCoordinator) {
delegate?.restartToRemoveServer(in: self)
removeCoordinator(coordinator)
}
}
extension SettingsCoordinator: PromptBackupCoordinatorSubtlePromptDelegate {

@ -3,9 +3,8 @@
import UIKit
protocol EnabledServersViewControllerDelegate: AnyObject {
func didSelectServers(servers: [RPCServer], in viewController: EnabledServersViewController)
func notifyRemoveCustomChainQueued(in viewController: EnabledServersViewController)
func didEditSelectedServer(customRpc: CustomRPC, in viewController: EnabledServersViewController)
func notifyReloadServersQueued(in viewController: EnabledServersViewController)
}
class EnabledServersViewController: UIViewController {
@ -35,6 +34,7 @@ class EnabledServersViewController: UIViewController {
private var sectionIndices: IndexSet {
IndexSet(integersIn: Range(uncheckedBounds: (lower: 0, sections.count)))
}
private let config: Config = Config()
var viewModel: EnabledServersViewModel
weak var delegate: EnabledServersViewControllerDelegate?
@ -82,7 +82,21 @@ class EnabledServersViewController: UIViewController {
}
@objc private func done() {
delegate?.didSelectServers(servers: viewModel.selectedServers, in: self)
pushReloadServersIfNeeded()
delegate?.notifyReloadServersQueued(in: self)
}
func pushReloadServersIfNeeded() {
let servers = viewModel.selectedServers
//Defensive. Shouldn't allow no server to be selected
guard !servers.isEmpty else { return }
let isUnchanged = config.enabledServers.sorted(by: { $0.chainID < $1.chainID }) == servers.sorted(by: { $0.chainID < $1.chainID })
if isUnchanged {
//no-op
} else {
restartQueue.add(.reloadServers(servers))
}
}
private func confirmDelete(server: RPCServer) {
@ -103,12 +117,15 @@ class EnabledServersViewController: UIViewController {
private func markForDeletion(server: RPCServer) {
guard let customRpc = server.customRpc else { return }
pushReloadServersIfNeeded()
restartQueue.add(.removeServer(customRpc))
delegate?.notifyRemoveCustomChainQueued(in: self)
delegate?.notifyReloadServersQueued(in: self)
}
}
extension EnabledServersViewController: UITableViewDelegate, UITableViewDataSource {
func numberOfSections(in tableView: UITableView) -> Int {
sections.count
}

@ -28,8 +28,7 @@ class SettingsCoordinatorTests: XCTestCase {
func didPressViewContractWebPage(forContract contract: AlphaWallet.Address, server: RPCServer, in viewController: UIViewController) {}
func didPressViewContractWebPage(_ url: URL, in viewController: UIViewController) {}
func didPressOpenWebPage(_ url: URL, in viewController: UIViewController) {}
func restartToAddEnableAndSwitchBrowserToServer(in coordinator: SettingsCoordinator) {}
func restartToRemoveServer(in coordinator: SettingsCoordinator) {}
func restartToReloadServersQueued(in coordinator: SettingsCoordinator) {}
}
let storage = FakeTransactionsStorage(server: .main)

Loading…
Cancel
Save