Mercurial > public > simoleon
changeset 50:7a6a7c677851
Handle errors with alerts
author | Dennis Concepción Martín <dennisconcepcionmartin@gmail.com> |
---|---|
date | Mon, 26 Jul 2021 21:52:15 +0100 |
parents | 67e76ce661a1 |
children | a86181d40c38 |
files | Simoleon.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate Simoleon/ContentView.swift Simoleon/Conversion.swift Simoleon/Helpers/CurrencyRow.swift Simoleon/Helpers/CurrencySelector.swift Simoleon/Helpers/FavouriteButton.swift Simoleon/Settings.swift |
diffstat | 7 files changed, 31 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
Binary file Simoleon.xcodeproj/project.xcworkspace/xcuserdata/dennis.xcuserdatad/UserInterfaceState.xcuserstate has changed
--- a/Simoleon/ContentView.swift Mon Jul 26 21:22:54 2021 +0100 +++ b/Simoleon/ContentView.swift Mon Jul 26 21:52:15 2021 +0100 @@ -8,10 +8,11 @@ import SwiftUI struct ContentView: View { - @State private var tab: Tab = .convert @Environment(\.managedObjectContext) private var viewContext @FetchRequest(sortDescriptors: []) private var defaultCurrency: FetchedResults<DefaultCurrency> + @State private var tab: Tab = .convert + var body: some View { TabView(selection: $tab) { Conversion(currencyPair: defaultCurrency.first?.pair ?? "USD/GBP")
--- a/Simoleon/Conversion.swift Mon Jul 26 21:22:54 2021 +0100 +++ b/Simoleon/Conversion.swift Mon Jul 26 21:52:15 2021 +0100 @@ -10,6 +10,7 @@ struct Conversion: View { var showNavigationView: Bool? + @State var currencyPair: String @State private var amountToConvert = "1000" @State private var price: Double = 1.00
--- a/Simoleon/Helpers/CurrencyRow.swift Mon Jul 26 21:22:54 2021 +0100 +++ b/Simoleon/Helpers/CurrencyRow.swift Mon Jul 26 21:52:15 2021 +0100 @@ -9,6 +9,7 @@ struct CurrencyRow: View { var currencyPair: String + let currencyMetadata: [String: CurrencyMetadataModel] = parseJson("CurrencyMetadata.json") var body: some View {
--- a/Simoleon/Helpers/CurrencySelector.swift Mon Jul 26 21:22:54 2021 +0100 +++ b/Simoleon/Helpers/CurrencySelector.swift Mon Jul 26 21:52:15 2021 +0100 @@ -14,6 +14,9 @@ @State private var searchCurrency = "" @State private var showingSubscriptionPaywall = false + @State private var alertTitle = "" + @State private var alertMessage = "" + @State private var showingAlert = false var body: some View { NavigationView { @@ -47,6 +50,9 @@ } } } + .alert(isPresented: $showingAlert) { + Alert(title: Text(alertTitle), message: Text(alertMessage), dismissButton: .default(Text("Ok"))) + } } /* @@ -86,6 +92,12 @@ } else { showingSubscriptionPaywall = true } + + if let error = error as NSError? { + alertTitle = error.localizedDescription + alertMessage = error.localizedFailureReason ?? "" + showingAlert = true + } } #endif }
--- a/Simoleon/Helpers/FavouriteButton.swift Mon Jul 26 21:22:54 2021 +0100 +++ b/Simoleon/Helpers/FavouriteButton.swift Mon Jul 26 21:52:15 2021 +0100 @@ -10,10 +10,11 @@ struct FavouriteButton: View { var currencyPair: String - @State private var starSymbol = "star" @Environment(\.managedObjectContext) private var viewContext @FetchRequest(sortDescriptors: []) private var favourite: FetchedResults<Favourite> + @State private var starSymbol = "star" + var body: some View { let favouriteCurrencyPairs = favourite.map { $0.currencyPair } Button(action: { favouriteAction(favouriteCurrencyPairs) }) {
--- a/Simoleon/Settings.swift Mon Jul 26 21:22:54 2021 +0100 +++ b/Simoleon/Settings.swift Mon Jul 26 21:52:15 2021 +0100 @@ -15,6 +15,9 @@ @State private var selectedDefaultCurrency = "" @State private var showingSubscriptionPaywall = false @State private var entitlementIsActive = false + @State private var alertTitle = "" + @State private var alertMessage = "" + @State private var showingAlert = false let currencyPairs: [String] = parseJson("CurrencyPairs.json") @@ -80,6 +83,9 @@ } } } + .alert(isPresented: $showingAlert) { + Alert(title: Text(alertTitle), message: Text(alertMessage), dismissButton: .default(Text("Ok"))) + } .onAppear { checkEntitlement() /* @@ -130,6 +136,7 @@ // We're in simulator entitlementIsActive = true #else + // We're in physical device Purchases.shared.purchaserInfo { (purchaserInfo, error) in if purchaserInfo?.entitlements["all"]?.isActive == true { entitlementIsActive = true @@ -138,6 +145,12 @@ entitlementIsActive = false print("Entitlement is NOT active") } + + if let error = error as NSError? { + alertTitle = error.localizedDescription + alertMessage = error.localizedFailureReason ?? "" + showingAlert = true + } } #endif }