-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from rrk12005/SWE-13-choose-bank-account
Swe 13 choose bank account
Showing
8 changed files
with
221 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
SynchronyFinancial/SynchronyFinancial WatchKit Extension/BankAcctCell.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// BankAcctCell.swift | ||
// SynchronyFinancial WatchKit Extension | ||
// | ||
// Created by Rahul Kantesaria on 4/5/19. | ||
// Copyright © 2019 Alan Maynard. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import WatchKit | ||
|
||
class BankAcctCell: NSObject { | ||
@IBOutlet weak var bankNameLabel: WKInterfaceLabel! | ||
@IBOutlet weak var last4Label: WKInterfaceLabel! | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...nyFinancial/SynchronyFinancial WatchKit Extension/PaymentOptionsInterfaceController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// | ||
// BankSelectionInterfaceController.swift | ||
// SynchronyFinancial WatchKit Extension | ||
// | ||
// Created by Rahul Kantesaria on 4/5/19. | ||
// Copyright © 2019 Alan Maynard. All rights reserved. | ||
// | ||
|
||
import WatchKit | ||
import Foundation | ||
|
||
class PaymentOptionsInterfaceController: WKInterfaceController { | ||
@IBOutlet weak var bankAcctTable: WKInterfaceTable! | ||
var bankAccts: [BankAcct] = [] | ||
var dictForDefault: [String: String] = [:] | ||
override func awake(withContext context: Any?) { | ||
super.awake(withContext: context) | ||
//grab the potential list of bank accounts from the payment detail controller | ||
guard let data = context as? [String: [BankAcct]], let accts = data["paymentOptions"] else { | ||
NSLog("Error receiving context containing bank accounts in PaymentOptionsInterfaceController") | ||
return | ||
} | ||
bankAccts = accts | ||
configureRows() | ||
} | ||
|
||
override func willActivate() { | ||
// This method is called when watch view controller is about to be visible to user | ||
super.willActivate() | ||
} | ||
|
||
override func didDeactivate() { | ||
// This method is called when watch view controller is no longer visible | ||
super.didDeactivate() | ||
} | ||
|
||
private func configureRows() { | ||
bankAcctTable.setNumberOfRows(bankAccts.count, withRowType: "bankAcctCell") | ||
for index in 0..<bankAcctTable.numberOfRows { | ||
if let row = bankAcctTable.rowController(at: index) as? BankAcctCell { | ||
row.bankNameLabel.setText(bankAccts[index].bankName) | ||
row.last4Label.setText("(\(bankAccts[index].last4Acct))") | ||
} | ||
} | ||
} | ||
|
||
override func table(_ table: WKInterfaceTable, didSelectRowAt rowIndex: Int) { | ||
let acct = bankAccts[rowIndex] | ||
dictForDefault.updateValue(acct.acctType.rawValue, forKey: "acctType") | ||
dictForDefault.updateValue(acct.bankAcctId, forKey: "bankAcctId") | ||
dictForDefault.updateValue(acct.bankName, forKey: "bankName") | ||
dictForDefault.updateValue(acct.last4Acct, forKey: "last4Acct") | ||
UserDefaults.standard.set(dictForDefault, forKey: "default_bank_acct") | ||
pop() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
SynchronyFinancial/SynchronyFinancial/UserDefaults+Extensions.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// | ||
// UserDefaults+Extensions.swift | ||
// SynchronyFinancial | ||
// | ||
// Created by Rahul Kantesaria on 4/8/19. | ||
// Copyright © 2019 Alan Maynard. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
extension UserDefaults { | ||
func setDefaultBankAccount(_ acct: BankAcct) { | ||
UserDefaults.standard.set(acct, forKey: "default_bank_acct") | ||
} | ||
|
||
func getDefaultBankAccount() -> BankAcct? { | ||
if let bankDict = UserDefaults.standard.value(forKey: "default_bank_acct") as? [String: String], | ||
let bankAcctId = bankDict["bankAcctId"], | ||
let acctTypeRaw: String = bankDict["acctType"], | ||
let bankName = bankDict["bankName"], | ||
let last4Acct = bankDict["last4Acct"], | ||
let acctType: AccountType = AccountType(rawValue: acctTypeRaw) { | ||
return BankAcct(bankAcctId: bankAcctId, acctType: acctType, bankName: bankName, last4Acct: last4Acct) | ||
} | ||
return nil | ||
} | ||
} |