Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IOS-8174 Send ring refcode #4014

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}
Loading