[Live] Use the JWT to determine registration status instead of deriving it through eigen logic #1638
Merged
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
23f5253
[Live] Use new graphQL syntax for observer role
orta e7961a3
Merge branch 'master' of https://github.com/artsy/eigen
orta 3e2dfe6
Merge branch 'master' of https://github.com/artsy/eigen
orta 76fb4fc
[Live] use the JWT to determine logged in / bidder status
orta 9114734
[Live] Use the JWT to determine the registration status [WIP]
orta 3d4ccf4
[Live JWT] Make green
orta 3798e94
Update Pods
orta
Jump to file
+21
−0
Contents.swift
Artsy/Eigen.playground/Contents.swift
+2
−3
LiveAuctionSocketCommunicator.swift
...ng/Live_Auctions/LiveAuctionSocketCommunicator.swift
+2
−1
Artsy-Bridging-Header.h
Artsy/Resources/Artsy-Bridging-Header.h
+7
−17
LiveAuctionLotViewController.swift
...ers/Live_Auctions/LiveAuctionLotViewController.swift
+13
−9
LiveAuctionStateManager.swift
...trollers/Live_Auctions/LiveAuctionStateManager.swift
+25
−18
LiveAuctionStateManagerSpec.swift
...lers/Live_Auctions/LiveAuctionStateManagerSpec.swift
+46
−4
LiveAuctionStaticDataFetcher.swift
...ers/Live_Auctions/LiveAuctionStaticDataFetcher.swift
+2
−1
LiveAuctionViewController.swift
...ollers/Live_Auctions/LiveAuctionViewController.swift
+3
−1
LiveAuctionBiddingViewModel.swift
...ive_Auctions/Views/LiveAuctionBiddingViewModel.swift
+4
−2
LiveAuctionSocketCommunicatorSpec.swift
...ive_Auctions/LiveAuctionSocketCommunicatorSpec.swift
+1
−1
LiveAuctionStaticDataFetcherSpec.swift
...Live_Auctions/LiveAuctionStaticDataFetcherSpec.swift
BIN
snapshots__looks_good_for_upcoming_lots@2x.png
...Tests/snapshots__looks_good_for_upcoming_lots@2x.png
BIN
snapshots__looks_good_when_its_lot_becomes_the_current_lot@2x.png
...oks_good_when_its_lot_becomes_the_current_lot@2x.png
+19
−1
FakeSalesPerson.swift
..._Controller_Tests/Live_Auction/FakeSalesPerson.swift
+4
−8
LiveAuctionLotViewControllerTests.swift
...Live_Auction/LiveAuctionLotViewControllerTests.swift
21
Artsy/Eigen.playground/Contents.swift
| @@ -1 +1,22 @@ | ||
| import Foundation | ||
| + | ||
| +let string = "eyJhdWQiOiJhdWN0aW9ucyIsInJvbGUiOiJiaWRkZXIiLCJ1c2VySWQiOiI0ZWM5MmNjYjU2YWU4ODAwMDEwMDAzOGUiLCJzYWxlSWQiOiI1NzU1YjA3YzVmOWY4ZjVjYjYwMDAwMDIiLCJiaWRkZXJJZCI6Ijk0MDIxNiIsImlhdCI6MTQ2NTI0MzkxMzIxMX0" | ||
| + | ||
| +let stringData = string.dataUsingEncoding(NSUTF8StringEncoding) | ||
| + | ||
| +//let decodedData = NSData(base64EncodedString: string, options:[.IgnoreUnknownCharacters]) | ||
| +//let decodedData = NSData(base64EncodedData:stringData!, options:[.IgnoreUnknownCharacters]) | ||
| + | ||
| +let paddedLength = string.characters.count + (4 - (string.characters.count % 4)); | ||
| +let correctBase64String = string.stringByPaddingToLength(paddedLength, withString:"=", startingAtIndex:0) | ||
| + | ||
| + | ||
| +let decodedData = NSData(base64EncodedString: correctBase64String, options: [.IgnoreUnknownCharacters]) | ||
| + | ||
| + | ||
| + | ||
| +//let decodedString = NSString(data: decodedData, encoding: NSUTF8StringEncoding) | ||
| + | ||
| +if let data = decodedData { | ||
| + let result = NSString(data: data, encoding:NSUTF8StringEncoding) | ||
| +} |
5
Artsy/Networking/Live_Auctions/LiveAuctionSocketCommunicator.swift
3
Artsy/Resources/Artsy-Bridging-Header.h
24
Artsy/View_Controllers/Live_Auctions/LiveAuctionLotViewController.swift
22
Artsy/View_Controllers/Live_Auctions/LiveAuctionStateManager.swift
| @@ -22,20 +22,12 @@ class LiveAuctionStateManager: NSObject { | ||
| let sale: LiveSale | ||
| let bidderID: String? | ||
| - | ||
| + let bidderStatus: ArtsyAPISaleRegistrationStatus | ||
| private let socketCommunicator: LiveAuctionSocketCommunicatorType | ||
| private let stateReconciler: LiveAuctionStateReconcilerType | ||
| private var biddingStates = [String: LiveAuctionBiddingViewModelType]() | ||
| - var bidderStatus: ArtsyAPISaleRegistrationStatus { | ||
| - let loggedIn = User.currentUser() != nil | ||
| - let hasBidder = bidderID != nil | ||
| - | ||
| - if !loggedIn { return .NotLoggedIn } | ||
| - return hasBidder ? .Registered : .NotRegistered | ||
| - } | ||
| - | ||
| var socketConnectionSignal: Observable<Bool> { | ||
| return socketCommunicator.socketConnectionSignal | ||
| } | ||
| @@ -53,6 +45,8 @@ class LiveAuctionStateManager: NSObject { | ||
| self.socketCommunicator = socketCommunicatorCreator(host: host, causalitySaleID: sale.causalitySaleID, jwt: jwt) | ||
| self.stateReconciler = stateReconcilerCreator(saleArtworks: saleArtworks) | ||
| + self.bidderStatus = LiveAuctionStateManager.registrationStatusFromJWT(jwt) | ||
| + | ||
| super.init() | ||
| socketCommunicator.updatedAuctionState.subscribe { [weak self] state in | ||
| @@ -80,6 +74,16 @@ class LiveAuctionStateManager: NSObject { | ||
| biddingViewModel?.bidPendingSignal.update(confirmed) | ||
| } | ||
| } | ||
| + | ||
| + private class func registrationStatusFromJWT(jwt: JWT) -> ArtsyAPISaleRegistrationStatus { | ||
|
ashfurrow
It makes sense to have this in a class function, but I can see a few alternatives, like in an extension on
orta
aye it is, but realistically, this will get lost in the noise for the next few weeks from Live, then WWDC. |
||
| + guard let _ = jwt.userID else { return .NotLoggedIn } | ||
| + switch jwt.role { | ||
| + case .Bidder: | ||
| + return .Registered | ||
| + default: | ||
| + return .NotRegistered | ||
| + } | ||
| + } | ||
| } | ||
| private typealias PublicFunctions = LiveAuctionStateManager | ||
43
Artsy/View_Controllers/Live_Auctions/LiveAuctionStateManagerSpec.swift
50
Artsy/View_Controllers/Live_Auctions/LiveAuctionStaticDataFetcher.swift
3
Artsy/View_Controllers/Live_Auctions/LiveAuctionViewController.swift
4
Artsy/View_Controllers/Live_Auctions/Views/LiveAuctionBiddingViewModel.swift
6
Artsy_Tests/Networking_Tests/Live_Auctions/LiveAuctionSocketCommunicatorSpec.swift
2
Artsy_Tests/Networking_Tests/Live_Auctions/LiveAuctionStaticDataFetcherSpec.swift
BIN
...ceImages/LiveAuctionLotViewControllerTests/snapshots__looks_good_for_upcoming_lots@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN
...nLotViewControllerTests/snapshots__looks_good_when_its_lot_becomes_the_current_lot@2x.png
Deleted file not rendered
20
Artsy_Tests/View_Controller_Tests/Live_Auction/FakeSalesPerson.swift
12
Artsy_Tests/View_Controller_Tests/Live_Auction/LiveAuctionLotViewControllerTests.swift
Oh gee, wish we had a linter!😉