Skip to content

Commit

Permalink
IOS-8174 Send ring refcode (#4014)
Browse files Browse the repository at this point in the history
  • Loading branch information
tureck1y authored Oct 4, 2024
1 parent 8caa2ca commit 59a93f9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@ struct ExpressAPIProviderFactory {
let publicKey = signVerifierPublicKey(expressAPIType: expressAPIType)
let exchangeDataDecoder = CommonExpressExchangeDataDecoder(publicKey: publicKey)

let containsRing = AppSettings.shared.userWalletIdsWithRing.contains(userId)
let refcode = containsRing ? Refcodes.ring.rawValue : nil

let credentials = ExpressAPICredential(
apiKey: apiKey,
userId: userId,
sessionId: AppConstants.sessionId
sessionId: AppConstants.sessionId,
refcode: refcode
)

let deviceInfo = ExpressDeviceInfo(
Expand Down Expand Up @@ -85,3 +89,9 @@ private extension ExpressAPIProviderFactory {
return .unknown.lowercased()
}
}

private extension ExpressAPIProviderFactory {
enum Refcodes: String {
case ring
}
}
7 changes: 5 additions & 2 deletions TangemExpress/Factory/TangemExpressFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public struct TangemExpressFactory {
ExpressAuthorizationPlugin(
apiKey: credential.apiKey,
userId: credential.userId,
sessionId: credential.sessionId
sessionId: credential.sessionId,
refcode: credential.refcode
),
ExpressDeviceInfoPlugin(deviceInfo: deviceInfo),
TangemNetworkLoggerPlugin(configuration: .init(
Expand All @@ -75,11 +76,13 @@ public struct ExpressAPICredential {
public let apiKey: String
public let userId: String
public let sessionId: String
public let refcode: String?

public init(apiKey: String, userId: String, sessionId: String) {
public init(apiKey: String, userId: String, sessionId: String, refcode: String?) {
self.apiKey = apiKey
self.userId = userId
self.sessionId = sessionId
self.refcode = refcode
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ struct ExpressAuthorizationPlugin: PluginType {
let apiKey: String
let userId: String
let sessionId: String
let refcode: String?

func prepare(_ request: URLRequest, target: TargetType) -> URLRequest {
var request = request
Expand All @@ -20,6 +21,10 @@ struct ExpressAuthorizationPlugin: PluginType {
request.headers.add(name: "user-id", value: userId)
request.headers.add(name: "session-id", value: sessionId)

if let refcode {
request.headers.add(name: "refcode", value: refcode)
}

return request
}
}

0 comments on commit 59a93f9

Please sign in to comment.