Skip to content

Commit

Permalink
gh-716 improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Scherbovich committed Nov 30, 2020
1 parent d5a2105 commit 5583f6f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 20 deletions.
Expand Up @@ -25,15 +25,18 @@ struct RegisterNotificationTokenRequest: JSONRequest {

typealias ResponseType = Response

init(deviceID: UUID,
init(deviceID: String,
safes: [Address],
token: String,
bundle: String,
version: String,
buildNumber: String,
timestamp: String?) throws {

self.uuid = deviceID.uuidString.lowercased()
guard UUID(uuidString: deviceID) != nil else {
throw "'deviceID' should be UUID string"
}
self.uuid = deviceID
self.safes = safes.map { $0.checksummed }
self.cloudMessagingToken = token
self.bundle = bundle
Expand Down Expand Up @@ -78,7 +81,7 @@ struct RegisterNotificationTokenRequest: JSONRequest {
extension SafeTransactionService {

@discardableResult
func register(deviceID: UUID,
func register(deviceID: String,
safes: [Address],
token: String,
bundle: String,
Expand Down
Expand Up @@ -17,9 +17,9 @@ struct UnregisterNotificationTokenRequest: JSONRequest {

typealias ResponseType = EmptyResponse

init(deviceID: UUID, address: Address) {
init(deviceID: String, address: Address) {
self.address = address.checksummed
self.deviceID = deviceID.uuidString.lowercased()
self.deviceID = deviceID
}

struct EmptyResponse: Decodable {
Expand All @@ -28,7 +28,7 @@ struct UnregisterNotificationTokenRequest: JSONRequest {
}

extension SafeTransactionService {
func unregister(deviceID: UUID, address: Address) throws {
func unregister(deviceID: String, address: Address) throws {
try execute(request: UnregisterNotificationTokenRequest(deviceID: deviceID, address: address))
}
}
21 changes: 7 additions & 14 deletions Multisig/UI/App/RemoteNotificationHandler.swift
Expand Up @@ -12,9 +12,8 @@ import UserNotifications
import Firebase

class RemoteNotificationHandler {

@UserDefaultWithDefault(key: "io.gnosis.multisig.deviceID", defaultValue: UUID().uuidString)
private var storedDeviceID: String
@UserDefault(key: "io.gnosis.multisig.deviceID")
private var storedDeviceID: String?

@EnumDefault(key: "io.gnosis.multisig.authorizationStatus")
private var authorizationStatus: UNAuthorizationStatus?
Expand All @@ -24,15 +23,6 @@ class RemoteNotificationHandler {

private var queue = DispatchQueue(label: "RemoteNotificationHandlerQueue")

private var deviceID: UUID {
get {
UUID(uuidString: storedDeviceID)!
}
set {
storedDeviceID = newValue.uuidString
}
}

func setUpMessaging(delegate: MessagingDelegate & UNUserNotificationCenterDelegate) {
logDebug("Setting up notification handling")
Messaging.messaging().delegate = delegate
Expand All @@ -48,6 +38,9 @@ class RemoteNotificationHandler {

func appStarted() {
logDebug("App started")
if storedDeviceID == nil {
storedDeviceID = UUID().uuidString
}
monitorAuthorizationStatus()
}

Expand Down Expand Up @@ -180,7 +173,7 @@ class RemoteNotificationHandler {
}
do {
try App.shared.safeTransactionService
.register(deviceID: self.deviceID,
.register(deviceID: self.storedDeviceID!,
safes: addresses,
token: token,
bundle: appConfig.bundleIdentifier,
Expand All @@ -196,7 +189,7 @@ class RemoteNotificationHandler {
private func unregister(address: Address) {
queue.async { [unowned self] in
do {
try App.shared.safeTransactionService.unregister(deviceID: self.deviceID, address: address)
try App.shared.safeTransactionService.unregister(deviceID: self.storedDeviceID!, address: address)
} catch {
logError("Failed to unregister device", error)
}
Expand Down

0 comments on commit 5583f6f

Please sign in to comment.