Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update TGK app with SDK 3.5.0 #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions Podfile

This file was deleted.

20 changes: 0 additions & 20 deletions Podfile.lock

This file was deleted.

292 changes: 177 additions & 115 deletions TGK.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

67 changes: 41 additions & 26 deletions TGK/Controllers/Home.storyboard

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion TGK/Controllers/HomeVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class HomeVC: UIViewController {

navigationItem.setHidesBackButton(true, animated: true)
navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Log out", style: .plain, target: self, action: #selector(playTapped))
navigationItem.rightBarButtonItem?.tintColor = .white
view.bringSubviewToFront(overview)
}

Expand Down
84 changes: 25 additions & 59 deletions TGK/Controllers/LoginVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ class LogInViewController: UIViewController {

var webAuthSession: ASWebAuthenticationSession?

let webService = WebService()

override func viewDidLoad() {
super.viewDidLoad()
}
Expand All @@ -37,65 +35,30 @@ class LogInViewController: UIViewController {
}

func getAuthTokenWithWebLogin() {
guard let clientId = StoredSetting.key else { return }
guard let redirectUri = StoredSetting.uri else { return }
updateSignInButtonState(enabled: false)
let authURL = URL(string: "https://account-d.docusign.com/oauth/auth?response_type=code&scope=signature&client_id=\(clientId)&redirect_uri=\(redirectUri)")
let callbackUrlScheme = redirectUri.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)

self.webAuthSession = ASWebAuthenticationSession.init(url: authURL!, callbackURLScheme: callbackUrlScheme, completionHandler: { [weak self] (callBack:URL?, error:Error?) in

guard error == nil, let successURL = callBack else {
self?.updateSignInButtonState(enabled: true)
return
}

let oauthToken = NSURLComponents(string: (successURL.absoluteString))?.queryItems?.filter({$0.name == "code"}).first
guard let code = oauthToken?.value else { return }
guard let clientId = StoredSetting.secret else { return }
guard let redirectUri = StoredSetting.uri else { return }
guard let IK = StoredSetting.key else { return }
DSMManager.login(withOAuthEnv: .demo, accountId: clientId, redirectUri: redirectUri, integratorKey: IK) { accountInfo, error in

self?.webService.getAccessToken(code: code) { result in
switch result {
case .failure(let error):
self?.updateSignInButtonState(enabled: true)
print(error)
case .success(let data):
let accessToken = data.accessToken

Keychain.set(accessToken, forKey: KeychainKeys.token)

self?.webService.getUserInfo(accessToken: accessToken) { result in
switch result {
case .failure(let error):
self?.updateSignInButtonState(enabled: true)
print(error)
case .success(let data):
let accountInfo = data.accounts[0]
guard let key = StoredSetting.key else { return }

let email = data.email
let recipientId = accountInfo.accountId
let signerName = accountInfo.accountName

Keychain.set(email, forKey: KeychainKeys.accountEmail)
Keychain.set(recipientId, forKey: KeychainKeys.accountId)
Keychain.set(signerName, forKey: KeychainKeys.signerName)

self?.login(accessToken: accessToken,
accountId: accountInfo.accountId,
userId: data.sub,
userName: accountInfo.accountName,
email: data.email,
integratorKey: key)
}
}
guard let accountInfo else { return }
Keychain.set(accountInfo.accessToken, forKey: KeychainKeys.token)
Keychain.set(accountInfo.email, forKey: KeychainKeys.accountEmail)
Keychain.set(accountInfo.accountId, forKey: KeychainKeys.accountId)
Keychain.set(accountInfo.userName, forKey: KeychainKeys.signerName)
Keychain.set(accountInfo.host.absoluteString, forKey: KeychainKeys.baseUrl)

self.updateSignInButtonState(enabled: true)
if let error = error {
print("Error logging in: \(error)")
} else {
print("User authenticated")
let homeVC = VCFactory.createHomeVC()
DispatchQueue.main.async {
self.navigationController?.pushViewController(homeVC, animated: true)
}
}
})

self.webAuthSession?.presentationContextProvider = self
self.webAuthSession?.prefersEphemeralWebBrowserSession = true

self.webAuthSession?.start()
}
}

func updateSignInButtonState(enabled: Bool) {
Expand All @@ -117,15 +80,18 @@ class LogInViewController: UIViewController {
host: String = "https://demo.docusign.net/restapi",
integratorKey: String) {
guard let hostURL = URL(string: host) else { return }
DSMManager.login(withAccessToken: accessToken, accountId: accountId, userId: userId, userName: userName, email: email, host: hostURL, integratorKey: integratorKey) { [weak self] accountInfo, error in

DSMManager.login(withAccessToken: accessToken, accountId: accountId, userId: userId, userName: userName, email: email, host: hostURL, integratorKey: integratorKey, refreshToken: nil, expiresIn: nil) { [weak self] accountInfo, error in

self?.updateSignInButtonState(enabled: true)
if let error = error {
print("Error logging in: \(error)")
} else {
print("User authenticated")
let homeVC = VCFactory.createHomeVC()
self?.navigationController?.pushViewController(homeVC, animated: true)
DispatchQueue.main.async {
self?.navigationController?.pushViewController(homeVC, animated: true)
}
}
}
}
Expand Down
35 changes: 35 additions & 0 deletions TGK/Controllers/OverviewVC.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

import UIKit
import DocuSignSDK

class OverviewVC: UIViewController {

Expand All @@ -20,6 +21,40 @@ class OverviewVC: UIViewController {

tableView.register(UINib(nibName: "OverviewDocCell", bundle: nil), forCellReuseIdentifier: "OverviewDocCell")
}

@IBAction func executeAPIButtonTapped(_ sender: Any) {
let basePath: String = Keychain.value(forKey: KeychainKeys.baseUrl)! // Base path for API calls (demo/prod)
if let accountId: String = Keychain.value(forKey: KeychainKeys.accountId){ // Param needed for API call

// Initializing the API client with the access token and base url
DSClientAPI.init(basePath: basePath , customHeaders: [:])

let activityIndicator = UIActivityIndicatorView(style: .large)
activityIndicator.frame = CGRect(x: 0, y: 0, width: 80, height: 80)
activityIndicator.center = self.view.center
self.view.addSubview(activityIndicator)
activityIndicator.startAnimating()
// Picking the needed api call and providing the needed params for this api call
AccountsAPI.accountsGetAccount(accountId: accountId, includeAccountSettings: nil, completion: { data, error in
activityIndicator.stopAnimating()
//completion handling for error and sucess of request
if let error = error {
let message = error.localizedDescription
let alert = UIAlertController(title: "Request failed", message: message, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Ok", style: .default, handler: nil))
self.present(alert, animated: true, completion: nil)
print(error)
}
else {
let message = "AccountName: \(String(describing: data?.accountName))\n PlanName: \(String(describing: data?.planName))"
let alert = UIAlertController(title: "Request Successful", message: message, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Ok", style: .default, handler: nil))
self.present(alert, animated: true, completion: nil)
print(message)
}
})
}
}
}

extension OverviewVC: UITableViewDelegate {
Expand Down
247 changes: 207 additions & 40 deletions TGK/Controllers/ViewAgreementVC.swift

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions TGK/Helpers/KeychainKeys.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ struct KeychainKeys {
static let accountEmail = "kAccountEmail"
static let accountId = "kAccountId"
static let signerName = "kSignerName"
static let baseUrl = "kBaseUrl"
}
9 changes: 5 additions & 4 deletions TGK/Managers/EnvelopeManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class EnvelopesManager {
// `Downloading remote envelopes for offline signing` is disabled for now as this feature is in beta.

// Download the remote envelope from DocuSign Server with a given envelope Id
/* self.mDSMEnvelopesManager?.downloadEnvelope(withId: envelopeId) { _, error in
self.mDSMEnvelopesManager?.downloadEnvelope(withId: envelopeId) { _, error in

guard error == nil else {
// Handle error ...
Expand All @@ -57,7 +57,7 @@ class EnvelopesManager {
// Envelope download is complete, start offline signing ceremony
self.resumeOfflineSigning(presentingViewController: presentingController, envelopeId: envelopeId, completion: completion)
}
} */
}
}

func resumeOfflineSigning(presentingViewController: UIViewController, envelopeId: String, completion: @escaping (UIViewController?, Error?) -> Void) {
Expand All @@ -69,8 +69,9 @@ class EnvelopesManager {
}

func applyAppearance() {
DSMAppearance.setNavigationBarTitleTextColor(TGKColors.navigationBackButtonTintColor, backgroundTintColor: TGKColors.background, fontSize: 12)
DSMAppearance.setBarButtonItemsTintColor(TGKColors.foreground)
DSMAppearance.setNavigationBarTitleTextColor(TGKColors.navigationBackButtonTintColor)
DSMAppearance.setNavigationBarTitleTextColor(TGKColors.foreground, backgroundTintColor: TGKColors.background, fontSize: 14)
DSMAppearance.setBarButtonItemsTintColor(TGKColors.foreground)
}

func composeEnvelopeOffline(presentingController: UIViewController) {
Expand Down
20 changes: 10 additions & 10 deletions TGK/Models/ClientModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,32 @@ struct ClientModel {

struct Clients {
func createdFakeClientData() -> [ClientModel] {
let file1 = ClientModel(firstName: "Tom",
lastName: "Wood",
let file1 = ClientModel(firstName: "Triston",
lastName: "Gilbert",
address: "726 Tennessee St",
city: "San Francisco",
state: "California",
country: "U.S.A.",
zipCode: "94107",
email: "tom.wood@digital.com",
phone: "415-555-1234",
email: "Triston.Gilbert@dsxtr.com",
phone: "510-555-1234",
clientNumber: "FA-45231-005",
investmentAmount: "$25,000.00",
datedDoc: "June 20, 2019",
investmentAmount: "$500,000.00",
datedDoc: "Oct 26, 2021",
status: "Unsigned")

let file2 = ClientModel(firstName: "Andrea",
lastName: "Ruhn",
address: "726 Tennessee St",
address: "221 Berkeley Drive",
city: "Los Angeles",
state: "California",
country: "U.S.A.",
zipCode: "70707",
zipCode: "90039",
email: "[email protected]",
phone: "555-666-1234",
phone: "213-666-1234",
clientNumber: "FA-43224-086",
investmentAmount: "$300,000.00",
datedDoc: "May 18, 2020",
datedDoc: "Oct 26, 2021",
status: "Unsigned")
let files = [file1, file2]
return files
Expand Down
34 changes: 0 additions & 34 deletions TGK/Network/APIRouter.swift

This file was deleted.

23 changes: 0 additions & 23 deletions TGK/Network/Models/AuthorizationResponse.swift

This file was deleted.

Loading