-
Notifications
You must be signed in to change notification settings - Fork 1
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
TRCL-3689 Add primer screen to prompt the user to enable notification #251
Changes from 8 commits
184cbdd
703f1b4
4bbd466
c104737
8bf7cee
a46598e
ebd0129
f82cfe3
08bc1b3
20a96ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// dydxPushNotifcationToggleWorker.swift | ||
// dydxPresenters | ||
// | ||
// Created by Rui Huang on 13/09/2024. | ||
// | ||
|
||
import Foundation | ||
import Combine | ||
import dydxStateManager | ||
import ParticlesKit | ||
import RoutingKit | ||
import Utilities | ||
|
||
public final class dydxPushNotifcationToggleWorker: BaseWorker { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sp check "notification" |
||
|
||
public override func start() { | ||
super.start() | ||
|
||
// Sync the app settings value to the system notification settings | ||
changeObservation(from: nil, to: NotificationService.shared, keyPath: #keyPath(NotificationHandler.permission)) { _, _, _, _ in | ||
let pushNotificationEnabled = NotificationService.shared?.permission == .authorized | ||
SettingsStore.shared?.setValue(pushNotificationEnabled, forKey: dydxSettingsStoreKey.shouldDisplayInAppNotifications.rawValue) | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,14 +22,14 @@ public enum dydxSettingsStoreKey: String, CaseIterable { | |
case .language: return DataLocalizer.shared?.language | ||
case .v4Theme: return dydxThemeType.classicDark.rawValue | ||
case .directionColorPreference: return "green_is_up" | ||
case .shouldDisplayInAppNotifications: return true | ||
case .shouldDisplayInAppNotifications: return false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. default is false here, but true in alerts worker dydx/dydxPresenters/dydxPresenters/_v4/GlobalWorkers/Workers/dydxAlertsWorker.swift Unsure if the default would ever actually be used in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will revert it back to true.. It's going to be overwritten by the worker anyway. |
||
case .gasToken: return "USDC" | ||
case .hidePredictionMarketsNoticeKey: return false | ||
} | ||
} | ||
} | ||
|
||
extension KeyValueStoreProtocol { | ||
public extension KeyValueStoreProtocol { | ||
|
||
var language: Bool { | ||
SettingsStore.shared?.value(forKey: dydxSettingsStoreKey.language.rawValue) as? Bool | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// | ||
// dydxNotificationPrimerViewPresenter.swift | ||
// dydxPresenters | ||
// | ||
// Created by Rui Huang on 11/09/2024. | ||
// | ||
|
||
import Utilities | ||
import dydxViews | ||
import PlatformParticles | ||
import RoutingKit | ||
import ParticlesKit | ||
import PlatformUI | ||
|
||
public class dydxNotificationPrimerViewBuilder: NSObject, ObjectBuilderProtocol { | ||
public func build<T>() -> T? { | ||
let presenter = dydxNotificationPrimerViewPresenter() | ||
let view = presenter.viewModel?.createView() ?? PlatformViewModel().createView() | ||
return dydxNotificationPrimerViewController(presenter: presenter, view: view, configuration: .default) as? T | ||
} | ||
} | ||
|
||
private class dydxNotificationPrimerViewController: HostingViewController<PlatformView, dydxNotificationPrimerViewModel> { | ||
override public func arrive(to request: RoutingRequest?, animated: Bool) -> Bool { | ||
if request?.path == "/primer/notification" { | ||
return true | ||
} | ||
return false | ||
} | ||
} | ||
|
||
private protocol dydxNotificationPrimerViewPresenterProtocol: HostedViewPresenterProtocol { | ||
var viewModel: dydxNotificationPrimerViewModel? { get } | ||
} | ||
|
||
private class dydxNotificationPrimerViewPresenter: HostedViewPresenter<dydxNotificationPrimerViewModel>, dydxNotificationPrimerViewPresenterProtocol { | ||
override init() { | ||
super.init() | ||
|
||
viewModel = dydxNotificationPrimerViewModel() | ||
viewModel?.ctaAction = { | ||
Router.shared?.navigate(to: RoutingRequest(path: "/action/dismiss", params: nil), animated: true) { _, _ in | ||
let notificationPermission = NotificationService.shared?.authorization | ||
if notificationPermission?.authorization == .notDetermined { | ||
notificationPermission?.promptToAuthorize() | ||
} | ||
Comment on lines
+44
to
+46
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if forget, is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, we should only show the primer when the state is .notDetermined, since it's the only time the app can prompt for the system notification toggle. In other cases, user has to manually toggle through the device's Settings. .ephemeral is only available for app clips. |
||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's this for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So subclass can overwrite with custom behavior.