Mercurial > public > simoleon
changeset 165:6f024e6a3b19
Remove unused purchase files
author | Dennis Concepcion Martin <dennisconcepcionmartin@gmail.com> |
---|---|
date | Sat, 11 Sep 2021 16:29:57 +0200 |
parents | b899c1142d9d |
children | e4cbb1eea394 |
files | Simoleon/UI/RestoreButton.swift Simoleon/UI/SubscribeButton.swift Simoleon/UI/SubscriptionFeature.swift Simoleon/UI/SubscriptionPaywall.swift |
diffstat | 4 files changed, 0 insertions(+), 297 deletions(-) [+] |
line wrap: on
line diff
--- a/Simoleon/UI/RestoreButton.swift Sat Sep 11 16:29:38 2021 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,57 +0,0 @@ -// -// RestoreButton.swift -// Simoleon -// -// Created by Dennis Concepción Martín on 22/07/2021. -// - -import SwiftUI -import Purchases - -struct RestoreButton: View { - @Binding var showingSubscriptionPaywall: Bool - @State private var alertTitle: LocalizedStringKey = "" - @State private var alertMessage: LocalizedStringKey = "" - @State private var restoringPurchases = false - @State private var showingAlert = false - - var body: some View { - Button(action: restorePurchases) { - if restoringPurchases { - ProgressView() - } else { - Text("Restore purchases") - } - } - .alert(isPresented: $showingAlert) { - Alert(title: Text(alertTitle), message: Text(alertMessage), dismissButton: .default(Text("Ok"))) - } - } - - private func restorePurchases() { - restoringPurchases = true - - Purchases.shared.restoreTransactions { purchaserInfo, error in - if purchaserInfo?.entitlements["all"]?.isActive == true { - showingSubscriptionPaywall = false - } else { - alertTitle = LocalizedStringKey("No subscriptions found") - alertMessage = LocalizedStringKey("You are not subscripted to Simoleon yet.") - restoringPurchases = false - showingAlert = true - } - - if let error = error as NSError? { - alertTitle = LocalizedStringKey(error.localizedDescription) - alertMessage = LocalizedStringKey(error.localizedFailureReason ?? "") - showingAlert = true - } - } - } -} - -struct RestoreButton_Previews: PreviewProvider { - static var previews: some View { - RestoreButton(showingSubscriptionPaywall: .constant(true)) - } -}
--- a/Simoleon/UI/SubscribeButton.swift Sat Sep 11 16:29:38 2021 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,104 +0,0 @@ -// -// SubscribeButton.swift -// Simoleon -// -// Created by Dennis Concepción Martín on 22/07/2021. -// - -import SwiftUI -import Purchases - -struct SubscribeButton: View { - @Binding var showingSubscriptionPaywall: Bool - @State private var price = "" - @State private var alertTitle = "" - @State private var alertMessage = "" - @State private var showingAlert = false - @State private var showingPrice = false - - var body: some View { - Button(action: purchaseMonthlySubscription) { - RoundedRectangle(cornerRadius: 15) - .frame(height: 60) - .overlay( - VStack { - if showingPrice { - Text("Subscribe for \(price) / month") - .foregroundColor(.white) - .fontWeight(.semibold) - } else { - ProgressView() - } - } - ) - } - .onAppear(perform: fetchMonthlySubscription) - .alert(isPresented: $showingAlert) { - Alert(title: Text(alertTitle), message: Text(alertMessage), dismissButton: .default(Text("Ok"))) - } - } - - private func fetchMonthlySubscription() { - Purchases.shared.offerings { (offerings, error) in - if let product = offerings?.current?.monthly?.product { - price = formatCurrency(product.priceLocale, product.price) - showingPrice = true - } - - if let error = error as NSError? { - alertTitle = error.localizedDescription - alertMessage = error.localizedFailureReason ?? "" - price = "-" - showingPrice = true - showingAlert = true - } - } - } - - private func purchaseMonthlySubscription() { - showingPrice = false - - 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 { - showingPrice = true - showingSubscriptionPaywall = false - } - - if let error = error as NSError? { - alertTitle = error.localizedDescription - alertMessage = error.localizedFailureReason ?? "" - showingPrice = true - showingAlert = true - } - } - - if let error = error as NSError? { - alertTitle = error.localizedDescription - alertMessage = error.localizedFailureReason ?? "" - showingPrice = true - showingAlert = true - } - } - } - } - - private func formatCurrency(_ locale: Locale, _ amount: NSDecimalNumber) -> String { - let formatter = NumberFormatter() - formatter.locale = locale - formatter.numberStyle = .currency - - // It won't fail. Check unit test - let formattedAmount = formatter.string(from: amount as NSNumber)! - - return formattedAmount - } -} - -struct SubscribeButton_Previews: PreviewProvider { - static var previews: some View { - SubscribeButton(showingSubscriptionPaywall: .constant(true)) - } -}
--- a/Simoleon/UI/SubscriptionFeature.swift Sat Sep 11 16:29:38 2021 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,41 +0,0 @@ -// -// SubscriptionFeature.swift -// Simoleon -// -// Created by Dennis Concepción Martín on 26/07/2021. -// - -import SwiftUI - -struct SubscriptionFeature: View { - var symbol: String - var colour: Color - var title: LocalizedStringKey - var description: LocalizedStringKey - - var body: some View { - HStack(alignment:.top) { - Image(systemName: symbol) - .foregroundColor(colour) - .font(.title) - - VStack(alignment: .leading) { - Text(title) - .font(.headline) - - Text(description) - } - } - } -} - -struct SubscriptionFeature_Previews: PreviewProvider { - static var previews: some View { - SubscriptionFeature( - symbol: "star.circle.fill", - colour: Color(.systemYellow), - title: "Favorite Currencies", - description: "Save your favorite currencies to access them quickly." - ) - } -}
--- a/Simoleon/UI/SubscriptionPaywall.swift Sat Sep 11 16:29:38 2021 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,95 +0,0 @@ -// -// SubscriptionPaywall.swift -// Simoleon -// -// Created by Dennis Concepción Martín on 22/07/2021. -// - -import SwiftUI - -struct SubscriptionPaywall: View { - @Binding var showingSubscriptionPaywall: Bool - - var body: some View { - NavigationView { - ScrollView { - VStack(alignment: .leading, spacing: 20) { - HStack { - Spacer() - VStack { - Image("Subscription") - .resizable() - .aspectRatio(contentMode: .fit) - .frame(width: 100, height: 100) - .cornerRadius(25) - .padding(.top) - - Text("Unlock All Access") - .font(.title) - .fontWeight(.semibold) - .fixedSize(horizontal: false, vertical: true) - .multilineTextAlignment(.center) - .padding(.top) - } - - Spacer() - } - - Divider() - - SubscriptionFeature( - symbol: "star.circle.fill", - colour: Color(.systemYellow), - title: "Favorite Forex Pairs", - description: "Save any currency pair to access them quickly." - ) - - SubscriptionFeature( - symbol: "flag.circle.fill", - colour: Color(.systemRed), - title: "Over 170 Currencies", - description: "Access almost every currency of the world." - ) - - SubscriptionFeature( - symbol: "icloud.circle.fill", - colour: Color(.systemBlue), - title: "Everything is Up-to-date", - description: "Your settings and favorite currencies in all your devices." - ) - - SubscriptionFeature( - symbol: "bitcoinsign.circle.fill", - colour: Color(.systemOrange), - title: "Cryptos and Commodities", - description: "Convert currency between cryptos, gold, and silver." - ) - - Spacer() - SubscribeButton(showingSubscriptionPaywall: $showingSubscriptionPaywall) - HStack { - Spacer() - RestoreButton(showingSubscriptionPaywall: $showingSubscriptionPaywall) - Spacer() - } - } - .padding(.bottom) - .padding(.horizontal, 40) - } - .navigationBarTitleDisplayMode(.inline) - .toolbar { - ToolbarItem(placement: .cancellationAction) { - Button(action: { showingSubscriptionPaywall = false }) { - Text("Cancel") - } - } - } - } - } -} - -struct SubscriptionPaywall_Previews: PreviewProvider { - static var previews: some View { - SubscriptionPaywall(showingSubscriptionPaywall: .constant(true)) - } -}