Skip to content

Commit

Permalink
feat(encryption): ux improvements to transfer views
Browse files Browse the repository at this point in the history
  • Loading branch information
mhamann committed Aug 19, 2022
1 parent 9087936 commit 16eb78d
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>RowndFrameworkTestApp.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
<integer>0</integer>
</dict>
<key>RowndSDK.xcscheme_^#shared#^_</key>
<dict>
Expand Down
32 changes: 29 additions & 3 deletions Sources/Rownd/Models/Context/Context.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ public struct RowndState: Codable, Hashable {

extension RowndState {
static func save(state: RowndState) {
let encoder = JSONEncoder()
if let encoded = try? encoder.encode(state) {
if let encoded = try? state.toJson() {
// logger.trace("storing: \(String(data: encoded, encoding: .utf8) ?? "{}")")
Storage.store?.set(String(data: encoded, encoding: .utf8), forKey: STORAGE_STATE_KEY)
Storage.store?.set(encoded, forKey: STORAGE_STATE_KEY)
}
}

Expand All @@ -35,6 +34,21 @@ extension RowndState {
store.dispatch(InitializeRowndState(payload: decoded))
}
}

public func toJson() throws -> String? {
let encoder = JSONEncoder()
if let encoded = try? encoder.encode(self) {
return String(data: encoded, encoding: .utf8)
}

throw StateError("Failed to encode state")
}

public func toDictionary() throws -> [String:Any?] {
let encoder = JSONEncoder()
let data = try encoder.encode(self)
return try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] ?? [:]
}
}

struct InitializeRowndState: Action {
Expand Down Expand Up @@ -66,3 +80,15 @@ let store = Store(
state: RowndState(),
middleware: [thunkMiddleware]
)

struct StateError: Error, CustomStringConvertible {
var message: String

init(_ message: String) {
self.message = message
}

public var description: String {
return message
}
}
3 changes: 2 additions & 1 deletion Sources/Rownd/Rownd.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ public class Rownd: NSObject {
var theme: LBBottomSheet.BottomSheetController.Theme = .init()
theme.grabber?.topMargin = CGFloat(10.0)

inst.getRootViewController()?.presentAsBottomSheet(KeyTransferViewController(), theme: theme, behavior: behavior)
let bottomSheet = inst.getRootViewController()?.presentAsBottomSheet(KeyTransferViewController(), theme: theme, behavior: behavior)
bottomSheet?.grow(toMaximumHeight: true)
}

public static func manageUser() {
Expand Down
11 changes: 8 additions & 3 deletions Sources/Rownd/Views/HubWebView/HubWebViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ public class HubWebViewController: UIViewController, WKUIDelegate {
webView.navigationDelegate = self
webView.scrollView.isScrollEnabled = false
webView.isOpaque = false
webView.backgroundColor = .systemGray6
webView.backgroundColor = UIColor.clear
webView.scrollView.backgroundColor = UIColor.clear
self.modalPresentationStyle = .pageSheet
view = webView
}
Expand All @@ -81,6 +82,10 @@ extension HubWebViewController: WKScriptMessageHandler, WKNavigationDelegate {
public func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
//This function is called when the webview finishes navigating to the webpage.
//We use this to send data to the webview when it's loaded.

webView.isOpaque = false
webView.backgroundColor = UIColor.clear
webView.scrollView.backgroundColor = UIColor.clear

hubViewController?.setLoading(false)

Expand Down Expand Up @@ -144,11 +149,11 @@ extension HubWebViewController: WKScriptMessageHandler, WKNavigationDelegate {
Rownd.requestSignIn(with: .appleId)

case .signOut:
store.dispatch(SetAuthState(payload: AuthState()))
store.dispatch(SetUserData(payload: [:]))
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { [weak self] in // Change `2.0` to the desired number of seconds.
self?.hubViewController?.hide()
}
store.dispatch(SetAuthState(payload: AuthState()))
store.dispatch(SetUserData(payload: [:]))
case .unknown:
break
}
Expand Down
21 changes: 18 additions & 3 deletions Sources/Rownd/Views/KeyTransfer/KeyCodeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,26 @@ struct KeyCodeView : View {
ZStack {
Color(.systemGray6).edgesIgnoringSafeArea(.all)
HStack(alignment: .top) {
VStack(alignment: .leading) {
HubViewControllerWrapper(targetPage: .qrCode, data: "https://rownd.io")
VStack(alignment: .leading, spacing: 10) {
Text("Your encryption key is automatically saved in your iCloud keychain. To sign in on another device, scan the QR code below with the new device.")

VStack(alignment: .center) {
HubViewControllerWrapper(targetPage: .qrCode, data: "https://rownd.io")


Button(action: {

}, label: {
Text("Copy to clipboard")
})
.modifier(RowndButton())
}

Text("You can also copy your account's secret encryption key in case you need to recover it later. Be sure to store it in a safe, secure location.")
}
}

}
.padding()
}
}
}
Expand Down

0 comments on commit 16eb78d

Please sign in to comment.