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

Sync system notification settings; filter out Abacus notifications #258

Merged
merged 16 commits into from
Sep 18, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,8 @@ private class dydxNotificationPrimerViewPresenter: HostedViewPresenter<dydxNotif
}
}
}
viewModel?.cancelAction = {
Router.shared?.navigate(to: RoutingRequest(path: "/action/dismiss", params: nil), animated: true, completion: nil)
}
Comment on lines +49 to +51
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙏

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ private class dydxNotificationsSettingsViewPresenter: SettingsViewPresenter {
viewModel?.headerViewModel = header
}

override func start() {
super.start()

changeObservation(from: nil, to: NotificationService.shared, keyPath: #keyPath(NotificationHandler.permission)) { [weak self] _, _, _, _ in
self?.reloadSettings()
}
}

override func onInputValueChanged(input: FieldInput) {
if input.fieldName == "should_display_in_app_notifications" {
promptToToggleNotification()
Expand All @@ -57,7 +65,10 @@ private class dydxNotificationsSettingsViewPresenter: SettingsViewPresenter {
cancelTitle: DataLocalizer.shared?.localize(path: "APP.GENERAL.CANCEL", params: nil) ?? "Cancel"
)
}
// sync the settings with the system permission
reloadSettings()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would this get called while user is being prompted to turn on notifications? Does this have an effect?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah.. it gets called, which sets the value back... But when the system notification value changes, it will be synced again.

}

private func reloadSettings() {
let pushNotificationEnabled = NotificationService.shared?.permission == .authorized
SettingsStore.shared?.setValue(pushNotificationEnabled, forKey: dydxSettingsStoreKey.shouldDisplayInAppNotifications.rawValue)
loadSettings()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ private extension Abacus.OrderStatus {
var statusIcon: dydxTradeStatusLogoViewModel.StatusIcon? {
switch self {
case .canceled: return .failed
case .canceling, .pending, .partiallyfilled: return .pending
case .canceling, .pending, .partiallyfilled, .partiallycanceled: return .pending
case .filled: return .filled
case .open, .untriggered: return .open
default: return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ public final class AbacusStateManager: NSObject {
}
}

appConfigs.accountConfigs.subaccountConfigs.notifications = [
NotificationProviderType.blockreward, NotificationProviderType.positions
]
appConfigs.onboardingConfigs.alchemyApiKey = CredientialConfig.shared.credential(for: "alchemyApiKey")
appConfigs.staticTyping = dydxBoolFeatureFlag.abacus_static_typing.isEnabled

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public extension MessageView {
let iconImage: UIImage?
switch type {
case .info, .wait, .success:
backgroundColor = UIColor { _ in ThemeColor.SemanticColor.colorPurple.uiColor }
backgroundColor = UIColor { _ in ThemeColor.SemanticColor.layer5.uiColor }
foregroundColor = UIColor { _ in ThemeColor.SemanticColor.colorWhite.uiColor }
iconImage = IconStyle.default.image(theme: .info)
case .warning:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Utilities

public class dydxNotificationPrimerViewModel: PlatformViewModel {
@Published public var ctaAction: (() -> Void)?
@Published public var cancelAction: (() -> Void)?

public init() { }

Expand All @@ -38,6 +39,12 @@ public class dydxNotificationPrimerViewModel: PlatformViewModel {
self?.ctaAction?()
}
.createView(parentStyle: style)

let cancelText = Text(DataLocalizer.localize(path: "APP.GENERAL.CANCEL", params: nil))
PlatformButtonViewModel(content: cancelText.wrappedViewModel, state: .secondary) { [weak self] in
self?.cancelAction?()
}
.createView(parentStyle: style)
}
.padding([.leading, .trailing])
.padding(.top, 40)
Expand Down
27 changes: 17 additions & 10 deletions dydxV4/dydxV4/_Localizer/dydxAbacusDataLocalizer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ public class dydxAbacusDataLocalizer: DataLocalizerProtocol, AbacusLocalizerProt
let language = keyValueStore?.value(forKey: _languageTag) as? String
UIImplementations.reset(language: language)
if let language = language {
setLanguage(language: language) { _ in
setLanguage(language: language) { success in
if !success {
Console.shared.log("dydxAbacusDataLocalizer setLanguage failed")
}
}
}
}
Expand All @@ -49,21 +52,25 @@ public class dydxAbacusDataLocalizer: DataLocalizerProtocol, AbacusLocalizerProt

public func setLanguage(language: String, callback: @escaping (KotlinBoolean, ParsingError?) -> Void) {
if let code = language.components(separatedBy: "-").first {
(UIImplementations.shared?.localizer as? DynamicLocalizer)?.setLanguage(language: code, callback: { [weak self] successful, error in
self?.language = (UIImplementations.shared?.localizer as? DynamicLocalizer)?.language
if successful.boolValue {
if let self = self {
self.keyValueStore?.setValue(code, forKey: self._languageTag)
let localizer = UIImplementations.shared?.localizer as? DynamicLocalizer
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add some logging; no functional change

if let localizer = localizer {
localizer.setLanguage(language: code, callback: { [weak self] successful, error in
self?.language = localizer.language
if successful.boolValue {
if let self = self {
self.keyValueStore?.setValue(code, forKey: self._languageTag)
}
}
}
callback(successful, error)
})
callback(successful, error)
})
} else {
callback(false, nil)
}
} else {
callback(false, nil)
}
}


private func json(params: [String: String]?) -> String? {
if let params = params {
if let data = try? JSONSerialization.data(withJSONObject: params, options: .prettyPrinted) {
Expand Down
Loading