Skip to content

Swe 24 show pending transactions and allow cancel #16

Merged
merged 9 commits into from Apr 9, 2019
Next

SWE-24 change context type to support passing account

- we require the `accountAlias` of the current account in order to cancel a payment
- changed the type of dictionary passed through Transactions functionality to support getting the account to transaction details, so we can ultimate use to cancel a pending payment
  • Loading branch information
ahm11003 committed Apr 8, 2019
commit 143ffe2ffd5075b655855473386b24441393204d
@@ -12,7 +12,7 @@ import Foundation
class AccountDetailsInterfaceController: WKInterfaceController {
var selectedAccount: Account?
var dictForAcct: [String: Account] = [:]
var transactionDict: [String: [Transaction]] = [:]
var transactionDict: [String: Any] = [:]

@IBOutlet var loadingLabel: WKInterfaceLabel!
@IBOutlet var activityIndicator: WKInterfaceImage!
@@ -41,6 +41,9 @@ class AccountDetailsInterfaceController: WKInterfaceController {
return
}

if let acct = self.selectedAccount {
self.transactionDict.updateValue(acct, forKey: "acct")
}
self.transactionDict.updateValue(transactions, forKey: "transactions")
self.pushController(withName: "Transactions", context: self.transactionDict)
self.configureInterfaceObjects(false)
@@ -14,19 +14,22 @@ class TransactionDetailsInterfaceController: WKInterfaceController {
@IBOutlet var dateLabel: WKInterfaceLabel!
@IBOutlet var amountLabel: WKInterfaceLabel!
@IBOutlet var cancelButton: WKInterfaceButton!
var account: Account?
override func awake(withContext context: Any?) {
super.awake(withContext: context)

guard let data = context as? [String: Any],
let transaction = data["transaction"] as? Transaction,
let merchant = data["merchant"] as? String,
let date = data["date"] as? Date,
let amount = data["amount"] as? Double else {
let amount = data["amount"] as? Double,
let acct = data["acct"] as? Account else {
NSLog("Error receiving context in TransactionDetails.")
return
}

setTitle("Dismiss")
account = acct
transactionName.setText(merchant)
dateLabel.setText("Date: \(DateFormatter.localizedString(from: date, dateStyle: .short, timeStyle: .none))")
amountLabel.setText(String(format: "Amount: $%.2f", amount))
@@ -12,15 +12,19 @@ import Foundation
class TransactionsInterfaceController: WKInterfaceController {
@IBOutlet weak var transactionsTable: WKInterfaceTable!
var transactions: [Transaction] = []
var account: Account?

override func awake(withContext context: Any?) {
super.awake(withContext: context)

guard let data = context as? [String: [Transaction]], let trans = data["transactions"] else {
NSLog("Error receiving context containing transactions in TransactionsInterfaceController")
return
guard let data = context as? [String: Any],
let trans = data["transactions"] as? [Transaction],
let acct = data["acct"] as? Account else {
NSLog("Error receiving context containing transactions in TransactionsInterfaceController")
return
}

account = acct
transactions = trans
configureRows()
}
@@ -36,11 +40,13 @@ class TransactionsInterfaceController: WKInterfaceController {
}

override func table(_ table: WKInterfaceTable, didSelectRowAt rowIndex: Int) {
guard let acct = account else { return }
let transaction = transactions[rowIndex]
let context: [String: Any] = ["transaction": transaction,
"merchant": transaction.merchantID,
"date": transaction.date,
"amount": transaction.amount]
"amount": transaction.amount,
"acct": acct]

presentController(withName: "TransactionDetails", context: context)
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.