diff --git a/dydx/dydxPresenters/dydxPresenters/_v4/GlobalWorkers/Workers/dydxTransferSubaccountWorker.swift b/dydx/dydxPresenters/dydxPresenters/_v4/GlobalWorkers/Workers/dydxTransferSubaccountWorker.swift index 255273096..072a5cde7 100644 --- a/dydx/dydxPresenters/dydxPresenters/_v4/GlobalWorkers/Workers/dydxTransferSubaccountWorker.swift +++ b/dydx/dydxPresenters/dydxPresenters/_v4/GlobalWorkers/Workers/dydxTransferSubaccountWorker.swift @@ -21,31 +21,18 @@ final class dydxTransferSubaccountWorker: BaseWorker { super.start() AbacusStateManager.shared.state.accountBalance(of: AbacusStateManager.shared.environment?.usdcTokenInfo?.denom) - .filter { value in - (value ?? 0) > dydxTransferSubaccountWorker.balanceRetainAmount - } .withLatestFrom( - Publishers.CombineLatest( - AbacusStateManager.shared.state.walletState, - AbacusStateManager.shared.state.selectedSubaccount - ) - .map { (walletState: $0, subaccount: $1) } - .eraseToAnyPublisher() + AbacusStateManager.shared.state.walletState ) - .sink { [weak self] balance, state in - let subaccountNumber: Int - if let subaccount = state.subaccount { - subaccountNumber = Int(subaccount.subaccountNumber) - } else { - subaccountNumber = 0 - } - let depositAmount = (balance ?? 0) - dydxTransferSubaccountWorker.balanceRetainAmount + .sink { [weak self] balance, walletState in + guard let balance, balance > dydxTransferSubaccountWorker.balanceRetainAmount else { return } + let depositAmount = balance - dydxTransferSubaccountWorker.balanceRetainAmount let amountString = dydxFormatter.shared.decimalLocaleAgnostic(number: NSNumber(value: depositAmount), digits: dydxTokenConstants.usdcTokenDecimal) if let amountString = amountString { self?.depositToSubaccount(amount: amountString, - subaccount: subaccountNumber, - walletState: state.walletState) + subaccount: AbacusStateManager.shared.selectedSubaccountNumber, + walletState: walletState) } else { Console.shared.log("dydxTransferSubaccountWorker: Invalid amount") } diff --git a/dydx/dydxStateManager/dydxStateManager/AbacusStateManager.swift b/dydx/dydxStateManager/dydxStateManager/AbacusStateManager.swift index 9c19fed7a..5da9b96ef 100644 --- a/dydx/dydxStateManager/dydxStateManager/AbacusStateManager.swift +++ b/dydx/dydxStateManager/dydxStateManager/AbacusStateManager.swift @@ -41,6 +41,10 @@ public final class AbacusStateManager: NSObject { public var environment: V4Environment? { asyncStateManager.environment } + + public var selectedSubaccountNumber: Int { + Int(asyncStateManager.subaccountNumber) + } public var appSetting: AppSetting? { asyncStateManager.appSettings?.ios @@ -134,7 +138,7 @@ public final class AbacusStateManager: NSObject { private var isStarted = false - private lazy var asyncStateManager: AsyncAbacusStateManagerProtocol & AsyncAbacusStateManagerSingletonProtocol = { + private lazy var asyncStateManager: SingletonAsyncAbacusStateManagerProtocol = { UIImplementations.reset(language: nil) let deployment: String