Skip to content

Commit

Permalink
SWF-21 Initial transaction implementation
Browse files Browse the repository at this point in the history
- we now fetch transactions for a given account when that account is selected from the table
- storyboard segue to present account details and transactions was deleted in favor of presenting programmatically in order to only perform the segue once web service to fetch transactions completes
- removed some code populating UI with demo data
  • Loading branch information
ahm11003 committed Mar 28, 2019
1 parent 21d742c commit 8487ce3
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder.WatchKit.Storyboard" version="3.0" toolsVersion="14460.31" targetRuntime="watchKit" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="Qge-pO-HLc">
<device id="watch38" orientation="portrait">
<document type="com.apple.InterfaceBuilder.WatchKit.Storyboard" version="3.0" toolsVersion="14490.64" targetRuntime="watchKit" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="Qge-pO-HLc">
<device id="watch42" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="watchOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14460.20"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBWatchKitPlugin" version="14460.16"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14490.47"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBWatchKitPlugin" version="14490.20"/>
</dependencies>
<scenes>
<!--Main Menu Interface Controller-->
Expand Down Expand Up @@ -100,7 +100,6 @@
</group>
<connections>
<outlet property="accountName" destination="Tl1-Kc-YJS" id="cgD-CY-lzh"/>
<segue destination="yrN-yp-gkH" kind="modal" identifier="showAccountDetails" id="geu-70-EU1"/>
</connections>
</tableRow>
</items>
Expand All @@ -113,10 +112,10 @@
</objects>
<point key="canvasLocation" x="414" y="-53"/>
</scene>
<!--Account Details Interface Controller-->
<!--AccountDetails-->
<scene sceneID="ozX-Kj-4yZ">
<objects>
<controller id="yrN-yp-gkH" customClass="AccountDetailsInterfaceController" customModule="SynchronyFinancial_WatchKit_Extension">
<controller identifier="AccountDetails" id="yrN-yp-gkH" customClass="AccountDetailsInterfaceController" customModule="SynchronyFinancial_WatchKit_Extension">
<items>
<label width="1" alignment="left" text="Label" textAlignment="center" id="qzl-GE-bpZ">
<fontDescription key="font" style="UICTFontTextStyleHeadline"/>
Expand All @@ -137,10 +136,10 @@
</objects>
<point key="canvasLocation" x="755" y="-53.5"/>
</scene>
<!--Transactions Interface Controller-->
<!--Transactions-->
<scene sceneID="yXO-yR-k6b">
<objects>
<controller id="Jfd-Hv-PHe" customClass="TransactionsInterfaceController" customModule="SynchronyFinancial_WatchKit_Extension">
<controller identifier="Transactions" id="Jfd-Hv-PHe" customClass="TransactionsInterfaceController" customModule="SynchronyFinancial_WatchKit_Extension">
<items>
<table alignment="left" id="OQb-xu-Ynf">
<items>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Foundation
class AccountTableInterfaceController: WKInterfaceController {
var accounts: [Account] = []
var acctDict: [String: Account] = [:]
var transactionDict: [String: [Transaction]] = [:]

@IBOutlet weak var accountTable: WKInterfaceTable!
override func awake(withContext context: Any?) {
Expand All @@ -38,12 +39,22 @@ class AccountTableInterfaceController: WKInterfaceController {
if segueIdentifier == "showAccountDetails" {
// account data is passed to the first interface controller in our new navigation stack
// if we want to pass to subsequent interface controllers, we would add them in corresponding order
acctDict.updateValue(accounts[rowIndex], forKey: "acct")
// acctDict.updateValue(accounts[rowIndex], forKey: "acct")
// acctDict.updateValue(transactions, forKey: "transactions")
return [acctDict]
}
return nil
}

override func table(_ table: WKInterfaceTable, didSelectRowAt rowIndex: Int) {
acctDict.updateValue(accounts[rowIndex], forKey: "acct")
FetchData.fetchTransactionsFor(accountAlias: accounts[rowIndex].accountAlias) { transactions, error in
guard error == nil else { return }
self.transactionDict.updateValue(transactions, forKey: "transactions")
self.presentController(withNames: ["AccountDetails", "Transactions"], contexts: [self.acctDict, self.transactionDict])
}
}

private func configureRows() {
accountTable.setNumberOfRows(accounts.count, withRowType: "account")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ class TransactionsInterfaceController: WKInterfaceController {

override func awake(withContext context: Any?) {
super.awake(withContext: context)
for i in 0..<5 {
transactions.append(Transaction(type: .purchase, amount: 50.00 * Double(i), merchantID: "WalMart Store 1245\(i)", date: Calendar.current.date(byAdding: .day, value: -i, to: Date()) ?? Date()))
transactions.append(Transaction(type: .reimbursement, amount: 12.5 * Double(i), merchantID: "Thank You", date: Calendar.current.date(byAdding: .day, value: -i, to: Date()) ?? Date()))

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

transactions = trans
configureRows()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
281283568A34D3C5D9C7B383 /* libPods-SynchronyFinancial WatchKit Extension.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CAA6D46F907ADAABF49FD409 /* libPods-SynchronyFinancial WatchKit Extension.a */; };
48DA0058221D12E70081A500 /* AccountCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48DA0057221D12E70081A500 /* AccountCell.swift */; };
48F243072214C98600B9C894 /* AccountTableInterfaceController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48F243062214C98600B9C894 /* AccountTableInterfaceController.swift */; };
48F243082214CA9600B9C894 /* AccountTableInterfaceController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48F243062214C98600B9C894 /* AccountTableInterfaceController.swift */; };
48F2430A2214CBA200B9C894 /* Interface.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 67BAC27C219E254800713FEF /* Interface.storyboard */; };
48F2430D2214CBF700B9C894 /* Account.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48F2430B2214CBF700B9C894 /* Account.swift */; };
48F2430E2214CBF700B9C894 /* Transaction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 48F2430C2214CBF700B9C894 /* Transaction.swift */; };
Expand Down Expand Up @@ -171,8 +170,6 @@
48F2430B2214CBF700B9C894 /* Account.swift */,
48F2430C2214CBF700B9C894 /* Transaction.swift */,
67E17B85223812C2008871FE /* Defaults.swift */,
6717460B21F8FCC100696468 /* Account.swift */,
6717460921F8FCBE00696468 /* Transaction.swift */,
67BAC268219E254700713FEF /* AppDelegate.swift */,
67BAC26C219E254700713FEF /* Main.storyboard */,
67BAC26F219E254800713FEF /* Assets.xcassets */,
Expand Down Expand Up @@ -455,13 +452,11 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
6717460A21F8FCBF00696468 /* Transaction.swift in Sources */,
67E17B86223812C2008871FE /* Defaults.swift in Sources */,
48F2430D2214CBF700B9C894 /* Account.swift in Sources */,
678C388622309F7D00FEAAF6 /* AccountCell.swift in Sources */,
48F2430E2214CBF700B9C894 /* Transaction.swift in Sources */,
67BAC269219E254700713FEF /* AppDelegate.swift in Sources */,
48F243082214CA9600B9C894 /* AccountTableInterfaceController.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -474,9 +469,7 @@
678C38842230950100FEAAF6 /* AccountDetailsInterfaceController.swift in Sources */,
673F396E21A644570051469E /* MainMenuInterfaceController.swift in Sources */,
67E17B87223812C2008871FE /* Defaults.swift in Sources */,
6717460E21F8FCDB00696468 /* Transaction.swift in Sources */,
1123372E223ABD6400B70925 /* FetchData.swift in Sources */,
6717460D21F8FCD800696468 /* Account.swift in Sources */,
48F243072214C98600B9C894 /* AccountTableInterfaceController.swift in Sources */,
676392B62242A3F800740A8C /* TransactionCell.swift in Sources */,
48F2430F2214CC2200B9C894 /* Transaction.swift in Sources */,
Expand Down

0 comments on commit 8487ce3

Please sign in to comment.