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

Migrate to Async Await #95

Merged
merged 11 commits into from
Jul 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 47 additions & 19 deletions Dialer/Dialer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
CB45381628AB9C6500F3F24C /* MySpaceView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB45381528AB9C6500F3F24C /* MySpaceView.swift */; };
CB544633289C5763009F3457 /* DialerUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB544632289C5763009F3457 /* DialerUITests.swift */; };
CB544635289C5763009F3457 /* DialerUITestsLaunchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB544634289C5763009F3457 /* DialerUITestsLaunchTests.swift */; };
CB56DDC62A4DB1F20007AF55 /* CircleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB56DDC52A4DB1F10007AF55 /* CircleView.swift */; };
CB582AEC29ABEB3100FAD610 /* FirebaseAnalyticsWithoutAdIdSupport in Frameworks */ = {isa = PBXBuildFile; productRef = CB582AEB29ABEB3100FAD610 /* FirebaseAnalyticsWithoutAdIdSupport */; };
CB582AEE29ABEB3100FAD610 /* FirebaseDatabase in Frameworks */ = {isa = PBXBuildFile; productRef = CB582AED29ABEB3100FAD610 /* FirebaseDatabase */; };
CB582AF029ABEB3100FAD610 /* FirebaseDatabaseSwift in Frameworks */ = {isa = PBXBuildFile; productRef = CB582AEF29ABEB3100FAD610 /* FirebaseDatabaseSwift */; };
Expand Down Expand Up @@ -106,6 +107,8 @@
CBE3D8AC290C168400DF5C09 /* DialerQuickCodeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CBE3D8AB290C168400DF5C09 /* DialerQuickCodeTests.swift */; };
CBE3D8AD290C1D5900DF5C09 /* CodePin.swift in Sources */ = {isa = PBXBuildFile; fileRef = CBE3D8A6290C147300DF5C09 /* CodePin.swift */; };
CBE3D8AE290C1D6500DF5C09 /* DialerQuickCode.swift in Sources */ = {isa = PBXBuildFile; fileRef = CB45381128AB8FE000F3F24C /* DialerQuickCode.swift */; };
CBE73C5E2A2C76BF00C7712B /* MockPreview.swift in Sources */ = {isa = PBXBuildFile; fileRef = CBE73C5D2A2C76BF00C7712B /* MockPreview.swift */; };
CBE73C612A2C789C00C7712B /* ContactRowView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CBE73C602A2C789C00C7712B /* ContactRowView.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -195,6 +198,7 @@
CB544630289C5763009F3457 /* DialerUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = DialerUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
CB544632289C5763009F3457 /* DialerUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DialerUITests.swift; sourceTree = "<group>"; };
CB544634289C5763009F3457 /* DialerUITestsLaunchTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DialerUITestsLaunchTests.swift; sourceTree = "<group>"; };
CB56DDC52A4DB1F10007AF55 /* CircleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CircleView.swift; sourceTree = "<group>"; };
CB63E0E029E5838E00E1BF77 /* UserMerchantStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserMerchantStore.swift; sourceTree = "<group>"; };
CB676C68279149B30050B3B9 /* AppReviewing.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppReviewing.swift; sourceTree = "<group>"; };
CB7426BE2A05C05D00BE76DF /* DeviceAccount.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeviceAccount.swift; sourceTree = "<group>"; };
Expand All @@ -216,6 +220,8 @@
CBD6BC7E27BD96D600719DB3 /* WhatsNewView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WhatsNewView.swift; sourceTree = "<group>"; };
CBE3D8A6290C147300DF5C09 /* CodePin.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CodePin.swift; sourceTree = "<group>"; };
CBE3D8AB290C168400DF5C09 /* DialerQuickCodeTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DialerQuickCodeTests.swift; sourceTree = "<group>"; };
CBE73C5D2A2C76BF00C7712B /* MockPreview.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockPreview.swift; sourceTree = "<group>"; };
CBE73C602A2C789C00C7712B /* ContactRowView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContactRowView.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -279,8 +285,6 @@
children = (
8255E68D2693959800657EFB /* CongratulationsView.swift */,
8255E690269395EE00657EFB /* CongratsViewController.swift */,
821C0737264DDFFB00DBD545 /* PinView.swift */,
820C10892766A31400A7CADE /* NumberField.swift */,
82550179263B467A00CB1BC2 /* HistoryRow.swift */,
CBAF13182785A54100D32E1F /* TappeableText.swift */,
CB393A2A28121501009CA95E /* CopiedUSSDLabel.swift */,
Expand Down Expand Up @@ -360,6 +364,7 @@
isa = PBXGroup;
children = (
82D41FBF25D1C1FF00551D22 /* Preview Assets.xcassets */,
CBE73C5D2A2C76BF00C7712B /* MockPreview.swift */,
);
path = "Preview Content";
sourceTree = "<group>";
Expand Down Expand Up @@ -409,21 +414,17 @@
82FBCC05261BB2F400F00FAE /* Views */ = {
isa = PBXGroup;
children = (
820C108B2766A4D400A7CADE /* Main */,
820C108C2766A51000A7CADE /* Details */,
CB18BD4629AE2FEE00A7B45C /* Map */,
82D41FBA25D1C1FE00551D22 /* ContentView.swift */,
CBD6BC7E27BD96D600719DB3 /* WhatsNewView.swift */,
8201D9B3261A3C94007D6892 /* DashBoardView.swift */,
821C0733264DD78F00DBD545 /* NewDialingView.swift */,
CB45380D28AB7CE200F3F24C /* QuickDialingView.swift */,
82E8E63A2676A7B300AB1723 /* ContactsListView.swift */,
828D79D626E1029800439F9A /* SettingsView.swift */,
CBC262BE2784C7D3000B8E0E /* MailView.swift */,
821BE13226FB19F200A3CA02 /* AboutView.swift */,
CBE73C642A2C7A8D00C7712B /* Widget */,
820C108B2766A4D400A7CADE /* Main */,
820C108C2766A51000A7CADE /* Details */,
CBE73C5F2A2C789200C7712B /* Contacts */,
CBE73C632A2C7A7D00C7712B /* Other */,
CB18BD5129AE913800A7B45C /* Merchant */,
CBA429DE29AB85E70041D578 /* Reusable */,
8218DBA72694644600E3C025 /* SubViews */,
CB56DDC52A4DB1F10007AF55 /* CircleView.swift */,
);
path = Views;
sourceTree = "<group>";
Expand All @@ -439,13 +440,6 @@
path = "View Models";
sourceTree = "<group>";
};
CB18BD4629AE2FEE00A7B45C /* Map */ = {
isa = PBXGroup;
children = (
);
path = Map;
sourceTree = "<group>";
};
CB18BD5129AE913800A7B45C /* Merchant */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -489,6 +483,8 @@
isa = PBXGroup;
children = (
CBA429DF29AB85F50041D578 /* SpeakerView.swift */,
821C0737264DDFFB00DBD545 /* PinView.swift */,
820C10892766A31400A7CADE /* NumberField.swift */,
);
path = Reusable;
sourceTree = "<group>";
Expand Down Expand Up @@ -519,6 +515,35 @@
path = "Test Cases";
sourceTree = "<group>";
};
CBE73C5F2A2C789200C7712B /* Contacts */ = {
isa = PBXGroup;
children = (
82E8E63A2676A7B300AB1723 /* ContactsListView.swift */,
CBE73C602A2C789C00C7712B /* ContactRowView.swift */,
);
path = Contacts;
sourceTree = "<group>";
};
CBE73C632A2C7A7D00C7712B /* Other */ = {
isa = PBXGroup;
children = (
821C0733264DD78F00DBD545 /* NewDialingView.swift */,
CB45380D28AB7CE200F3F24C /* QuickDialingView.swift */,
828D79D626E1029800439F9A /* SettingsView.swift */,
CBC262BE2784C7D3000B8E0E /* MailView.swift */,
821BE13226FB19F200A3CA02 /* AboutView.swift */,
CBD6BC7E27BD96D600719DB3 /* WhatsNewView.swift */,
);
path = Other;
sourceTree = "<group>";
};
CBE73C642A2C7A8D00C7712B /* Widget */ = {
isa = PBXGroup;
children = (
);
path = Widget;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -670,6 +695,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
CB56DDC62A4DB1F20007AF55 /* CircleView.swift in Sources */,
8207FA9526776AB600412AE1 /* TransactionModel.swift in Sources */,
CBD6BC7F27BD96D600719DB3 /* WhatsNewView.swift in Sources */,
CB18BD5729AE929F00A7B45C /* MerchantsListView.swift in Sources */,
Expand All @@ -680,6 +706,7 @@
82D41FB725D1C1FE00551D22 /* AppDelegate.swift in Sources */,
820C108A2766A31400A7CADE /* NumberField.swift in Sources */,
821BE13526FB28CB00A3CA02 /* AppVersioning.swift in Sources */,
CBE73C5E2A2C76BF00C7712B /* MockPreview.swift in Sources */,
CB18BD4529AE0C3200A7B45C /* FirebaseRemoteConfig.swift in Sources */,
CB7426BF2A05C05D00BE76DF /* DeviceAccount.swift in Sources */,
82D41FB925D1C1FE00551D22 /* SceneDelegate.swift in Sources */,
Expand Down Expand Up @@ -714,6 +741,7 @@
8255017A263B467A00CB1BC2 /* HistoryRow.swift in Sources */,
CB3B81E229ABC742001FAFF6 /* Merchant.swift in Sources */,
CB18BD4329AE0C0800A7B45C /* ForceUpdateManager.swift in Sources */,
CBE73C612A2C789C00C7712B /* ContactRowView.swift in Sources */,
CB1CC86C29C4524200FF2116 /* FirebaseCRUD.swift in Sources */,
821C0734264DD78F00DBD545 /* NewDialingView.swift in Sources */,
CB676C69279149B30050B3B9 /* AppReviewing.swift in Sources */,
Expand Down
5 changes: 4 additions & 1 deletion Dialer/Dialer/Extensions/Views+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ struct BiometricsAccessibility: ViewModifier {

private func manageBiometrics() {
if allowBiometrics {
biometrics.onStateChanged(onEvaluation)
Task { @MainActor in
let state = await biometrics.onStateChanged()
onEvaluation(state)
}
} else {
onEvaluation(true)
}
Expand Down
4 changes: 0 additions & 4 deletions Dialer/Dialer/Models/ContactModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,4 @@ struct Contact: Identifiable {
mutating func updatePhones(_ numbers: [String]) {
phoneNumbers = numbers
}
static let example = Contact(names: "Kate Bell",
phoneNumbers: ["(555) 564-8583", "(415) 555-3695"])
static let example1 = Contact(names: "John Smith",
phoneNumbers: ["(415) 555-3695"])
}
12 changes: 0 additions & 12 deletions Dialer/Dialer/Models/Merchant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,3 @@ struct Merchant: Codable, Identifiable {
self.createdDate = createdDate
}
}


#if DEBUG
extension Merchant {
static let sample = [
Merchant(Optional("JkSKq9QM4vrBjeZHpg4d"), name: "La gardienne", address: "12 KN 41St, Kigali", code: "004422", ownerId: UUID().uuidString),
Merchant(Optional("eHJNvwKhbdB1sdV19F3P"), name: "Cedrics", address: "", code: "12345", ownerId: UUID().uuidString),
Merchant(Optional("sLcVGrcUfNrNdgq8HJhn"), name: "Emilienne", address: "Gishushu", code: "028508", ownerId: UUID().uuidString),
Merchant(Optional("xW5nAHmPgTmvyohe0XtI"), name: "La gardienne", address: "12 KN 41St, Kigali", code: "004422", ownerId: UUID().uuidString)
]
}
#endif
15 changes: 5 additions & 10 deletions Dialer/Dialer/Models/PurchaseDetailModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,18 @@
import Foundation

struct PurchaseDetailModel: Hashable, Codable {
private var prefixCode: String { "*182*2*1*1*1*" }
var amount: Int = 0
var fullCode: String {
"\(prefixCode)\(amount)*PIN#"
}
var purchaseDate: Date = .now
var fullCode: String { "\(prefixCode)\(amount)*PIN#" }

private var prefixCode: String { "*182*2*1*1*1*" }

func getDialCode(pin: String) -> String {
// 27/03/2023: MTN disabled the ability to dial airtime USSD that includes Momo PIN for an amount greater than 100.
/// `27/03/2023`: MTN disabled the ability to dial airtime USSD that includes Momo PIN for an amount greater than 100.
if amount > 100 || pin.isEmpty {
return "\(prefixCode)\(amount)#"
} else {
return "\(prefixCode)\(amount)*\(pin)#"
}
}
static let example = PurchaseDetailModel()
}

enum USSD {
static let momo = "*182*"
}
5 changes: 1 addition & 4 deletions Dialer/Dialer/Models/RecentDialCode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

struct RecentDialCode: Identifiable, Hashable, Codable {
struct RecentDialCode: Identifiable, Codable {
static func == (lhs: RecentDialCode, rhs: RecentDialCode) -> Bool {
lhs.id == rhs.id
}
Expand All @@ -24,7 +24,4 @@ struct RecentDialCode: Identifiable, Hashable, Codable {
var totalPrice: Int { detail.amount * count }

mutating func increaseCount() { count += 1 }

static let example = RecentDialCode(detail: .example)

}
28 changes: 28 additions & 0 deletions Dialer/Dialer/Preview Content/MockPreview.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// MockPreview.swift
// Dialer
//
// Created by Cédric Bahirwe on 04/06/2023.
//

import Foundation

#if DEBUG
enum MockPreview {
static let contact1 = Contact(names: "Kate Bell",
phoneNumbers: ["(555) 564-8583", "(415) 555-3695"])
static let contact2 = Contact(names: "John Smith",
phoneNumbers: ["(415) 555-3695"])

static let recentDial = RecentDialCode(detail: emptyPurchase)

static let emptyPurchase = PurchaseDetailModel()

static let merchants = [
Merchant(Optional("JkSKq9QM4vrBjeZHpg4d"), name: "La gardienne", address: "12 KN 41St, Kigali", code: "004422", ownerId: UUID().uuidString),
Merchant(Optional("eHJNvwKhbdB1sdV19F3P"), name: "Cedrics", address: "", code: "12345", ownerId: UUID().uuidString),
Merchant(Optional("sLcVGrcUfNrNdgq8HJhn"), name: "Emilienne", address: "Gishushu", code: "028508", ownerId: UUID().uuidString),
Merchant(Optional("xW5nAHmPgTmvyohe0XtI"), name: "La gardienne", address: "12 KN 41St, Kigali", code: "004422", ownerId: UUID().uuidString)
]
}
#endif
14 changes: 8 additions & 6 deletions Dialer/Dialer/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import UIKit
import SwiftUI

@MainActor
class SceneDelegate: UIResponder, UIWindowSceneDelegate {

// List of known shortcut actions.
Expand Down Expand Up @@ -70,14 +71,15 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
and the window scene is already connected.
*/
/// - Tag: PerformAction
func windowScene(_ windowScene: UIWindowScene, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
let handled = handleShortCutItem(shortcutItem: shortcutItem)
completionHandler(handled)
func windowScene(_ windowScene: UIWindowScene, performActionFor shortcutItem: UIApplicationShortcutItem) async -> Bool {
await handleShortCutItem(shortcutItem: shortcutItem)
}

func sceneDidBecomeActive(_ scene: UIScene) {
if savedShortCutItem != nil {
_ = handleShortCutItem(shortcutItem: savedShortCutItem)
Task {
_ = await handleShortCutItem(shortcutItem: savedShortCutItem)
}
}
}

Expand Down Expand Up @@ -126,7 +128,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
DialerNotificationCenter.shared.scheduleMorningNotification()
}

func handleShortCutItem(shortcutItem: UIApplicationShortcutItem) -> Bool {
func handleShortCutItem(shortcutItem: UIApplicationShortcutItem) async -> Bool {
/** In this sample an alert is being shown to indicate that the action has been triggered,
but in real code the functionality for the quick action would be triggered.
*/
Expand All @@ -139,7 +141,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
// Go to that particular code shortcut.
if let codeIdentifier = shortcutItem.userInfo?[SceneDelegate.codeIdentifierInfoKey] as? String {
// Find the code from the userInfo identifier.
if let foundRecentCode = dialingStore.rencentDialCode(codeIdentifier) {
if let foundRecentCode = dialingStore.getRecentDialCode(with: codeIdentifier) {
dialingStore.performRecentDialing(for: foundRecentCode)
}
}
Expand Down
4 changes: 4 additions & 0 deletions Dialer/Dialer/Services/FirebaseTracker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,15 @@ class FirebaseTracker {
// screen_session_length - Name of the Event
// name - Name of the screen parameter
// length - The session time in milliseconds
#if DEBUG
#else
logEvent(name: AppAnalyticsEventType.screenSessionLength,
parameters: [
EventParameterKey.name.rawValue: screen.rawValue,
EventParameterKey.length.rawValue: seconds
])
#endif

/// 4. remove start date from cache
sessions.removeValue(forKey: screen)
}
Expand Down
2 changes: 1 addition & 1 deletion Dialer/Dialer/Utilities/AppReviewing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ enum ReviewHandler {
static func requestReviewManually() {
guard let writeReviewURL = URL(string: DialerlLinks.dialerAppReview)
else { return }
UIApplication.shared.open(writeReviewURL, options: [:], completionHandler: nil)
UIApplication.shared.open(writeReviewURL)
}
}
Loading