Add diagnostic action in Settings > Advanced > Ping Infura

pull/3508/head
Hwee-Boon Yar 3 years ago
parent 79ae11b8b9
commit b7532915cd
  1. 4
      AlphaWallet.xcodeproj/project.pbxproj
  2. 1
      AlphaWallet/Analytics/Models/AnalyticsTypes.swift
  3. 3
      AlphaWallet/Localization/en.lproj/Localizable.strings
  4. 3
      AlphaWallet/Localization/es.lproj/Localizable.strings
  5. 3
      AlphaWallet/Localization/ja.lproj/Localizable.strings
  6. 3
      AlphaWallet/Localization/ko.lproj/Localizable.strings
  7. 3
      AlphaWallet/Localization/zh-Hans.lproj/Localizable.strings
  8. 78
      AlphaWallet/Settings/Coordinators/PingInfuraCoordinator.swift
  9. 19
      AlphaWallet/Settings/Coordinators/SettingsCoordinator.swift
  10. 6
      AlphaWallet/Settings/ViewControllers/AdvancedSettingsViewController.swift
  11. 10
      AlphaWallet/Settings/ViewModels/AdvancedSettingsViewModel.swift

@ -220,6 +220,7 @@
5E7C70397E7E3A9C88E995B1 /* WKWebViewExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C7BEDC786FB048A1DD9A8 /* WKWebViewExtension.swift */; };
5E7C7041A8A78E0EF84A94A2 /* ActivityViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C71DB4EDD10EA665101C2 /* ActivityViewCell.swift */; };
5E7C705166218753CAA19A6D /* TokenIdOrigin.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C7587F30FF1896039B8C8 /* TokenIdOrigin.swift */; };
5E7C7062A44AF416B110008A /* PingInfuraCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C757AEC6586F51EC75646 /* PingInfuraCoordinator.swift */; };
5E7C706322B52C0D0CED8018 /* aETH.tsml in Resources */ = {isa = PBXBuildFile; fileRef = 5E7C7B211FF0FE5BE98BB7D0 /* aETH.tsml */; };
5E7C7066794663954D9C18E5 /* withRetry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C71AFE747055742986023 /* withRetry.swift */; };
5E7C7067E8FEA5055BF83553 /* HDWallet+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5E7C7C6759CA1C223DABA462 /* HDWallet+Extension.swift */; };
@ -1377,6 +1378,7 @@
5E7C7553BB089397B7E74BE0 /* WalletSecurityLevelIndicator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WalletSecurityLevelIndicator.swift; sourceTree = "<group>"; };
5E7C7558286761EF1ADD2988 /* ABIError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ABIError.swift; sourceTree = "<group>"; };
5E7C7570889AD33EA942D9A6 /* AlphaWalletAddressTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AlphaWalletAddressTests.swift; sourceTree = "<group>"; };
5E7C757AEC6586F51EC75646 /* PingInfuraCoordinator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PingInfuraCoordinator.swift; sourceTree = "<group>"; };
5E7C7587F30FF1896039B8C8 /* TokenIdOrigin.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TokenIdOrigin.swift; sourceTree = "<group>"; };
5E7C758EB5C7B77A0EE6BC9E /* MixpanelCoordinator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MixpanelCoordinator.swift; sourceTree = "<group>"; };
5E7C758EEBD945A3451C96C8 /* OpenSeaNonFungibleTokenHandling.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OpenSeaNonFungibleTokenHandling.swift; sourceTree = "<group>"; };
@ -2483,6 +2485,7 @@
5E7C7C51CEC4AAFDFBD75482 /* ConsoleCoordinator.swift */,
5E7C72571AB0FECB26FEB1B1 /* ClearDappBrowserCacheCoordinator.swift */,
02220CFB273A9A02006A09BF /* SaveCustomRpcCoordinator.swift */,
5E7C757AEC6586F51EC75646 /* PingInfuraCoordinator.swift */,
);
path = Coordinators;
sourceTree = "<group>";
@ -6204,6 +6207,7 @@
5E7C7FF312AB61DBEBD86C94 /* WhatsNewViewModels.swift in Sources */,
5E7C7CC1E06FFC3A5BEBF1EC /* WhatsNewViews.swift in Sources */,
5E7C71967C34DD3F207F8126 /* WhatsNewExperimentCoordinator.swift in Sources */,
5E7C7062A44AF416B110008A /* PingInfuraCoordinator.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

@ -58,6 +58,7 @@ enum Analytics {
case walletConnectConnectionTimeout = "WalletConnect Connection Timeout"
case walletConnectConnectionFailed = "WalletConnect Connection Failed"
case clearBrowserCache = "Clear Browser Cache"
case pingInfura = "Ping Infura"
case rectifySendTransactionErrorInActionSheet = "Rectify Send Txn Error"
case nameWallet = "Name Wallet"
case firstWalletAction = "First Wallet Action"

@ -102,6 +102,9 @@
"settings.contactUs.title" = "Contact Us";
"settings.changeCurrency.title" = "Change Currency";
"settings.analitycs.title" = "Analytics";
"settings.pingInfura.title" = "Ping Infura";
"settings.pingInfura.successful" = "Infura looks OK";
"settings.pingInfura.fail" = "Infura Error";
"settings.support.title" = "Support";
"settings.notifications.title" = "Notifications";
"settings.passcode.title" = "Passcode / Touch ID";

@ -102,6 +102,9 @@
"settings.contactUs.title" = "Contacta con nosotros";
"settings.changeCurrency.title" = "Cambiar moneda";
"settings.analitycs.title" = "Análisis";
"settings.pingInfura.title" = "Ping Infura";
"settings.pingInfura.successful" = "Infura looks OK";
"settings.pingInfura.fail" = "Infura Error";
"settings.support.title" = "Asistencia";
"settings.notifications.title" = "Notificaciones";
"settings.passcode.title" = "Código / Touch ID";

@ -101,6 +101,9 @@
"settings.contactUs.title" = "Contact Us";
"settings.changeCurrency.title" = "Change Currency";
"settings.analitycs.title" = "Analytics";
"settings.pingInfura.title" = "Ping Infura";
"settings.pingInfura.successful" = "Infura looks OK";
"settings.pingInfura.fail" = "Infura Error";
"settings.support.title" = "Support";
"settings.notifications.title" = "Notifications";
"settings.passcode.title" = "Passcode / Touch ID";

@ -101,6 +101,9 @@
"settings.contactUs.title" = "Contact Us";
"settings.changeCurrency.title" = "Change Currency";
"settings.analitycs.title" = "Analytics";
"settings.pingInfura.title" = "Ping Infura";
"settings.pingInfura.successful" = "Infura looks OK";
"settings.pingInfura.fail" = "Infura Error";
"settings.support.title" = "Support";
"settings.notifications.title" = "Notifications";
"settings.passcode.title" = "Passcode / Touch ID";

@ -102,6 +102,9 @@
"settings.contactUs.title" = "联系我们";
"settings.changeCurrency.title" = "更改货币";
"settings.analitycs.title" = "分析";
"settings.pingInfura.title" = "Ping Infura";
"settings.pingInfura.successful" = "Infura looks OK";
"settings.pingInfura.fail" = "Infura Error";
"settings.support.title" = "支持";
"settings.notifications.title" = "通知设置";
"settings.passcode.title" = "密码 / Touch ID";

@ -0,0 +1,78 @@
// Copyright © 2021 Stormbird PTE. LTD.
import UIKit
import APIKit
import JSONRPCKit
import PromiseKit
protocol PingInfuraCoordinatorDelegate: AnyObject {
func didPing(in coordinator: PingInfuraCoordinator)
func didCancel(in coordinator: PingInfuraCoordinator)
}
class PingInfuraCoordinator: Coordinator {
private let viewController: UIViewController
private let analyticsCoordinator: AnalyticsCoordinator
var coordinators: [Coordinator] = []
weak var delegate: PingInfuraCoordinatorDelegate?
init(inViewController viewController: UIViewController, analyticsCoordinator: AnalyticsCoordinator) {
self.viewController = viewController
self.analyticsCoordinator = analyticsCoordinator
}
func start() {
UIAlertController.alert(title: "\(R.string.localizable.settingsPingInfuraTitle())?",
message: nil,
alertButtonTitles: [R.string.localizable.oK(), R.string.localizable.cancel()],
alertButtonStyles: [.default, .cancel],
viewController: viewController,
completion: { choice in
guard choice == 0 else {
self.delegate?.didCancel(in: self)
return
}
self.pingInfura()
self.logUse()
self.delegate?.didPing(in: self)
})
}
private func pingInfura() {
let request = EtherServiceRequest(server: .main, batch: BatchFactory().create(BlockNumberRequest()))
firstly {
Session.send(request)
}.done { (x: Int) in
UIAlertController.alert(
title: R.string.localizable.settingsPingInfuraSuccessful(),
message: nil,
alertButtonTitles: [
R.string.localizable.oK()
],
alertButtonStyles: [
.cancel
],
viewController: self.viewController,
style: .alert)
}.catch { error in
UIAlertController.alert(title: R.string.localizable.settingsPingInfuraFail(),
message: "\(error)",
alertButtonTitles: [
R.string.localizable.oK(),
],
alertButtonStyles: [
.cancel
],
viewController: self.viewController,
style: .alert)
}
}
}
// MARK: Analytics
extension PingInfuraCoordinator {
private func logUse() {
analyticsCoordinator.log(action: Analytics.Action.pingInfura)
}
}

@ -310,10 +310,27 @@ extension SettingsCoordinator: AdvancedSettingsViewControllerDelegate {
controller.delegate = self
navigationController.pushViewController(controller, animated: true)
}
func advancedSettingsViewControllerPingInfuraSelected(in controller: AdvancedSettingsViewController) {
let coordinator = PingInfuraCoordinator(inViewController: rootViewController, analyticsCoordinator: analyticsCoordinator)
coordinator.delegate = self
coordinator.start()
addCoordinator(coordinator)
}
}
extension SettingsCoordinator: ChooseSendPrivateTransactionsProviderViewControllerDelegate {
func privateTransactionProviderSelected(provider: SendPrivateTransactionsProvider?, inController viewController: ChooseSendPrivateTransactionsProviderViewController) {
advancedSettingsViewController?.configure()
}
}
}
extension SettingsCoordinator: PingInfuraCoordinatorDelegate {
func didPing(in coordinator: PingInfuraCoordinator) {
removeCoordinator(self)
}
func didCancel(in coordinator: PingInfuraCoordinator) {
removeCoordinator(self)
}
}

@ -15,6 +15,7 @@ protocol AdvancedSettingsViewControllerDelegate: AnyObject {
func advancedSettingsViewControllerChangeCurrencySelected(in controller: AdvancedSettingsViewController)
func advancedSettingsViewControllerAnalyticsSelected(in controller: AdvancedSettingsViewController)
func advancedSettingsViewControllerUsePrivateNetworkSelected(in controller: AdvancedSettingsViewController)
func advancedSettingsViewControllerPingInfuraSelected(in controller: AdvancedSettingsViewController)
}
class AdvancedSettingsViewController: UIViewController {
@ -78,10 +79,9 @@ extension AdvancedSettingsViewController: UITableViewDataSource {
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let row = viewModel.rows[indexPath.row]
switch row {
case .analytics, .changeCurrency, .changeLanguage, .clearBrowserCache, .console, .tokenScript:
case .analytics, .changeCurrency, .changeLanguage, .clearBrowserCache, .console, .tokenScript, .pingInfura:
let cell: SettingTableViewCell = tableView.dequeueReusableCell(for: indexPath)
cell.configure(viewModel: .init(titleText: row.title, subTitleText: nil, icon: row.icon))
return cell
case .usePrivateNetwork:
let cell: SettingTableViewCell = tableView.dequeueReusableCell(for: indexPath)
@ -132,6 +132,8 @@ extension AdvancedSettingsViewController: UITableViewDelegate {
delegate?.advancedSettingsViewControllerAnalyticsSelected(in: self)
case .usePrivateNetwork:
delegate?.advancedSettingsViewControllerUsePrivateNetworkSelected(in: self)
case .pingInfura:
delegate?.advancedSettingsViewControllerPingInfuraSelected(in: self)
}
}
}

@ -12,9 +12,9 @@ struct AdvancedSettingsViewModel {
var rows: [AdvancedSettingsRow] = {
let privateNerworkRow: [AdvancedSettingsRow] = Features.isUsingPrivateNetwork ? [.usePrivateNetwork] : []
if Features.isLanguageSwitcherDisabled {
return [.console, .clearBrowserCache, .tokenScript] + privateNerworkRow
return [.console, .clearBrowserCache, .tokenScript, .pingInfura] + privateNerworkRow
} else {
return [.console, .clearBrowserCache, .tokenScript, .changeLanguage] + privateNerworkRow
return [.console, .clearBrowserCache, .tokenScript, .changeLanguage, .pingInfura] + privateNerworkRow
}
}()
@ -31,6 +31,7 @@ enum AdvancedSettingsRow: CaseIterable {
case changeCurrency
case analytics
case usePrivateNetwork
case pingInfura
var title: String {
switch self {
@ -48,6 +49,8 @@ enum AdvancedSettingsRow: CaseIterable {
return R.string.localizable.settingsAnalitycsTitle()
case .usePrivateNetwork:
return R.string.localizable.settingsChooseSendPrivateTransactionsProviderButtonTitle()
case .pingInfura:
return R.string.localizable.settingsPingInfuraTitle()
}
}
@ -67,6 +70,9 @@ enum AdvancedSettingsRow: CaseIterable {
return R.image.settings_analytics()!
case .usePrivateNetwork:
return R.image.iconsSettingsEthermine()!
case .pingInfura:
//TODO need a more appropriate icon, maybe represent diagnostic or (to a lesser degree Infura)
return R.image.settings_analytics()!
}
}
}

Loading…
Cancel
Save