Skip to content

Commit

Permalink
fix cancel orders bug when orders cancellations fail (#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-dydx committed Aug 21, 2024
1 parent 5d42011 commit c265072
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,28 @@ private class dydxCancelPendingIsolatedOrdersViewBuilderPresenter: HostedViewPre
override func start() {
super.start()

let pendingOrdersPublisher = AbacusStateManager.shared.state.selectedSubaccountOrders
.filterMany { [weak self] order in
order.marketId == self?.marketId && order.status == .open
}

Publishers.CombineLatest(
AbacusStateManager.shared.state.configsAndAssetMap,
AbacusStateManager.shared.state.selectedSubaccountOrders
pendingOrdersPublisher
)
.receive(on: RunLoop.main)
.sink { [weak self] configsAndAssetMap, orders in
.sink { [weak self] configsAndAssetMap, pendingOrders in
guard let self = self,
let marketId = self.marketId,
let asset = configsAndAssetMap[marketId]?.asset
else { return }
let pendingOrders = orders.filter { $0.marketId == marketId && $0.status == .open }
self.viewModel?.marketLogoUrl = URL(string: asset.resources?.imageUrl ?? "")
self.viewModel?.marketName = asset.name ?? "--"
self.viewModel?.marketId = asset.id
self.viewModel?.orderCount = pendingOrders.count
self.viewModel?.failureCount = self.viewModel?.failureCount
self.viewModel?.cancelAction = { [weak self] in
self?.tryCancelOrders(orderIds: orders.map(\.id))
self?.tryCancelOrders(orderIds: pendingOrders.map(\.id))
}
}
.store(in: &subscriptions)
Expand Down

0 comments on commit c265072

Please sign in to comment.