Skip to content

Commit

Permalink
Adding popup to transfer consent data
Browse files Browse the repository at this point in the history
  • Loading branch information
manhlx3006 committed Jan 14, 2020
1 parent 2e27377 commit 43368e3
Show file tree
Hide file tree
Showing 10 changed files with 434 additions and 0 deletions.
16 changes: 16 additions & 0 deletions KyberNetwork.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,8 @@
C6AA668723A772AA0050C610 /* KNListNotificationViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = C6AA668523A772AA0050C610 /* KNListNotificationViewController.xib */; };
C6AA668B23A77C690050C610 /* KNNotificationTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6AA668923A77C690050C610 /* KNNotificationTableViewCell.swift */; };
C6AA668C23A77C690050C610 /* KNNotificationTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = C6AA668A23A77C690050C610 /* KNNotificationTableViewCell.xib */; };
C6B4CA2923CC50190049C843 /* KNTransferConsentViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6B4CA2723CC50190049C843 /* KNTransferConsentViewController.swift */; };
C6B4CA2A23CC50190049C843 /* KNTransferConsentViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = C6B4CA2823CC50190049C843 /* KNTransferConsentViewController.xib */; };
C6FE41812383A0C10096AAD8 /* KNWalletConnectViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C6FE417F2383A0C10096AAD8 /* KNWalletConnectViewController.swift */; };
C6FE41822383A0C10096AAD8 /* KNWalletConnectViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = C6FE41802383A0C10096AAD8 /* KNWalletConnectViewController.xib */; };
CCA4FE361FD4282400749AE4 /* DeviceChecker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CCA4FE351FD4282400749AE4 /* DeviceChecker.swift */; };
Expand Down Expand Up @@ -1222,6 +1224,8 @@
C6AA668523A772AA0050C610 /* KNListNotificationViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = KNListNotificationViewController.xib; sourceTree = "<group>"; };
C6AA668923A77C690050C610 /* KNNotificationTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KNNotificationTableViewCell.swift; sourceTree = "<group>"; };
C6AA668A23A77C690050C610 /* KNNotificationTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = KNNotificationTableViewCell.xib; sourceTree = "<group>"; };
C6B4CA2723CC50190049C843 /* KNTransferConsentViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KNTransferConsentViewController.swift; sourceTree = "<group>"; };
C6B4CA2823CC50190049C843 /* KNTransferConsentViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = KNTransferConsentViewController.xib; sourceTree = "<group>"; };
C6FE417F2383A0C10096AAD8 /* KNWalletConnectViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KNWalletConnectViewController.swift; sourceTree = "<group>"; };
C6FE41802383A0C10096AAD8 /* KNWalletConnectViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = KNWalletConnectViewController.xib; sourceTree = "<group>"; };
CCA4FE351FD4282400749AE4 /* DeviceChecker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeviceChecker.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2267,6 +2271,7 @@
25696F4720BD0ED5002CC53F /* CommonViews */ = {
isa = PBXGroup;
children = (
C6B4CA2623CC47C40049C843 /* TransferConsent */,
C6AA667723A761860050C610 /* Notifications */,
258BF6A5230689EF00988EDD /* AllowCamera */,
254CD0E7214925BF0079EA7A /* KYCStepView */,
Expand Down Expand Up @@ -4091,6 +4096,15 @@
path = TableViewCell;
sourceTree = "<group>";
};
C6B4CA2623CC47C40049C843 /* TransferConsent */ = {
isa = PBXGroup;
children = (
C6B4CA2723CC50190049C843 /* KNTransferConsentViewController.swift */,
C6B4CA2823CC50190049C843 /* KNTransferConsentViewController.xib */,
);
path = TransferConsent;
sourceTree = "<group>";
};
C6FE417E2383A0AB0096AAD8 /* WalletConnect */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -4268,6 +4282,7 @@
254EAB2A221D9EFD00C0EDC8 /* KyberNetwork.entitlements in Resources */,
259BF5C121918B0D004D70F9 /* kyc_industry_code.json in Resources */,
613D04891FDE15F8008DE72E /* COMODO ECC Domain Validation Secure Server CA 2.cer in Resources */,
C6B4CA2A23CC50190049C843 /* KNTransferConsentViewController.xib in Resources */,
2582332122549420007D5480 /* KNPromoSwapConfirmViewController.xib in Resources */,
25696F6920BE9EB6002CC53F /* KNSearchTokenViewController.xib in Resources */,
256E61EE20B3C0830084CA3F /* KNBalanceTabHamburgerMenuViewController.xib in Resources */,
Expand Down Expand Up @@ -4964,6 +4979,7 @@
2923D9B51FDA4E07000CF3F8 /* PasswordGenerator.swift in Sources */,
25C45AE620AEB4A700CDA1FF /* KNEnterWalletNameViewController.swift in Sources */,
25377B1122842BB30012178F /* KNCreateLimitOrderViewController.swift in Sources */,
C6B4CA2923CC50190049C843 /* KNTransferConsentViewController.swift in Sources */,
255C40F0209306B800475871 /* KNTokenTransactionStorage.swift in Sources */,
25CC0AB420591AFA0009D0D5 /* KNTransaction.swift in Sources */,
25CC0AAA2058F1A00009D0D5 /* KNGetUserCapInWei.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class KNAppTracker {
static let kFirstTimeSwapKey: String = "kFirstTimeSwapKey"
static let kFirstTimeLimitOrderKey: String = "kFirstTimeLimitOrderKey"
static let kFirstTimePriceAlertKey: String = "kFirstTimePriceAlertKey"
static let kHasShownTransferConsentKey: String = "kHasShownTransferConsentKey"

static let userDefaults: UserDefaults = UserDefaults.standard

Expand Down Expand Up @@ -343,6 +344,15 @@ class KNAppTracker {
userDefaults.synchronize()
}

static func shouldShowUserTranserConsentPopUp() -> Bool {
return userDefaults.value(forKey: kHasShownTransferConsentKey) as? Bool == true
}

static func updateShouldShowUserTranserConsentPopUp(_ shouldShown: Bool) {
userDefaults.set(shouldShown, forKey: kHasShownTransferConsentKey)
userDefaults.synchronize()
}

static func saveFirstInstallTimeIfNeeded() {
if userDefaults.value(forKey: kFirstInstallTimeKey) == nil {
userDefaults.set(Date().timeIntervalSince1970, forKey: kFirstInstallTimeKey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ extension KNAppCoordinator {

// reset history filter every time open app
KNAppTracker.removeHistoryFilterData()
KNAppTracker.updateShouldShowUserTranserConsentPopUp(true)
}

func appDidBecomeActive() {
Expand Down
14 changes: 14 additions & 0 deletions KyberNetwork/KyberNetwork/Extensions/String+Kyber.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,18 @@ extension String {
let value2 = val21 * 1000000 + val22 * 1000 + val23
return value1 >= value2
}

func height(withConstrainedWidth width: CGFloat, font: UIFont) -> CGFloat {
let constraintRect = CGSize(width: width, height: .greatestFiniteMagnitude)
let boundingBox = self.boundingRect(with: constraintRect, options: .usesLineFragmentOrigin, attributes: [NSAttributedStringKey.font: font], context: nil)

return ceil(boundingBox.height)
}

func width(withConstrainedHeight height: CGFloat, font: UIFont) -> CGFloat {
let constraintRect = CGSize(width: .greatestFiniteMagnitude, height: height)
let boundingBox = self.boundingRect(with: constraintRect, options: .usesLineFragmentOrigin, attributes: [NSAttributedStringKey.font: font], context: nil)

return ceil(boundingBox.width)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ enum NativeSignInUpService {
case getUserAuthToken(email: String, password: String)
case refreshToken(refreshToken: String)
case getUserInfo(authToken: String)
case transferConsent(authToken: String, answer: String)
}

extension NativeSignInUpService: MoyaCacheable {
Expand All @@ -428,6 +429,7 @@ extension NativeSignInUpService: TargetType {
case .getUserAuthToken: return KNSecret.getAuthTokenURL
case .refreshToken: return KNSecret.refreshTokenURL
case .getUserInfo: return KNSecret.getUserInfoURL
case .transferConsent: return KNSecret.transferConsentURL
}
}()
return URL(string: "\(baseString)\(endpoint)")!
Expand Down Expand Up @@ -520,6 +522,12 @@ extension NativeSignInUpService: TargetType {
]
let data = try! JSONSerialization.data(withJSONObject: json, options: [])
return .requestData(data)
case .transferConsent(_, let answer):
let json: JSONDictionary = [
"transfer_permission": answer,
]
let data = try! JSONSerialization.data(withJSONObject: json, options: [])
return .requestData(data)
}
}
var sampleData: Data { return Data() }
Expand All @@ -540,6 +548,14 @@ extension NativeSignInUpService: TargetType {
"Authorization": authenToken,
]
}
if case .transferConsent(let authenToken, _) = self {
return [
"content-type": "application/json",
"client": Bundle.main.bundleIdentifier ?? "",
"client-build": Bundle.main.buildNumber ?? "",
"Authorization": authenToken,
]
}
return [
"content-type": "application/json",
"client": Bundle.main.bundleIdentifier ?? "",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// Copyright SIX DAY LLC. All rights reserved.

import UIKit

protocol KNTransferConsentViewControllerDelegate: class {
// yes/no/undecide
func transferConsentViewController(
_ controller: KNTransferConsentViewController,
answer: Bool?,
isForceLogout: Bool,
authInfo: JSONDictionary,
userInfo: JSONDictionary
)
}

class KNTransferConsentViewController: KNBaseViewController {

@IBOutlet weak var headerContainerView: UIView!

@IBOutlet weak var yesButton: UIButton!
@IBOutlet weak var noButton: UIButton!
@IBOutlet weak var descriptionTextLabel: UILabel!
@IBOutlet weak var scrollView: UIScrollView!
@IBOutlet weak var backButton: UIButton!

let isForceLogout: Bool
let authInfo: JSONDictionary
let userInfo: JSONDictionary

weak var delegate: KNTransferConsentViewControllerDelegate?

init(isForceLogout: Bool, authInfo: JSONDictionary, userInfo: JSONDictionary) {
self.isForceLogout = isForceLogout
self.authInfo = authInfo
self.userInfo = userInfo
super.init(nibName: KNTransferConsentViewController.className, bundle: nil)
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override func viewDidLoad() {
super.viewDidLoad()
self.yesButton.rounded(
color: UIColor.Kyber.border,
width: 1.0,
radius: self.yesButton.frame.height / 2.0
)
self.noButton.rounded(radius: self.noButton.frame.height / 2.0)
self.noButton.applyGradient()
self.headerContainerView.applyGradient(with: UIColor.Kyber.headerColors)
self.backButton.isHidden = true

//swiftlint:disable line_length
self.descriptionTextLabel.text = "Please note that in view of business and strategic considerations, Kyber Network International Limited (“Kyber Network”) no longer operates kyberswap.com.\n\nKYRD International Limited (“KYRD International”) now operates kyberswap.com. We assure you that no other change is in place other than that KYRD International is now the entity operating kyberswap.com instead of Kyber Network.\n\nIf you wish, to continue using kyberswap.com without the need of providing your personal data again, Kyber Network can transfer your personal data to KYRD International upon your explicit consent.\n\nPlease do note that KYRD International is a company in British Virgin Islands (\"BVI\") and as such, the country is not subject to an adequacy decision by the EU Commission on the processing of personal data nor are there the appropriate safeguards for data protection purposes that are present in EU jurisdictions.\n\nKindly click:\n\"Yes\" if you wish that Kyber Network transfers your personal data to KYRD International; or\n\"No\" if you do not wish that Kyber Network transfers your personal data to KYRD International Do note that if you click “No”, your personal shall be erased in accordance with the retention periods specified in Kyber Network’s Privacy Policy."
self.scrollView.delegate = self
}

override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
self.noButton.removeSublayer(at: 0)
self.noButton.applyGradient()
self.headerContainerView.removeSublayer(at: 0)
self.headerContainerView.applyGradient(with: UIColor.Kyber.headerColors)
}

@IBAction func yesButtonPressed(_ sender: Any) {
self.delegate?.transferConsentViewController(
self,
answer: true,
isForceLogout: self.isForceLogout,
authInfo: self.authInfo,
userInfo: self.userInfo
)
}

@IBAction func noButtonPressed(_ sender: Any) {
let alert = UIAlertController(
title: "Your profile will not be copied",
message: "\nYou would have to create a new profile to use some services like Limit Order, Price Alerts, Notifications, etc. \n\nDo you want to continue?".toBeLocalised(),
preferredStyle: .alert
)
alert.addAction(UIAlertAction(title: "Go back", style: .cancel, handler: nil))
alert.addAction(UIAlertAction(title: "Continue", style: .destructive, handler: { _ in
self.delegate?.transferConsentViewController(
self,
answer: false,
isForceLogout: self.isForceLogout,
authInfo: self.authInfo,
userInfo: self.userInfo
)
}))
self.present(alert, animated: true, completion: nil)
}

@IBAction func backButtonPressed(_ sender: Any) {
self.delegate?.transferConsentViewController(
self,
answer: nil,
isForceLogout: self.isForceLogout,
authInfo: self.authInfo,
userInfo: self.userInfo
)
}
}

extension KNTransferConsentViewController: UIScrollViewDelegate {
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if scrollView.contentOffset.y >= scrollView.contentSize.height - scrollView.frame.size.height {
self.backButton.isHidden = false // show back button, allow to back
}
}
}
Loading

0 comments on commit 43368e3

Please sign in to comment.