Skip to content

Commit

Permalink
fix(buy sell): checks for cancellable orders when a user opens
Browse files Browse the repository at this point in the history
the buy sell modal
  • Loading branch information
blockdylanb committed Apr 12, 2022
1 parent c21bc12 commit 2ccc2c8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Expand Up @@ -1791,7 +1791,19 @@ export default ({ api, coreSagas, networks }: { api: APIType; coreSagas: any; ne
return bankAccount
}

const cleanupCancellableOrders = function* () {
const order = S.getCancelableOrder(yield select())
if (order) {
yield call(api.cancelBSOrder, order)
yield put(A.fetchOrders())
yield take(A.fetchOrdersSuccess.type)
}
}

const showModal = function* ({ payload }: ReturnType<typeof A.showModal>) {
// When opening the buy modal if there are any existing orders that are cancellable, cancel them
yield call(cleanupCancellableOrders)

const { cryptoCurrency, orderType, origin } = payload
let hasPendingOBOrder = false
const latestPendingOrder = S.getBSLatestPendingOrder(yield select())
Expand Down
Expand Up @@ -200,6 +200,11 @@ export const getBSLatestPendingOrder = (state: RootState) =>
return order.state === 'PENDING_CONFIRMATION' || order.state === 'PENDING_DEPOSIT'
})

export const getCancelableOrder = createSelector(getBSOrders, (ordersR) => {
const orders = ordersR.getOrElse([])
return orders.find((order) => order.state === 'PENDING_CONFIRMATION')
})

export const getBuyQuote = (state: RootState) => state.components.buySell.buyQuote

export const getSellQuote = (state: RootState) => state.components.buySell.sellQuote
Expand Down

0 comments on commit 2ccc2c8

Please sign in to comment.