Skip to content

Commit

Permalink
Merge branch 'refactor/notification-service' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
bigearsenal committed Jan 26, 2024
2 parents d038e32 + 08589cb commit 1eadfe5
Show file tree
Hide file tree
Showing 13 changed files with 60 additions and 184 deletions.
11 changes: 0 additions & 11 deletions p2p_wallet/Common/Services/Networking/Codable+SnakeCase.swift

This file was deleted.

This file was deleted.

15 changes: 0 additions & 15 deletions p2p_wallet/Common/Services/Networking/Dto/JsonRpcResponseDto.swift

This file was deleted.

23 changes: 0 additions & 23 deletions p2p_wallet/Common/Services/Networking/Endpoint.swift

This file was deleted.

29 changes: 0 additions & 29 deletions p2p_wallet/Common/Services/Networking/ErrorModel.swift

This file was deleted.

42 changes: 0 additions & 42 deletions p2p_wallet/Common/Services/Networking/HttpClient.swift

This file was deleted.

9 changes: 0 additions & 9 deletions p2p_wallet/Common/Services/Networking/RequestMethod.swift

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,11 @@ struct DeleteDeviceTokenDto: Encodable {
let clientId: String
let ethPubkey: String?
let type = "device"

enum CodingKeys: String, CodingKey {
case deviceToken = "device_token"
case clientId = "client_id"
case ethPubkey = "eth_pubkey"
case type
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,12 @@ struct DeviceTokenDto: Encodable {
let ethPubkey: String?
let type = "device"
let deviceInfo: DeviceTokenInfo?

enum CodingKeys: String, CodingKey {
case deviceToken = "device_token"
case clientId = "client_id"
case ethPubkey = "eth_pubkey"
case type
case deviceInfo = "device_info"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,10 @@ struct DeviceTokenInfo: Codable {
let osName: String
let osVersion: String
let deviceModel: String

enum CodingKeys: String, CodingKey {
case osName = "os_name"
case osVersion = "os_version"
case deviceModel = "device_model"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,10 @@ struct DeviceTokenResponseDto: Decodable {
let deviceToken: String
let timestamp: String
let clientId: String

enum CodingKeys: String, CodingKey {
case deviceToken = "device_token"
case timestamp
case clientId = "client_id"
}
}
Original file line number Diff line number Diff line change
@@ -1,34 +1,44 @@
import Foundation
import KeyAppNetworking
import Resolver

protocol NotificationRepository {
typealias DeviceTokenResponse = JsonRpcResponseDto<DeviceTokenResponseDto>

func sendDeviceToken(model: DeviceTokenDto) async throws -> DeviceTokenResponse
func removeDeviceToken(model: DeleteDeviceTokenDto) async throws -> DeviceTokenResponse
func sendDeviceToken(model: DeviceTokenDto) async throws -> DeviceTokenResponseDto
func removeDeviceToken(model: DeleteDeviceTokenDto) async throws -> DeviceTokenResponseDto
}

final class NotificationRepositoryImpl: NotificationRepository {
let httpClient = HttpClientImpl()
let httpClient = JSONRPCHTTPClient(urlSession: DebugLoggingURLSession())

private var baseURL: String {
GlobalAppState.shared.pushServiceEndpoint
}

func sendDeviceToken(model: DeviceTokenDto) async throws -> DeviceTokenResponse {
private var header: [String: String] {
[
"Content-Type": "application/json",
"Accept": "application/json",
"CHANNEL_ID": "P2PWALLET_MOBILE",
]
}

func sendDeviceToken(model: DeviceTokenDto) async throws -> DeviceTokenResponseDto {
do {
return try await httpClient.sendRequest(
endpoint: NotifierEndpoint.addDevice(dto: .init(
return try await httpClient.request(
baseURL: baseURL,
header: header,
body: .init(
method: "add_device",
params: [model]
)),
responseModel: DeviceTokenResponse.self
)
)
} catch let error as JsonRpcError {
} catch let error as JSONRPCError<EmptyData> {
if error.code == -32001 {
// Already sent
return .init(
id: "",
result: .init(
deviceToken: model.deviceToken,
timestamp: String(Date().timeIntervalSince1970),
clientId: model.clientId
)
deviceToken: model.deviceToken,
timestamp: String(Date().timeIntervalSince1970),
clientId: model.clientId
)
}
throw error
Expand All @@ -37,13 +47,14 @@ final class NotificationRepositoryImpl: NotificationRepository {
}
}

func removeDeviceToken(model: DeleteDeviceTokenDto) async throws -> DeviceTokenResponse {
try await httpClient.sendRequest(
endpoint: NotifierEndpoint.deleteDevice(dto: .init(
func removeDeviceToken(model: DeleteDeviceTokenDto) async throws -> DeviceTokenResponseDto {
try await httpClient.request(
baseURL: baseURL,
header: header,
body: .init(
method: "delete_device",
params: [model]
)),
responseModel: DeviceTokenResponse.self
)
)
}
}

This file was deleted.

0 comments on commit 1eadfe5

Please sign in to comment.