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.
 
 
 
 

149 lines
4.4 KiB

//
// DebugManager.swift
// GME Remit
//
// Created by InKwon James Kim on 07/10/2019.
// Copyright © 2019 Gobal Money Express Co. Ltd. All rights reserved.
//
import UIKit
#if DEBUG
class DebugManager {
static let shared = DebugManager()
var testAccountID: String {
switch server {
case .live:
return "demo.gme@gmeremit.com"
default:
return "maxkim@gmeremit.com"
}
}
var testAccountPW: String {
switch server {
case .live:
return "4D544B31" +
"316F6E65656238383165626E6F386E72" +
"773D8130C548A4605ADE3CF5457E3654" +
"76DE37B9DA2A9004AFA1D827BC650CAB" +
"580D9B8B93B176DAC5F91CFED8A6DE53" +
"C0BBF01D209ADFB3E41B0266E7FE6102" +
"3F2A078EDAB0C42CEFE9BE99D669AC62" +
"EB00AAC64E7E2531E7EBE8ED3BE21927" +
"FAC9A6B5BF0DA009A4652FE4A35E0560"
default:
return "4D544B31" +
"54546E386E65696C614B69656154696F" +
"291C7DA9B5DEBA7E0CBA2C6DABE461B4" +
"0FFF47EEED3448FA85530F5238D2DBCB" +
"F03D6764191913A4272A7D8E4D5F650A"
}
}
func setTestAccount(target: UIViewController, completion: ((String, String) -> Void)? = nil) {
let alertcontroller = UIAlertController(title: "Test Account", message: nil, preferredStyle: .actionSheet)
alertcontroller.view.tintColor = .themeText
let testAction = UIAlertAction(title: testAccountID, style: .destructive, handler: { _ in
completion?(self.testAccountID, self.testAccountPW)
})
let otherAction = UIAlertAction(title: "Other", style: .default, handler: nil)
alertcontroller.addAction(testAction)
alertcontroller.addAction(otherAction)
if UIDevice.current.userInterfaceIdiom == .pad {
if let popoverController = alertcontroller.popoverPresentationController {
popoverController.sourceView = target.view
popoverController.sourceRect = CGRect(
x: target.view.bounds.midX,
y: target.view.bounds.midY,
width: 0,
height: 0
)
popoverController.permittedArrowDirections = []
target.present(alertcontroller, animated: true, completion: nil)
}
} else {
target.present(alertcontroller, animated: true, completion: nil)
}
}
func selectServerAlert(target: UIViewController, completion: (() -> Void)? = nil ) {
let alertcontroller = UIAlertController(
title: "Select Test Server",
message: nil,
preferredStyle: .actionSheet
)
alertcontroller.view.tintColor = .themeText
var actions = [UIAlertAction]()
Server.allCases.forEach { value in
let action = UIAlertAction(title: value.rawValue, style: .default, handler: { _ in
server = value
UrlManager.sharedInstance.refreshBaseURL()
switch server {
case .ngrok:
let alert = UIAlertController(
title: "ngrok",
message: "Set your ngrok code",
preferredStyle: .alert
)
alert.addTextField {
$0.text = GMEDB.shared.app.string(.ngrokHost)
$0.sendActions(for: .editingChanged)
$0.clearButtonMode = .whileEditing
}
let ok = UIAlertAction(title: "Set", style: .default) { _ in
GMEDB.shared.app.set(alert.textFields?[0].text, .ngrokHost)
completion?()
}
let cancel = UIAlertAction(title: "Cancel", style: .destructive) { _ in
self.selectServerAlert(target: target, completion: completion)
}
alert.addAction(ok)
alert.addAction(cancel)
target.present(alert, animated: true, completion: nil)
default:
completion?()
}
})
actions.append(action)
}
actions.forEach {
alertcontroller.addAction($0)
}
if UIDevice.current.userInterfaceIdiom == .pad {
if let popoverController = alertcontroller.popoverPresentationController {
popoverController.sourceView = target.view
popoverController.sourceRect = CGRect(
x: target.view.bounds.midX,
y: target.view.bounds.midY,
width: 0,
height: 0
)
popoverController.permittedArrowDirections = []
target.present(alertcontroller, animated: true, completion: nil)
}
} else {
target.present(alertcontroller, animated: true, completion: nil)
}
}
}
#endif