Skip to content

Commit

Permalink
feat: remove old Networking
Browse files Browse the repository at this point in the history
  • Loading branch information
bigearsenal committed Jan 26, 2024
1 parent d038e32 commit 2228a4d
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 186 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
@@ -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
params: model
)
)
} 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
params: model
)
)
}
}

This file was deleted.

0 comments on commit 2228a4d

Please sign in to comment.