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

🦺[Tech debt] Add develop & GS keys file 43 #45

Merged
merged 11 commits into from
May 8, 2021
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,4 @@ fastlane/screenshots
fastlane/test_output
Screenshots/shots
.DS_Store
loafwallet/GoogleService-Info.plist
partner-keys.plist
loafwallet/file-resources/release/*
40 changes: 34 additions & 6 deletions loafwallet.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
22A9A9641DF61FE7000F0016 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 22A9A9631DF61FE7000F0016 /* Security.framework */; };
22A9A9661DF61FEE000F0016 /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 22A9A9651DF61FEE000F0016 /* WebKit.framework */; };
22A9A9A31DF63497000F0016 /* libbz2.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 22A9A9671DF61FF8000F0016 /* libbz2.tbd */; };
24016D8E23F887C3006A6791 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 24016D8D23F887C2006A6791 /* GoogleService-Info.plist */; };
24016D9023F913C1006A6791 /* LWAnalytics.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24016D8F23F913C1006A6791 /* LWAnalytics.swift */; };
2427342D2381C21800E2D22F /* MainViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2427342B2381C21800E2D22F /* MainViewController.swift */; };
24306797238F3DF900EBEA99 /* BartyCrouch.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24306796238F3DF900EBEA99 /* BartyCrouch.swift */; };
Expand Down Expand Up @@ -287,6 +286,8 @@
C35ABD232574070A002BB9BB /* PartnersView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C35ABD222574070A002BB9BB /* PartnersView.swift */; };
C35ABD332574073F002BB9BB /* PartnersViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = C35ABD322574073F002BB9BB /* PartnersViewModel.swift */; };
C379F228259B9BF000B25883 /* RegistrationAlertView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C379F227259B9BF000B25883 /* RegistrationAlertView.swift */; };
C383192D264169CF002EF205 /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = C383192826414E7B002EF205 /* GoogleService-Info.plist */; };
C383192E264169DC002EF205 /* partner-keys.plist in Resources */ = {isa = PBXBuildFile; fileRef = C383192A26414EC6002EF205 /* partner-keys.plist */; };
C39A71472608CB4300E7B640 /* EmptyTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = C39A71462608CB4300E7B640 /* EmptyTableViewCell.swift */; };
C3A4647D259A646A00D74D81 /* DataValidation.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3A4647C259A646A00D74D81 /* DataValidation.swift */; };
C3B7C3B9255EABBF00E98A64 /* SupportSafariViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3B7C3B8255EABBF00E98A64 /* SupportSafariViewModel.swift */; };
Expand All @@ -307,7 +308,6 @@
C3D783A72565EA4B0004FF70 /* UnstoppableDomainView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3D783A62565EA4A0004FF70 /* UnstoppableDomainView.swift */; };
C3D783B72565EA6B0004FF70 /* UnstoppableDomainViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3D783B62565EA6B0004FF70 /* UnstoppableDomainViewModel.swift */; };
C3D783C02565ECF60004FF70 /* UnstoppableDomainViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3D783BF2565ECF60004FF70 /* UnstoppableDomainViewModelTests.swift */; };
C3EB574C257D95B7003E3949 /* partner-keys.plist in Resources */ = {isa = PBXBuildFile; fileRef = C3EB574B257D95B7003E3949 /* partner-keys.plist */; };
C3F55645255A193D005F786F /* SupportLitecoinFoundationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3F55644255A193D005F786F /* SupportLitecoinFoundationView.swift */; };
C3F55655255A195B005F786F /* SupportLitecoinFoundationViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3F55654255A195B005F786F /* SupportLitecoinFoundationViewModel.swift */; };
C3F7BCDC25FEC6AD00694C28 /* FailedAlertView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3F7BCD925FEC6AC00694C28 /* FailedAlertView.swift */; };
Expand Down Expand Up @@ -1462,6 +1462,8 @@
C35ABD222574070A002BB9BB /* PartnersView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PartnersView.swift; sourceTree = "<group>"; };
C35ABD322574073F002BB9BB /* PartnersViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PartnersViewModel.swift; sourceTree = "<group>"; };
C379F227259B9BF000B25883 /* RegistrationAlertView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RegistrationAlertView.swift; sourceTree = "<group>"; };
C383192826414E7B002EF205 /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
C383192A26414EC6002EF205 /* partner-keys.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "partner-keys.plist"; sourceTree = "<group>"; };
C39A71462608CB4300E7B640 /* EmptyTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyTableViewCell.swift; sourceTree = "<group>"; };
C3A4647C259A646A00D74D81 /* DataValidation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataValidation.swift; sourceTree = "<group>"; };
C3ACF2DE25DED601008671D4 /* CHANGELOG.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = CHANGELOG.md; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2965,7 +2967,7 @@
75A2A7921DA5934300A983D8 /* loafwallet */ = {
isa = PBXGroup;
children = (
C3EB574B257D95B7003E3949 /* partner-keys.plist */,
C383192526414E07002EF205 /* file-resources */,
C35ABD07257404C6002BB9BB /* SwiftUI+UIKit */,
75A2A87C1DA59E4E00A983D8 /* loafwallet.entitlements */,
75A2A7931DA5934300A983D8 /* AppDelegate.swift */,
Expand Down Expand Up @@ -3007,7 +3009,6 @@
75A2A79F1DA5934300A983D8 /* Info.plist */,
24B523AF238A53DC0030594D /* BIP39Words.plist */,
2485F7CE23728C19005962F1 /* RELEASE_NOTES.md */,
24016D8D23F887C2006A6791 /* GoogleService-Info.plist */,
C3ACF2DE25DED601008671D4 /* CHANGELOG.md */,
);
path = loafwallet;
Expand Down Expand Up @@ -3140,6 +3141,33 @@
name = About;
sourceTree = "<group>";
};
C383192526414E07002EF205 /* file-resources */ = {
isa = PBXGroup;
children = (
C383192726414E42002EF205 /* release */,
C383192626414E3C002EF205 /* debug */,
);
path = "file-resources";
sourceTree = "<group>";
};
C383192626414E3C002EF205 /* debug */ = {
isa = PBXGroup;
children = (
C383192826414E7B002EF205 /* GoogleService-Info.plist */,
C383192A26414EC6002EF205 /* partner-keys.plist */,
);
path = debug;
sourceTree = "<group>";
};
C383192726414E42002EF205 /* release */ = {
isa = PBXGroup;
children = (
24016D8D23F887C2006A6791 /* GoogleService-Info.plist */,
C3EB574B257D95B7003E3949 /* partner-keys.plist */,
);
path = release;
sourceTree = "<group>";
};
C3B7C3EC255FF56100E98A64 /* Constants Tests */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -3857,6 +3885,8 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
C383192E264169DC002EF205 /* partner-keys.plist in Resources */,
C383192D264169CF002EF205 /* GoogleService-Info.plist in Resources */,
24B8FAD72162B6FB00A155B1 /* bitrefill_index.html in Resources */,
75A2A79E1DA5934300A983D8 /* LaunchScreen.storyboard in Resources */,
24D5F23822599C0B00225462 /* BarlowSemiCondensed-Italic.ttf in Resources */,
Expand All @@ -3883,10 +3913,8 @@
24313CAA23824F9800A83F69 /* Main.storyboard in Resources */,
24D5F25F22599C0B00225462 /* BarlowSemiCondensed-Regular.ttf in Resources */,
24DFCE6823B89CDE001F17F8 /* Settings.storyboard in Resources */,
24016D8E23F887C3006A6791 /* GoogleService-Info.plist in Resources */,
24393B5C23C259400075218D /* Phrase.storyboard in Resources */,
24313CA723824F5800A83F69 /* Card.storyboard in Resources */,
C3EB574C257D95B7003E3949 /* partner-keys.plist in Resources */,
75A2A79B1DA5934300A983D8 /* Assets.xcassets in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
54 changes: 38 additions & 16 deletions loafwallet/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@

import UIKit
import SwiftUI
import LocalAuthentication
import LocalAuthentication
import Firebase

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?
let applicationController = ApplicationController()

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

setFirebaseConfiguration()
Expand All @@ -46,47 +46,69 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

return true
}

func applicationDidBecomeActive(_ application: UIApplication) {
UIApplication.shared.applicationIconBadgeNumber = 0
}

func applicationWillEnterForeground(_ application: UIApplication) {
applicationController.willEnterForeground()
}

func applicationDidEnterBackground(_ application: UIApplication) {
applicationController.didEnterBackground()
}

func applicationWillResignActive(_ application: UIApplication) {
applicationController.willResignActive()
}

func application(_ application: UIApplication, performFetchWithCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
applicationController.performFetch(completionHandler)
}

func application(_ application: UIApplication, shouldAllowExtensionPointIdentifier extensionPointIdentifier: UIApplicationExtensionPointIdentifier) -> Bool {
return false // disable extensions such as custom keyboards for security purposes
}

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
return applicationController.open(url: url)
}

func application(_ application: UIApplication, shouldSaveApplicationState coder: NSCoder) -> Bool {
return true
return true
}

func application(_ application: UIApplication, shouldRestoreApplicationState coder: NSCoder) -> Bool {
return true
}


/// Sets the correct plist file
private func setFirebaseConfiguration() {
//Conditional to pass the CircleCI checks
if Bundle.main.path(forResource: "GoogleService-Info", ofType: "plist") != nil {
FirebaseApp.configure()

var filePath: String = ""

#if Release
guard let releasePath = Bundle.main.path(forResource: "file-resource/release/GoogleService-Info", ofType: "plist") else { return
}

filePath = releasePath

#else
guard let debugPath = Bundle.main.path(forResource: "file-resource/release/GoogleService-Info", ofType: "plist") else {
return
}

filePath = debugPath

#endif

guard let fileopts = FirebaseOptions(contentsOfFile: filePath) else {
assert(false, "Couldn't load config file")
}

FirebaseApp.configure(options: fileopts)
}
}
}

72 changes: 72 additions & 0 deletions loafwallet/PartnerData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@

import Foundation
import UIKit


enum PartnerName {
case infura
case changeNow
}

struct Partner {

Expand All @@ -20,6 +26,32 @@ struct Partner {
let simplex = Partner(logo: UIImage(named: "simplexLogo")!, headerTitle: S.BuyCenter.Cells.simplexTitle, details: S.BuyCenter.Cells.simplexFinancialDetails)
return [moonpay, simplex]
}

static func partnerKeyPath(name: PartnerName) -> String {
Copy link
Contributor

@mosadialiou mosadialiou May 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kcw-grunt this function is difficult to read. it should be refactored but for now we can live with it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @mosadialiou
this is a built-in feature provided by Xcode and wherever I can I'm updating methods accordingly:

Screen Shot 2021-05-08 at 12 42 11 PM


switch name {
case .infura:

if let path = Bundle.main.path(forResource: "partner-keys", ofType: "plist"),
let dictionary = NSDictionary(contentsOfFile:path) as? Dictionary<String, AnyObject>,
let key = dictionary["infura-api"] as? String {
return "https://mainnet.infura.io/v3/" + key
} else {
return "ERROR-INFURA_KEY"
}

case .changeNow:

if let path = Bundle.main.path(forResource: "partner-keys", ofType: "plist"),
let dictionary = NSDictionary(contentsOfFile:path) as? Dictionary<String, AnyObject>,
let key = dictionary["change-now-api"] as? String {
return key
} else {
return "ERROR-CHANGENOW_KEY"
}
}

}

//TODO: Uncomment as integration progresses, kcw-grunt
// let coinbaseDictionary =
Expand All @@ -39,3 +71,43 @@ struct Partner {
// "logo":UIImage(named:"bitrefillLogo") ?? " ",
// "baseColor":#colorLiteral(red: 0.2235294118, green: 0.5490196078, blue: 0.9333333333, alpha: 1)] as [String : AnyObject]
}

//
//
//private func fetchKeyPath() -> String? {
//
// if let path = Bundle.main.path(forResource: "partner-keys", ofType: "plist"),
// let dictionary = NSDictionary(contentsOfFile:path) as? Dictionary<String, AnyObject>,
// let key = dictionary["infura-api"] as? String {
// return "https://mainnet.infura.io/v3/" + key
// } else {
// return nil
// }
//
//
// private func setFirebaseConfiguration() {
//
// var partnerFilePath: String = ""
//
// #if Release
// guard let releasePath = Bundle.main.path(forResource: "file-resource/release/GoogleService-Info", ofType: "plist") else { return
// }
//
// filePath = releasePath
//
// #else
// guard let debugPath = Bundle.main.path(forResource: "file-resource/release/GoogleService-Info", ofType: "plist") else { return
// return
// }
//
// filePath = debugPath
//
// #endif
//
// guard let fileopts = FirebaseOptions(contentsOfFile: filePath) else {
// assert(false, "Couldn't load config file")
// }
//
// FirebaseApp.configure(options: fileopts)
// }
//}
34 changes: 10 additions & 24 deletions loafwallet/UnstoppableDomainViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation
import SwiftUI
import Combine
import UnstoppableDomainsResolution

class UnstoppableDomainViewModel: ObservableObject {

//MARK: - Combine Variables
Expand All @@ -25,9 +25,9 @@ class UnstoppableDomainViewModel: ObservableObject {

//MARK: - Public Variables
var didResolveUDAddress: ((String) -> Void)?

var shouldClearAddressField: (() -> Void)?

var didFailToResolve: ((String) -> Void)?

//MARK: - Private Variables
Expand Down Expand Up @@ -67,11 +67,8 @@ class UnstoppableDomainViewModel: ObservableObject {
// Otherwise, we may never get in the callback relative to UDR v0.1.6
let group = DispatchGroup()

guard let keyPath = fetchKeyPath() else {
print ("Error: Key path not found")
return
}

let keyPath = Partner.partnerKeyPath(name: .infura)

guard let resolution = try? Resolution(configs: Configurations(
cns: NamingServiceConfig(
providerUrl: keyPath,
Expand Down Expand Up @@ -102,7 +99,7 @@ class UnstoppableDomainViewModel: ObservableObject {
self.didResolveUDAddress?(self.ltcAddress)
self.isDomainResolving = false
}

case .failure(let error):
print(error)
let errorMessage = DomainResolutionFailure().messageWith(error: error)
Expand All @@ -118,9 +115,9 @@ class UnstoppableDomainViewModel: ObservableObject {
///Quicker resolution: When the resolution is done, the activity indicatior stops and the address is updated
DispatchQueue.main.asyncAfter(deadline: .now() + 2,
execute: {

self.didFailToResolve?(error.localizedDescription)
self.didFailToResolve?(error.localizedDescription)

self.didFailToResolve?(errorMessage)
self.isDomainResolving = false

Expand All @@ -131,17 +128,6 @@ class UnstoppableDomainViewModel: ObservableObject {
group.wait()
}

/// Lookup the API Key
/// - Returns: String or nil
private func fetchKeyPath() -> String? {

if let path = Bundle.main.path(forResource: "partner-keys", ofType: "plist"),
let dictionary = NSDictionary(contentsOfFile:path) as? Dictionary<String, AnyObject>,
let key = dictionary["infura-api"] as? String {
return "https://mainnet.infura.io/v3/" + key
} else {
return nil
}
}
}


Loading