You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

158 lines
4.8 KiB

  1. //
  2. // DebugManager.swift
  3. // GME Remit
  4. //
  5. // Created by InKwon James Kim on 07/10/2019.
  6. // Copyright © 2019 Gobal Money Express Co. Ltd. All rights reserved.
  7. //
  8. import UIKit
  9. #if DEBUG
  10. class DebugManager {
  11. static let shared = DebugManager()
  12. var testAccountID: String {
  13. switch server {
  14. case .live:
  15. return "demo.gme@gmeremit.com"
  16. default:
  17. return "maxkim@gmeremit.com"
  18. }
  19. }
  20. var testAccountPW: String {
  21. switch server {
  22. case .live:
  23. return "4D544B31" +
  24. "316F6E65656238383165626E6F386E72" +
  25. "773D8130C548A4605ADE3CF5457E3654" +
  26. "76DE37B9DA2A9004AFA1D827BC650CAB" +
  27. "580D9B8B93B176DAC5F91CFED8A6DE53" +
  28. "C0BBF01D209ADFB3E41B0266E7FE6102" +
  29. "3F2A078EDAB0C42CEFE9BE99D669AC62" +
  30. "EB00AAC64E7E2531E7EBE8ED3BE21927" +
  31. "FAC9A6B5BF0DA009A4652FE4A35E0560"
  32. case .staging:
  33. return "4D544B31" +
  34. "616C3173547262696E6C627972793169" +
  35. "4CA2454B8DC6023AEA498848CB87D85D" +
  36. "4D846586FF1CD66BD78A7A9340C78506" +
  37. "02D49F49BE08197C5018F65B5F20F1D1" +
  38. "67B108BAD1595003B48582EB6E89AF66" +
  39. "E8F58B70EC3EF40F1F06739F6270640E" +
  40. "0C05ED3FE76C6B59607258B65F9C7E8C"
  41. default:
  42. return "4D544B31" +
  43. "54546E386E65696C614B69656154696F" +
  44. "291C7DA9B5DEBA7E0CBA2C6DABE461B4" +
  45. "0FFF47EEED3448FA85530F5238D2DBCB" +
  46. "F03D6764191913A4272A7D8E4D5F650A"
  47. }
  48. }
  49. func setTestAccount(target: UIViewController, completion: ((String, String) -> Void)? = nil) {
  50. let alertcontroller = UIAlertController(title: "Test Account", message: nil, preferredStyle: .actionSheet)
  51. alertcontroller.view.tintColor = .themeText
  52. let testAction = UIAlertAction(title: testAccountID, style: .destructive, handler: { _ in
  53. completion?(self.testAccountID, self.testAccountPW)
  54. })
  55. let otherAction = UIAlertAction(title: "Other", style: .default, handler: nil)
  56. alertcontroller.addAction(testAction)
  57. alertcontroller.addAction(otherAction)
  58. if UIDevice.current.userInterfaceIdiom == .pad {
  59. if let popoverController = alertcontroller.popoverPresentationController {
  60. popoverController.sourceView = target.view
  61. popoverController.sourceRect = CGRect(
  62. x: target.view.bounds.midX,
  63. y: target.view.bounds.midY,
  64. width: 0,
  65. height: 0
  66. )
  67. popoverController.permittedArrowDirections = []
  68. target.present(alertcontroller, animated: true, completion: nil)
  69. }
  70. } else {
  71. target.present(alertcontroller, animated: true, completion: nil)
  72. }
  73. }
  74. func selectServerAlert(target: UIViewController, completion: (() -> Void)? = nil ) {
  75. let alertcontroller = UIAlertController(
  76. title: "Select Test Server",
  77. message: nil,
  78. preferredStyle: .actionSheet
  79. )
  80. alertcontroller.view.tintColor = .themeText
  81. var actions = [UIAlertAction]()
  82. Server.allCases.forEach { value in
  83. let action = UIAlertAction(title: value.rawValue, style: .default, handler: { _ in
  84. server = value
  85. UrlManager.sharedInstance.refreshBaseURL()
  86. switch server {
  87. case .ngrok:
  88. let alert = UIAlertController(
  89. title: "ngrok",
  90. message: "Set your ngrok code",
  91. preferredStyle: .alert
  92. )
  93. alert.addTextField {
  94. $0.text = GMEDB.shared.app.string(.ngrokHost)
  95. $0.sendActions(for: .editingChanged)
  96. $0.clearButtonMode = .whileEditing
  97. }
  98. let ok = UIAlertAction(title: "Set", style: .default) { _ in
  99. GMEDB.shared.app.set(alert.textFields?[0].text, .ngrokHost)
  100. completion?()
  101. }
  102. let cancel = UIAlertAction(title: "Cancel", style: .destructive) { _ in
  103. self.selectServerAlert(target: target, completion: completion)
  104. }
  105. alert.addAction(ok)
  106. alert.addAction(cancel)
  107. target.present(alert, animated: true, completion: nil)
  108. default:
  109. completion?()
  110. }
  111. })
  112. actions.append(action)
  113. }
  114. actions.forEach {
  115. alertcontroller.addAction($0)
  116. }
  117. if UIDevice.current.userInterfaceIdiom == .pad {
  118. if let popoverController = alertcontroller.popoverPresentationController {
  119. popoverController.sourceView = target.view
  120. popoverController.sourceRect = CGRect(
  121. x: target.view.bounds.midX,
  122. y: target.view.bounds.midY,
  123. width: 0,
  124. height: 0
  125. )
  126. popoverController.permittedArrowDirections = []
  127. target.present(alertcontroller, animated: true, completion: nil)
  128. }
  129. } else {
  130. target.present(alertcontroller, animated: true, completion: nil)
  131. }
  132. }
  133. }
  134. #endif