Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #2584: No longer check clipboard if ref code exists on launch. #2585

Merged
merged 27 commits into from May 27, 2020
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7101d33
Added support for pre-determined / binary related ref codes.
jhreis May 11, 2020
646e5bd
Clipboard processing added.
jhreis May 11, 2020
2359577
Merge branch 'development' into referral_fixes
jhreis May 11, 2020
624dabc
Clear clipboard after successful ref promo read.
jhreis May 11, 2020
15bfead
Cleaned up code a bit, no functional changes.
jhreis May 18, 2020
6fdb085
Added ref code validation.
jhreis May 18, 2020
8214d99
Changed ref code sanitzation to use regex.
jhreis May 18, 2020
285fe1e
Added unit tests for ref code sanitization.
jhreis May 18, 2020
aaa762e
Removed unnecessary comment.
jhreis May 18, 2020
3ce30ea
Merge branch 'development' into referral_fixes
jhreis May 18, 2020
16d5037
Added path components helper to avoid manually adding forward slashes.
jhreis May 18, 2020
576ae4a
Comment cleanup.
jhreis May 20, 2020
834a1fc
Fixed crash from bad referral situation.
jhreis May 20, 2020
98253b6
Fixed S3 bucket endpoint for enterprise builds.
jhreis May 21, 2020
ade056f
Merge branch 'development' into referral_fixes
jhreis May 21, 2020
411481f
Fix #2565: Retry ref code lookup on subsequent launches.
jhreis May 22, 2020
17f0717
Merge branch 'development' into referral_fixes
jhreis May 22, 2020
c8e6630
Merge branch 'referral_fixes' into fix-2565
jhreis May 22, 2020
6bcc4f9
Merge remote-tracking branch 'origin/development' into fix-2565
iccub May 25, 2020
9f20fc8
Merge remote-tracking branch 'origin/development' into fix-2565
iccub May 25, 2020
24744c4
Merge branch 'development' into fix-2565
jhreis May 26, 2020
aae0eb8
Fixed URP lookup flag placement.
jhreis May 26, 2020
92f0562
Add retry timer.
iccub May 27, 2020
78d2f75
Move to struct.
iccub May 27, 2020
6c8edfc
Fix #2584: No longer check clipboard if ref code exists on launch.
jhreis May 27, 2020
d55b022
Merge branch 'fix-2565' into fix-2584
jhreis May 27, 2020
350f766
Merge branch 'development' into fix-2584
jhreis May 27, 2020
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Clipboard processing added.

  • Loading branch information
jhreis committed May 11, 2020
commit 646e5bd8ac6ca2f6d8ce5f759f21ab935115e6b3
@@ -16,6 +16,7 @@ public class UserReferralProgram {
public static let shared = UserReferralProgram()

private static let apiKeyPlistKey = "API_KEY"
private static let clipboardPrefix = "F83AB73F-9852-4F01-ABA8-7830B8825993"

struct HostUrl {
static let staging = "https://brave-laptop-updates-staging.herokuapp.com"
@@ -44,7 +45,7 @@ public class UserReferralProgram {
}

/// Looks for referral and returns its landing page if possible.
public func referralLookup(completion: @escaping (String?) -> Void) {
public func referralLookup(refCode: String?, completion: @escaping (String?) -> Void) {
UrpLog.log("first run referral lookup")

let referralBlock: (ReferralData?, UrpError?) -> Void = { referral, _ in
@@ -79,6 +80,10 @@ public class UserReferralProgram {
completion(nil)
}

if let refCode = refCode {
Preferences.URP.referralCode.value = refCode
}

service.referralCodeLookup(refCode: UserReferralProgram.getReferralCode(), completion: referralBlock)
}

@@ -182,6 +187,19 @@ public class UserReferralProgram {
return nil
}

/// Passing string, attempts to derive a ref code from it.
/// Uses very strict matching.
/// Returns the sanitized code, or nil if no code was found
public class func sanitize(input: String?) -> String? {
guard var input = input, input.hasPrefix(self.clipboardPrefix) else { return nil }

input.removeFirst(self.clipboardPrefix.count + 1)
// Add any other potential validation here, e.g. validating the actual ref code string
if input.isEmpty { return nil }
return input
}

/// Same as `customHeaders` only blocking on result, to gaurantee data is available
private func fetchNewCustomHeaders() -> Deferred<[CustomHeaderData]> {
let result = Deferred<[CustomHeaderData]>()
@@ -259,9 +259,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UIViewControllerRestorati
FavoritesHelper.addDefaultFavorites()
profile?.searchEngines.regionalSearchEngineSetup()
}

if let urp = UserReferralProgram.shared {
if isFirstLaunch {
urp.referralLookup { url in
let refCode = UserReferralProgram.sanitize(input: UIPasteboard.general.string)

// This should be called each time, since if have
urp.referralLookup(refCode: refCode) { url in
guard let url = url?.asURL else { return }
self.browserViewController.openReferralLink(url: url)
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.