# HG changeset patch # User Dennis Concepción Martín # Date 1627164850 -3600 # Node ID 41a905e591e47d9b5ed8e08f9641004edac34624 # Parent a8d76aa51da294374189c21fbffd072c3490616d Fixes minor bugs diff -r a8d76aa51da2 -r 41a905e591e4 Simoleon.xcodeproj/project.pbxproj --- a/Simoleon.xcodeproj/project.pbxproj Fri Jul 23 13:57:30 2021 +0100 +++ b/Simoleon.xcodeproj/project.pbxproj Sat Jul 24 23:14:10 2021 +0100 @@ -13,7 +13,6 @@ 9555933D269B0E0A000FD726 /* CurrencyMetadata.json in Resources */ = {isa = PBXBuildFile; fileRef = 9555933C269B0E0A000FD726 /* CurrencyMetadata.json */; }; 95562D4D26A8962A0047E778 /* StoreKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 95562D4C26A8962A0047E778 /* StoreKit.framework */; }; 95562D5226A8AEF60047E778 /* Purchases in Frameworks */ = {isa = PBXBuildFile; productRef = 95562D5126A8AEF60047E778 /* Purchases */; }; - 95562D5526A8B0B70047E778 /* RevenueCatTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 95562D5426A8B0B70047E778 /* RevenueCatTest.swift */; }; 957065E226A5FE0400523E68 /* Settings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 957065E126A5FE0400523E68 /* Settings.swift */; }; 9585BB1226A6B71B00E3193E /* ReadConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9585BB1126A6B71B00E3193E /* ReadConfig.swift */; }; 9585BB1426A6B7F400E3193E /* Request.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9585BB1326A6B7F400E3193E /* Request.swift */; }; @@ -78,7 +77,6 @@ 95559339269B0AB8000FD726 /* ParseJson.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParseJson.swift; sourceTree = ""; }; 9555933C269B0E0A000FD726 /* CurrencyMetadata.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = CurrencyMetadata.json; sourceTree = ""; }; 95562D4C26A8962A0047E778 /* StoreKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = StoreKit.framework; path = System/Library/Frameworks/StoreKit.framework; sourceTree = SDKROOT; }; - 95562D5426A8B0B70047E778 /* RevenueCatTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RevenueCatTest.swift; sourceTree = ""; }; 957065E126A5FE0400523E68 /* Settings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Settings.swift; sourceTree = ""; }; 9585BB0F26A6B58500E3193E /* Config.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Config.xcconfig; sourceTree = ""; }; 9585BB1026A6B5ED00E3193E /* ConfigTemplate.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigTemplate.xcconfig; sourceTree = ""; }; @@ -195,7 +193,6 @@ 95562D5326A8B0A70047E778 /* Tests */ = { isa = PBXGroup; children = ( - 95562D5426A8B0B70047E778 /* RevenueCatTest.swift */, ); path = Tests; sourceTree = ""; @@ -515,7 +512,6 @@ 95C5179D26A5EFBE00BC2B24 /* Favourite+CoreDataProperties.swift in Sources */, 95C5179F26A5F34200BC2B24 /* Favourites.swift in Sources */, 95C5B2282697752600941585 /* SimoleonApp.swift in Sources */, - 95562D5526A8B0B70047E778 /* RevenueCatTest.swift in Sources */, 95B54F4A26A4A450001DC0D8 /* ConversionBox.swift in Sources */, 95D8C8C726A95D2900BCC188 /* Subscription.swift in Sources */, 95D8C8D126A9BC6200BCC188 /* LockedCurrencyPicker.swift in Sources */, @@ -713,7 +709,7 @@ ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_ENTITLEMENTS = Simoleon/Simoleon.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 8; + CURRENT_PROJECT_VERSION = 10; DEVELOPMENT_ASSET_PATHS = "\"Simoleon/Preview Content\""; DEVELOPMENT_TEAM = MTX83R5H8X; ENABLE_PREVIEWS = YES; @@ -738,7 +734,7 @@ ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_ENTITLEMENTS = Simoleon/Simoleon.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 8; + CURRENT_PROJECT_VERSION = 10; DEVELOPMENT_ASSET_PATHS = "\"Simoleon/Preview Content\""; DEVELOPMENT_TEAM = MTX83R5H8X; ENABLE_PREVIEWS = YES; diff -r a8d76aa51da2 -r 41a905e591e4 Simoleon.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate Binary file Simoleon.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate has changed diff -r a8d76aa51da2 -r 41a905e591e4 Simoleon/ContentViewPad.swift --- a/Simoleon/ContentViewPad.swift Fri Jul 23 13:57:30 2021 +0100 +++ b/Simoleon/ContentViewPad.swift Sat Jul 24 23:14:10 2021 +0100 @@ -6,12 +6,29 @@ // import SwiftUI +import Purchases struct ContentViewPad: View { + @StateObject var subscriptionController = SubscriptionController() + var body: some View { NavigationView { Sidebar() + .environmentObject(subscriptionController) + Conversion(fetchUserSettings: true, currencyPair: "USD/GBP") + .environmentObject(subscriptionController) + } + .onAppear(perform: checkEntitlements) + } + + private func checkEntitlements() { + Purchases.shared.purchaserInfo { (purchaserInfo, error) in + if purchaserInfo?.entitlements["all"]?.isActive == true { + self.subscriptionController.isActive = true + } else { + // User subscription is not active + } } } } diff -r a8d76aa51da2 -r 41a905e591e4 Simoleon/Conversion.swift --- a/Simoleon/Conversion.swift Fri Jul 23 13:57:30 2021 +0100 +++ b/Simoleon/Conversion.swift Sat Jul 24 23:14:10 2021 +0100 @@ -10,6 +10,7 @@ struct Conversion: View { var fetchUserSettings: Bool @State var currencyPair: String + @EnvironmentObject var subscriptionController: SubscriptionController @State private var amountToConvert = "1000" @State private var price: Double = 1.00 @@ -60,6 +61,7 @@ }) .sheet(isPresented: $showingCurrencySelector) { CurrencySelector(currencyPair: $currencyPair, showingCurrencySelector: $showingCurrencySelector) + .environmentObject(subscriptionController) } } .navigationTitle(Text("Convert", comment: "Navigation title")) diff -r a8d76aa51da2 -r 41a905e591e4 Simoleon/Favourites.swift --- a/Simoleon/Favourites.swift Fri Jul 23 13:57:30 2021 +0100 +++ b/Simoleon/Favourites.swift Sat Jul 24 23:14:10 2021 +0100 @@ -13,6 +13,7 @@ sortDescriptors: [NSSortDescriptor(keyPath: \Favourite.currencyPair, ascending: true)], animation: .default) private var favourite: FetchedResults + @EnvironmentObject var subscriptionController: SubscriptionController var body: some View { VStack { @@ -26,7 +27,9 @@ } else { List { ForEach(favourite) { favourite in - NavigationLink(destination: Conversion(fetchUserSettings: false, currencyPair: favourite.currencyPair)) { + NavigationLink(destination: Conversion(fetchUserSettings: false, currencyPair: favourite.currencyPair) + .environmentObject(subscriptionController) + ) { CurrencyRow(currencyPair: favourite.currencyPair) } } diff -r a8d76aa51da2 -r 41a905e591e4 Simoleon/Helpers/ConversionBox.swift --- a/Simoleon/Helpers/ConversionBox.swift Fri Jul 23 13:57:30 2021 +0100 +++ b/Simoleon/Helpers/ConversionBox.swift Sat Jul 24 23:14:10 2021 +0100 @@ -9,7 +9,7 @@ struct ConversionBox: View { @Binding var currencyPair: String - @Binding var amountToConvert: String { willSet { print(newValue) }} + @Binding var amountToConvert: String @Binding var price: Double @Binding var showingConversion: Bool @Binding var showingCurrencySelector: Bool @@ -65,12 +65,10 @@ private func makeConversion() -> Double { - if amountToConvert.isEmpty { /// Avoid nil error when string is empty - return 0 + if let amountToConvert = Double(amountToConvert) { + return amountToConvert * price /// Conversion } else { - let conversion = Double(amountToConvert) ?? 0 * price - - return conversion + return 0 } } } diff -r a8d76aa51da2 -r 41a905e591e4 Simoleon/Helpers/Sidebar.swift --- a/Simoleon/Helpers/Sidebar.swift Fri Jul 23 13:57:30 2021 +0100 +++ b/Simoleon/Helpers/Sidebar.swift Sat Jul 24 23:14:10 2021 +0100 @@ -8,27 +8,26 @@ import SwiftUI struct Sidebar: View { + @EnvironmentObject var subscriptionController: SubscriptionController + var body: some View { List { - NavigationLink(destination: Conversion(fetchUserSettings: true, currencyPair: "USD/GBP")) { - HStack { - Text("Convert", comment: "Tab bar button to show conversion") - Image(systemName: "arrow.counterclockwise.circle") - } + NavigationLink(destination: Conversion(fetchUserSettings: true, currencyPair: "USD/GBP") + .environmentObject(subscriptionController) + ) { + Label("Convert", systemImage: "arrow.counterclockwise.circle") } - NavigationLink(destination: Favourites()) { - HStack { - Text("Favourites", comment: "Tab bar button to show favourites") - Image(systemName: "star") - } + NavigationLink(destination: Favourites() + .environmentObject(subscriptionController) + ) { + Label("Favourites", systemImage: "star") } - NavigationLink(destination: Settings()) { - HStack { - Text("Settings", comment: "Tab bar button to show settings") - Image(systemName: "gear") - } + NavigationLink(destination: Settings() + .environmentObject(subscriptionController) + ) { + Label("Settings", systemImage: "gear") } } .listStyle(SidebarListStyle()) diff -r a8d76aa51da2 -r 41a905e591e4 Simoleon/Settings.swift --- a/Simoleon/Settings.swift Fri Jul 23 13:57:30 2021 +0100 +++ b/Simoleon/Settings.swift Sat Jul 24 23:14:10 2021 +0100 @@ -26,8 +26,9 @@ Text("Information", comment: "Button to show subscription information in settings") } } else { - Text("Subscribe", comment: "Button to suscribe in settings") - .onTapGesture { showingSubscriptionPaywall = true } + Button(action: { showingSubscriptionPaywall = true }) { + Text("Subscribe", comment: "Button to suscribe in settings") + } } } diff -r a8d76aa51da2 -r 41a905e591e4 Simoleon/Tests/RevenueCatTest.swift --- a/Simoleon/Tests/RevenueCatTest.swift Fri Jul 23 13:57:30 2021 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,63 +0,0 @@ -// -// RevenueCatTest.swift -// Simoleon -// -// Created by Dennis Concepción Martín on 21/07/2021. -// - -import SwiftUI -import Purchases - -struct RevenueCatTest: View { - @State private var productName = "" - @State private var price = "" - - var body: some View { - VStack (alignment: .leading) { - Text(productName) - Text(price) - Button("Buy", action: purchaseProMonthlySubscription) - } - .onAppear(perform: fetchProMonthlySubscription) - } - - private func fetchProMonthlySubscription() { - Purchases.shared.offerings { (offerings, error) in - if let product = offerings?.current?.monthly?.product { - self.productName = product.localizedTitle - self.price = formatCurrency(product.priceLocale, product.price) - } - } - } - - private func purchaseProMonthlySubscription() { - Purchases.shared.offerings { (offerings, error) in - if let package = offerings?.current?.monthly { - Purchases.shared.purchasePackage(package) { (transaction, purchaserInfo, error, userCancelled) in - if purchaserInfo?.entitlements["all"]?.isActive == true { - print("Ok") - } - } - } - } - } - - private func formatCurrency(_ locale: Locale, _ amount: NSDecimalNumber) -> String { - let formatter = NumberFormatter() - formatter.locale = locale - formatter.numberStyle = .currency - - if let formattedAmount = formatter.string(from: amount as NSNumber) { - return formattedAmount - } else { - // Handle error - return "" - } - } -} - -struct RevenueCatTest_Previews: PreviewProvider { - static var previews: some View { - RevenueCatTest() - } -}