Skip to content

Commit

Permalink
handle new compliance statuses
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-dydx committed May 3, 2024
1 parent 44bbb8a commit 21f7154
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,61 @@ public final class dydxRestrictionsWorker: BaseWorker {
public override func start() {
super.start()

// used in protocol 4.0
AbacusStateManager.shared.state.restriction
.compactMap { $0 }
.removeDuplicates()
.sink { restriction in
Self.handle(restriction: restriction)
}
.store(in: &subscriptions)

// used in protocol 4.0
AbacusStateManager.shared.state.complianceStatus
.prepend([.firstStrike, .firstStrikeCloseOnly, .closeOnly, .blocked])
.compactMap { $0 }
.removeDuplicates()
.sink { complianceStatus in
Self.handle(complianceStatus: complianceStatus)
}
.store(in: &subscriptions)
}

public static func handle(complianceStatus: ComplianceStatus) {
let title: String?
let body: String?
switch complianceStatus {
case .compliant:
return
case .firstStrike, .firstStrikeCloseOnly, .closeOnly:
// TODO: add DATE & EMAIL
// [MOB-478 : update copy params for new compliance status strings](https://linear.app/dydx/issue/MOB-478/update-copy-params-for-new-compliance-status-strings)
title = DataLocalizer.shared?.localize(
path: "APP.COMPLIANCE.CLOSE_ONLY_TITLE",
params: nil) ?? ""
body = DataLocalizer.shared?.localize(
path: "APP.COMPLIANCE.CLOSE_ONLY_BODY",
params: [
"DATE": "--",
"EMAIL": "--"
]) ?? ""
case .blocked:
// TODO: add DATE & EMAIL
// [MOB-478 : update copy params for new compliance status strings](https://linear.app/dydx/issue/MOB-478/update-copy-params-for-new-compliance-status-strings)
title = DataLocalizer.shared?.localize(
path: "APP.COMPLIANCE.PERMANENTLY_BLOCKED_TITLE",
params: nil) ?? ""
body = DataLocalizer.shared?.localize(
path: "APP.COMPLIANCE.PERMANENTLY_BLOCKED_BODY",
params: [
"EMAIL": "--"
]) ?? ""
default:
assertionFailure("unknown restriction error, please add support for restriction \(complianceStatus)")
return
}
ErrorInfo.shared?.info(title: title, message: body, type: .error, error: nil, time: 30.0)
AbacusStateManager.shared.disconnectAndReplaceCurrentWallet()
}

public static func handle(restriction: Restriction) {
Expand All @@ -40,7 +88,7 @@ public final class dydxRestrictionsWorker: BaseWorker {
case .userRestrictionUnknown:
let title = DataLocalizer.shared?.localize(path: "ERRORS.GENERAL.RATE_LIMIT_REACHED_ERROR_TITLE", params: nil) ?? ""
let body = DataLocalizer.shared?.localize(path: "ERRORS.GENERAL.RATE_LIMIT_REACHED_ERROR_MESSAGE", params: nil) ?? ""
ErrorInfo.shared?.info(title: title, message: body, type: .error, error: nil)
ErrorInfo.shared?.info(title: title, message: body, type: .error, error: nil, time: 10.0)
default:
assertionFailure("unknown restriction error, please add support for restriction \(restriction)")
}
Expand Down
10 changes: 10 additions & 0 deletions dydx/dydxStateManager/dydxStateManager/AbacusState+Combine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public final class AbacusState {
.eraseToAnyPublisher()
}

/// protocol pre v5.0
public var restriction: AnyPublisher<Restriction, Never> {
statePublisher
.compactMap { $0?.restriction?.restriction ?? .noRestriction }
Expand All @@ -108,6 +109,15 @@ public final class AbacusState {
.eraseToAnyPublisher()
}

// protocol v5.0 and up
public var complianceStatus: AnyPublisher<ComplianceStatus, Never> {
statePublisher
.compactMap { $0?.compliance?.status }
.removeDuplicates()
.share()
.eraseToAnyPublisher()
}

public func accountBalance(of tokenDenom: String?) -> AnyPublisher<Double?, Never> {
account
.map { account in
Expand Down

0 comments on commit 21f7154

Please sign in to comment.