Skip to content

Commit

Permalink
Sync system notification settings; filter out Abacus notifications (#258
Browse files Browse the repository at this point in the history
)

* WIP

* WIP

* Settings

* Lint

* Clean up

* Clean up

* WIP

* WIP

* Update app settings when system settings change

* Revert

* Clean up
  • Loading branch information
ruixhuang authored and mike-dydx committed Oct 16, 2024
1 parent 963736d commit 20be7cc
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 13 deletions.
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)
}
}
}
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()
}

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
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

0 comments on commit 20be7cc

Please sign in to comment.