summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrej Mihajlov <and@mullvad.net>2022-10-28 10:00:43 +0200
committerAndrej Mihajlov <and@mullvad.net>2022-10-31 13:10:42 +0100
commit14d407d3197aba5f04385dcb4df1f9c7b0595d05 (patch)
treec008431107edd886c0894c149cac7c8eabcc6a37
parent0aa84c5c41a489507560ff2cac3c9ac015b024e8 (diff)
downloadmullvadvpn-14d407d3197aba5f04385dcb4df1f9c7b0595d05.tar.xz
mullvadvpn-14d407d3197aba5f04385dcb4df1f9c7b0595d05.zip
Extract PaymentState and ProductState types
-rw-r--r--ios/MullvadVPN.xcodeproj/project.pbxproj8
-rw-r--r--ios/MullvadVPN/AccountViewController.swift77
-rw-r--r--ios/MullvadVPN/OutOfTimeViewController.swift79
-rw-r--r--ios/MullvadVPN/PaymentState.swift25
-rw-r--r--ios/MullvadVPN/ProductState.swift70
5 files changed, 103 insertions, 156 deletions
diff --git a/ios/MullvadVPN.xcodeproj/project.pbxproj b/ios/MullvadVPN.xcodeproj/project.pbxproj
index dc134a6eb4..e0662fb177 100644
--- a/ios/MullvadVPN.xcodeproj/project.pbxproj
+++ b/ios/MullvadVPN.xcodeproj/project.pbxproj
@@ -135,6 +135,8 @@
585CA70F25F8C44600B47C62 /* UIMetrics.swift in Sources */ = {isa = PBXBuildFile; fileRef = 585CA70E25F8C44600B47C62 /* UIMetrics.swift */; };
585E820327F3285E00939F0E /* SendStoreReceiptOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 585E820227F3285E00939F0E /* SendStoreReceiptOperation.swift */; };
5862805422428EF100F5A6E1 /* TranslucentButtonBlurView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5862805322428EF100F5A6E1 /* TranslucentButtonBlurView.swift */; };
+ 5867771429097BCD006F721F /* PaymentState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5867771329097BCD006F721F /* PaymentState.swift */; };
+ 5867771629097C5B006F721F /* ProductState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5867771529097C5B006F721F /* ProductState.swift */; };
5868585524054096000B8131 /* AppButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5868585424054096000B8131 /* AppButton.swift */; };
5868BD33261DCD2600E6027F /* CustomSplitViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5868BD32261DCD2600E6027F /* CustomSplitViewController.swift */; };
586A950C290125EE007BAF2B /* AlertPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58B9EB122488ED2100095626 /* AlertPresenter.swift */; };
@@ -615,6 +617,8 @@
585E820227F3285E00939F0E /* SendStoreReceiptOperation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SendStoreReceiptOperation.swift; sourceTree = "<group>"; };
5862805322428EF100F5A6E1 /* TranslucentButtonBlurView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TranslucentButtonBlurView.swift; sourceTree = "<group>"; };
5866F39B2243B82D00168AE5 /* MullvadVPN.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = MullvadVPN.entitlements; sourceTree = "<group>"; };
+ 5867771329097BCD006F721F /* PaymentState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaymentState.swift; sourceTree = "<group>"; };
+ 5867771529097C5B006F721F /* ProductState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductState.swift; sourceTree = "<group>"; };
5868585424054096000B8131 /* AppButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppButton.swift; sourceTree = "<group>"; };
5868BD32261DCD2600E6027F /* CustomSplitViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomSplitViewController.swift; sourceTree = "<group>"; };
586A95112901321B007BAF2B /* IPv6Endpoint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IPv6Endpoint.swift; sourceTree = "<group>"; };
@@ -1206,6 +1210,8 @@
58CCA01D2242787B004F3011 /* AccountTextField.swift */,
582AE30F2440A6CA00E6733A /* AccountTokenInput.swift */,
58CCA01722426713004F3011 /* AccountViewController.swift */,
+ 5867771329097BCD006F721F /* PaymentState.swift */,
+ 5867771529097C5B006F721F /* ProductState.swift */,
5868585424054096000B8131 /* AppButton.swift */,
58CE5E63224146200008646E /* AppDelegate.swift */,
5846226F26E229CD0035F7C2 /* StorePaymentManager */,
@@ -2032,6 +2038,7 @@
587B75412668FD7800DEF7E9 /* AccountExpiryNotificationProvider.swift in Sources */,
587988C728A2A01F00E3DF54 /* AccountDataThrottling.swift in Sources */,
5896CEF226972DEB00B0FAE8 /* AccountContentView.swift in Sources */,
+ 5867771429097BCD006F721F /* PaymentState.swift in Sources */,
587D96742886D87C00CD8F1C /* DeviceManagementContentView.swift in Sources */,
589A454C28DDF5E100565204 /* Swizzle.swift in Sources */,
5857F24724C882D700CF6F47 /* SelectLocationNavigationController.swift in Sources */,
@@ -2103,6 +2110,7 @@
5868585524054096000B8131 /* AppButton.swift in Sources */,
58E25F812837BBBB002CFB2C /* SceneDelegate.swift in Sources */,
585E820327F3285E00939F0E /* SendStoreReceiptOperation.swift in Sources */,
+ 5867771629097C5B006F721F /* ProductState.swift in Sources */,
584B17AB27637DE40057F3B8 /* ReconnectTunnelOperation.swift in Sources */,
5820676426E771DB00655B05 /* TunnelManagerErrors.swift in Sources */,
585B4B8726D9098900555C4C /* TunnelStatusNotificationProvider.swift in Sources */,
diff --git a/ios/MullvadVPN/AccountViewController.swift b/ios/MullvadVPN/AccountViewController.swift
index 11862d8f9a..83ae252191 100644
--- a/ios/MullvadVPN/AccountViewController.swift
+++ b/ios/MullvadVPN/AccountViewController.swift
@@ -412,80 +412,3 @@ class AccountViewController: UIViewController, StorePaymentObserver, TunnelObser
}
}
}
-
-private extension AccountViewController {
- enum PaymentState: Equatable {
- case none
- case makingPayment(SKPayment)
- case restoringPurchases
-
- var allowsViewInteraction: Bool {
- switch self {
- case .none:
- return true
- case .restoringPurchases, .makingPayment:
- return false
- }
- }
- }
-
- enum ProductState {
- case none
- case fetching(StoreSubscription)
- case received(SKProduct)
- case failed
- case cannotMakePurchases
-
- var isFetching: Bool {
- if case .fetching = self {
- return true
- }
- return false
- }
-
- var isReceived: Bool {
- if case .received = self {
- return true
- }
- return false
- }
-
- var purchaseButtonTitle: String? {
- switch self {
- case .none:
- return nil
-
- case let .fetching(subscription):
- return subscription.localizedTitle
-
- case let .received(product):
- let localizedTitle = product.customLocalizedTitle ?? ""
- let localizedPrice = product.localizedPrice ?? ""
-
- let format = NSLocalizedString(
- "PURCHASE_BUTTON_TITLE_FORMAT",
- tableName: "Account",
- value: "%1$@ (%2$@)",
- comment: ""
- )
- return String(format: format, localizedTitle, localizedPrice)
-
- case .failed:
- return NSLocalizedString(
- "PURCHASE_BUTTON_CANNOT_CONNECT_TO_APPSTORE_LABEL",
- tableName: "Account",
- value: "Cannot connect to AppStore",
- comment: ""
- )
-
- case .cannotMakePurchases:
- return NSLocalizedString(
- "PURCHASE_BUTTON_PAYMENTS_RESTRICTED_LABEL",
- tableName: "Account",
- value: "Payments restricted",
- comment: ""
- )
- }
- }
- }
-}
diff --git a/ios/MullvadVPN/OutOfTimeViewController.swift b/ios/MullvadVPN/OutOfTimeViewController.swift
index d55490ccc2..0a037bf281 100644
--- a/ios/MullvadVPN/OutOfTimeViewController.swift
+++ b/ios/MullvadVPN/OutOfTimeViewController.swift
@@ -363,82 +363,3 @@ extension OutOfTimeViewController: RootContainment {
false
}
}
-
-// MARK: - UI Restrictions
-
-private extension OutOfTimeViewController {
- enum PaymentState: Equatable {
- case none
- case makingPayment(SKPayment)
- case restoringPurchases
-
- var allowsViewInteraction: Bool {
- switch self {
- case .none:
- return true
- case .restoringPurchases, .makingPayment:
- return false
- }
- }
- }
-
- enum ProductState {
- case none
- case fetching(StoreSubscription)
- case received(SKProduct)
- case failed
- case cannotMakePurchases
-
- var isFetching: Bool {
- if case .fetching = self {
- return true
- }
- return false
- }
-
- var isReceived: Bool {
- if case .received = self {
- return true
- }
- return false
- }
-
- var purchaseButtonTitle: String? {
- switch self {
- case .none:
- return nil
-
- case let .fetching(subscription):
- return subscription.localizedTitle
-
- case let .received(product):
- let localizedTitle = product.customLocalizedTitle ?? ""
- let localizedPrice = product.localizedPrice ?? ""
-
- let format = NSLocalizedString(
- "PURCHASE_BUTTON_TITLE_FORMAT",
- tableName: "OutOfTime",
- value: "%1$@ (%2$@)",
- comment: ""
- )
- return String(format: format, localizedTitle, localizedPrice)
-
- case .failed:
- return NSLocalizedString(
- "PURCHASE_BUTTON_CANNOT_CONNECT_TO_APPSTORE_LABEL",
- tableName: "OutOfTime",
- value: "Cannot connect to AppStore",
- comment: ""
- )
-
- case .cannotMakePurchases:
- return NSLocalizedString(
- "PURCHASE_BUTTON_PAYMENTS_RESTRICTED_LABEL",
- tableName: "OutOfTime",
- value: "Payments restricted",
- comment: ""
- )
- }
- }
- }
-}
diff --git a/ios/MullvadVPN/PaymentState.swift b/ios/MullvadVPN/PaymentState.swift
new file mode 100644
index 0000000000..b50263f831
--- /dev/null
+++ b/ios/MullvadVPN/PaymentState.swift
@@ -0,0 +1,25 @@
+//
+// PaymentState.swift
+// MullvadVPN
+//
+// Created by pronebird on 26/10/2022.
+// Copyright © 2022 Mullvad VPN AB. All rights reserved.
+//
+
+import Foundation
+import StoreKit
+
+enum PaymentState: Equatable {
+ case none
+ case makingPayment(SKPayment)
+ case restoringPurchases
+
+ var allowsViewInteraction: Bool {
+ switch self {
+ case .none:
+ return true
+ case .restoringPurchases, .makingPayment:
+ return false
+ }
+ }
+}
diff --git a/ios/MullvadVPN/ProductState.swift b/ios/MullvadVPN/ProductState.swift
new file mode 100644
index 0000000000..72287e0803
--- /dev/null
+++ b/ios/MullvadVPN/ProductState.swift
@@ -0,0 +1,70 @@
+//
+// ProductState.swift
+// MullvadVPN
+//
+// Created by pronebird on 26/10/2022.
+// Copyright © 2022 Mullvad VPN AB. All rights reserved.
+//
+
+import Foundation
+import StoreKit
+
+enum ProductState {
+ case none
+ case fetching(AppStoreSubscription)
+ case received(SKProduct)
+ case failed
+ case cannotMakePurchases
+
+ var isFetching: Bool {
+ if case .fetching = self {
+ return true
+ }
+ return false
+ }
+
+ var isReceived: Bool {
+ if case .received = self {
+ return true
+ }
+ return false
+ }
+
+ var purchaseButtonTitle: String? {
+ switch self {
+ case .none:
+ return nil
+
+ case let .fetching(subscription):
+ return subscription.localizedTitle
+
+ case let .received(product):
+ let localizedTitle = product.customLocalizedTitle ?? ""
+ let localizedPrice = product.localizedPrice ?? ""
+
+ let format = NSLocalizedString(
+ "PURCHASE_BUTTON_TITLE_FORMAT",
+ tableName: "Account",
+ value: "%1$@ (%2$@)",
+ comment: ""
+ )
+ return String(format: format, localizedTitle, localizedPrice)
+
+ case .failed:
+ return NSLocalizedString(
+ "PURCHASE_BUTTON_CANNOT_CONNECT_TO_APPSTORE_LABEL",
+ tableName: "Account",
+ value: "Cannot connect to AppStore",
+ comment: ""
+ )
+
+ case .cannotMakePurchases:
+ return NSLocalizedString(
+ "PURCHASE_BUTTON_PAYMENTS_RESTRICTED_LABEL",
+ tableName: "Account",
+ value: "Payments restricted",
+ comment: ""
+ )
+ }
+ }
+}